gdiplus: Fix a GdipSetPageScale return status.
[wine.git] / dlls / gdiplus / tests / graphics.c
blob5f502b72593f85534bdc74952f5da38b01bd1b34
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 "winspool.h"
27 #include "wine/test.h"
29 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
30 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
31 #define expectf(expected, got) expectf_((expected), (got), 0.001)
33 static GpStatus (WINAPI *pGdipGraphicsSetAbort)(GpGraphics*,GdiplusAbort*);
35 static const REAL mm_per_inch = 25.4;
36 static const REAL point_per_inch = 72.0;
37 static HWND hwnd;
39 static void set_rect_empty(RectF *rc)
41 rc->X = 0.0;
42 rc->Y = 0.0;
43 rc->Width = 0.0;
44 rc->Height = 0.0;
47 /* converts a given unit to its value in pixels */
48 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
50 switch (unit)
52 case UnitPixel:
53 case UnitDisplay:
54 return units;
55 case UnitPoint:
56 return units * dpi / point_per_inch;
57 case UnitInch:
58 return units * dpi;
59 case UnitDocument:
60 return units * dpi / 300.0; /* Per MSDN */
61 case UnitMillimeter:
62 return units * dpi / mm_per_inch;
63 default:
64 ok(0, "Unsupported unit: %d\n", unit);
65 return 0;
69 /* converts value in pixels to a given unit */
70 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
72 switch (unit)
74 case UnitPixel:
75 case UnitDisplay:
76 return pixels;
77 case UnitPoint:
78 return pixels * point_per_inch / dpi;
79 case UnitInch:
80 return pixels / dpi;
81 case UnitDocument:
82 return pixels * 300.0 / dpi;
83 case UnitMillimeter:
84 return pixels * mm_per_inch / dpi;
85 default:
86 ok(0, "Unsupported unit: %d\n", unit);
87 return 0;
91 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
93 REAL pixels = units_to_pixels(1.0, from, dpi);
94 return pixels_to_units(pixels, to, dpi);
97 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale, GpImage **image)
99 GpStatus status;
100 union
102 GpBitmap *bitmap;
103 GpImage *image;
104 } u;
105 GpGraphics *graphics = NULL;
106 REAL res;
108 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
109 expect(Ok, status);
111 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
112 expect(Ok, status);
113 status = GdipGetImageHorizontalResolution(u.image, &res);
114 expect(Ok, status);
115 expectf(res_x, res);
116 status = GdipGetImageVerticalResolution(u.image, &res);
117 expect(Ok, status);
118 expectf(res_y, res);
120 status = GdipGetImageGraphicsContext(u.image, &graphics);
121 expect(Ok, status);
123 *image = u.image;
125 status = GdipGetDpiX(graphics, &res);
126 expect(Ok, status);
127 expectf(res_x, res);
128 status = GdipGetDpiY(graphics, &res);
129 expect(Ok, status);
130 expectf(res_y, res);
132 status = GdipSetPageUnit(graphics, unit);
133 expect(Ok, status);
134 status = GdipSetPageScale(graphics, scale);
135 expect(Ok, status);
137 return graphics;
140 static void test_constructor_destructor(void)
142 GpStatus stat;
143 GpGraphics *graphics = NULL;
144 HDC hdc = GetDC( hwnd );
146 stat = GdipCreateFromHDC(NULL, &graphics);
147 expect(OutOfMemory, stat);
148 stat = GdipDeleteGraphics(graphics);
149 expect(InvalidParameter, stat);
151 stat = GdipCreateFromHDC(hdc, &graphics);
152 expect(Ok, stat);
153 stat = GdipDeleteGraphics(graphics);
154 expect(Ok, stat);
156 stat = GdipCreateFromHWND(NULL, &graphics);
157 expect(Ok, stat);
158 stat = GdipDeleteGraphics(graphics);
159 expect(Ok, stat);
161 stat = GdipCreateFromHWNDICM(NULL, &graphics);
162 expect(Ok, stat);
163 stat = GdipDeleteGraphics(graphics);
164 expect(Ok, stat);
166 stat = GdipDeleteGraphics(NULL);
167 expect(InvalidParameter, stat);
168 ReleaseDC(hwnd, hdc);
171 typedef struct node{
172 GraphicsState data;
173 struct node * next;
174 } node;
176 /* Linked list prepend function. */
177 static void log_state(GraphicsState data, node ** log)
179 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
181 new_entry->data = data;
182 new_entry->next = *log;
183 *log = new_entry;
186 /* Checks if there are duplicates in the list, and frees it. */
187 static void check_no_duplicates(node * log)
189 INT dups = 0;
190 node * temp = NULL;
191 node * temp2 = NULL;
192 node * orig = log;
194 if(!log)
195 goto end;
198 temp = log;
199 while((temp = temp->next)){
200 if(log->data == temp->data){
201 dups++;
202 break;
204 if(dups > 0)
205 break;
207 }while((log = log->next));
209 temp = orig;
211 temp2 = temp->next;
212 HeapFree(GetProcessHeap(), 0, temp);
213 temp = temp2;
214 }while(temp);
216 end:
217 expect(0, dups);
220 static void test_save_restore(void)
222 GpStatus stat;
223 GraphicsState state_a, state_b, state_c;
224 InterpolationMode mode;
225 GpGraphics *graphics1, *graphics2;
226 node * state_log = NULL;
227 HDC hdc = GetDC( hwnd );
228 state_a = state_b = state_c = 0xdeadbeef;
230 /* Invalid saving. */
231 GdipCreateFromHDC(hdc, &graphics1);
232 stat = GdipSaveGraphics(graphics1, NULL);
233 expect(InvalidParameter, stat);
234 stat = GdipSaveGraphics(NULL, &state_a);
235 expect(InvalidParameter, stat);
236 GdipDeleteGraphics(graphics1);
238 log_state(state_a, &state_log);
240 /* Basic save/restore. */
241 GdipCreateFromHDC(hdc, &graphics1);
242 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
243 stat = GdipSaveGraphics(graphics1, &state_a);
244 expect(Ok, stat);
245 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
246 stat = GdipRestoreGraphics(graphics1, state_a);
247 expect(Ok, stat);
248 GdipGetInterpolationMode(graphics1, &mode);
249 expect(InterpolationModeBilinear, mode);
250 GdipDeleteGraphics(graphics1);
252 log_state(state_a, &state_log);
254 /* Restoring garbage doesn't affect saves. */
255 GdipCreateFromHDC(hdc, &graphics1);
256 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
257 GdipSaveGraphics(graphics1, &state_a);
258 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
259 GdipSaveGraphics(graphics1, &state_b);
260 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
261 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
262 expect(Ok, stat);
263 GdipRestoreGraphics(graphics1, state_b);
264 GdipGetInterpolationMode(graphics1, &mode);
265 expect(InterpolationModeBicubic, mode);
266 GdipRestoreGraphics(graphics1, state_a);
267 GdipGetInterpolationMode(graphics1, &mode);
268 expect(InterpolationModeBilinear, mode);
269 GdipDeleteGraphics(graphics1);
271 log_state(state_a, &state_log);
272 log_state(state_b, &state_log);
274 /* Restoring older state invalidates newer saves (but not older saves). */
275 GdipCreateFromHDC(hdc, &graphics1);
276 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
277 GdipSaveGraphics(graphics1, &state_a);
278 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
279 GdipSaveGraphics(graphics1, &state_b);
280 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
281 GdipSaveGraphics(graphics1, &state_c);
282 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
283 GdipRestoreGraphics(graphics1, state_b);
284 GdipGetInterpolationMode(graphics1, &mode);
285 expect(InterpolationModeBicubic, mode);
286 GdipRestoreGraphics(graphics1, state_c);
287 GdipGetInterpolationMode(graphics1, &mode);
288 expect(InterpolationModeBicubic, mode);
289 GdipRestoreGraphics(graphics1, state_a);
290 GdipGetInterpolationMode(graphics1, &mode);
291 expect(InterpolationModeBilinear, mode);
292 GdipDeleteGraphics(graphics1);
294 log_state(state_a, &state_log);
295 log_state(state_b, &state_log);
296 log_state(state_c, &state_log);
298 /* Restoring older save from one graphics object does not invalidate
299 * newer save from other graphics object. */
300 GdipCreateFromHDC(hdc, &graphics1);
301 GdipCreateFromHDC(hdc, &graphics2);
302 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
303 GdipSaveGraphics(graphics1, &state_a);
304 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
305 GdipSaveGraphics(graphics2, &state_b);
306 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
307 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
308 GdipRestoreGraphics(graphics1, state_a);
309 GdipGetInterpolationMode(graphics1, &mode);
310 expect(InterpolationModeBilinear, mode);
311 GdipRestoreGraphics(graphics2, state_b);
312 GdipGetInterpolationMode(graphics2, &mode);
313 expect(InterpolationModeBicubic, mode);
314 GdipDeleteGraphics(graphics1);
315 GdipDeleteGraphics(graphics2);
317 /* You can't restore a state to a graphics object that didn't save it. */
318 GdipCreateFromHDC(hdc, &graphics1);
319 GdipCreateFromHDC(hdc, &graphics2);
320 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
321 GdipSaveGraphics(graphics1, &state_a);
322 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
323 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
324 GdipRestoreGraphics(graphics2, state_a);
325 GdipGetInterpolationMode(graphics2, &mode);
326 expect(InterpolationModeNearestNeighbor, mode);
327 GdipDeleteGraphics(graphics1);
328 GdipDeleteGraphics(graphics2);
330 log_state(state_a, &state_log);
332 /* A state created by SaveGraphics cannot be restored with EndContainer. */
333 GdipCreateFromHDC(hdc, &graphics1);
334 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
335 stat = GdipSaveGraphics(graphics1, &state_a);
336 expect(Ok, stat);
337 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
338 stat = GdipEndContainer(graphics1, state_a);
339 expect(Ok, stat);
340 GdipGetInterpolationMode(graphics1, &mode);
341 expect(InterpolationModeBicubic, mode);
342 stat = GdipRestoreGraphics(graphics1, state_a);
343 expect(Ok, stat);
344 GdipGetInterpolationMode(graphics1, &mode);
345 expect(InterpolationModeBilinear, mode);
346 GdipDeleteGraphics(graphics1);
348 log_state(state_a, &state_log);
350 /* A state created by BeginContainer cannot be restored with RestoreGraphics. */
351 stat = GdipCreateFromHDC(hdc, &graphics1);
352 expect(Ok, stat);
353 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
354 stat = GdipBeginContainer2(graphics1, &state_a);
355 expect(Ok, stat);
356 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
357 stat = GdipRestoreGraphics(graphics1, state_a);
358 expect(Ok, stat);
359 GdipGetInterpolationMode(graphics1, &mode);
360 expect(InterpolationModeBicubic, mode);
361 stat = GdipEndContainer(graphics1, state_a);
362 expect(Ok, stat);
363 GdipGetInterpolationMode(graphics1, &mode);
364 expect(InterpolationModeBilinear, mode);
365 GdipDeleteGraphics(graphics1);
367 log_state(state_a, &state_log);
369 /* BeginContainer and SaveGraphics use the same stack. */
370 stat = GdipCreateFromHDC(hdc, &graphics1);
371 expect(Ok, stat);
372 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
373 stat = GdipBeginContainer2(graphics1, &state_a);
374 expect(Ok, stat);
375 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
376 stat = GdipSaveGraphics(graphics1, &state_b);
377 expect(Ok, stat);
378 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
379 stat = GdipEndContainer(graphics1, state_a);
380 expect(Ok, stat);
381 GdipGetInterpolationMode(graphics1, &mode);
382 expect(InterpolationModeBilinear, mode);
383 stat = GdipRestoreGraphics(graphics1, state_b);
384 expect(Ok, stat);
385 GdipGetInterpolationMode(graphics1, &mode);
386 expect(InterpolationModeBilinear, mode);
387 GdipDeleteGraphics(graphics1);
389 log_state(state_a, &state_log);
390 log_state(state_b, &state_log);
392 /* The same state value should never be returned twice. */
393 todo_wine
394 check_no_duplicates(state_log);
396 ReleaseDC(hwnd, hdc);
399 static void test_GdipFillClosedCurve2(void)
401 GpStatus status;
402 GpGraphics *graphics = NULL;
403 GpSolidFill *brush = NULL;
404 HDC hdc = GetDC( hwnd );
405 GpPointF points[3];
407 points[0].X = 0;
408 points[0].Y = 0;
410 points[1].X = 40;
411 points[1].Y = 20;
413 points[2].X = 10;
414 points[2].Y = 40;
416 /* make a graphics object and brush object */
417 ok(hdc != NULL, "Expected HDC to be initialized\n");
419 status = GdipCreateFromHDC(hdc, &graphics);
420 expect(Ok, status);
421 ok(graphics != NULL, "Expected graphics to be initialized\n");
423 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
425 /* InvalidParameter cases: null graphics, null brush, null points */
426 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
427 expect(InvalidParameter, status);
429 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
430 expect(InvalidParameter, status);
432 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
433 expect(InvalidParameter, status);
435 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
436 expect(InvalidParameter, status);
438 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
439 expect(InvalidParameter, status);
441 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
442 expect(InvalidParameter, status);
444 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
445 expect(InvalidParameter, status);
447 /* InvalidParameter cases: invalid count */
448 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
449 expect(InvalidParameter, status);
451 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
452 expect(InvalidParameter, status);
454 /* Valid test cases */
455 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
456 expect(Ok, status);
458 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
459 expect(Ok, status);
461 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
462 expect(Ok, status);
464 GdipDeleteGraphics(graphics);
465 GdipDeleteBrush((GpBrush*)brush);
467 ReleaseDC(hwnd, hdc);
470 static void test_GdipFillClosedCurve2I(void)
472 GpStatus status;
473 GpGraphics *graphics = NULL;
474 GpSolidFill *brush = NULL;
475 HDC hdc = GetDC( hwnd );
476 GpPoint points[3];
478 points[0].X = 0;
479 points[0].Y = 0;
481 points[1].X = 40;
482 points[1].Y = 20;
484 points[2].X = 10;
485 points[2].Y = 40;
487 /* make a graphics object and brush object */
488 ok(hdc != NULL, "Expected HDC to be initialized\n");
490 status = GdipCreateFromHDC(hdc, &graphics);
491 expect(Ok, status);
492 ok(graphics != NULL, "Expected graphics to be initialized\n");
494 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
496 /* InvalidParameter cases: null graphics, null brush */
497 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
498 when points == NULL, so don't test this condition */
499 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
500 expect(InvalidParameter, status);
502 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
503 expect(InvalidParameter, status);
505 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
506 expect(InvalidParameter, status);
508 /* InvalidParameter cases: invalid count */
509 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
510 expect(InvalidParameter, status);
512 /* OutOfMemory cases: large (unsigned) int */
513 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
514 expect(OutOfMemory, status);
516 /* Valid test cases */
517 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
518 expect(Ok, status);
520 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
521 expect(Ok, status);
523 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
524 expect(Ok, status);
526 GdipDeleteGraphics(graphics);
527 GdipDeleteBrush((GpBrush*)brush);
529 ReleaseDC(hwnd, hdc);
532 static void test_GdipDrawArc(void)
534 GpStatus status;
535 GpGraphics *graphics = NULL;
536 GpPen *pen = NULL;
537 HDC hdc = GetDC( hwnd );
539 /* make a graphics object and pen object */
540 ok(hdc != NULL, "Expected HDC to be initialized\n");
542 status = GdipCreateFromHDC(hdc, &graphics);
543 expect(Ok, status);
544 ok(graphics != NULL, "Expected graphics to be initialized\n");
546 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
547 expect(Ok, status);
548 ok(pen != NULL, "Expected pen to be initialized\n");
550 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
551 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
552 expect(InvalidParameter, status);
554 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
555 expect(InvalidParameter, status);
557 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
558 expect(InvalidParameter, status);
560 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
561 expect(InvalidParameter, status);
563 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
564 expect(InvalidParameter, status);
566 /* successful case */
567 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
568 expect(Ok, status);
570 GdipDeletePen(pen);
571 GdipDeleteGraphics(graphics);
573 ReleaseDC(hwnd, hdc);
576 static void test_GdipDrawArcI(void)
578 GpStatus status;
579 GpGraphics *graphics = NULL;
580 GpPen *pen = NULL;
581 HDC hdc = GetDC( hwnd );
583 /* make a graphics object and pen object */
584 ok(hdc != NULL, "Expected HDC to be initialized\n");
586 status = GdipCreateFromHDC(hdc, &graphics);
587 expect(Ok, status);
588 ok(graphics != NULL, "Expected graphics to be initialized\n");
590 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
591 expect(Ok, status);
592 ok(pen != NULL, "Expected pen to be initialized\n");
594 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
595 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
596 expect(InvalidParameter, status);
598 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
599 expect(InvalidParameter, status);
601 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
602 expect(InvalidParameter, status);
604 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
605 expect(InvalidParameter, status);
607 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
608 expect(InvalidParameter, status);
610 /* successful case */
611 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
612 expect(Ok, status);
614 GdipDeletePen(pen);
615 GdipDeleteGraphics(graphics);
617 ReleaseDC(hwnd, hdc);
620 static void test_BeginContainer2(void)
622 GpMatrix *transform;
623 GpRectF clip;
624 REAL defClip[] = {5, 10, 15, 20};
625 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
626 GraphicsContainer cont1, cont2, cont3, cont4;
627 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
628 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
629 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
630 REAL scale, defScale = 17;
631 GpUnit unit, defUnit = UnitPixel;
632 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
633 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
634 UINT contrast, defContrast = 5;
635 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
637 GpStatus status;
638 GpGraphics *graphics = NULL;
639 HDC hdc = GetDC( hwnd );
641 ok(hdc != NULL, "Expected HDC to be initialized\n");
643 status = GdipCreateFromHDC(hdc, &graphics);
644 expect(Ok, status);
645 ok(graphics != NULL, "Expected graphics to be initialized\n");
647 /* null graphics, null container */
648 status = GdipBeginContainer2(NULL, &cont1);
649 expect(InvalidParameter, status);
651 status = GdipBeginContainer2(graphics, NULL);
652 expect(InvalidParameter, status);
654 status = GdipEndContainer(NULL, cont1);
655 expect(InvalidParameter, status);
657 /* test all quality-related values */
658 GdipSetCompositingMode(graphics, defCompmode);
659 GdipSetCompositingQuality(graphics, defCompqual);
660 GdipSetInterpolationMode(graphics, defInterp);
661 GdipSetPageScale(graphics, defScale);
662 GdipSetPageUnit(graphics, defUnit);
663 GdipSetPixelOffsetMode(graphics, defOffsetmode);
664 GdipSetSmoothingMode(graphics, defSmoothmode);
665 GdipSetTextContrast(graphics, defContrast);
666 GdipSetTextRenderingHint(graphics, defTexthint);
668 status = GdipBeginContainer2(graphics, &cont1);
669 expect(Ok, status);
671 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
672 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
673 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
674 GdipSetPageScale(graphics, 10);
675 GdipSetPageUnit(graphics, UnitDocument);
676 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
677 GdipSetSmoothingMode(graphics, SmoothingModeNone);
678 GdipSetTextContrast(graphics, 7);
679 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
681 status = GdipEndContainer(graphics, cont1);
682 expect(Ok, status);
684 GdipGetCompositingMode(graphics, &compmode);
685 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
687 GdipGetCompositingQuality(graphics, &compqual);
688 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
690 GdipGetInterpolationMode(graphics, &interp);
691 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
693 GdipGetPageScale(graphics, &scale);
694 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
696 GdipGetPageUnit(graphics, &unit);
697 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
699 GdipGetPixelOffsetMode(graphics, &offsetmode);
700 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
702 GdipGetSmoothingMode(graphics, &smoothmode);
703 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
705 GdipGetTextContrast(graphics, &contrast);
706 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
708 status = GdipGetTextRenderingHint(graphics, &texthint);
709 expect(Ok, status);
710 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
712 /* test world transform */
713 status = GdipBeginContainer2(graphics, &cont1);
714 expect(Ok, status);
716 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
717 defTrans[4], defTrans[5], &transform);
718 expect(Ok, status);
719 GdipSetWorldTransform(graphics, transform);
720 GdipDeleteMatrix(transform);
721 transform = NULL;
723 status = GdipBeginContainer2(graphics, &cont2);
724 expect(Ok, status);
726 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
727 expect(Ok, status);
728 status = GdipSetWorldTransform(graphics, transform);
729 expect(Ok, status);
730 GdipDeleteMatrix(transform);
731 transform = NULL;
733 status = GdipEndContainer(graphics, cont2);
734 expect(Ok, status);
736 status = GdipCreateMatrix(&transform);
737 expect(Ok, status);
738 status = GdipGetWorldTransform(graphics, transform);
739 expect(Ok, status);
740 status = GdipGetMatrixElements(transform, elems);
741 expect(Ok, status);
742 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
743 fabs(defTrans[1] - elems[1]) < 0.0001 &&
744 fabs(defTrans[2] - elems[2]) < 0.0001 &&
745 fabs(defTrans[3] - elems[3]) < 0.0001 &&
746 fabs(defTrans[4] - elems[4]) < 0.0001 &&
747 fabs(defTrans[5] - elems[5]) < 0.0001,
748 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
749 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
750 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
751 GdipDeleteMatrix(transform);
752 transform = NULL;
754 status = GdipEndContainer(graphics, cont1);
755 expect(Ok, status);
757 /* test clipping */
758 status = GdipBeginContainer2(graphics, &cont1);
759 expect(Ok, status);
761 status = GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
762 expect(Ok, status);
764 status = GdipBeginContainer2(graphics, &cont2);
765 expect(Ok, status);
767 status = GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
768 expect(Ok, status);
770 status = GdipEndContainer(graphics, cont2);
771 expect(Ok, status);
773 status = GdipGetClipBounds(graphics, &clip);
774 expect(Ok, status);
776 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
777 fabs(defClip[1] - clip.Y) < 0.0001 &&
778 fabs(defClip[2] - clip.Width) < 0.0001 &&
779 fabs(defClip[3] - clip.Height) < 0.0001,
780 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
781 defClip[0], defClip[1], defClip[2], defClip[3],
782 clip.X, clip.Y, clip.Width, clip.Height);
784 status = GdipEndContainer(graphics, cont1);
785 expect(Ok, status);
787 /* nesting */
788 status = GdipBeginContainer2(graphics, &cont1);
789 expect(Ok, status);
791 status = GdipBeginContainer2(graphics, &cont2);
792 expect(Ok, status);
794 status = GdipBeginContainer2(graphics, &cont3);
795 expect(Ok, status);
797 status = GdipEndContainer(graphics, cont3);
798 expect(Ok, status);
800 status = GdipBeginContainer2(graphics, &cont4);
801 expect(Ok, status);
803 status = GdipEndContainer(graphics, cont4);
804 expect(Ok, status);
806 /* skip cont2 */
807 status = GdipEndContainer(graphics, cont1);
808 expect(Ok, status);
810 /* end an already-ended container */
811 status = GdipEndContainer(graphics, cont1);
812 expect(Ok, status);
814 GdipDeleteGraphics(graphics);
815 ReleaseDC(hwnd, hdc);
818 static void test_GdipDrawBezierI(void)
820 GpStatus status;
821 GpGraphics *graphics = NULL;
822 GpPen *pen = NULL;
823 HDC hdc = GetDC( hwnd );
825 /* make a graphics object and pen object */
826 ok(hdc != NULL, "Expected HDC to be initialized\n");
828 status = GdipCreateFromHDC(hdc, &graphics);
829 expect(Ok, status);
830 ok(graphics != NULL, "Expected graphics to be initialized\n");
832 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
833 expect(Ok, status);
834 ok(pen != NULL, "Expected pen to be initialized\n");
836 /* InvalidParameter cases: null graphics, null pen */
837 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
838 expect(InvalidParameter, status);
840 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
841 expect(InvalidParameter, status);
843 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
844 expect(InvalidParameter, status);
846 /* successful case */
847 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
848 expect(Ok, status);
850 GdipDeletePen(pen);
851 GdipDeleteGraphics(graphics);
853 ReleaseDC(hwnd, hdc);
856 static void test_GdipDrawCurve3(void)
858 GpStatus status;
859 GpGraphics *graphics = NULL;
860 GpPen *pen = NULL;
861 HDC hdc = GetDC( hwnd );
862 GpPointF points[3];
864 points[0].X = 0;
865 points[0].Y = 0;
867 points[1].X = 40;
868 points[1].Y = 20;
870 points[2].X = 10;
871 points[2].Y = 40;
873 /* make a graphics object and pen object */
874 ok(hdc != NULL, "Expected HDC to be initialized\n");
876 status = GdipCreateFromHDC(hdc, &graphics);
877 expect(Ok, status);
878 ok(graphics != NULL, "Expected graphics to be initialized\n");
880 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
881 expect(Ok, status);
882 ok(pen != NULL, "Expected pen to be initialized\n");
884 /* InvalidParameter cases: null graphics, null pen */
885 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
886 expect(InvalidParameter, status);
888 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
889 expect(InvalidParameter, status);
891 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
892 expect(InvalidParameter, status);
894 /* InvalidParameter cases: invalid count */
895 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
896 expect(InvalidParameter, status);
898 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
899 expect(InvalidParameter, status);
901 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
902 expect(InvalidParameter, status);
904 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
905 expect(InvalidParameter, status);
907 /* InvalidParameter cases: invalid number of segments */
908 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
909 expect(InvalidParameter, status);
911 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
912 expect(InvalidParameter, status);
914 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
915 expect(InvalidParameter, status);
917 /* Valid test cases */
918 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
919 expect(Ok, status);
921 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
922 expect(Ok, status);
924 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
925 expect(Ok, status);
927 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
928 expect(Ok, status);
930 GdipDeletePen(pen);
931 GdipDeleteGraphics(graphics);
933 ReleaseDC(hwnd, hdc);
936 static void test_GdipDrawCurve3I(void)
938 GpStatus status;
939 GpGraphics *graphics = NULL;
940 GpPen *pen = NULL;
941 HDC hdc = GetDC( hwnd );
942 GpPoint points[3];
944 points[0].X = 0;
945 points[0].Y = 0;
947 points[1].X = 40;
948 points[1].Y = 20;
950 points[2].X = 10;
951 points[2].Y = 40;
953 /* make a graphics object and pen object */
954 ok(hdc != NULL, "Expected HDC to be initialized\n");
956 status = GdipCreateFromHDC(hdc, &graphics);
957 expect(Ok, status);
958 ok(graphics != NULL, "Expected graphics to be initialized\n");
960 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
961 expect(Ok, status);
962 ok(pen != NULL, "Expected pen to be initialized\n");
964 /* InvalidParameter cases: null graphics, null pen */
965 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
966 expect(InvalidParameter, status);
968 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
969 expect(InvalidParameter, status);
971 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
972 expect(InvalidParameter, status);
974 /* InvalidParameter cases: invalid count */
975 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
976 expect(OutOfMemory, status);
978 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
979 expect(InvalidParameter, status);
981 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
982 expect(InvalidParameter, status);
984 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
985 expect(InvalidParameter, status);
987 /* InvalidParameter cases: invalid number of segments */
988 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
989 expect(InvalidParameter, status);
991 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
992 expect(InvalidParameter, status);
994 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
995 expect(InvalidParameter, status);
997 /* Valid test cases */
998 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
999 expect(Ok, status);
1001 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
1002 expect(Ok, status);
1004 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
1005 expect(Ok, status);
1007 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
1008 expect(Ok, status);
1010 GdipDeletePen(pen);
1011 GdipDeleteGraphics(graphics);
1013 ReleaseDC(hwnd, hdc);
1016 static void test_GdipDrawCurve2(void)
1018 GpStatus status;
1019 GpGraphics *graphics = NULL;
1020 GpPen *pen = NULL;
1021 HDC hdc = GetDC( hwnd );
1022 GpPointF points[3];
1024 points[0].X = 0;
1025 points[0].Y = 0;
1027 points[1].X = 40;
1028 points[1].Y = 20;
1030 points[2].X = 10;
1031 points[2].Y = 40;
1033 /* make a graphics object and pen object */
1034 ok(hdc != NULL, "Expected HDC to be initialized\n");
1036 status = GdipCreateFromHDC(hdc, &graphics);
1037 expect(Ok, status);
1038 ok(graphics != NULL, "Expected graphics to be initialized\n");
1040 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1041 expect(Ok, status);
1042 ok(pen != NULL, "Expected pen to be initialized\n");
1044 /* InvalidParameter cases: null graphics, null pen */
1045 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
1046 expect(InvalidParameter, status);
1048 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
1049 expect(InvalidParameter, status);
1051 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
1052 expect(InvalidParameter, status);
1054 /* InvalidParameter cases: invalid count */
1055 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
1056 expect(InvalidParameter, status);
1058 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
1059 expect(InvalidParameter, status);
1061 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
1062 expect(InvalidParameter, status);
1064 /* Valid test cases */
1065 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1066 expect(Ok, status);
1068 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1069 expect(Ok, status);
1071 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1072 expect(Ok, status);
1074 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1075 expect(Ok, status);
1077 GdipDeletePen(pen);
1078 GdipDeleteGraphics(graphics);
1080 ReleaseDC(hwnd, hdc);
1083 static void test_GdipDrawCurve2I(void)
1085 GpStatus status;
1086 GpGraphics *graphics = NULL;
1087 GpPen *pen = NULL;
1088 HDC hdc = GetDC( hwnd );
1089 GpPoint points[3];
1091 points[0].X = 0;
1092 points[0].Y = 0;
1094 points[1].X = 40;
1095 points[1].Y = 20;
1097 points[2].X = 10;
1098 points[2].Y = 40;
1100 /* make a graphics object and pen object */
1101 ok(hdc != NULL, "Expected HDC to be initialized\n");
1103 status = GdipCreateFromHDC(hdc, &graphics);
1104 expect(Ok, status);
1105 ok(graphics != NULL, "Expected graphics to be initialized\n");
1107 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1108 expect(Ok, status);
1109 ok(pen != NULL, "Expected pen to be initialized\n");
1111 /* InvalidParameter cases: null graphics, null pen */
1112 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1113 expect(InvalidParameter, status);
1115 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1116 expect(InvalidParameter, status);
1118 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1119 expect(InvalidParameter, status);
1121 /* InvalidParameter cases: invalid count */
1122 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1123 expect(OutOfMemory, status);
1125 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1126 expect(InvalidParameter, status);
1128 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1129 expect(InvalidParameter, status);
1131 /* Valid test cases */
1132 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1133 expect(Ok, status);
1135 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1136 expect(Ok, status);
1138 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1139 expect(Ok, status);
1141 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1142 expect(Ok, status);
1144 GdipDeletePen(pen);
1145 GdipDeleteGraphics(graphics);
1147 ReleaseDC(hwnd, hdc);
1150 static void test_GdipDrawCurve(void)
1152 GpStatus status;
1153 GpGraphics *graphics = NULL;
1154 GpPen *pen = NULL;
1155 HDC hdc = GetDC( hwnd );
1156 GpPointF points[3];
1158 points[0].X = 0;
1159 points[0].Y = 0;
1161 points[1].X = 40;
1162 points[1].Y = 20;
1164 points[2].X = 10;
1165 points[2].Y = 40;
1167 /* make a graphics object and pen object */
1168 ok(hdc != NULL, "Expected HDC to be initialized\n");
1170 status = GdipCreateFromHDC(hdc, &graphics);
1171 expect(Ok, status);
1172 ok(graphics != NULL, "Expected graphics to be initialized\n");
1174 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1175 expect(Ok, status);
1176 ok(pen != NULL, "Expected pen to be initialized\n");
1178 /* InvalidParameter cases: null graphics, null pen */
1179 status = GdipDrawCurve(NULL, NULL, points, 3);
1180 expect(InvalidParameter, status);
1182 status = GdipDrawCurve(graphics, NULL, points, 3);
1183 expect(InvalidParameter, status);
1185 status = GdipDrawCurve(NULL, pen, points, 3);
1186 expect(InvalidParameter, status);
1188 /* InvalidParameter cases: invalid count */
1189 status = GdipDrawCurve(graphics, pen, points, -1);
1190 expect(InvalidParameter, status);
1192 status = GdipDrawCurve(graphics, pen, points, 0);
1193 expect(InvalidParameter, status);
1195 status = GdipDrawCurve(graphics, pen, points, 1);
1196 expect(InvalidParameter, status);
1198 /* Valid test cases */
1199 status = GdipDrawCurve(graphics, pen, points, 2);
1200 expect(Ok, status);
1202 status = GdipDrawCurve(graphics, pen, points, 3);
1203 expect(Ok, status);
1205 GdipDeletePen(pen);
1206 GdipDeleteGraphics(graphics);
1208 ReleaseDC(hwnd, hdc);
1211 static void test_GdipDrawCurveI(void)
1213 GpStatus status;
1214 GpGraphics *graphics = NULL;
1215 GpPen *pen = NULL;
1216 HDC hdc = GetDC( hwnd );
1217 GpPoint points[3];
1219 points[0].X = 0;
1220 points[0].Y = 0;
1222 points[1].X = 40;
1223 points[1].Y = 20;
1225 points[2].X = 10;
1226 points[2].Y = 40;
1228 /* make a graphics object and pen object */
1229 ok(hdc != NULL, "Expected HDC to be initialized\n");
1231 status = GdipCreateFromHDC(hdc, &graphics);
1232 expect(Ok, status);
1233 ok(graphics != NULL, "Expected graphics to be initialized\n");
1235 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1236 expect(Ok, status);
1237 ok(pen != NULL, "Expected pen to be initialized\n");
1239 /* InvalidParameter cases: null graphics, null pen */
1240 status = GdipDrawCurveI(NULL, NULL, points, 3);
1241 expect(InvalidParameter, status);
1243 status = GdipDrawCurveI(graphics, NULL, points, 3);
1244 expect(InvalidParameter, status);
1246 status = GdipDrawCurveI(NULL, pen, points, 3);
1247 expect(InvalidParameter, status);
1249 /* InvalidParameter cases: invalid count */
1250 status = GdipDrawCurveI(graphics, pen, points, -1);
1251 expect(OutOfMemory, status);
1253 status = GdipDrawCurveI(graphics, pen, points, 0);
1254 expect(InvalidParameter, status);
1256 status = GdipDrawCurveI(graphics, pen, points, 1);
1257 expect(InvalidParameter, status);
1259 /* Valid test cases */
1260 status = GdipDrawCurveI(graphics, pen, points, 2);
1261 expect(Ok, status);
1263 status = GdipDrawCurveI(graphics, pen, points, 3);
1264 expect(Ok, status);
1266 GdipDeletePen(pen);
1267 GdipDeleteGraphics(graphics);
1269 ReleaseDC(hwnd, hdc);
1272 static void test_GdipDrawLineI(void)
1274 GpStatus status;
1275 GpGraphics *graphics = NULL;
1276 GpPen *pen = NULL;
1277 HDC hdc = GetDC( hwnd );
1279 /* make a graphics object and pen object */
1280 ok(hdc != NULL, "Expected HDC to be initialized\n");
1282 status = GdipCreateFromHDC(hdc, &graphics);
1283 expect(Ok, status);
1284 ok(graphics != NULL, "Expected graphics to be initialized\n");
1286 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1287 expect(Ok, status);
1288 ok(pen != NULL, "Expected pen to be initialized\n");
1290 /* InvalidParameter cases: null graphics, null pen */
1291 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1292 expect(InvalidParameter, status);
1294 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1295 expect(InvalidParameter, status);
1297 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1298 expect(InvalidParameter, status);
1300 /* successful case */
1301 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1302 expect(Ok, status);
1304 GdipDeletePen(pen);
1305 GdipDeleteGraphics(graphics);
1307 ReleaseDC(hwnd, hdc);
1310 static void test_GdipDrawImagePointsRect(void)
1312 GpStatus status;
1313 GpGraphics *graphics = NULL;
1314 GpPointF ptf[4];
1315 GpBitmap *bm = NULL;
1316 BYTE buff[400];
1317 BITMAPINFOHEADER bmihdr;
1318 HDC hdc = GetDC( hwnd );
1319 if (!hdc)
1320 return;
1322 memset(&bmihdr, 0, sizeof(bmihdr));
1323 bmihdr.biSize = sizeof(BITMAPINFOHEADER);
1324 bmihdr.biWidth = 10;
1325 bmihdr.biHeight = 10;
1326 bmihdr.biPlanes = 1;
1327 bmihdr.biBitCount = 32;
1328 bmihdr.biCompression = BI_RGB;
1329 status = GdipCreateBitmapFromGdiDib((BITMAPINFO*)&bmihdr, buff, &bm);
1330 expect(Ok, status);
1331 ok(NULL != bm, "Expected bitmap to be initialized\n");
1332 status = GdipCreateFromHDC(hdc, &graphics);
1333 expect(Ok, status);
1334 ptf[0].X = 0;
1335 ptf[0].Y = 0;
1336 ptf[1].X = 10;
1337 ptf[1].Y = 0;
1338 ptf[2].X = 0;
1339 ptf[2].Y = 10;
1340 ptf[3].X = 10;
1341 ptf[3].Y = 10;
1342 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1343 expect(NotImplemented, status);
1344 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 5, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1345 expect(InvalidParameter, status);
1346 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1347 expect(InvalidParameter, status);
1348 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1349 expect(Ok, status);
1350 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1351 expect(InvalidParameter, status);
1352 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1353 expect(InvalidParameter, status);
1354 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1355 expect(Ok, status);
1356 memset(ptf, 0, sizeof(ptf));
1357 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1358 expect(Ok, status);
1360 GdipDisposeImage((GpImage*)bm);
1361 GdipDeleteGraphics(graphics);
1362 ReleaseDC(hwnd, hdc);
1365 static void test_GdipDrawLinesI(void)
1367 GpStatus status;
1368 GpGraphics *graphics = NULL;
1369 GpPen *pen = NULL;
1370 GpPoint *ptf = NULL;
1371 HDC hdc = GetDC( hwnd );
1373 /* make a graphics object and pen object */
1374 ok(hdc != NULL, "Expected HDC to be initialized\n");
1376 status = GdipCreateFromHDC(hdc, &graphics);
1377 expect(Ok, status);
1378 ok(graphics != NULL, "Expected graphics to be initialized\n");
1380 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1381 expect(Ok, status);
1382 ok(pen != NULL, "Expected pen to be initialized\n");
1384 /* make some arbitrary valid points*/
1385 ptf = GdipAlloc(2 * sizeof(GpPointF));
1387 ptf[0].X = 1;
1388 ptf[0].Y = 1;
1390 ptf[1].X = 2;
1391 ptf[1].Y = 2;
1393 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1394 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1395 expect(InvalidParameter, status);
1397 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1398 expect(InvalidParameter, status);
1400 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1401 expect(InvalidParameter, status);
1403 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1404 expect(InvalidParameter, status);
1406 /* successful case */
1407 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1408 expect(Ok, status);
1410 GdipFree(ptf);
1411 GdipDeletePen(pen);
1412 GdipDeleteGraphics(graphics);
1414 ReleaseDC(hwnd, hdc);
1417 static void test_GdipFillClosedCurve(void)
1419 GpStatus status;
1420 GpGraphics *graphics = NULL;
1421 GpSolidFill *brush = NULL;
1422 HDC hdc = GetDC( hwnd );
1423 GpPointF points[3];
1425 points[0].X = 0;
1426 points[0].Y = 0;
1428 points[1].X = 40;
1429 points[1].Y = 20;
1431 points[2].X = 10;
1432 points[2].Y = 40;
1434 /* make a graphics object and brush object */
1435 ok(hdc != NULL, "Expected HDC to be initialized\n");
1437 status = GdipCreateFromHDC(hdc, &graphics);
1438 expect(Ok, status);
1439 ok(graphics != NULL, "Expected graphics to be initialized\n");
1441 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1443 /* InvalidParameter cases: null graphics, null brush, null points */
1444 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1445 expect(InvalidParameter, status);
1447 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1448 expect(InvalidParameter, status);
1450 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1451 expect(InvalidParameter, status);
1453 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1454 expect(InvalidParameter, status);
1456 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1457 expect(InvalidParameter, status);
1459 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1460 expect(InvalidParameter, status);
1462 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1463 expect(InvalidParameter, status);
1465 /* InvalidParameter cases: invalid count */
1466 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1467 expect(InvalidParameter, status);
1469 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1470 expect(InvalidParameter, status);
1472 /* Valid test cases */
1473 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1474 expect(Ok, status);
1476 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1477 expect(Ok, status);
1479 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1480 expect(Ok, status);
1482 GdipDeleteGraphics(graphics);
1483 GdipDeleteBrush((GpBrush*)brush);
1485 ReleaseDC(hwnd, hdc);
1488 static void test_GdipFillClosedCurveI(void)
1490 GpStatus status;
1491 GpGraphics *graphics = NULL;
1492 GpSolidFill *brush = NULL;
1493 HDC hdc = GetDC( hwnd );
1494 GpPoint points[3];
1496 points[0].X = 0;
1497 points[0].Y = 0;
1499 points[1].X = 40;
1500 points[1].Y = 20;
1502 points[2].X = 10;
1503 points[2].Y = 40;
1505 /* make a graphics object and brush object */
1506 ok(hdc != NULL, "Expected HDC to be initialized\n");
1508 status = GdipCreateFromHDC(hdc, &graphics);
1509 expect(Ok, status);
1510 ok(graphics != NULL, "Expected graphics to be initialized\n");
1512 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1514 /* InvalidParameter cases: null graphics, null brush */
1515 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1516 when points == NULL, so don't test this condition */
1517 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1518 expect(InvalidParameter, status);
1520 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1521 expect(InvalidParameter, status);
1523 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1524 expect(InvalidParameter, status);
1526 /* InvalidParameter cases: invalid count */
1527 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1528 expect(InvalidParameter, status);
1530 /* OutOfMemory cases: large (unsigned) int */
1531 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1532 expect(OutOfMemory, status);
1534 /* Valid test cases */
1535 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1536 expect(Ok, status);
1538 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1539 expect(Ok, status);
1541 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1542 expect(Ok, status);
1544 GdipDeleteGraphics(graphics);
1545 GdipDeleteBrush((GpBrush*)brush);
1547 ReleaseDC(hwnd, hdc);
1550 static void test_GdipFillPath(void)
1552 GpStatus status;
1553 GpGraphics *graphics;
1554 GpSolidFill *brush;
1555 GpPath *path;
1556 HDC hdc = GetDC(hwnd);
1558 ok(hdc != NULL, "Expected HDC to be initialized\n");
1559 status = GdipCreateFromHDC(hdc, &graphics);
1560 expect(Ok, status);
1561 ok(graphics != NULL, "Expected graphics to be initialized\n");
1562 status = GdipCreateSolidFill((ARGB)0xffffffff, &brush);
1563 expect(Ok, status);
1564 ok(brush != NULL, "Expected brush to be initialized\n");
1565 status = GdipCreatePath(FillModeAlternate, &path);
1566 expect(Ok, status);
1567 ok(path != NULL, "Expected path to be initialized\n");
1569 /* Empty path */
1570 GdipResetPath(path);
1571 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1572 expect(Ok, status);
1574 /* Not closed path */
1575 GdipResetPath(path);
1576 status = GdipAddPathLineI(path, 0, 0, 2, 2);
1577 expect(Ok, status);
1578 status = GdipAddPathLineI(path, 2, 2, 4, 0);
1579 expect(Ok, status);
1580 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1581 expect(Ok, status);
1583 /* Closed path */
1584 GdipResetPath(path);
1585 status = GdipAddPathRectangle(path, 0, 0, 4, 4);
1586 expect(Ok, status);
1587 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1588 expect(Ok, status);
1590 GdipDeletePath(path);
1591 GdipDeleteBrush((GpBrush *)brush);
1592 GdipDeleteGraphics(graphics);
1593 ReleaseDC(hwnd, hdc);
1596 static void test_Get_Release_DC(void)
1598 GpStatus status;
1599 GpGraphics *graphics = NULL;
1600 GpPen *pen;
1601 GpSolidFill *brush;
1602 GpPath *path;
1603 HDC hdc = GetDC( hwnd );
1604 HDC retdc;
1605 REAL r;
1606 CompositingQuality quality;
1607 CompositingMode compmode;
1608 InterpolationMode intmode;
1609 GpMatrix *m;
1610 GpRegion *region;
1611 GpUnit unit;
1612 PixelOffsetMode offsetmode;
1613 SmoothingMode smoothmode;
1614 TextRenderingHint texthint;
1615 GpPointF ptf[5];
1616 GpPoint pt[5];
1617 GpRectF rectf[2];
1618 GpRect rect[2];
1619 GpRegion *clip;
1620 INT i;
1621 BOOL res;
1622 ARGB color = 0x00000000;
1623 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1625 pt[0].X = 10;
1626 pt[0].Y = 10;
1627 pt[1].X = 20;
1628 pt[1].Y = 15;
1629 pt[2].X = 40;
1630 pt[2].Y = 80;
1631 pt[3].X = -20;
1632 pt[3].Y = 20;
1633 pt[4].X = 50;
1634 pt[4].Y = 110;
1636 for(i = 0; i < 5;i++){
1637 ptf[i].X = (REAL)pt[i].X;
1638 ptf[i].Y = (REAL)pt[i].Y;
1641 rect[0].X = 0;
1642 rect[0].Y = 0;
1643 rect[0].Width = 50;
1644 rect[0].Height = 70;
1645 rect[1].X = 0;
1646 rect[1].Y = 0;
1647 rect[1].Width = 10;
1648 rect[1].Height = 20;
1650 for(i = 0; i < 2;i++){
1651 rectf[i].X = (REAL)rect[i].X;
1652 rectf[i].Y = (REAL)rect[i].Y;
1653 rectf[i].Height = (REAL)rect[i].Height;
1654 rectf[i].Width = (REAL)rect[i].Width;
1657 status = GdipCreateMatrix(&m);
1658 expect(Ok, status);
1659 status = GdipCreateRegion(&region);
1660 expect(Ok, status);
1661 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1662 GdipCreatePath(FillModeAlternate, &path);
1663 status = GdipCreateRegion(&clip);
1664 expect(Ok, status);
1666 status = GdipCreateFromHDC(hdc, &graphics);
1667 expect(Ok, status);
1668 ok(graphics != NULL, "Expected graphics to be initialized\n");
1669 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1670 expect(Ok, status);
1672 /* NULL arguments */
1673 status = GdipGetDC(NULL, NULL);
1674 expect(InvalidParameter, status);
1675 status = GdipGetDC(graphics, NULL);
1676 expect(InvalidParameter, status);
1677 status = GdipGetDC(NULL, &retdc);
1678 expect(InvalidParameter, status);
1680 status = GdipReleaseDC(NULL, NULL);
1681 expect(InvalidParameter, status);
1682 status = GdipReleaseDC(graphics, NULL);
1683 expect(InvalidParameter, status);
1684 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1685 expect(InvalidParameter, status);
1687 /* Release without Get */
1688 status = GdipReleaseDC(graphics, hdc);
1689 expect(InvalidParameter, status);
1691 retdc = NULL;
1692 status = GdipGetDC(graphics, &retdc);
1693 expect(Ok, status);
1694 ok(retdc == hdc, "Invalid HDC returned\n");
1695 /* call it once more */
1696 status = GdipGetDC(graphics, &retdc);
1697 expect(ObjectBusy, status);
1699 /* try all Graphics calls here */
1700 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1701 expect(ObjectBusy, status);
1702 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1703 expect(ObjectBusy, status);
1704 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1705 expect(ObjectBusy, status);
1706 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1707 expect(ObjectBusy, status);
1708 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1709 expect(ObjectBusy, status);
1710 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1711 expect(ObjectBusy, status);
1712 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1713 expect(ObjectBusy, status);
1714 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1715 expect(ObjectBusy, status);
1716 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1717 expect(ObjectBusy, status);
1718 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1719 expect(ObjectBusy, status);
1720 status = GdipDrawCurve(graphics, pen, ptf, 5);
1721 expect(ObjectBusy, status);
1722 status = GdipDrawCurveI(graphics, pen, pt, 5);
1723 expect(ObjectBusy, status);
1724 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1725 expect(ObjectBusy, status);
1726 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1727 expect(ObjectBusy, status);
1728 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1729 expect(ObjectBusy, status);
1730 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1731 expect(ObjectBusy, status);
1732 /* GdipDrawImage/GdipDrawImageI */
1733 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1734 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1735 /* GdipDrawImageRect/GdipDrawImageRectI */
1736 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1737 expect(ObjectBusy, status);
1738 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1739 expect(ObjectBusy, status);
1740 status = GdipDrawLines(graphics, pen, ptf, 5);
1741 expect(ObjectBusy, status);
1742 status = GdipDrawLinesI(graphics, pen, pt, 5);
1743 expect(ObjectBusy, status);
1744 status = GdipDrawPath(graphics, pen, path);
1745 expect(ObjectBusy, status);
1746 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1747 expect(ObjectBusy, status);
1748 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1749 expect(ObjectBusy, status);
1750 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1751 expect(ObjectBusy, status);
1752 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1753 expect(ObjectBusy, status);
1754 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1755 expect(ObjectBusy, status);
1756 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1757 expect(ObjectBusy, status);
1758 /* GdipDrawString */
1759 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1760 expect(ObjectBusy, status);
1761 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1762 expect(ObjectBusy, status);
1763 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1764 expect(ObjectBusy, status);
1765 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1766 expect(ObjectBusy, status);
1767 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1768 expect(ObjectBusy, status);
1769 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1770 expect(ObjectBusy, status);
1771 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1772 expect(ObjectBusy, status);
1773 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1774 expect(ObjectBusy, status);
1775 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1776 expect(ObjectBusy, status);
1777 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1778 expect(ObjectBusy, status);
1779 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1780 expect(ObjectBusy, status);
1781 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1782 expect(ObjectBusy, status);
1783 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1784 expect(ObjectBusy, status);
1785 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1786 expect(ObjectBusy, status);
1787 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1788 expect(ObjectBusy, status);
1789 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1790 expect(ObjectBusy, status);
1791 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1792 expect(ObjectBusy, status);
1793 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1794 expect(ObjectBusy, status);
1795 status = GdipFlush(graphics, FlushIntentionFlush);
1796 expect(ObjectBusy, status);
1797 status = GdipGetClipBounds(graphics, rectf);
1798 expect(ObjectBusy, status);
1799 status = GdipGetClipBoundsI(graphics, rect);
1800 expect(ObjectBusy, status);
1801 status = GdipGetCompositingMode(graphics, &compmode);
1802 expect(ObjectBusy, status);
1803 status = GdipGetCompositingQuality(graphics, &quality);
1804 expect(ObjectBusy, status);
1805 status = GdipGetInterpolationMode(graphics, &intmode);
1806 expect(ObjectBusy, status);
1807 status = GdipGetNearestColor(graphics, &color);
1808 expect(ObjectBusy, status);
1809 status = GdipGetPageScale(graphics, &r);
1810 expect(ObjectBusy, status);
1811 status = GdipGetPageUnit(graphics, &unit);
1812 expect(ObjectBusy, status);
1813 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1814 expect(ObjectBusy, status);
1815 status = GdipGetSmoothingMode(graphics, &smoothmode);
1816 expect(ObjectBusy, status);
1817 status = GdipGetTextRenderingHint(graphics, &texthint);
1818 expect(ObjectBusy, status);
1819 status = GdipGetWorldTransform(graphics, m);
1820 expect(ObjectBusy, status);
1821 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1822 expect(ObjectBusy, status);
1823 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1824 expect(ObjectBusy, status);
1825 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1826 expect(ObjectBusy, status);
1827 /* GdipMeasureCharacterRanges */
1828 /* GdipMeasureString */
1829 status = GdipResetClip(graphics);
1830 expect(ObjectBusy, status);
1831 status = GdipResetPageTransform(graphics);
1832 expect(ObjectBusy, status);
1833 status = GdipResetWorldTransform(graphics);
1834 expect(ObjectBusy, status);
1835 /* GdipRestoreGraphics */
1836 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1837 expect(ObjectBusy, status);
1838 /* GdipSaveGraphics */
1839 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1840 expect(ObjectBusy, status);
1841 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1842 expect(ObjectBusy, status);
1843 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1844 expect(ObjectBusy, status);
1845 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1846 expect(ObjectBusy, status);
1847 status = GdipSetPageScale(graphics, 1.0);
1848 expect(ObjectBusy, status);
1849 status = GdipSetPageScale(graphics, 0.0);
1850 expect(ObjectBusy, status);
1851 status = GdipSetPageUnit(graphics, UnitWorld);
1852 expect(ObjectBusy, status);
1853 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1854 expect(ObjectBusy, status);
1855 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1856 expect(ObjectBusy, status);
1857 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1858 expect(ObjectBusy, status);
1859 status = GdipSetWorldTransform(graphics, m);
1860 expect(ObjectBusy, status);
1861 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1862 expect(ObjectBusy, status);
1863 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1864 expect(ObjectBusy, status);
1865 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1866 expect(ObjectBusy, status);
1867 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1868 expect(ObjectBusy, status);
1869 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1870 expect(ObjectBusy, status);
1871 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1872 expect(ObjectBusy, status);
1873 status = GdipTranslateClip(graphics, 0.0, 0.0);
1874 expect(ObjectBusy, status);
1875 status = GdipTranslateClipI(graphics, 0, 0);
1876 expect(ObjectBusy, status);
1877 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1878 expect(ObjectBusy, status);
1879 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1880 expect(ObjectBusy, status);
1881 status = GdipGetDpiX(graphics, &r);
1882 expect(ObjectBusy, status);
1883 status = GdipGetDpiY(graphics, &r);
1884 expect(ObjectBusy, status);
1885 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1886 expect(ObjectBusy, status);
1887 status = GdipGetClip(graphics, region);
1888 expect(ObjectBusy, status);
1889 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1890 expect(ObjectBusy, status);
1892 /* try to delete before release */
1893 status = GdipDeleteGraphics(graphics);
1894 expect(ObjectBusy, status);
1896 status = GdipReleaseDC(graphics, retdc);
1897 expect(Ok, status);
1899 GdipDeletePen(pen);
1900 GdipDeleteGraphics(graphics);
1902 GdipDeleteRegion(clip);
1903 GdipDeletePath(path);
1904 GdipDeleteBrush((GpBrush*)brush);
1905 GdipDeleteRegion(region);
1906 GdipDeleteMatrix(m);
1907 DeleteObject(hrgn);
1909 ReleaseDC(hwnd, hdc);
1912 static void test_transformpoints(void)
1914 GpStatus status;
1915 GpGraphics *graphics = NULL;
1916 HDC hdc = GetDC( hwnd );
1917 GpPointF ptf[2];
1918 GpPoint pt[2];
1920 status = GdipCreateFromHDC(hdc, &graphics);
1921 expect(Ok, status);
1923 /* NULL arguments */
1924 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1925 expect(InvalidParameter, status);
1926 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1927 expect(InvalidParameter, status);
1928 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1929 expect(InvalidParameter, status);
1930 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1931 expect(InvalidParameter, status);
1933 status = GdipTransformPoints(graphics, CoordinateSpaceDevice+1, CoordinateSpaceWorld, ptf, 2);
1934 expect(InvalidParameter, status);
1935 status = GdipTransformPoints(graphics, -1, CoordinateSpaceWorld, ptf, 2);
1936 expect(InvalidParameter, status);
1937 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceDevice+1, ptf, 2);
1938 expect(InvalidParameter, status);
1939 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, -1, ptf, 2);
1940 expect(InvalidParameter, status);
1942 ptf[0].X = 1.0;
1943 ptf[0].Y = 0.0;
1944 ptf[1].X = 0.0;
1945 ptf[1].Y = 1.0;
1946 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1947 expect(Ok, status);
1948 expectf(1.0, ptf[0].X);
1949 expectf(0.0, ptf[0].Y);
1950 expectf(0.0, ptf[1].X);
1951 expectf(1.0, ptf[1].Y);
1953 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1954 expect(Ok, status);
1955 status = GdipSetPageUnit(graphics, UnitPixel);
1956 expect(Ok, status);
1957 status = GdipSetPageScale(graphics, 3.0);
1958 expect(Ok, status);
1960 ptf[0].X = 1.0;
1961 ptf[0].Y = 0.0;
1962 ptf[1].X = 0.0;
1963 ptf[1].Y = 1.0;
1964 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1965 expect(Ok, status);
1966 expectf(18.0, ptf[0].X);
1967 expectf(15.0, ptf[0].Y);
1968 expectf(15.0, ptf[1].X);
1969 expectf(18.0, ptf[1].Y);
1971 ptf[0].X = 1.0;
1972 ptf[0].Y = 0.0;
1973 ptf[1].X = 0.0;
1974 ptf[1].Y = 1.0;
1975 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1976 expect(Ok, status);
1977 expectf(6.0, ptf[0].X);
1978 expectf(5.0, ptf[0].Y);
1979 expectf(5.0, ptf[1].X);
1980 expectf(6.0, ptf[1].Y);
1982 ptf[0].X = 1.0;
1983 ptf[0].Y = 0.0;
1984 ptf[1].X = 0.0;
1985 ptf[1].Y = 1.0;
1986 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1987 expect(Ok, status);
1988 expectf(3.0, ptf[0].X);
1989 expectf(0.0, ptf[0].Y);
1990 expectf(0.0, ptf[1].X);
1991 expectf(3.0, ptf[1].Y);
1993 ptf[0].X = 18.0;
1994 ptf[0].Y = 15.0;
1995 ptf[1].X = 15.0;
1996 ptf[1].Y = 18.0;
1997 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1998 expect(Ok, status);
1999 expectf(1.0, ptf[0].X);
2000 expectf(0.0, ptf[0].Y);
2001 expectf(0.0, ptf[1].X);
2002 expectf(1.0, ptf[1].Y);
2004 ptf[0].X = 6.0;
2005 ptf[0].Y = 5.0;
2006 ptf[1].X = 5.0;
2007 ptf[1].Y = 6.0;
2008 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
2009 expect(Ok, status);
2010 expectf(1.0, ptf[0].X);
2011 expectf(0.0, ptf[0].Y);
2012 expectf(0.0, ptf[1].X);
2013 expectf(1.0, ptf[1].Y);
2015 ptf[0].X = 3.0;
2016 ptf[0].Y = 0.0;
2017 ptf[1].X = 0.0;
2018 ptf[1].Y = 3.0;
2019 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
2020 expect(Ok, status);
2021 expectf(1.0, ptf[0].X);
2022 expectf(0.0, ptf[0].Y);
2023 expectf(0.0, ptf[1].X);
2024 expectf(1.0, ptf[1].Y);
2026 pt[0].X = 1;
2027 pt[0].Y = 0;
2028 pt[1].X = 0;
2029 pt[1].Y = 1;
2030 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
2031 expect(Ok, status);
2032 expect(18, pt[0].X);
2033 expect(15, pt[0].Y);
2034 expect(15, pt[1].X);
2035 expect(18, pt[1].Y);
2037 GdipDeleteGraphics(graphics);
2038 ReleaseDC(hwnd, hdc);
2041 static void test_get_set_clip(void)
2043 GpStatus status;
2044 GpGraphics *graphics = NULL;
2045 HDC hdc = GetDC( hwnd );
2046 GpRegion *clip;
2047 GpRectF rect;
2048 BOOL res;
2050 status = GdipCreateFromHDC(hdc, &graphics);
2051 expect(Ok, status);
2053 rect.X = rect.Y = 0.0;
2054 rect.Height = rect.Width = 100.0;
2056 status = GdipCreateRegionRect(&rect, &clip);
2057 expect(Ok, status);
2059 /* NULL arguments */
2060 status = GdipGetClip(NULL, NULL);
2061 expect(InvalidParameter, status);
2062 status = GdipGetClip(graphics, NULL);
2063 expect(InvalidParameter, status);
2064 status = GdipGetClip(NULL, clip);
2065 expect(InvalidParameter, status);
2067 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
2068 expect(InvalidParameter, status);
2069 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
2070 expect(InvalidParameter, status);
2072 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
2073 expect(InvalidParameter, status);
2074 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
2075 expect(InvalidParameter, status);
2077 res = FALSE;
2078 status = GdipGetClip(graphics, clip);
2079 expect(Ok, status);
2080 status = GdipIsInfiniteRegion(clip, graphics, &res);
2081 expect(Ok, status);
2082 expect(TRUE, res);
2084 /* remains infinite after reset */
2085 res = FALSE;
2086 status = GdipResetClip(graphics);
2087 expect(Ok, status);
2088 status = GdipGetClip(graphics, clip);
2089 expect(Ok, status);
2090 status = GdipIsInfiniteRegion(clip, graphics, &res);
2091 expect(Ok, status);
2092 expect(TRUE, res);
2094 /* set to empty and then reset to infinite */
2095 status = GdipSetEmpty(clip);
2096 expect(Ok, status);
2097 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
2098 expect(Ok, status);
2100 status = GdipGetClip(graphics, clip);
2101 expect(Ok, status);
2102 res = FALSE;
2103 status = GdipIsEmptyRegion(clip, graphics, &res);
2104 expect(Ok, status);
2105 expect(TRUE, res);
2106 status = GdipResetClip(graphics);
2107 expect(Ok, status);
2108 status = GdipGetClip(graphics, clip);
2109 expect(Ok, status);
2110 res = FALSE;
2111 status = GdipIsInfiniteRegion(clip, graphics, &res);
2112 expect(Ok, status);
2113 expect(TRUE, res);
2115 GdipDeleteRegion(clip);
2117 GdipDeleteGraphics(graphics);
2118 ReleaseDC(hwnd, hdc);
2121 static void test_clip_xform(void)
2123 GpStatus status;
2124 GpGraphics *graphics = NULL;
2125 HDC hdc = GetDC( hwnd );
2126 GpRegion *clip;
2127 COLORREF color;
2128 UINT region_data_size;
2129 struct {
2130 DWORD size;
2131 DWORD checksum;
2132 DWORD magic;
2133 DWORD num_children;
2134 DWORD element_type;
2135 REAL x;
2136 REAL y;
2137 REAL width;
2138 REAL height;
2139 } region_data;
2141 status = GdipCreateFromHDC(hdc, &graphics);
2142 expect(Ok, status);
2143 status = GdipCreateRegion(&clip);
2144 expect(Ok, status);
2146 status = GdipGraphicsClear(graphics, 0xff000000);
2147 expect(Ok, status);
2149 status = GdipSetClipRect(graphics, 10, 10, -10, -10, CombineModeReplace);
2150 expect(Ok, status);
2151 status = GdipGetClip(graphics, clip);
2152 expect(Ok, status);
2153 status = GdipGetRegionData(clip, (BYTE*)&region_data, sizeof(region_data), &region_data_size);
2154 expect(Ok, status);
2155 expect(36, region_data_size);
2156 expect(28, region_data.size);
2157 expect(0, region_data.num_children);
2158 expect(0x10000000 /* RegionDataRect */, region_data.element_type);
2159 expectf(0.0, region_data.x);
2160 expectf(0.0, region_data.y);
2161 expectf(10.0, region_data.width);
2162 expectf(10.0, region_data.height);
2164 /* No effect with negative width/height */
2165 status = GdipGraphicsClear(graphics, 0xffff0000);
2166 expect(Ok, status);
2167 color = GetPixel(hdc, 5, 5);
2168 expect(0, color);
2170 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderAppend);
2171 expect(Ok, status);
2173 status = GdipGraphicsClear(graphics, 0xffff0000);
2174 expect(Ok, status);
2175 color = GetPixel(hdc, 5, 5);
2176 expect(0, color);
2178 status = GdipResetClip(graphics);
2179 expect(Ok, status);
2180 status = GdipResetWorldTransform(graphics);
2181 expect(Ok, status);
2182 status = GdipGraphicsClear(graphics, 0xff000000);
2183 expect(Ok, status);
2185 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderAppend);
2186 expect(Ok, status);
2188 status = GdipSetClipRect(graphics, 5, 5, -5, -5, CombineModeReplace);
2189 expect(Ok, status);
2190 status = GdipGetClip(graphics, clip);
2191 expect(Ok, status);
2192 status = GdipGetRegionData(clip, (BYTE*)&region_data, sizeof(region_data), &region_data_size);
2193 expect(Ok, status);
2194 expect(36, region_data_size);
2195 expect(28, region_data.size);
2196 expect(0, region_data.num_children);
2197 expect(0x10000000 /* RegionDataRect */, region_data.element_type);
2198 expectf(0.0, region_data.x);
2199 expectf(0.0, region_data.y);
2200 expectf(5.0, region_data.width);
2201 expectf(5.0, region_data.height);
2203 status = GdipGraphicsClear(graphics, 0xffff0000);
2204 expect(Ok, status);
2205 color = GetPixel(hdc, 5, 5);
2206 expect(0xff, color);
2208 GdipDeleteGraphics(graphics);
2209 GdipDeleteRegion(clip);
2210 ReleaseDC(hwnd, hdc);
2213 static void test_isempty(void)
2215 GpStatus status;
2216 GpGraphics *graphics = NULL;
2217 HDC hdc = GetDC( hwnd );
2218 GpRegion *clip;
2219 BOOL res;
2221 status = GdipCreateFromHDC(hdc, &graphics);
2222 expect(Ok, status);
2224 status = GdipCreateRegion(&clip);
2225 expect(Ok, status);
2227 /* NULL */
2228 status = GdipIsClipEmpty(NULL, NULL);
2229 expect(InvalidParameter, status);
2230 status = GdipIsClipEmpty(graphics, NULL);
2231 expect(InvalidParameter, status);
2232 status = GdipIsClipEmpty(NULL, &res);
2233 expect(InvalidParameter, status);
2235 /* default is infinite */
2236 res = TRUE;
2237 status = GdipIsClipEmpty(graphics, &res);
2238 expect(Ok, status);
2239 expect(FALSE, res);
2241 GdipDeleteRegion(clip);
2243 GdipDeleteGraphics(graphics);
2244 ReleaseDC(hwnd, hdc);
2247 static void test_clear(void)
2249 GpStatus status;
2251 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2252 expect(InvalidParameter, status);
2255 static void test_textcontrast(void)
2257 GpStatus status;
2258 HDC hdc = GetDC( hwnd );
2259 GpGraphics *graphics;
2260 UINT contrast;
2262 status = GdipGetTextContrast(NULL, NULL);
2263 expect(InvalidParameter, status);
2265 status = GdipCreateFromHDC(hdc, &graphics);
2266 expect(Ok, status);
2268 status = GdipGetTextContrast(graphics, NULL);
2269 expect(InvalidParameter, status);
2270 status = GdipGetTextContrast(graphics, &contrast);
2271 expect(Ok, status);
2272 expect(4, contrast);
2274 GdipDeleteGraphics(graphics);
2275 ReleaseDC(hwnd, hdc);
2278 static void test_GdipDrawString(void)
2280 GpStatus status;
2281 GpGraphics *graphics = NULL;
2282 GpFont *fnt = NULL;
2283 RectF rect;
2284 GpStringFormat *format;
2285 GpBrush *brush;
2286 LOGFONTA logfont;
2287 HDC hdc = GetDC( hwnd );
2288 static const WCHAR string[] = L"Test";
2289 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2290 GpMatrix *matrix;
2292 memset(&logfont,0,sizeof(logfont));
2293 strcpy(logfont.lfFaceName,"Arial");
2294 logfont.lfHeight = 12;
2295 logfont.lfCharSet = DEFAULT_CHARSET;
2297 status = GdipCreateFromHDC(hdc, &graphics);
2298 expect(Ok, status);
2300 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2301 if (status == NotTrueTypeFont || status == FileNotFound)
2303 skip("Arial not installed.\n");
2304 return;
2306 expect(Ok, status);
2308 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2309 expect(Ok, status);
2311 status = GdipCreateStringFormat(0,0,&format);
2312 expect(Ok, status);
2314 rect.X = 0;
2315 rect.Y = 0;
2316 rect.Width = 0;
2317 rect.Height = 12;
2319 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2320 expect(Ok, status);
2322 status = GdipCreateMatrix(&matrix);
2323 expect(Ok, status);
2325 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2326 expect(InvalidParameter, status);
2328 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2329 expect(InvalidParameter, status);
2331 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2332 expect(InvalidParameter, status);
2334 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2335 expect(InvalidParameter, status);
2337 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2338 expect(InvalidParameter, status);
2340 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2341 expect(Ok, status);
2343 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2344 expect(Ok, status);
2346 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2347 expect(Ok, status);
2349 GdipDeleteMatrix(matrix);
2350 GdipDeleteGraphics(graphics);
2351 GdipDeleteBrush(brush);
2352 GdipDeleteFont(fnt);
2353 GdipDeleteStringFormat(format);
2355 ReleaseDC(hwnd, hdc);
2358 static void test_GdipGetVisibleClipBounds_screen(void)
2360 GpStatus status;
2361 GpGraphics *graphics = NULL;
2362 HDC hdc = GetDC(0);
2363 GpRectF rectf, exp, clipr;
2364 GpRect recti;
2366 ok(hdc != NULL, "Expected HDC to be initialized\n");
2368 status = GdipCreateFromHDC(hdc, &graphics);
2369 expect(Ok, status);
2370 ok(graphics != NULL, "Expected graphics to be initialized\n");
2372 /* no clipping rect */
2373 exp.X = 0;
2374 exp.Y = 0;
2375 exp.Width = GetDeviceCaps(hdc, HORZRES);
2376 exp.Height = GetDeviceCaps(hdc, VERTRES);
2378 status = GdipGetVisibleClipBounds(graphics, &rectf);
2379 expect(Ok, status);
2380 ok(rectf.X == exp.X &&
2381 rectf.Y == exp.Y &&
2382 rectf.Width == exp.Width &&
2383 rectf.Height == exp.Height,
2384 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2385 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2386 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2387 exp.X, exp.Y, exp.Width, exp.Height);
2389 /* clipping rect entirely within window */
2390 exp.X = clipr.X = 10;
2391 exp.Y = clipr.Y = 12;
2392 exp.Width = clipr.Width = 14;
2393 exp.Height = clipr.Height = 16;
2395 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2396 expect(Ok, status);
2398 status = GdipGetVisibleClipBounds(graphics, &rectf);
2399 expect(Ok, status);
2400 ok(rectf.X == exp.X &&
2401 rectf.Y == exp.Y &&
2402 rectf.Width == exp.Width &&
2403 rectf.Height == exp.Height,
2404 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2405 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2406 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2407 exp.X, exp.Y, exp.Width, exp.Height);
2409 /* clipping rect partially outside of screen */
2410 clipr.X = -10;
2411 clipr.Y = -12;
2412 clipr.Width = 20;
2413 clipr.Height = 24;
2415 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2416 expect(Ok, status);
2418 exp.X = 0;
2419 exp.Y = 0;
2420 exp.Width = 10;
2421 exp.Height = 12;
2423 status = GdipGetVisibleClipBounds(graphics, &rectf);
2424 expect(Ok, status);
2425 ok(rectf.X == exp.X &&
2426 rectf.Y == exp.Y &&
2427 rectf.Width == exp.Width &&
2428 rectf.Height == exp.Height,
2429 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2430 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2431 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2432 exp.X, exp.Y, exp.Width, exp.Height);
2434 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2435 expect(Ok, status);
2436 ok(recti.X == exp.X &&
2437 recti.Y == exp.Y &&
2438 recti.Width == exp.Width &&
2439 recti.Height == exp.Height,
2440 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2441 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2442 recti.X, recti.Y, recti.Width, recti.Height,
2443 exp.X, exp.Y, exp.Width, exp.Height);
2445 GdipDeleteGraphics(graphics);
2446 ReleaseDC(0, hdc);
2449 static void test_GdipGetVisibleClipBounds_window(void)
2451 GpStatus status;
2452 GpGraphics *graphics = NULL;
2453 GpRectF rectf, window, exp, clipr;
2454 GpRect recti;
2455 HDC hdc;
2456 PAINTSTRUCT ps;
2457 RECT wnd_rect;
2459 /* get client area size */
2460 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2461 window.X = wnd_rect.left;
2462 window.Y = wnd_rect.top;
2463 window.Width = wnd_rect.right - wnd_rect.left;
2464 window.Height = wnd_rect.bottom - wnd_rect.top;
2466 hdc = BeginPaint(hwnd, &ps);
2468 status = GdipCreateFromHDC(hdc, &graphics);
2469 expect(Ok, status);
2470 ok(graphics != NULL, "Expected graphics to be initialized\n");
2472 status = GdipGetVisibleClipBounds(graphics, &rectf);
2473 expect(Ok, status);
2474 ok(rectf.X == window.X &&
2475 rectf.Y == window.Y &&
2476 rectf.Width == window.Width &&
2477 rectf.Height == window.Height,
2478 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2479 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2480 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2481 window.X, window.Y, window.Width, window.Height);
2483 /* clipping rect entirely within window */
2484 exp.X = clipr.X = 20;
2485 exp.Y = clipr.Y = 8;
2486 exp.Width = clipr.Width = 30;
2487 exp.Height = clipr.Height = 20;
2489 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2490 expect(Ok, status);
2492 status = GdipGetVisibleClipBounds(graphics, &rectf);
2493 expect(Ok, status);
2494 ok(rectf.X == exp.X &&
2495 rectf.Y == exp.Y &&
2496 rectf.Width == exp.Width &&
2497 rectf.Height == exp.Height,
2498 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2499 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2500 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2501 exp.X, exp.Y, exp.Width, exp.Height);
2503 /* clipping rect partially outside of window */
2504 clipr.X = window.Width - 10;
2505 clipr.Y = window.Height - 15;
2506 clipr.Width = 20;
2507 clipr.Height = 30;
2509 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2510 expect(Ok, status);
2512 exp.X = window.Width - 10;
2513 exp.Y = window.Height - 15;
2514 exp.Width = 10;
2515 exp.Height = 15;
2517 status = GdipGetVisibleClipBounds(graphics, &rectf);
2518 expect(Ok, status);
2519 ok(rectf.X == exp.X &&
2520 rectf.Y == exp.Y &&
2521 rectf.Width == exp.Width &&
2522 rectf.Height == exp.Height,
2523 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2524 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2525 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2526 exp.X, exp.Y, exp.Width, exp.Height);
2528 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2529 expect(Ok, status);
2530 ok(recti.X == exp.X &&
2531 recti.Y == exp.Y &&
2532 recti.Width == exp.Width &&
2533 recti.Height == exp.Height,
2534 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2535 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2536 recti.X, recti.Y, recti.Width, recti.Height,
2537 exp.X, exp.Y, exp.Width, exp.Height);
2539 /* window bounds with transform applied */
2540 status = GdipResetClip(graphics);
2541 expect(Ok, status);
2543 status = GdipScaleWorldTransform(graphics, 0.5, 0.5, MatrixOrderPrepend);
2544 expect(Ok, status);
2546 exp.X = window.X * 2.0;
2547 exp.Y = window.Y * 2.0;
2548 exp.Width = window.Width * 2.0;
2549 exp.Height = window.Height * 2.0;
2551 status = GdipGetVisibleClipBounds(graphics, &rectf);
2552 expect(Ok, status);
2553 ok(rectf.X == exp.X &&
2554 rectf.Y == exp.Y &&
2555 rectf.Width == exp.Width &&
2556 rectf.Height == exp.Height,
2557 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be "
2558 "twice the window size (%0.f, %0.f, %0.f, %0.f)\n",
2559 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2560 exp.X, exp.Y, exp.Width, exp.Height);
2562 GdipDeleteGraphics(graphics);
2563 EndPaint(hwnd, &ps);
2566 static void test_GdipGetVisibleClipBounds(void)
2568 GpGraphics* graphics = NULL;
2569 GpRectF rectf;
2570 GpRect rect;
2571 HDC hdc = GetDC( hwnd );
2572 GpStatus status;
2574 status = GdipCreateFromHDC(hdc, &graphics);
2575 expect(Ok, status);
2576 ok(graphics != NULL, "Expected graphics to be initialized\n");
2578 /* test null parameters */
2579 status = GdipGetVisibleClipBounds(graphics, NULL);
2580 expect(InvalidParameter, status);
2582 status = GdipGetVisibleClipBounds(NULL, &rectf);
2583 expect(InvalidParameter, status);
2585 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2586 expect(InvalidParameter, status);
2588 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2589 expect(InvalidParameter, status);
2591 GdipDeleteGraphics(graphics);
2592 ReleaseDC(hwnd, hdc);
2594 test_GdipGetVisibleClipBounds_screen();
2595 test_GdipGetVisibleClipBounds_window();
2598 static void test_fromMemoryBitmap(void)
2600 GpStatus status;
2601 GpGraphics *graphics = NULL;
2602 GpBitmap *bitmap = NULL;
2603 BYTE bits[48] = {0};
2604 HDC hdc=NULL;
2605 COLORREF color;
2607 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2608 expect(Ok, status);
2610 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2611 expect(Ok, status);
2613 status = GdipGraphicsClear(graphics, 0xff686868);
2614 expect(Ok, status);
2616 GdipDeleteGraphics(graphics);
2618 /* drawing writes to the memory provided */
2619 expect(0x68, bits[10]);
2621 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2622 expect(Ok, status);
2624 status = GdipGetDC(graphics, &hdc);
2625 expect(Ok, status);
2626 ok(hdc != NULL, "got NULL hdc\n");
2628 color = GetPixel(hdc, 0, 0);
2629 /* The HDC is write-only, and native fills with a solid color to figure out
2630 * which pixels have changed. */
2631 todo_wine expect(0x0c0b0d, color);
2633 SetPixel(hdc, 0, 0, 0x797979);
2634 SetPixel(hdc, 1, 0, 0x0c0b0d);
2636 status = GdipReleaseDC(graphics, hdc);
2637 expect(Ok, status);
2639 GdipDeleteGraphics(graphics);
2641 expect(0x79, bits[0]);
2642 todo_wine expect(0x68, bits[3]);
2644 GdipDisposeImage((GpImage*)bitmap);
2646 /* We get the same kind of write-only HDC for a "normal" bitmap */
2647 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2648 expect(Ok, status);
2650 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2651 expect(Ok, status);
2653 status = GdipGetDC(graphics, &hdc);
2654 expect(Ok, status);
2655 ok(hdc != NULL, "got NULL hdc\n");
2657 color = GetPixel(hdc, 0, 0);
2658 todo_wine expect(0x0c0b0d, color);
2660 status = GdipReleaseDC(graphics, hdc);
2661 expect(Ok, status);
2663 GdipDeleteGraphics(graphics);
2665 GdipDisposeImage((GpImage*)bitmap);
2667 /* If we don't draw to the HDC, the bits are never accessed */
2668 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, (BYTE*)1, &bitmap);
2669 expect(Ok, status);
2671 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2672 expect(Ok, status);
2674 status = GdipGetDC(graphics, &hdc);
2675 expect(Ok, status);
2676 ok(hdc != NULL, "got NULL hdc\n");
2678 color = GetPixel(hdc, 0, 0);
2679 todo_wine expect(0x0c0b0d, color);
2681 status = GdipReleaseDC(graphics, hdc);
2682 expect(Ok, status);
2684 GdipDeleteGraphics(graphics);
2686 GdipDisposeImage((GpImage*)bitmap);
2689 static void test_GdipIsVisiblePoint(void)
2691 GpStatus status;
2692 GpGraphics *graphics = NULL;
2693 HDC hdc = GetDC( hwnd );
2694 REAL x, y;
2695 BOOL val;
2697 ok(hdc != NULL, "Expected HDC to be initialized\n");
2699 status = GdipCreateFromHDC(hdc, &graphics);
2700 expect(Ok, status);
2701 ok(graphics != NULL, "Expected graphics to be initialized\n");
2703 /* null parameters */
2704 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2705 expect(InvalidParameter, status);
2707 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2708 expect(InvalidParameter, status);
2710 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2711 expect(InvalidParameter, status);
2713 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2714 expect(InvalidParameter, status);
2716 x = 0;
2717 y = 0;
2718 status = GdipIsVisiblePoint(graphics, x, y, &val);
2719 expect(Ok, status);
2720 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2722 x = -10;
2723 y = 0;
2724 status = GdipIsVisiblePoint(graphics, x, y, &val);
2725 expect(Ok, status);
2726 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2728 x = 0;
2729 y = -5;
2730 status = GdipIsVisiblePoint(graphics, x, y, &val);
2731 expect(Ok, status);
2732 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2734 x = 1;
2735 y = 1;
2736 status = GdipIsVisiblePoint(graphics, x, y, &val);
2737 expect(Ok, status);
2738 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2740 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2741 expect(Ok, status);
2743 x = 1;
2744 y = 1;
2745 status = GdipIsVisiblePoint(graphics, x, y, &val);
2746 expect(Ok, status);
2747 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2749 x = 15.5;
2750 y = 40.5;
2751 status = GdipIsVisiblePoint(graphics, x, y, &val);
2752 expect(Ok, status);
2753 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2755 /* translate into the center of the rect */
2756 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2758 x = 0;
2759 y = 0;
2760 status = GdipIsVisiblePoint(graphics, x, y, &val);
2761 expect(Ok, status);
2762 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2764 x = 25;
2765 y = 40;
2766 status = GdipIsVisiblePoint(graphics, x, y, &val);
2767 expect(Ok, status);
2768 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2770 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2772 /* corner cases */
2773 x = 9;
2774 y = 19;
2775 status = GdipIsVisiblePoint(graphics, x, y, &val);
2776 expect(Ok, status);
2777 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2779 x = 9.25;
2780 y = 19.25;
2781 status = GdipIsVisiblePoint(graphics, x, y, &val);
2782 expect(Ok, status);
2783 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2785 x = 9.5;
2786 y = 19.5;
2787 status = GdipIsVisiblePoint(graphics, x, y, &val);
2788 expect(Ok, status);
2789 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2791 x = 9.75;
2792 y = 19.75;
2793 status = GdipIsVisiblePoint(graphics, x, y, &val);
2794 expect(Ok, status);
2795 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2797 x = 10;
2798 y = 20;
2799 status = GdipIsVisiblePoint(graphics, x, y, &val);
2800 expect(Ok, status);
2801 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2803 x = 40;
2804 y = 20;
2805 status = GdipIsVisiblePoint(graphics, x, y, &val);
2806 expect(Ok, status);
2807 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2809 x = 39;
2810 y = 59;
2811 status = GdipIsVisiblePoint(graphics, x, y, &val);
2812 expect(Ok, status);
2813 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2815 x = 39.25;
2816 y = 59.25;
2817 status = GdipIsVisiblePoint(graphics, x, y, &val);
2818 expect(Ok, status);
2819 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2821 x = 39.5;
2822 y = 39.5;
2823 status = GdipIsVisiblePoint(graphics, x, y, &val);
2824 expect(Ok, status);
2825 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2827 x = 39.75;
2828 y = 59.75;
2829 status = GdipIsVisiblePoint(graphics, x, y, &val);
2830 expect(Ok, status);
2831 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2833 x = 40;
2834 y = 60;
2835 status = GdipIsVisiblePoint(graphics, x, y, &val);
2836 expect(Ok, status);
2837 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2839 x = 40.15;
2840 y = 60.15;
2841 status = GdipIsVisiblePoint(graphics, x, y, &val);
2842 expect(Ok, status);
2843 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2845 x = 10;
2846 y = 60;
2847 status = GdipIsVisiblePoint(graphics, x, y, &val);
2848 expect(Ok, status);
2849 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2851 /* integer version */
2852 x = 25;
2853 y = 30;
2854 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2855 expect(Ok, status);
2856 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2858 x = 50;
2859 y = 100;
2860 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2861 expect(Ok, status);
2862 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2864 GdipDeleteGraphics(graphics);
2865 ReleaseDC(hwnd, hdc);
2868 static void test_GdipIsVisibleRect(void)
2870 GpStatus status;
2871 GpGraphics *graphics = NULL;
2872 HDC hdc = GetDC( hwnd );
2873 REAL x, y, width, height;
2874 BOOL val;
2876 ok(hdc != NULL, "Expected HDC to be initialized\n");
2878 status = GdipCreateFromHDC(hdc, &graphics);
2879 expect(Ok, status);
2880 ok(graphics != NULL, "Expected graphics to be initialized\n");
2882 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2883 expect(InvalidParameter, status);
2885 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2886 expect(InvalidParameter, status);
2888 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2889 expect(InvalidParameter, status);
2891 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2892 expect(InvalidParameter, status);
2894 /* entirely within the visible region */
2895 x = 0; width = 10;
2896 y = 0; height = 10;
2897 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2898 expect(Ok, status);
2899 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2901 /* partially outside */
2902 x = -10; width = 20;
2903 y = -10; height = 20;
2904 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2905 expect(Ok, status);
2906 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2908 /* entirely outside */
2909 x = -10; width = 5;
2910 y = -10; height = 5;
2911 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2912 expect(Ok, status);
2913 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2915 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2916 expect(Ok, status);
2918 /* entirely within the visible region */
2919 x = 12; width = 10;
2920 y = 22; height = 10;
2921 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2922 expect(Ok, status);
2923 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2925 /* partially outside */
2926 x = 35; width = 10;
2927 y = 55; height = 10;
2928 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2929 expect(Ok, status);
2930 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2932 /* entirely outside */
2933 x = 45; width = 5;
2934 y = 65; height = 5;
2935 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2936 expect(Ok, status);
2937 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2939 /* translate into center of clipping rect */
2940 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2942 x = 0; width = 10;
2943 y = 0; height = 10;
2944 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2945 expect(Ok, status);
2946 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2948 x = 25; width = 5;
2949 y = 40; height = 5;
2950 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2951 expect(Ok, status);
2952 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2954 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2956 /* corners entirely outside, but some intersections */
2957 x = 0; width = 70;
2958 y = 0; height = 90;
2959 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2960 expect(Ok, status);
2961 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2963 x = 0; width = 70;
2964 y = 0; height = 30;
2965 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2966 expect(Ok, status);
2967 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2969 x = 0; width = 30;
2970 y = 0; height = 90;
2971 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2972 expect(Ok, status);
2973 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2975 /* edge cases */
2976 x = 0; width = 10;
2977 y = 20; height = 40;
2978 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2979 expect(Ok, status);
2980 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2982 x = 10; width = 30;
2983 y = 0; height = 20;
2984 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2985 expect(Ok, status);
2986 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2988 x = 40; width = 10;
2989 y = 20; height = 40;
2990 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2991 expect(Ok, status);
2992 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2994 x = 10; width = 30;
2995 y = 60; height = 10;
2996 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2997 expect(Ok, status);
2998 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
3000 /* rounding tests */
3001 x = 0.4; width = 10.4;
3002 y = 20; height = 40;
3003 status = GdipIsVisibleRect(graphics, x, y, width, 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 = 10; width = 30;
3008 y = 0.4; height = 20.4;
3009 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
3010 expect(Ok, status);
3011 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3013 /* integer version */
3014 x = 0; width = 30;
3015 y = 0; height = 90;
3016 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
3017 expect(Ok, status);
3018 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3020 x = 12; width = 10;
3021 y = 22; height = 10;
3022 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
3023 expect(Ok, status);
3024 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3026 GdipDeleteGraphics(graphics);
3027 ReleaseDC(hwnd, hdc);
3030 static void test_GdipGetNearestColor(void)
3032 GpStatus status;
3033 GpGraphics *graphics;
3034 GpBitmap *bitmap;
3035 ARGB color = 0xdeadbeef;
3036 HDC hdc = GetDC( hwnd );
3038 /* create a graphics object */
3039 ok(hdc != NULL, "Expected HDC to be initialized\n");
3041 status = GdipCreateFromHDC(hdc, &graphics);
3042 expect(Ok, status);
3043 ok(graphics != NULL, "Expected graphics to be initialized\n");
3045 status = GdipGetNearestColor(graphics, NULL);
3046 expect(InvalidParameter, status);
3048 status = GdipGetNearestColor(NULL, &color);
3049 expect(InvalidParameter, status);
3050 GdipDeleteGraphics(graphics);
3052 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, 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, PixelFormat4bppIndexed, 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, PixelFormat8bppIndexed, NULL, &bitmap);
3079 expect(Ok, status);
3080 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3081 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3082 if (status == Ok)
3084 status = GdipGetNearestColor(graphics, &color);
3085 expect(Ok, status);
3086 expect(0xdeadbeef, color);
3087 GdipDeleteGraphics(graphics);
3089 GdipDisposeImage((GpImage*)bitmap);
3091 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
3092 expect(Ok, status);
3093 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3094 todo_wine expect(OutOfMemory, status);
3095 if (status == Ok)
3096 GdipDeleteGraphics(graphics);
3097 GdipDisposeImage((GpImage*)bitmap);
3099 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
3100 expect(Ok, status);
3101 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3102 expect(Ok, status);
3103 status = GdipGetNearestColor(graphics, &color);
3104 expect(Ok, status);
3105 expect(0xdeadbeef, color);
3106 GdipDeleteGraphics(graphics);
3107 GdipDisposeImage((GpImage*)bitmap);
3109 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
3110 expect(Ok, status);
3111 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3112 expect(Ok, status);
3113 status = GdipGetNearestColor(graphics, &color);
3114 expect(Ok, status);
3115 expect(0xdeadbeef, color);
3116 GdipDeleteGraphics(graphics);
3117 GdipDisposeImage((GpImage*)bitmap);
3119 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
3120 expect(Ok, status);
3121 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3122 expect(Ok, status);
3123 status = GdipGetNearestColor(graphics, &color);
3124 expect(Ok, status);
3125 expect(0xdeadbeef, color);
3126 GdipDeleteGraphics(graphics);
3127 GdipDisposeImage((GpImage*)bitmap);
3129 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, 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, PixelFormat64bppARGB, 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, PixelFormat64bppPARGB, NULL, &bitmap);
3156 expect(Ok, status);
3157 if (status == Ok)
3159 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3160 expect(Ok, status);
3161 status = GdipGetNearestColor(graphics, &color);
3162 expect(Ok, status);
3163 expect(0xdeadbeef, color);
3164 GdipDeleteGraphics(graphics);
3165 GdipDisposeImage((GpImage*)bitmap);
3168 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
3169 expect(Ok, status);
3170 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3171 expect(Ok, status);
3172 status = GdipGetNearestColor(graphics, &color);
3173 expect(Ok, status);
3174 todo_wine expect(0xffa8bce8, color);
3175 GdipDeleteGraphics(graphics);
3176 GdipDisposeImage((GpImage*)bitmap);
3178 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
3179 expect(Ok, status);
3180 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3181 expect(Ok, status);
3182 status = GdipGetNearestColor(graphics, &color);
3183 expect(Ok, status);
3184 todo_wine
3185 ok(color == 0xffa8b8e8 ||
3186 broken(color == 0xffa0b8e0), /* Win98/WinMe */
3187 "Expected ffa8b8e8, got %.8lx\n", color);
3188 GdipDeleteGraphics(graphics);
3189 GdipDisposeImage((GpImage*)bitmap);
3191 ReleaseDC(hwnd, hdc);
3194 static void test_string_functions(void)
3196 GpStatus status;
3197 GpGraphics *graphics;
3198 GpFontFamily *family;
3199 GpFont *font;
3200 RectF rc, char_bounds, bounds;
3201 GpBrush *brush;
3202 ARGB color = 0xff000000;
3203 HDC hdc = GetDC( hwnd );
3204 const WCHAR teststring[] = L"MM M\nM";
3205 const WCHAR teststring2[] = L"j";
3206 const WCHAR teststring3[] = L"MM M\r\nM\0";
3207 REAL char_width, char_height;
3208 INT codepointsfitted, linesfilled;
3209 GpStringFormat *format;
3210 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
3211 GpRegion *regions[4];
3212 BOOL region_isempty[4];
3213 int i;
3214 PointF positions[8];
3215 GpMatrix *identity;
3217 ok(hdc != NULL, "Expected HDC to be initialized\n");
3218 status = GdipCreateFromHDC(hdc, &graphics);
3219 expect(Ok, status);
3220 ok(graphics != NULL, "Expected graphics to be initialized\n");
3222 status = GdipCreateFontFamilyFromName(L"Tahoma", NULL, &family);
3223 expect(Ok, status);
3225 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
3226 expect(Ok, status);
3228 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
3229 expect(Ok, status);
3231 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3232 expect(Ok, status);
3234 rc.X = 0;
3235 rc.Y = 0;
3236 rc.Width = 100.0;
3237 rc.Height = 100.0;
3239 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
3240 expect(InvalidParameter, status);
3242 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
3243 expect(InvalidParameter, status);
3245 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
3246 expect(InvalidParameter, status);
3248 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
3249 expect(InvalidParameter, status);
3251 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
3252 expect(InvalidParameter, status);
3254 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
3255 expect(Ok, status);
3257 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3258 expect(InvalidParameter, status);
3260 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3261 expect(InvalidParameter, status);
3263 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3264 expect(InvalidParameter, status);
3266 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3267 expect(InvalidParameter, status);
3269 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3270 expect(InvalidParameter, status);
3272 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3273 expect(Ok, status);
3275 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3276 expect(Ok, status);
3278 /* new line handling */
3279 status = GdipMeasureString(graphics, teststring3, -1, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3280 expect(Ok, status);
3281 expect(7, codepointsfitted);
3282 expect(2, linesfilled);
3284 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3285 expect(Ok, status);
3286 expectf(0.0, char_bounds.X);
3287 expectf(0.0, char_bounds.Y);
3288 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3289 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3290 expect(1, codepointsfitted);
3291 expect(1, linesfilled);
3293 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3294 expect(Ok, status);
3295 expectf(0.0, bounds.X);
3296 expectf(0.0, bounds.Y);
3297 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3298 expectf(char_bounds.Height, bounds.Height);
3299 expect(2, codepointsfitted);
3300 expect(1, linesfilled);
3301 char_width = bounds.Width - char_bounds.Width;
3303 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3304 expect(Ok, status);
3305 expectf(0.0, bounds.X);
3306 expectf(0.0, bounds.Y);
3307 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3308 bounds.Width, char_bounds.Width + char_width * 2);
3309 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3310 expect(6, codepointsfitted);
3311 expect(2, linesfilled);
3312 char_height = bounds.Height - char_bounds.Height;
3314 /* Measure the first line. */
3315 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3316 expect(Ok, status);
3317 expectf(0.0, bounds.X);
3318 expectf(0.0, bounds.Y);
3319 expect(4, codepointsfitted);
3320 expect(1, linesfilled);
3322 /* Give just enough space to fit the first line. */
3323 rc.Width = bounds.Width;
3324 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3325 expect(Ok, status);
3326 expectf(0.0, bounds.X);
3327 expectf(0.0, bounds.Y);
3328 todo_wine expect(5, codepointsfitted);
3329 todo_wine expect(1, linesfilled);
3331 /* Cut off everything after the first space. */
3332 rc.Width = char_bounds.Width + char_width * 2.1;
3334 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3335 expect(Ok, status);
3336 expectf(0.0, bounds.X);
3337 expectf(0.0, bounds.Y);
3338 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3339 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3340 expect(6, codepointsfitted);
3341 expect(3, linesfilled);
3343 /* Cut off everything including the first space. */
3344 rc.Width = char_bounds.Width + char_width * 1.7;
3346 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3347 expect(Ok, status);
3348 expectf(0.0, bounds.X);
3349 expectf(0.0, bounds.Y);
3350 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3351 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3352 expect(6, codepointsfitted);
3353 expect(3, linesfilled);
3355 /* Cut off everything after the first character. */
3356 rc.Width = char_bounds.Width + char_width * 0.8;
3358 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3359 expect(Ok, status);
3360 expectf(0.0, bounds.X);
3361 expectf(0.0, bounds.Y);
3362 expectf_(char_bounds.Width, bounds.Width, 0.01);
3363 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3364 expect(6, codepointsfitted);
3365 todo_wine expect(4, linesfilled);
3367 for (i = 0; i < 4; i++)
3368 regions[i] = (GpRegion *)0xdeadbeef;
3370 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3371 expect(Ok, status);
3373 for (i = 0; i < 4; i++)
3374 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3376 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3377 expect(Ok, status);
3379 for (i = 0; i < 4; i++)
3380 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3382 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3383 expect(Ok, status);
3385 set_rect_empty(&rc);
3387 for (i=0; i<4; i++)
3389 status = GdipCreateRegion(&regions[i]);
3390 expect(Ok, status);
3391 status = GdipSetEmpty(regions[i]);
3392 expect(Ok, status);
3395 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3396 expect(InvalidParameter, status);
3398 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3399 expect(InvalidParameter, status);
3401 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3402 expect(InvalidParameter, status);
3404 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3405 expect(InvalidParameter, status);
3407 if (0)
3409 /* Crashes on Windows XP */
3410 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3411 expect(InvalidParameter, status);
3414 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3415 expect(InvalidParameter, status);
3417 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3418 expect(InvalidParameter, status);
3420 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3421 expect(Ok, status);
3423 for (i = 0; i < 4; i++)
3425 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3426 expect(Ok, status);
3429 ok(region_isempty[0], "region should be empty\n");
3430 ok(region_isempty[1], "region should be empty\n");
3431 ok(region_isempty[2], "region should be empty\n");
3432 ok(region_isempty[3], "region should be empty\n");
3434 rc.Width = 100.0;
3435 rc.Height = 100.0;
3437 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3438 expect(Ok, status);
3440 for (i=0; i<4; i++)
3442 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3443 expect(Ok, status);
3446 ok(!region_isempty[0], "region shouldn't be empty\n");
3447 ok(!region_isempty[1], "region shouldn't be empty\n");
3448 ok(!region_isempty[2], "region shouldn't be empty\n");
3449 ok(region_isempty[3], "region should be empty\n");
3451 /* Cut off everything after the first space, and the second line. */
3452 rc.Width = char_bounds.Width + char_width * 2.1;
3453 rc.Height = char_bounds.Height + char_height * 0.5;
3455 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3456 expect(Ok, status);
3458 for (i=0; i<4; i++)
3460 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3461 expect(Ok, status);
3464 ok(!region_isempty[0], "region shouldn't be empty\n");
3465 ok(!region_isempty[1], "region shouldn't be empty\n");
3466 ok(region_isempty[2], "region should be empty\n");
3467 ok(region_isempty[3], "region should be empty\n");
3469 for (i=0; i<4; i++)
3470 GdipDeleteRegion(regions[i]);
3472 status = GdipCreateMatrix(&identity);
3473 expect(Ok, status);
3475 rc.X = 0;
3476 rc.Y = 0;
3477 rc.Width = 0;
3478 rc.Height = 0;
3479 memset(positions, 0, sizeof(positions));
3480 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3481 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3482 identity, &rc);
3483 expect(InvalidParameter, status);
3485 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3486 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3487 identity, &rc);
3488 expect(InvalidParameter, status);
3490 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3491 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3492 identity, &rc);
3493 expect(InvalidParameter, status);
3495 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3496 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3497 identity, &rc);
3498 expect(InvalidParameter, status);
3500 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3501 0x100, identity, &rc);
3502 expect(Ok, status);
3504 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3505 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3506 NULL, &rc);
3507 expect(Ok, status);
3509 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3510 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3511 identity, NULL);
3512 expect(InvalidParameter, status);
3514 rc.X = 0;
3515 rc.Y = 0;
3516 rc.Width = 0;
3517 rc.Height = 0;
3518 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3519 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3520 identity, &rc);
3521 expect(Ok, status);
3523 expectf(0.0, rc.X);
3524 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3525 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3526 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3528 char_width = rc.Width;
3529 char_height = rc.Height;
3531 rc.X = 0;
3532 rc.Y = 0;
3533 rc.Width = 0;
3534 rc.Height = 0;
3535 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3536 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3537 identity, &rc);
3538 expect(Ok, status);
3540 expectf(0.0, rc.X);
3541 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3542 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3543 expectf(char_height, rc.Height);
3545 rc.X = 0;
3546 rc.Y = 0;
3547 rc.Width = 0;
3548 rc.Height = 0;
3549 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3550 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3551 identity, &rc);
3552 expect(Ok, status);
3554 expectf(rc.X, 0.0);
3555 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3556 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3557 expectf(rc.Height, char_height);
3559 GdipDeleteMatrix(identity);
3560 GdipDeleteStringFormat(format);
3561 GdipDeleteBrush(brush);
3562 GdipDeleteFont(font);
3563 GdipDeleteFontFamily(family);
3564 GdipDeleteGraphics(graphics);
3566 ReleaseDC(hwnd, hdc);
3569 static void test_get_set_interpolation(void)
3571 GpGraphics *graphics;
3572 HDC hdc = GetDC( hwnd );
3573 GpStatus status;
3574 InterpolationMode mode;
3576 ok(hdc != NULL, "Expected HDC to be initialized\n");
3577 status = GdipCreateFromHDC(hdc, &graphics);
3578 expect(Ok, status);
3579 ok(graphics != NULL, "Expected graphics to be initialized\n");
3581 status = GdipGetInterpolationMode(NULL, &mode);
3582 expect(InvalidParameter, status);
3584 if (0)
3586 /* Crashes on Windows XP */
3587 status = GdipGetInterpolationMode(graphics, NULL);
3588 expect(InvalidParameter, status);
3591 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3592 expect(InvalidParameter, status);
3594 /* out of range */
3595 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3596 expect(InvalidParameter, status);
3598 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3599 expect(InvalidParameter, status);
3601 status = GdipGetInterpolationMode(graphics, &mode);
3602 expect(Ok, status);
3603 expect(InterpolationModeBilinear, mode);
3605 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3606 expect(Ok, status);
3608 status = GdipGetInterpolationMode(graphics, &mode);
3609 expect(Ok, status);
3610 expect(InterpolationModeNearestNeighbor, mode);
3612 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3613 expect(Ok, status);
3615 status = GdipGetInterpolationMode(graphics, &mode);
3616 expect(Ok, status);
3617 expect(InterpolationModeBilinear, mode);
3619 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3620 expect(Ok, status);
3622 status = GdipGetInterpolationMode(graphics, &mode);
3623 expect(Ok, status);
3624 expect(InterpolationModeBilinear, mode);
3626 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3627 expect(Ok, status);
3629 status = GdipGetInterpolationMode(graphics, &mode);
3630 expect(Ok, status);
3631 expect(InterpolationModeHighQualityBicubic, mode);
3633 GdipDeleteGraphics(graphics);
3635 ReleaseDC(hwnd, hdc);
3638 static void test_get_set_textrenderinghint(void)
3640 GpGraphics *graphics;
3641 HDC hdc = GetDC( hwnd );
3642 GpStatus status;
3643 TextRenderingHint hint;
3645 ok(hdc != NULL, "Expected HDC to be initialized\n");
3646 status = GdipCreateFromHDC(hdc, &graphics);
3647 expect(Ok, status);
3648 ok(graphics != NULL, "Expected graphics to be initialized\n");
3650 status = GdipGetTextRenderingHint(NULL, &hint);
3651 expect(InvalidParameter, status);
3653 status = GdipGetTextRenderingHint(graphics, NULL);
3654 expect(InvalidParameter, status);
3656 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3657 expect(InvalidParameter, status);
3659 /* out of range */
3660 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3661 expect(InvalidParameter, status);
3663 status = GdipGetTextRenderingHint(graphics, &hint);
3664 expect(Ok, status);
3665 expect(TextRenderingHintSystemDefault, hint);
3667 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3668 expect(Ok, status);
3670 status = GdipGetTextRenderingHint(graphics, &hint);
3671 expect(Ok, status);
3672 expect(TextRenderingHintSystemDefault, hint);
3674 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3675 expect(Ok, status);
3677 status = GdipGetTextRenderingHint(graphics, &hint);
3678 expect(Ok, status);
3679 expect(TextRenderingHintAntiAliasGridFit, hint);
3681 GdipDeleteGraphics(graphics);
3683 ReleaseDC(hwnd, hdc);
3686 static void test_getdc_scaled(void)
3688 GpStatus status;
3689 GpGraphics *graphics = NULL;
3690 GpBitmap *bitmap = NULL;
3691 HDC hdc=NULL;
3692 HBRUSH hbrush, holdbrush;
3693 ARGB color;
3695 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3696 expect(Ok, status);
3698 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3699 expect(Ok, status);
3701 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3702 expect(Ok, status);
3704 status = GdipGetDC(graphics, &hdc);
3705 expect(Ok, status);
3706 ok(hdc != NULL, "got NULL hdc\n");
3708 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3710 holdbrush = SelectObject(hdc, hbrush);
3712 Rectangle(hdc, 2, 2, 6, 6);
3714 SelectObject(hdc, holdbrush);
3716 DeleteObject(hbrush);
3718 status = GdipReleaseDC(graphics, hdc);
3719 expect(Ok, status);
3721 GdipDeleteGraphics(graphics);
3723 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3724 expect(Ok, status);
3725 expect(0xffff0000, color);
3727 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3728 expect(Ok, status);
3729 expect(0xff000000, color);
3731 GdipDisposeImage((GpImage*)bitmap);
3734 static void test_GdipMeasureString(void)
3736 static const struct test_data
3738 REAL res_x, res_y, page_scale;
3739 GpUnit unit;
3740 } td[] =
3742 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3743 { 200.0, 200.0, 2.0, UnitPixel },
3744 { 200.0, 200.0, 1.0, UnitDisplay },
3745 { 200.0, 200.0, 2.0, UnitDisplay },
3746 { 200.0, 200.0, 1.0, UnitInch },
3747 { 200.0, 200.0, 2.0, UnitInch },
3748 { 200.0, 600.0, 1.0, UnitPoint },
3749 { 200.0, 600.0, 2.0, UnitPoint },
3750 { 200.0, 600.0, 1.0, UnitDocument },
3751 { 200.0, 600.0, 2.0, UnitDocument },
3752 { 200.0, 600.0, 1.0, UnitMillimeter },
3753 { 200.0, 600.0, 2.0, UnitMillimeter },
3754 { 200.0, 600.0, 1.0, UnitDisplay },
3755 { 200.0, 600.0, 2.0, UnitDisplay },
3756 { 200.0, 600.0, 1.0, UnitPixel },
3757 { 200.0, 600.0, 2.0, UnitPixel },
3759 static const WCHAR string[] = L"1234567";
3760 GpStatus status;
3761 GpGraphics *graphics;
3762 GpFontFamily *family;
3763 GpFont *font;
3764 GpStringFormat *format;
3765 RectF bounds, rc;
3766 REAL base_cx = 0, base_cy = 0, height;
3767 INT chars, lines;
3768 LOGFONTW lf;
3769 UINT i;
3770 REAL font_size;
3771 GpUnit font_unit, unit;
3773 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3774 expect(Ok, status);
3775 status = GdipCreateFontFamilyFromName(L"Tahoma", NULL, &family);
3776 expect(Ok, status);
3778 /* font size in pixels */
3779 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3780 expect(Ok, status);
3781 status = GdipGetFontSize(font, &font_size);
3782 expect(Ok, status);
3783 expectf(100.0, font_size);
3784 status = GdipGetFontUnit(font, &font_unit);
3785 expect(Ok, status);
3786 expect(UnitPixel, font_unit);
3788 for (i = 0; i < ARRAY_SIZE(td); i++)
3790 GpImage *image;
3792 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3794 lf.lfHeight = 0xdeadbeef;
3795 status = GdipGetLogFontW(font, graphics, &lf);
3796 expect(Ok, status);
3797 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3798 if (td[i].unit != UnitDisplay)
3799 height *= td[i].page_scale;
3800 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %ld (%f), got %ld\n",
3801 i, (LONG)(height + 0.5), height, lf.lfHeight);
3803 height = font_size + 2.0 * font_size / 6.0;
3805 set_rect_empty(&rc);
3806 set_rect_empty(&bounds);
3807 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3808 expect(Ok, status);
3810 if (i == 0)
3812 base_cx = bounds.Width;
3813 base_cy = bounds.Height;
3816 expectf(0.0, bounds.X);
3817 expectf(0.0, bounds.Y);
3818 todo_wine
3819 expectf_(height, bounds.Height, height / 100.0);
3820 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3821 expect(7, chars);
3822 expect(1, lines);
3824 /* make sure it really fits */
3825 bounds.Width += 1.0;
3826 bounds.Height += 1.0;
3827 rc = bounds;
3828 rc.X = 50.0;
3829 rc.Y = 50.0;
3830 set_rect_empty(&bounds);
3831 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3832 expect(Ok, status);
3833 expectf(50.0, bounds.X);
3834 expectf(50.0, bounds.Y);
3835 todo_wine
3836 expectf_(height, bounds.Height, height / 100.0);
3837 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3838 expect(7, chars);
3839 expect(1, lines);
3841 status = GdipDeleteGraphics(graphics);
3842 expect(Ok, status);
3844 status = GdipDisposeImage(image);
3845 expect(Ok, status);
3848 GdipDeleteFont(font);
3850 /* font size in logical units */
3851 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3852 for (unit = 3; unit <= 6; unit++)
3854 /* create a font which final height is 100.0 pixels with 200 dpi device */
3855 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3856 height = pixels_to_units(75.0, unit, 200.0);
3857 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3858 expect(Ok, status);
3859 status = GdipGetFontSize(font, &font_size);
3860 expect(Ok, status);
3861 expectf(height, font_size);
3862 status = GdipGetFontUnit(font, &font_unit);
3863 expect(Ok, status);
3864 expect(unit, font_unit);
3866 for (i = 0; i < ARRAY_SIZE(td); i++)
3868 REAL unit_scale;
3869 GpImage *image;
3871 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3873 lf.lfHeight = 0xdeadbeef;
3874 status = GdipGetLogFontW(font, graphics, &lf);
3875 expect(Ok, status);
3876 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3877 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3878 else
3879 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3880 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3881 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %ld (%f), got %ld\n",
3882 i, (LONG)(height + 0.5), height, lf.lfHeight);
3884 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3885 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3886 else
3887 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3888 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3889 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3890 if (td[i].unit != UnitDisplay)
3891 height /= td[i].page_scale;
3892 /*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);*/
3894 set_rect_empty(&rc);
3895 set_rect_empty(&bounds);
3896 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3897 expect(Ok, status);
3899 if (i == 0)
3901 base_cx = bounds.Width;
3902 base_cy = bounds.Height;
3905 expectf(0.0, bounds.X);
3906 expectf(0.0, bounds.Y);
3907 todo_wine
3908 expectf_(height, bounds.Height, height / 85.0);
3909 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3910 expect(7, chars);
3911 expect(1, lines);
3913 /* make sure it really fits */
3914 bounds.Width += 1.0;
3915 bounds.Height += 1.0;
3916 rc = bounds;
3917 rc.X = 50.0;
3918 rc.Y = 50.0;
3919 set_rect_empty(&bounds);
3920 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3921 expect(Ok, status);
3922 expectf(50.0, bounds.X);
3923 expectf(50.0, bounds.Y);
3924 todo_wine
3925 expectf_(height, bounds.Height, height / 85.0);
3926 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3927 expect(7, chars);
3928 expect(1, lines);
3930 /* verify the result */
3931 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3932 if (td[i].unit != UnitDisplay)
3933 height *= td[i].page_scale;
3934 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3935 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3936 todo_wine
3937 expectf_(100.0, height, 1.1);
3939 status = GdipDeleteGraphics(graphics);
3940 expect(Ok, status);
3942 status = GdipDisposeImage(image);
3943 expect(Ok, status);
3946 GdipDeleteFont(font);
3949 /* Font with units = UnitWorld */
3950 for (i = 0; i < ARRAY_SIZE(td); i++)
3952 GpPointF pt = {0.0, 100.0};
3953 GpImage* image;
3954 REAL expected_width, expected_height;
3956 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3958 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3959 expect(Ok, status);
3961 status = GdipCreateFont(family, pt.Y, FontStyleRegular, UnitWorld, &font);
3962 expect(Ok, status);
3964 status = GdipGetFontUnit(font, &font_unit);
3965 expect(Ok, status);
3966 expect(UnitWorld, font_unit);
3968 lf.lfHeight = 0xdeadbeef;
3969 status = GdipGetLogFontW(font, graphics, &lf);
3970 expect(Ok, status);
3971 ok(lf.lfHeight == -100, "%u: expected -100, got %ld\n", i, lf.lfHeight);
3973 set_rect_empty(&rc);
3974 set_rect_empty(&bounds);
3975 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3976 expect(Ok, status);
3978 if (i == 0)
3980 base_cx = bounds.Width;
3981 base_cy = bounds.Height;
3984 pt.X = 1.0;
3985 pt.Y = 1.0;
3987 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3988 expect(Ok, status);
3990 /* height is constant in device space, width is proportional to height in world space */
3991 expected_width = base_cx * pt.Y;
3992 expected_height = base_cy * pt.Y;
3994 todo_wine_if(td[i].unit != UnitDisplay && td[i].unit != UnitPixel)
3995 ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width);
3996 ok(fabs(expected_height - bounds.Height) <= 0.001, "%u: expected %f, got %f\n", i, expected_height, bounds.Height);
3998 GdipDeleteGraphics(graphics);
3999 GdipDisposeImage(image);
4000 GdipDeleteFont(font);
4003 GdipDeleteFontFamily(family);
4004 GdipDeleteStringFormat(format);
4007 static void test_transform(void)
4009 static const struct test_data
4011 REAL res_x, res_y, scale;
4012 GpUnit unit;
4013 GpPointF in[2], out[2];
4014 } td[] =
4016 { 96.0, 96.0, 1.0, UnitPixel,
4017 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4018 { 96.0, 96.0, 1.0, UnitDisplay,
4019 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4020 { 96.0, 96.0, 1.0, UnitInch,
4021 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
4022 { 123.0, 456.0, 1.0, UnitPoint,
4023 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
4024 { 123.0, 456.0, 1.0, UnitDocument,
4025 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
4026 { 123.0, 456.0, 2.0, UnitMillimeter,
4027 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
4028 { 196.0, 296.0, 1.0, UnitDisplay,
4029 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4030 { 196.0, 296.0, 1.0, UnitPixel,
4031 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4033 GpStatus status;
4034 GpGraphics *graphics;
4035 GpImage *image;
4036 GpPointF ptf[2];
4037 UINT i;
4039 for (i = 0; i < ARRAY_SIZE(td); i++)
4041 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
4042 ptf[0].X = td[i].in[0].X;
4043 ptf[0].Y = td[i].in[0].Y;
4044 ptf[1].X = td[i].in[1].X;
4045 ptf[1].Y = td[i].in[1].Y;
4046 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
4047 expect(Ok, status);
4048 expectf(td[i].out[0].X, ptf[0].X);
4049 expectf(td[i].out[0].Y, ptf[0].Y);
4050 expectf(td[i].out[1].X, ptf[1].X);
4051 expectf(td[i].out[1].Y, ptf[1].Y);
4052 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4053 expect(Ok, status);
4054 expectf(td[i].in[0].X, ptf[0].X);
4055 expectf(td[i].in[0].Y, ptf[0].Y);
4056 expectf(td[i].in[1].X, ptf[1].X);
4057 expectf(td[i].in[1].Y, ptf[1].Y);
4058 status = GdipDeleteGraphics(graphics);
4059 expect(Ok, status);
4060 status = GdipDisposeImage(image);
4061 expect(Ok, status);
4065 static void test_set_page_transform(void)
4067 static const struct
4069 GpUnit unit;
4070 BOOL isInvalid;
4071 } td_unit[] =
4073 {UnitWorld, TRUE},
4074 {UnitDisplay},
4075 {UnitPixel},
4076 {UnitPoint},
4077 {UnitInch},
4078 {UnitDocument},
4079 {UnitMillimeter},
4080 {UnitMillimeter + 1, TRUE},
4082 static const struct {
4083 REAL scale;
4084 BOOL isInvalid;
4085 } td_scale[] =
4087 {-1.0, TRUE},
4088 {0.0, TRUE},
4089 {0.5},
4090 {1.0},
4091 {2.0},
4093 GpStatus status;
4094 GpGraphics *graphics;
4095 HDC hdc = GetDC( hwnd );
4096 GpUnit unit;
4097 REAL scale;
4098 UINT i;
4100 status = GdipCreateFromHDC(hdc, &graphics);
4101 expect(Ok, status);
4103 for (i = 0; i < ARRAY_SIZE(td_unit); i++)
4105 winetest_push_context("%u", i);
4106 status = GdipSetPageUnit(graphics, td_unit[i].unit);
4107 todo_wine_if(td_unit[i].unit > UnitMillimeter)
4108 expect(td_unit[i].isInvalid ? InvalidParameter : Ok, status);
4109 if (status == Ok)
4111 status = GdipGetPageUnit(graphics, &unit);
4112 expect(Ok, status);
4113 expect(td_unit[i].unit, unit);
4115 winetest_pop_context();
4118 for (i = 0; i < ARRAY_SIZE(td_scale); i++)
4120 winetest_push_context("%u", i);
4121 status = GdipSetPageScale(graphics, td_scale[i].scale);
4122 expect(td_scale[i].isInvalid ? InvalidParameter : Ok, status);
4123 if (status == Ok)
4125 status = GdipGetPageScale(graphics, &scale);
4126 expect(Ok, status);
4127 expectf_(td_scale[i].scale, scale, 0);
4129 winetest_pop_context();
4132 status = GdipGetPageUnit(graphics, &unit);
4133 expect(Ok, status);
4134 todo_wine
4135 expect(UnitMillimeter, unit);
4136 status = GdipGetPageScale(graphics, &scale);
4137 expect(Ok, status);
4138 expectf_(2.0, scale, 0);
4139 status = GdipResetPageTransform(graphics);
4140 expect(Ok, status);
4141 status = GdipGetPageUnit(graphics, &unit);
4142 expect(Ok, status);
4143 expect(UnitDisplay, unit);
4144 status = GdipGetPageScale(graphics, &scale);
4145 expect(Ok, status);
4146 expectf_(1.0, scale, 0);
4148 GdipDeleteGraphics(graphics);
4149 ReleaseDC(hwnd, hdc);
4152 static void test_pen_thickness(void)
4154 static const struct test_data
4156 REAL res_x, res_y, scale;
4157 GpUnit pen_unit, page_unit;
4158 REAL pen_width;
4159 INT cx, cy, path_cx, path_cy;
4160 } td[] =
4162 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 1.0, 1, 1, 1, 1 },
4163 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 0.0, 0, 0, 1, 1 },
4164 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 0.1, 1, 1, 1, 1 },
4165 { 10.0, 10.0, 3.0, UnitPixel, UnitPixel, 2.0, 2, 2, 2, 2 },
4166 { 10.0, 10.0, 30.0, UnitPixel, UnitInch, 1.0, 1, 1, 1, 1 },
4167 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 1.0, 1, 1, 1, 1 },
4168 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 0.0, 1, 1, 1, 1 },
4169 { 10.0, 10.0, 3.0, UnitWorld, UnitPixel, 2.0, 6, 6, 6, 6 },
4170 { 10.0, 10.0, 2.0, UnitWorld, UnitInch, 1.0, 20, 20, 20, 20 },
4172 GpStatus status;
4173 int i, j;
4174 GpGraphics *graphics;
4175 union
4177 GpBitmap *bitmap;
4178 GpImage *image;
4179 } u;
4180 GpPen *pen;
4181 GpPointF corner;
4182 GpPath *path;
4183 BitmapData bd;
4184 INT min, max, size;
4186 for (i = 0; i < ARRAY_SIZE(td); i++)
4188 status = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat24bppRGB, NULL, &u.bitmap);
4189 expect(Ok, status);
4191 status = GdipBitmapSetResolution(u.bitmap, td[i].res_x, td[i].res_y);
4192 expect(Ok, status);
4194 status = GdipGetImageGraphicsContext(u.image, &graphics);
4195 expect(Ok, status);
4197 status = GdipSetPageUnit(graphics, td[i].page_unit);
4198 expect(Ok, status);
4200 status = GdipSetPageScale(graphics, td[i].scale);
4201 expect(Ok, status);
4203 status = GdipCreatePen1(0xffffffff, td[i].pen_width, td[i].pen_unit, &pen);
4204 expect(Ok, status);
4206 corner.X = corner.Y = 100.0;
4207 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &corner, 1);
4208 expect(Ok, status);
4210 status = GdipDrawLine(graphics, pen, corner.X/2, 0, corner.X/2, corner.Y);
4211 expect(Ok, status);
4213 status = GdipDrawLine(graphics, pen, 0, corner.Y/2, corner.X, corner.Y/2);
4214 expect(Ok, status);
4216 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
4217 expect(Ok, status);
4219 min = -1;
4220 max = -2;
4222 for (j=0; j<100; j++)
4224 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4226 min = j;
4227 break;
4231 for (j=99; j>=0; j--)
4233 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4235 max = j;
4236 break;
4240 size = max-min+1;
4242 ok(size == td[i].cx || broken (i == 1 && size == 1), "%u: expected %d, got %d\n", i, td[i].cx, size);
4244 min = -1;
4245 max = -2;
4247 for (j=0; j<100; j++)
4249 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4251 min = j;
4252 break;
4256 for (j=99; j>=0; j--)
4258 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4260 max = j;
4261 break;
4265 size = max-min+1;
4267 ok(size == td[i].cy || broken (i == 1 && size == 1), "%u: expected %d, got %d\n", i, td[i].cy, size);
4269 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4270 expect(Ok, status);
4272 status = GdipGraphicsClear(graphics, 0xff000000);
4273 expect(Ok, status);
4275 status = GdipCreatePath(FillModeAlternate, &path);
4276 expect(Ok, status);
4278 status = GdipAddPathLine(path, corner.X/2, 0, corner.X/2, corner.Y);
4279 expect(Ok, status);
4281 status = GdipClosePathFigure(path);
4282 expect(Ok, status);
4284 status = GdipAddPathLine(path, 0, corner.Y/2, corner.X, corner.Y/2);
4285 expect(Ok, status);
4287 status = GdipDrawPath(graphics, pen, path);
4288 expect(Ok, status);
4290 GdipDeletePath(path);
4292 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
4293 expect(Ok, status);
4295 min = -1;
4296 max = -2;
4298 for (j=0; j<100; j++)
4300 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4302 min = j;
4303 break;
4307 for (j=99; j>=0; j--)
4309 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4311 max = j;
4312 break;
4316 size = max-min+1;
4318 ok(size == td[i].path_cx, "%u: expected %d, got %d\n", i, td[i].path_cx, size);
4320 min = -1;
4321 max = -2;
4323 for (j=0; j<100; j++)
4325 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4327 min = j;
4328 break;
4332 for (j=99; j>=0; j--)
4334 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4336 max = j;
4337 break;
4341 size = max-min+1;
4343 ok(size == td[i].path_cy, "%u: expected %d, got %d\n", i, td[i].path_cy, size);
4345 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4346 expect(Ok, status);
4348 GdipDeletePen(pen);
4349 GdipDeleteGraphics(graphics);
4350 GdipDisposeImage(u.image);
4354 /* Many people on the net ask why there is so much difference in rendered
4355 * text height between gdiplus and gdi32, this test suggests an answer to
4356 * that question. Important: this test assumes that font dpi == device dpi.
4358 static void test_font_height_scaling(void)
4360 static const WCHAR string[] = L"1234567";
4361 HDC hdc;
4362 GpStringFormat *format;
4363 CharacterRange range = { 0, 7 };
4364 GpRegion *region;
4365 GpGraphics *graphics;
4366 GpFontFamily *family;
4367 GpFont *font;
4368 GpStatus status;
4369 RectF bounds, rect;
4370 REAL height, dpi, scale;
4371 PointF ptf;
4372 GpUnit gfx_unit, font_unit;
4374 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4375 expect(Ok, status);
4376 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4377 expect(Ok, status);
4378 status = GdipCreateRegion(&region);
4379 expect(Ok, status);
4381 status = GdipCreateFontFamilyFromName(L"Tahoma", NULL, &family);
4382 expect(Ok, status);
4384 hdc = CreateCompatibleDC(0);
4385 status = GdipCreateFromHDC(hdc, &graphics);
4386 expect(Ok, status);
4388 status = GdipGetDpiY(graphics, &dpi);
4389 expect(Ok, status);
4391 /* First check if tested functionality works:
4392 * under XP if font and graphics units differ then GdipTransformPoints
4393 * followed by GdipSetPageUnit to change the graphics units breaks region
4394 * scaling in GdipMeasureCharacterRanges called later.
4396 status = GdipSetPageUnit(graphics, UnitDocument);
4397 expect(Ok, status);
4399 ptf.X = 0.0;
4400 ptf.Y = 0.0;
4401 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4402 expect(Ok, status);
4404 status = GdipSetPageUnit(graphics, UnitInch);
4405 expect(Ok, status);
4407 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
4408 expect(Ok, status);
4410 set_rect_empty(&rect);
4411 set_rect_empty(&bounds);
4412 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4413 expect(Ok, status);
4414 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
4416 set_rect_empty(&rect);
4417 rect.Width = 32000.0;
4418 rect.Height = 32000.0;
4419 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4420 expect(Ok, status);
4422 set_rect_empty(&rect);
4423 status = GdipGetRegionBounds(region, graphics, &rect);
4424 expect(Ok, status);
4425 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4427 GdipDeleteFont(font);
4429 scale = rect.Height / bounds.Height;
4430 if (fabs(scale - 1.0) > 0.1)
4432 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
4433 goto cleanup;
4436 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
4437 expect(Ok, status);
4439 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4440 /* UnitPixel as a font base unit is not tested because it drastically
4441 differs in behaviour */
4442 for (font_unit = 3; font_unit <= 6; font_unit++)
4444 /* create a font for the final text height of 100 pixels */
4445 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
4446 status = GdipSetPageUnit(graphics, font_unit);
4447 expect(Ok, status);
4448 ptf.X = 0;
4449 ptf.Y = 75.0;
4450 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4451 expect(Ok, status);
4452 height = ptf.Y;
4453 /*trace("height %f units\n", height);*/
4454 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
4455 expect(Ok, status);
4457 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4458 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4460 RectF bounds_1, bounds_2;
4461 REAL margin, margin_y, font_height;
4462 int match;
4464 status = GdipSetPageUnit(graphics, gfx_unit);
4465 expect(Ok, status);
4467 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
4468 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
4470 status = GdipGetFontHeight(font, graphics, &font_height);
4471 expect(Ok, status);
4473 set_rect_empty(&rect);
4474 set_rect_empty(&bounds);
4475 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4476 expect(Ok, status);
4477 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
4478 todo_wine
4479 expectf_(font_height + margin_y, bounds.Height, 0.005);
4481 ptf.X = 0;
4482 ptf.Y = bounds.Height;
4483 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
4484 expect(Ok, status);
4485 match = fabs(100.0 - ptf.Y) <= 1.0;
4486 todo_wine
4487 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4489 /* verify the result */
4490 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
4491 ptf.Y /= 100.0;
4492 match = fabs(100.0 - ptf.Y) <= 1.0;
4493 todo_wine
4494 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4496 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4497 set_rect_empty(&rect);
4498 set_rect_empty(&bounds_1);
4499 status = GdipMeasureString(graphics, L"W", 1, font, &rect, format, &bounds_1, NULL, NULL);
4500 expect(Ok, status);
4501 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4502 set_rect_empty(&rect);
4503 set_rect_empty(&bounds_2);
4504 status = GdipMeasureString(graphics, L"WW", 2, font, &rect, format, &bounds_2, NULL, NULL);
4505 expect(Ok, status);
4507 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4508 margin = bounds_1.Width - bounds_2.Width / 2.0;
4509 /*trace("margin %f\n", margin);*/
4510 ok(margin > 0.0, "wrong margin %f\n", margin);
4512 set_rect_empty(&rect);
4513 rect.Width = 320000.0;
4514 rect.Height = 320000.0;
4515 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4516 expect(Ok, status);
4517 set_rect_empty(&rect);
4518 status = GdipGetRegionBounds(region, graphics, &rect);
4519 expect(Ok, status);
4520 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
4521 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
4522 expectf(0.0, rect.Y);
4523 match = fabs(1.0 - margin / rect.X) <= 0.05;
4524 ok(match, "Expected %f, got %f\n", margin, rect.X);
4525 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
4526 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
4527 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
4528 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
4531 GdipDeleteFont(font);
4534 cleanup:
4535 status = GdipDeleteGraphics(graphics);
4536 expect(Ok, status);
4537 DeleteDC(hdc);
4539 GdipDeleteFontFamily(family);
4540 GdipDeleteRegion(region);
4541 GdipDeleteStringFormat(format);
4544 static void test_measure_string(void)
4546 static const WCHAR string[] = L"A01";
4547 static const WCHAR string2[] = L"M MM";
4548 HDC hdc;
4549 GpStringFormat *format, *format_no_wrap;
4550 CharacterRange range;
4551 GpRegion *region;
4552 GpGraphics *graphics;
4553 GpFontFamily *family;
4554 GpFont *font;
4555 GpStatus status;
4556 RectF bounds, rect;
4557 REAL width, height, width_1, width_2, width_MM, width_M_M;
4558 REAL margin_x, margin_y, width_rgn, height_rgn;
4559 int lines, glyphs;
4561 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4562 expect(Ok, status);
4563 expect(Ok, status);
4565 status = GdipCreateRegion(&region);
4566 expect(Ok, status);
4568 status = GdipCreateFontFamilyFromName(L"Tahoma", NULL, &family);
4569 expect(Ok, status);
4571 hdc = CreateCompatibleDC(0);
4572 status = GdipCreateFromHDC(hdc, &graphics);
4574 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
4575 expect(Ok, status);
4577 margin_x = 20.0 / 6.0;
4578 margin_y = 20.0 / 8.0;
4580 set_rect_empty(&rect);
4581 set_rect_empty(&bounds);
4582 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4583 expect(Ok, status);
4584 expect(3, glyphs);
4585 expect(1, lines);
4586 expectf(0.0, bounds.X);
4587 expectf(0.0, bounds.Y);
4588 width = bounds.Width;
4589 height = bounds.Height;
4591 set_rect_empty(&rect);
4592 rect.Height = height / 2.0;
4593 set_rect_empty(&bounds);
4594 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4595 expect(Ok, status);
4596 expect(3, glyphs);
4597 expect(1, lines);
4598 expectf(0.0, bounds.X);
4599 expectf(0.0, bounds.Y);
4600 expectf(width, bounds.Width);
4601 todo_wine
4602 expectf(height / 2.0, bounds.Height);
4604 range.First = 0;
4605 range.Length = lstrlenW(string);
4606 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4607 expect(Ok, status);
4609 rect.X = 5.0;
4610 rect.Y = 5.0;
4611 rect.Width = 32000.0;
4612 rect.Height = 32000.0;
4613 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4614 expect(Ok, status);
4615 set_rect_empty(&bounds);
4616 status = GdipGetRegionBounds(region, graphics, &bounds);
4617 expect(Ok, status);
4618 expectf_(5.0 + margin_x, bounds.X, 1.0);
4619 expectf(5.0, bounds.Y);
4620 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4621 todo_wine
4622 expectf_(height - margin_y, bounds.Height, 1.0);
4624 width_rgn = bounds.Width;
4625 height_rgn = bounds.Height;
4627 range.First = 0;
4628 range.Length = 1;
4629 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4630 expect(Ok, status);
4632 set_rect_empty(&rect);
4633 rect.Width = 32000.0;
4634 rect.Height = 32000.0;
4635 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4636 expect(Ok, status);
4637 set_rect_empty(&bounds);
4638 status = GdipGetRegionBounds(region, graphics, &bounds);
4639 expect(Ok, status);
4640 expectf_(margin_x, bounds.X, 1.0);
4641 expectf(0.0, bounds.Y);
4642 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4643 expectf(height_rgn, bounds.Height);
4644 width_1 = bounds.Width;
4646 range.First = 0;
4647 range.Length = lstrlenW(string);
4648 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4649 expect(Ok, status);
4651 rect.X = 5.0;
4652 rect.Y = 5.0;
4653 rect.Width = 0.0;
4654 rect.Height = 0.0;
4655 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4656 expect(Ok, status);
4657 set_rect_empty(&bounds);
4658 status = GdipGetRegionBounds(region, graphics, &bounds);
4659 expect(Ok, status);
4660 expectf(0.0, bounds.X);
4661 expectf(0.0, bounds.Y);
4662 expectf(0.0, bounds.Width);
4663 expectf(0.0, bounds.Height);
4665 rect.X = 5.0;
4666 rect.Y = 5.0;
4667 rect.Width = width_rgn / 2.0;
4668 rect.Height = 32000.0;
4669 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4670 expect(Ok, status);
4671 set_rect_empty(&bounds);
4672 status = GdipGetRegionBounds(region, graphics, &bounds);
4673 expect(Ok, status);
4674 expectf_(5.0 + margin_x, bounds.X, 1.0);
4675 expectf(5.0, bounds.Y);
4676 expectf_(width_1, bounds.Width, 1.0);
4677 todo_wine
4678 expectf_(height - margin_y, bounds.Height, 1.0);
4680 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4682 rect.X = 5.0;
4683 rect.Y = 5.0;
4684 rect.Width = 0.0;
4685 rect.Height = 0.0;
4686 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4687 expect(Ok, status);
4688 set_rect_empty(&bounds);
4689 status = GdipGetRegionBounds(region, graphics, &bounds);
4690 expect(Ok, status);
4691 expectf_(5.0 + margin_x, bounds.X, 1.0);
4692 expectf(5.0, bounds.Y);
4693 expectf(width_rgn, bounds.Width);
4694 expectf(height_rgn, bounds.Height);
4696 rect.X = 5.0;
4697 rect.Y = 5.0;
4698 rect.Width = width_rgn / 2.0;
4699 rect.Height = 32000.0;
4700 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4701 expect(Ok, status);
4702 set_rect_empty(&bounds);
4703 status = GdipGetRegionBounds(region, graphics, &bounds);
4704 expect(Ok, status);
4705 expectf_(5.0 + margin_x, bounds.X, 1.0);
4706 expectf(5.0, bounds.Y);
4707 expectf_(width_1, bounds.Width, 1.0);
4708 expectf(height_rgn, bounds.Height);
4710 set_rect_empty(&rect);
4711 rect.Height = height / 2.0;
4712 set_rect_empty(&bounds);
4713 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4714 expect(Ok, status);
4715 expect(3, glyphs);
4716 expect(1, lines);
4717 expectf(0.0, bounds.X);
4718 expectf(0.0, bounds.Y);
4719 expectf_(width, bounds.Width, 0.01);
4720 todo_wine
4721 expectf(height, bounds.Height);
4723 set_rect_empty(&rect);
4724 set_rect_empty(&bounds);
4725 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4726 expect(Ok, status);
4727 expect(1, glyphs);
4728 expect(1, lines);
4729 expectf(0.0, bounds.X);
4730 expectf(0.0, bounds.Y);
4731 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4732 expectf(height, bounds.Height);
4733 width_1 = bounds.Width;
4735 set_rect_empty(&rect);
4736 set_rect_empty(&bounds);
4737 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4738 expect(Ok, status);
4739 expect(2, glyphs);
4740 expect(1, lines);
4741 expectf(0.0, bounds.X);
4742 expectf(0.0, bounds.Y);
4743 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4744 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4745 expectf(height, bounds.Height);
4746 width_2 = bounds.Width;
4748 set_rect_empty(&rect);
4749 rect.Width = width / 2.0;
4750 set_rect_empty(&bounds);
4751 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4752 expect(Ok, status);
4753 expect(1, glyphs);
4754 expect(1, lines);
4755 expectf(0.0, bounds.X);
4756 expectf(0.0, bounds.Y);
4757 expectf_(width_1, bounds.Width, 0.01);
4758 expectf(height, bounds.Height);
4760 set_rect_empty(&rect);
4761 rect.Height = height;
4762 rect.Width = width - 0.05;
4763 set_rect_empty(&bounds);
4764 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4765 expect(Ok, status);
4766 expect(2, glyphs);
4767 expect(1, lines);
4768 expectf(0.0, bounds.X);
4769 expectf(0.0, bounds.Y);
4770 expectf_(width_2, bounds.Width, 0.01);
4771 expectf(height, bounds.Height);
4773 set_rect_empty(&rect);
4774 rect.Height = height;
4775 rect.Width = width_2 - 0.05;
4776 set_rect_empty(&bounds);
4777 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4778 expect(Ok, status);
4779 expect(1, glyphs);
4780 expect(1, lines);
4781 expectf(0.0, bounds.X);
4782 expectf(0.0, bounds.Y);
4783 expectf_(width_1, bounds.Width, 0.01);
4784 expectf(height, bounds.Height);
4786 /* Default (Near) alignment */
4787 rect.X = 5.0;
4788 rect.Y = 5.0;
4789 rect.Width = width * 2.0;
4790 rect.Height = height * 2.0;
4791 set_rect_empty(&bounds);
4792 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4793 expect(Ok, status);
4794 expect(3, glyphs);
4795 expect(1, lines);
4796 expectf(5.0, bounds.X);
4797 expectf(5.0, bounds.Y);
4798 expectf_(width, bounds.Width, 0.01);
4799 expectf(height, bounds.Height);
4801 rect.X = 5.0;
4802 rect.Y = 5.0;
4803 rect.Width = 32000.0;
4804 rect.Height = 32000.0;
4805 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4806 expect(Ok, status);
4807 set_rect_empty(&bounds);
4808 status = GdipGetRegionBounds(region, graphics, &bounds);
4809 expect(Ok, status);
4810 expectf_(5.0 + margin_x, bounds.X, 1.0);
4811 expectf(5.0, bounds.Y);
4812 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4813 todo_wine
4814 expectf_(height - margin_y, bounds.Height, 1.0);
4816 width_rgn = bounds.Width;
4817 height_rgn = bounds.Height;
4819 /* Center alignment */
4820 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4821 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4823 rect.X = 5.0;
4824 rect.Y = 5.0;
4825 rect.Width = width * 2.0;
4826 rect.Height = height * 2.0;
4827 set_rect_empty(&bounds);
4828 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4829 expect(Ok, status);
4830 expect(3, glyphs);
4831 expect(1, lines);
4832 todo_wine
4833 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4834 todo_wine
4835 expectf(5.0 + height/2.0, bounds.Y);
4836 expectf_(width, bounds.Width, 0.01);
4837 expectf(height, bounds.Height);
4839 rect.X = 5.0;
4840 rect.Y = 5.0;
4841 rect.Width = 0.0;
4842 rect.Height = 0.0;
4843 set_rect_empty(&bounds);
4844 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4845 expect(Ok, status);
4846 expect(3, glyphs);
4847 expect(1, lines);
4848 todo_wine
4849 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4850 todo_wine
4851 expectf(5.0 - height/2.0, bounds.Y);
4852 expectf_(width, bounds.Width, 0.01);
4853 expectf(height, bounds.Height);
4855 rect.X = 5.0;
4856 rect.Y = 5.0;
4857 rect.Width = width_rgn * 2.0;
4858 rect.Height = height_rgn * 2.0;
4859 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4860 expect(Ok, status);
4861 set_rect_empty(&bounds);
4862 status = GdipGetRegionBounds(region, graphics, &bounds);
4863 expect(Ok, status);
4864 todo_wine
4865 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4866 todo_wine
4867 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4868 expectf_(width_rgn, bounds.Width, 1.0);
4869 expectf_(height_rgn, bounds.Height, 1.0);
4871 rect.X = 5.0;
4872 rect.Y = 5.0;
4873 rect.Width = 0.0;
4874 rect.Height = 0.0;
4875 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4876 expect(Ok, status);
4877 set_rect_empty(&bounds);
4878 status = GdipGetRegionBounds(region, graphics, &bounds);
4879 expect(Ok, status);
4880 todo_wine
4881 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4882 todo_wine
4883 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4884 expectf_(width_rgn, bounds.Width, 1.0);
4885 expectf_(height_rgn, bounds.Height, 1.0);
4887 /* Far alignment */
4888 GdipSetStringFormatAlign(format, StringAlignmentFar);
4889 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4891 rect.X = 5.0;
4892 rect.Y = 5.0;
4893 rect.Width = width * 2.0;
4894 rect.Height = height * 2.0;
4895 set_rect_empty(&bounds);
4896 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4897 expect(Ok, status);
4898 expect(3, glyphs);
4899 expect(1, lines);
4900 todo_wine
4901 expectf_(5.0 + width, bounds.X, 0.01);
4902 todo_wine
4903 expectf(5.0 + height, bounds.Y);
4904 expectf_(width, bounds.Width, 0.01);
4905 expectf(height, bounds.Height);
4907 rect.X = 5.0;
4908 rect.Y = 5.0;
4909 rect.Width = 0.0;
4910 rect.Height = 0.0;
4911 set_rect_empty(&bounds);
4912 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4913 expect(Ok, status);
4914 expect(3, glyphs);
4915 expect(1, lines);
4916 todo_wine
4917 expectf_(5.0 - width, bounds.X, 0.01);
4918 todo_wine
4919 expectf(5.0 - height, bounds.Y);
4920 expectf_(width, bounds.Width, 0.01);
4921 expectf(height, bounds.Height);
4923 rect.X = 5.0;
4924 rect.Y = 5.0;
4925 rect.Width = width_rgn * 2.0;
4926 rect.Height = height_rgn * 2.0;
4927 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4928 expect(Ok, status);
4929 set_rect_empty(&bounds);
4930 status = GdipGetRegionBounds(region, graphics, &bounds);
4931 expect(Ok, status);
4932 todo_wine
4933 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4934 todo_wine
4935 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4936 expectf_(width_rgn, bounds.Width, 1.0);
4937 expectf_(height_rgn, bounds.Height, 1.0);
4939 rect.X = 5.0;
4940 rect.Y = 5.0;
4941 rect.Width = 0.0;
4942 rect.Height = 0.0;
4943 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4944 expect(Ok, status);
4945 set_rect_empty(&bounds);
4946 status = GdipGetRegionBounds(region, graphics, &bounds);
4947 expect(Ok, status);
4948 todo_wine
4949 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4950 todo_wine
4951 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4952 expectf_(width_rgn, bounds.Width, 1.0);
4953 expectf_(height_rgn, bounds.Height, 1.0);
4955 /* Measure "MM" */
4956 rect.X = 5.0;
4957 rect.Y = 5.0;
4958 rect.Width = 32000.0;
4959 rect.Height = 32000.0;
4960 status = GdipMeasureString(graphics, string2 + 2, 2, font, &rect, NULL, &bounds, &glyphs, &lines);
4961 expect(Ok, status);
4962 expect(2, glyphs);
4963 expect(1, lines);
4964 width_MM = bounds.Width;
4966 /* Measure "M M" */
4967 rect.X = 5.0;
4968 rect.Y = 5.0;
4969 rect.Width = 32000.0;
4970 rect.Height = 32000.0;
4971 status = GdipMeasureString(graphics, string2, 3, font, &rect, NULL, &bounds, &glyphs, &lines);
4972 expect(Ok, status);
4973 expect(3, glyphs);
4974 expect(1, lines);
4975 width_M_M = bounds.Width;
4977 /* With wrap */
4978 rect.X = 5.0;
4979 rect.Y = 5.0;
4980 rect.Width = width_M_M;
4981 rect.Height = 32000.0;
4982 status = GdipMeasureString(graphics, string2, -1, font, &rect, NULL, &bounds, &glyphs, &lines);
4983 expect(Ok, status);
4984 expectf_(width_MM, bounds.Width, 0.1);
4985 expect(4, glyphs);
4986 expect(2, lines);
4988 /* Without wrap */
4989 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format_no_wrap);
4990 expect(Ok, status);
4992 rect.X = 5.0;
4993 rect.Y = 5.0;
4994 rect.Width = width_M_M;
4995 rect.Height = 32000.0;
4996 status = GdipMeasureString(graphics, string2, -1, font, &rect, format_no_wrap, &bounds, &glyphs, &lines);
4997 expect(Ok, status);
4998 expectf_(width_M_M, bounds.Width, 0.1);
4999 expect(3, glyphs);
5000 expect(1, lines);
5002 status = GdipDeleteFont(font);
5003 expect(Ok, status);
5005 status = GdipDeleteGraphics(graphics);
5006 expect(Ok, status);
5007 DeleteDC(hdc);
5009 GdipDeleteFontFamily(family);
5010 GdipDeleteRegion(region);
5011 GdipDeleteStringFormat(format);
5012 GdipDeleteStringFormat(format_no_wrap);
5015 static void test_measured_extra_space(void)
5017 GpStringFormat *format;
5018 HDC hdc;
5019 GpGraphics *graphics;
5020 GpFontFamily *family;
5021 GpFont *font;
5022 GpStatus status;
5023 GpUnit gfx_unit, font_unit;
5024 RectF bounds_1, bounds_2, rect;
5025 REAL margin, font_size, dpi;
5027 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
5028 expect(Ok, status);
5030 status = GdipCreateFontFamilyFromName(L"Tahoma", NULL, &family);
5031 expect(Ok, status);
5032 hdc = CreateCompatibleDC(0);
5033 status = GdipCreateFromHDC(hdc, &graphics);
5034 expect(Ok, status);
5036 status = GdipGetDpiX(graphics, &dpi);
5037 expect(Ok, status);
5039 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
5040 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
5041 for (font_unit = 3; font_unit <= 6; font_unit++)
5043 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
5044 expect(Ok, status);
5046 status = GdipGetFontSize(font, &font_size);
5047 expect(Ok, status);
5048 font_size = units_to_pixels(font_size, font_unit, dpi);
5049 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
5051 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
5052 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
5054 status = GdipSetPageUnit(graphics, gfx_unit);
5055 expect(Ok, status);
5057 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
5058 set_rect_empty(&rect);
5059 set_rect_empty(&bounds_1);
5060 status = GdipMeasureString(graphics, L"W", 1, font, &rect, format, &bounds_1, NULL, NULL);
5061 expect(Ok, status);
5062 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
5063 set_rect_empty(&rect);
5064 set_rect_empty(&bounds_2);
5065 status = GdipMeasureString(graphics, L"WW", 2, font, &rect, format, &bounds_2, NULL, NULL);
5066 expect(Ok, status);
5068 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
5069 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
5070 /*trace("margin %f pixels\n", margin);*/
5071 expectf_(font_size / 6.0, margin, font_size / 100.0);
5074 GdipDeleteFont(font);
5077 GdipDeleteGraphics(graphics);
5078 DeleteDC(hdc);
5079 GdipDeleteFontFamily(family);
5080 GdipDeleteStringFormat(format);
5083 static void test_alpha_hdc(void)
5085 GpStatus status;
5086 HDC hdc, gp_hdc;
5087 HBITMAP hbm, old_hbm;
5088 GpGraphics *graphics;
5089 ULONG *bits;
5090 BITMAPINFO bmi;
5091 GpRectF bounds;
5092 COLORREF colorref;
5094 hdc = CreateCompatibleDC(0);
5095 ok(hdc != NULL, "CreateCompatibleDC failed\n");
5096 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
5097 bmi.bmiHeader.biHeight = 5;
5098 bmi.bmiHeader.biWidth = 5;
5099 bmi.bmiHeader.biBitCount = 32;
5100 bmi.bmiHeader.biPlanes = 1;
5101 bmi.bmiHeader.biCompression = BI_RGB;
5102 bmi.bmiHeader.biClrUsed = 0;
5104 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
5105 ok(hbm != NULL, "CreateDIBSection failed\n");
5107 old_hbm = SelectObject(hdc, hbm);
5109 status = GdipCreateFromHDC(hdc, &graphics);
5110 expect(Ok, status);
5112 status = GdipGetVisibleClipBounds(graphics, &bounds);
5113 expect(Ok, status);
5114 expectf(0.0, bounds.X);
5115 expectf(0.0, bounds.Y);
5116 expectf(5.0, bounds.Width);
5117 expectf(5.0, bounds.Height);
5119 bits[0] = 0xdeadbeef;
5121 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
5122 expect(Ok, status);
5124 expect(0xffaaaaaa, bits[0]);
5126 bits[0] = 0xdeadbeef;
5128 status = GdipGetDC(graphics, &gp_hdc);
5129 expect(Ok, status);
5131 colorref = GetPixel(gp_hdc, 0, 4);
5132 expect(0xefbead, colorref);
5134 SetPixel(gp_hdc, 0, 4, 0xffffff);
5136 expect(0xffffff, bits[0]);
5138 status = GdipReleaseDC(graphics, gp_hdc);
5139 expect(Ok, status);
5141 SelectObject(hdc, old_hbm);
5143 bits[0] = 0xdeadbeef;
5145 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
5146 expect(Ok, status);
5148 todo_wine expect(0xffbbbbbb, bits[0]);
5150 GdipDeleteGraphics(graphics);
5152 DeleteObject(hbm);
5153 DeleteDC(hdc);
5156 static void test_bitmapfromgraphics(void)
5158 GpStatus stat;
5159 GpGraphics *graphics = NULL;
5160 HDC hdc = GetDC( hwnd );
5161 GpBitmap *bitmap = NULL;
5162 PixelFormat format;
5163 REAL imageres, graphicsres;
5164 UINT width, height;
5166 stat = GdipCreateFromHDC(hdc, &graphics);
5167 expect(Ok, stat);
5169 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
5170 expect(InvalidParameter, stat);
5172 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
5173 expect(InvalidParameter, stat);
5175 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
5176 expect(Ok, stat);
5178 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
5179 expect(Ok, stat);
5180 expect(PixelFormat32bppPARGB, format);
5182 stat = GdipGetDpiX(graphics, &graphicsres);
5183 expect(Ok, stat);
5185 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
5186 expect(Ok, stat);
5187 expectf(graphicsres, imageres);
5189 stat = GdipGetDpiY(graphics, &graphicsres);
5190 expect(Ok, stat);
5192 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
5193 expect(Ok, stat);
5194 expectf(graphicsres, imageres);
5196 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
5197 expect(Ok, stat);
5198 expect(12, width);
5200 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
5201 expect(Ok, stat);
5202 expect(13, height);
5204 GdipDeleteGraphics(graphics);
5205 GdipDisposeImage((GpImage*)bitmap);
5208 static void test_clipping(void)
5210 HDC hdc;
5211 GpStatus status;
5212 GpGraphics *graphics;
5213 GpRegion *region, *region100x100;
5214 GpMatrix *matrix;
5215 GpRectF rect;
5216 GpRect recti;
5217 GpPointF ptf[4];
5218 GpUnit unit;
5219 HRGN hrgn;
5220 int ret;
5221 RECT rc;
5223 hdc = CreateCompatibleDC(0);
5224 status = GdipCreateFromHDC(hdc, &graphics);
5225 expect(Ok, status);
5227 status = GdipGetPageUnit(graphics, &unit);
5228 expect(Ok, status);
5229 expect(UnitDisplay, unit);
5231 status = GdipCreateRegion(&region);
5232 expect(Ok, status);
5233 status = GdipSetEmpty(region);
5234 expect(Ok, status);
5236 status = GdipCreateRegion(&region100x100);
5237 expect(Ok, status);
5238 status = GdipSetEmpty(region100x100);
5239 expect(Ok, status);
5241 rect.X = rect.Y = 100.0;
5242 rect.Width = rect.Height = 100.0;
5243 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
5244 expect(Ok, status);
5245 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
5246 expect(Ok, status);
5248 status = GdipGetClipBounds(graphics, &rect);
5249 expect(Ok, status);
5250 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5251 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5253 status = GdipGetClipBoundsI(graphics, &recti);
5254 expect(Ok, status);
5255 ok(recti.X == 100 && recti.Y == 100 && recti.Width == 100 && recti.Height == 100,
5256 "expected 100,100-100,100, got %i,%i-%i,%i\n", recti.X, recti.Y, recti.Width, recti.Height);
5258 /* Clip region does not account for changes to gdi32 transform */
5259 SetViewportOrgEx(hdc, 10, 10, NULL);
5261 status = GdipGetClipBounds(graphics, &rect);
5262 expect(Ok, status);
5263 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5264 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5266 SetViewportOrgEx(hdc, 0, 0, NULL);
5268 status = GdipSetEmpty(region);
5269 expect(Ok, status);
5270 status = GdipGetClip(graphics, region);
5271 expect(Ok, status);
5272 status = GdipGetRegionBounds(region, graphics, &rect);
5273 expect(Ok, status);
5274 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5275 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5277 ptf[0].X = 100.0;
5278 ptf[0].Y = 100.0;
5279 ptf[1].X = 200.0;
5280 ptf[1].Y = 200.0;
5281 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5282 expect(Ok, status);
5283 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5284 "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);
5286 status = GdipCreateMatrix(&matrix);
5287 expect(Ok, status);
5288 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
5289 expect(Ok, status);
5290 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
5291 expect(Ok, status);
5292 status = GdipSetWorldTransform(graphics, matrix);
5293 expect(Ok, status);
5295 status = GdipGetClipBounds(graphics, &rect);
5296 expect(Ok, status);
5297 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5298 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5300 status = GdipGetClipBoundsI(graphics, &recti);
5301 expect(Ok, status);
5302 ok(recti.X == 45 && recti.Y == 20 && recti.Width == 50 && recti.Height == 25,
5303 "expected 45,20-50,25, got %i,%i-%i,%i\n", recti.X, recti.Y, recti.Width, recti.Height);
5305 status = GdipSetEmpty(region);
5306 expect(Ok, status);
5307 status = GdipGetClip(graphics, region);
5308 expect(Ok, status);
5309 status = GdipGetRegionBounds(region, graphics, &rect);
5310 expect(Ok, status);
5311 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5312 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5314 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5315 expect(Ok, status);
5316 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5317 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5319 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5320 expect(Ok, status);
5321 ret = GetRgnBox(hrgn, &rc);
5322 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5323 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
5324 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
5325 DeleteObject(hrgn);
5327 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5328 expect(Ok, status);
5329 ret = GetRgnBox(hrgn, &rc);
5330 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5331 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5332 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5333 DeleteObject(hrgn);
5335 ptf[0].X = 100.0;
5336 ptf[0].Y = 100.0;
5337 ptf[1].X = 200.0;
5338 ptf[1].Y = 200.0;
5339 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5340 expect(Ok, status);
5341 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5342 "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);
5344 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5345 expect(Ok, status);
5346 ret = GetRgnBox(hrgn, &rc);
5347 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5348 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5349 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5350 DeleteObject(hrgn);
5352 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5353 expect(Ok, status);
5354 ret = GetRgnBox(hrgn, &rc);
5355 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5356 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5357 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5358 DeleteObject(hrgn);
5360 ptf[0].X = 210.0;
5361 ptf[0].Y = 420.0;
5362 ptf[1].X = 410.0;
5363 ptf[1].Y = 820.0;
5364 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5365 expect(Ok, status);
5366 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5367 "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);
5369 status = GdipSetPageScale(graphics, 2.0);
5370 expect(Ok, status);
5372 status = GdipGetClipBounds(graphics, &rect);
5373 expect(Ok, status);
5374 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5375 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5377 status = GdipSetEmpty(region);
5378 expect(Ok, status);
5379 status = GdipGetClip(graphics, region);
5380 expect(Ok, status);
5381 status = GdipGetRegionBounds(region, graphics, &rect);
5382 expect(Ok, status);
5383 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5384 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5386 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5387 expect(Ok, status);
5388 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5389 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5391 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5392 expect(Ok, status);
5393 ret = GetRgnBox(hrgn, &rc);
5394 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5395 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
5396 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
5397 DeleteObject(hrgn);
5399 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5400 expect(Ok, status);
5401 ret = GetRgnBox(hrgn, &rc);
5402 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5403 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5404 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5405 DeleteObject(hrgn);
5407 ptf[0].X = 100.0;
5408 ptf[0].Y = 100.0;
5409 ptf[1].X = 200.0;
5410 ptf[1].Y = 200.0;
5411 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5412 expect(Ok, status);
5413 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5414 "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);
5416 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5417 expect(Ok, status);
5418 ret = GetRgnBox(hrgn, &rc);
5419 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5420 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5421 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5422 DeleteObject(hrgn);
5424 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5425 expect(Ok, status);
5426 ret = GetRgnBox(hrgn, &rc);
5427 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5428 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5429 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5430 DeleteObject(hrgn);
5432 ptf[0].X = 210.0;
5433 ptf[0].Y = 420.0;
5434 ptf[1].X = 410.0;
5435 ptf[1].Y = 820.0;
5436 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5437 expect(Ok, status);
5438 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5439 "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);
5441 GdipSetPageUnit(graphics, UnitPoint);
5442 expect(Ok, status);
5444 status = GdipGetClipBounds(graphics, &rect);
5445 expect(Ok, status);
5446 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5447 /* rounding under Wine is slightly different */
5448 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5449 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5450 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5452 status = GdipSetEmpty(region);
5453 expect(Ok, status);
5454 status = GdipGetClip(graphics, region);
5455 expect(Ok, status);
5456 status = GdipGetRegionBounds(region, graphics, &rect);
5457 expect(Ok, status);
5458 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5459 /* rounding under Wine is slightly different */
5460 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5461 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5462 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5464 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5465 expect(Ok, status);
5466 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5467 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5469 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5470 expect(Ok, status);
5471 ret = GetRgnBox(hrgn, &rc);
5472 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5473 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
5474 /* rounding under Wine is slightly different */
5475 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
5476 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
5477 "expected 14,5-33,14, got %s\n", wine_dbgstr_rect(&rc));
5478 DeleteObject(hrgn);
5480 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5481 expect(Ok, status);
5482 ret = GetRgnBox(hrgn, &rc);
5483 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5484 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5485 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
5486 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5487 DeleteObject(hrgn);
5489 ptf[0].X = 100.0;
5490 ptf[0].Y = 100.0;
5491 ptf[1].X = 200.0;
5492 ptf[1].Y = 200.0;
5493 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5494 expect(Ok, status);
5495 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
5496 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
5497 "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);
5499 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5500 expect(Ok, status);
5501 ret = GetRgnBox(hrgn, &rc);
5502 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5503 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5504 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5505 DeleteObject(hrgn);
5507 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5508 expect(Ok, status);
5509 ret = GetRgnBox(hrgn, &rc);
5510 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5511 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
5512 /* rounding under Wine is slightly different */
5513 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
5514 "expected 560,1120-1094,2187, got %s\n", wine_dbgstr_rect(&rc));
5515 DeleteObject(hrgn);
5517 ptf[0].X = 560.0;
5518 ptf[0].Y = 1120.0;
5519 ptf[1].X = 1094.0;
5520 ptf[1].Y = 2187.0;
5521 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5522 expect(Ok, status);
5523 if (fabs(ptf[0].X - 100.0) < 0.001)
5525 expectf(100.0, ptf[0].X);
5526 expectf(100.0, ptf[0].Y);
5527 expectf(200.125, ptf[1].X);
5528 expectf(200.03125, ptf[1].Y);
5530 else /* before Win7 */
5532 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
5533 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
5534 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
5535 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
5538 status = GdipTransformRegion(region100x100, matrix);
5539 expect(Ok, status);
5541 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5542 expect(Ok, status);
5543 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5544 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5546 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5547 expect(Ok, status);
5548 ret = GetRgnBox(hrgn, &rc);
5549 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5550 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5551 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5552 DeleteObject(hrgn);
5554 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5555 expect(Ok, status);
5556 ret = GetRgnBox(hrgn, &rc);
5557 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5558 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
5559 /* rounding under Wine is slightly different */
5560 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
5561 "expected 1147,4534-2214,8800, got %s\n", wine_dbgstr_rect(&rc));
5562 DeleteObject(hrgn);
5564 ptf[0].X = 1147.0;
5565 ptf[0].Y = 4534.0;
5566 ptf[1].X = 2214.0;
5567 ptf[1].Y = 8800.0;
5568 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5569 expect(Ok, status);
5570 if (fabs(ptf[0].X - 210.0625) < 0.001)
5572 expectf(210.0625, ptf[0].X);
5573 expectf(420.0625, ptf[0].Y);
5574 expectf(410.125, ptf[1].X);
5575 expectf(820.0, ptf[1].Y);
5577 else /* before Win7 */
5579 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
5580 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
5581 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
5582 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
5585 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
5586 expect(Ok, status);
5587 status = GdipSetWorldTransform(graphics, matrix);
5588 expect(Ok, status);
5590 status = GdipGetClipBounds(graphics, &rect);
5591 expect(Ok, status);
5592 expectf_(20.612978, rect.X, 1.0);
5593 expectf_(-6.256012, rect.Y, 1.5);
5594 expectf_(25.612978, rect.Width, 1.0);
5595 expectf_(12.806489, rect.Height, 1.0);
5597 status = GdipSetEmpty(region);
5598 expect(Ok, status);
5599 status = GdipGetClip(graphics, region);
5600 expect(Ok, status);
5601 status = GdipGetRegionBounds(region, graphics, &rect);
5602 expect(Ok, status);
5603 /* rounding under Wine is slightly different */
5604 expectf_(20.612978, rect.X, 1.0);
5605 expectf_(-6.256012, rect.Y, 1.5);
5606 expectf_(25.612978, rect.Width, 1.0);
5607 expectf_(12.806489, rect.Height, 1.0);
5609 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5610 expect(Ok, status);
5611 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5612 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5614 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5615 expect(Ok, status);
5616 ret = GetRgnBox(hrgn, &rc);
5617 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5618 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
5619 /* rounding under Wine is slightly different */
5620 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
5621 "expected (22,-6)-(46,7), got %s\n", wine_dbgstr_rect(&rc));
5622 DeleteObject(hrgn);
5624 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5625 expect(Ok, status);
5626 ret = GetRgnBox(hrgn, &rc);
5627 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5628 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5629 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5630 DeleteObject(hrgn);
5632 ptf[0].X = 100.0;
5633 ptf[0].Y = 100.0;
5634 ptf[1].X = 200.0;
5635 ptf[1].Y = 200.0;
5636 ptf[2].X = 200.0;
5637 ptf[2].Y = 100.0;
5638 ptf[3].X = 100.0;
5639 ptf[3].Y = 200.0;
5640 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5641 expect(Ok, status);
5642 expectf(20.612978, ptf[0].X);
5643 expectf(-1.568512, ptf[0].Y);
5644 expectf(46.225956, ptf[1].X);
5645 expectf(1.862977, ptf[1].Y);
5646 expectf(36.850956, ptf[2].X);
5647 expectf(-6.256012, ptf[2].Y);
5648 expectf(29.987980, ptf[3].X);
5649 expectf(6.550478, ptf[3].Y);
5651 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5652 expect(Ok, status);
5653 ret = GetRgnBox(hrgn, &rc);
5654 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5655 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5656 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5657 DeleteObject(hrgn);
5659 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5660 expect(Ok, status);
5661 ret = GetRgnBox(hrgn, &rc);
5662 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5663 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
5664 /* rounding under Wine is slightly different */
5665 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
5666 "expected (-3406,4500)-(-350,8728), got %s\n", wine_dbgstr_rect(&rc));
5667 DeleteObject(hrgn);
5669 ptf[0].X = -3406.0;
5670 ptf[0].Y = 4500.0;
5671 ptf[1].X = -350.0;
5672 ptf[1].Y = 8728.0;
5673 ptf[2].X = -350.0;
5674 ptf[2].Y = 4500.0;
5675 ptf[3].X = -3406.0;
5676 ptf[3].Y = 8728.0;
5677 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5678 expect(Ok, status);
5679 expectf(-136.190491, ptf[0].X);
5680 expectf(520.010742, ptf[0].Y);
5681 expectf(756.417175, ptf[1].X);
5682 expectf(720.031616, ptf[1].Y);
5683 expectf(360.042114, ptf[2].X);
5684 expectf(376.760742, ptf[2].Y);
5685 expectf(260.184570, ptf[3].X);
5686 expectf(863.281616, ptf[3].Y);
5688 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
5689 expect(Ok, status);
5690 status = GdipSetWorldTransform(graphics, matrix);
5691 expect(Ok, status);
5693 status = GdipGetClipBounds(graphics, &rect);
5694 expect(Ok, status);
5695 expectf_(-28.100956, rect.X, 1.0);
5696 expectf_(7.806488, rect.Y, 1.5);
5697 expectf_(25.612978, rect.Width, 1.0);
5698 expectf_(12.806489, rect.Height, 1.0);
5700 status = GdipSetEmpty(region);
5701 expect(Ok, status);
5702 status = GdipGetClip(graphics, region);
5703 expect(Ok, status);
5704 status = GdipGetRegionBounds(region, graphics, &rect);
5705 expect(Ok, status);
5706 /* rounding under Wine is slightly different */
5707 expectf_(-28.100956, rect.X, 1.0);
5708 expectf_(7.806488, rect.Y, 1.5);
5709 expectf_(25.612978, rect.Width, 1.0);
5710 expectf_(12.806489, rect.Height, 1.0);
5712 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5713 expect(Ok, status);
5714 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5715 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5717 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5718 expect(Ok, status);
5719 ret = GetRgnBox(hrgn, &rc);
5720 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5721 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5722 /* rounding under Wine is slightly different */
5723 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5724 "expected (-27,8)-(-2,21), got %s\n", wine_dbgstr_rect(&rc));
5725 DeleteObject(hrgn);
5727 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5728 expect(Ok, status);
5729 ret = GetRgnBox(hrgn, &rc);
5730 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5731 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5732 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5733 DeleteObject(hrgn);
5735 ptf[0].X = 100.0;
5736 ptf[0].Y = 100.0;
5737 ptf[1].X = 200.0;
5738 ptf[1].Y = 200.0;
5739 ptf[2].X = 200.0;
5740 ptf[2].Y = 100.0;
5741 ptf[3].X = 100.0;
5742 ptf[3].Y = 200.0;
5743 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5744 expect(Ok, status);
5745 expectf(-11.862979, ptf[0].X);
5746 expectf(7.806488, ptf[0].Y);
5747 expectf(-18.725958, ptf[1].X);
5748 expectf(20.612976, ptf[1].Y);
5749 expectf(-2.487981, ptf[2].X);
5750 expectf(15.925477, ptf[2].Y);
5751 expectf(-28.100956, ptf[3].X);
5752 expectf(12.493987, ptf[3].Y);
5754 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5755 expect(Ok, status);
5756 ret = GetRgnBox(hrgn, &rc);
5757 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5758 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5759 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5760 DeleteObject(hrgn);
5762 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5763 expect(Ok, status);
5764 ret = GetRgnBox(hrgn, &rc);
5765 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5766 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5767 /* rounding under Wine is slightly different */
5768 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5769 "expected (4500,351)-(8728,3407), got %s\n", wine_dbgstr_rect(&rc));
5770 DeleteObject(hrgn);
5772 ptf[0].X = -3406.0;
5773 ptf[0].Y = 4500.0;
5774 ptf[1].X = -350.0;
5775 ptf[1].Y = 8728.0;
5776 ptf[2].X = -350.0;
5777 ptf[2].Y = 4500.0;
5778 ptf[3].X = -3406.0;
5779 ptf[3].Y = 8728.0;
5780 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5781 expect(Ok, status);
5782 expectf(-1055.021484, ptf[0].X);
5783 expectf(-70.595329, ptf[0].Y);
5784 expectf(-1455.063232, ptf[1].X);
5785 expectf(375.708435, ptf[1].Y);
5786 expectf(-768.521484, ptf[2].X);
5787 expectf(177.520981, ptf[2].Y);
5788 expectf(-1741.563110, ptf[3].X);
5789 expectf(127.592125, ptf[3].Y);
5791 GdipDeleteMatrix(matrix);
5792 GdipDeleteRegion(region);
5793 GdipDeleteRegion(region100x100);
5794 GdipDeleteGraphics(graphics);
5795 DeleteDC(hdc);
5798 static void test_clipping_2(void)
5801 HDC hdc;
5802 GpStatus status;
5803 GpGraphics *graphics;
5804 GpRegion *region;
5805 GpMatrix *matrix;
5806 GpRectF rect;
5807 GpPointF ptf[4];
5808 GpUnit unit;
5809 HRGN hrgn;
5810 int ret;
5811 RECT rc;
5813 hdc = CreateCompatibleDC(0);
5814 status = GdipCreateFromHDC(hdc, &graphics);
5815 expect(Ok, status);
5817 status = GdipGetPageUnit(graphics, &unit);
5818 expect(Ok, status);
5819 expect(UnitDisplay, unit);
5821 GdipSetPageUnit(graphics, UnitInch);
5823 status = GdipCreateRegion(&region);
5824 expect(Ok, status);
5825 status = GdipSetEmpty(region);
5826 expect(Ok, status);
5827 rect.X = rect.Y = 100.0;
5828 rect.Width = rect.Height = 100.0;
5829 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5830 expect(Ok, status);
5831 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5832 expect(Ok, status);
5834 status = GdipGetClip(graphics, region);
5835 expect(Ok, status);
5836 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5837 expect(Ok, status);
5838 ret = GetRgnBox(hrgn, &rc);
5839 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5840 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5841 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5842 DeleteObject(hrgn);
5843 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5844 expect(Ok, status);
5845 ret = GetRgnBox(hrgn, &rc);
5846 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5847 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5848 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5849 DeleteObject(hrgn);
5851 ptf[0].X = 9600.0;
5852 ptf[0].Y = 9600.0;
5853 ptf[1].X = 19200.0;
5854 ptf[1].Y = 19200.0;
5855 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5856 expect(Ok, status);
5857 expectf(100.0, ptf[0].X);
5858 expectf(100.0, ptf[0].Y);
5859 expectf(200.0, ptf[1].X);
5860 expectf(200.0, ptf[1].X);
5862 GdipSetPageUnit(graphics, UnitPoint);
5864 status = GdipGetClip(graphics, region);
5865 expect(Ok, status);
5866 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5867 expect(Ok, status);
5868 ret = GetRgnBox(hrgn, &rc);
5869 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5870 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5871 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5872 "expected 7200,7200-14400,14400, got %s\n", wine_dbgstr_rect(&rc));
5873 DeleteObject(hrgn);
5874 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5875 expect(Ok, status);
5876 ret = GetRgnBox(hrgn, &rc);
5877 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5878 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5879 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5880 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5881 DeleteObject(hrgn);
5883 ptf[0].X = 9600.0;
5884 ptf[0].Y = 9600.0;
5885 ptf[1].X = 19200.0;
5886 ptf[1].Y = 19200.0;
5887 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5888 expect(Ok, status);
5889 if (fabs(ptf[0].X - 7200.0) < 0.001)
5890 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5891 "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);
5892 else /* before Win7 */
5894 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5895 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5896 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5897 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5900 GdipDeleteRegion(region);
5902 GdipSetPageUnit(graphics, UnitPixel);
5904 status = GdipCreateRegion(&region);
5905 expect(Ok, status);
5906 status = GdipSetEmpty(region);
5907 expect(Ok, status);
5908 rect.X = rect.Y = 100.0;
5909 rect.Width = rect.Height = 100.0;
5910 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5911 expect(Ok, status);
5912 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5913 expect(Ok, status);
5915 status = GdipGetClip(graphics, region);
5916 expect(Ok, status);
5917 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5918 expect(Ok, status);
5919 ret = GetRgnBox(hrgn, &rc);
5920 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5921 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5922 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5923 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5924 DeleteObject(hrgn);
5925 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5926 expect(Ok, status);
5927 ret = GetRgnBox(hrgn, &rc);
5928 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5929 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5930 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5931 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5932 DeleteObject(hrgn);
5934 ptf[0].X = 100.0;
5935 ptf[0].Y = 100.0;
5936 ptf[1].X = 200.0;
5937 ptf[1].Y = 200.0;
5938 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5939 expect(Ok, status);
5940 if (fabs(ptf[0].X - 100.0) < 0.001)
5941 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5942 "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);
5943 else /* before Win7 */
5945 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5946 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5947 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5948 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5951 GdipSetPageUnit(graphics, UnitPoint);
5953 status = GdipGetClip(graphics, region);
5954 expect(Ok, status);
5955 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5956 expect(Ok, status);
5957 ret = GetRgnBox(hrgn, &rc);
5958 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5959 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5960 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5961 "expected 75,75-150,150, 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 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5969 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5970 DeleteObject(hrgn);
5972 ptf[0].X = 100.0;
5973 ptf[0].Y = 100.0;
5974 ptf[1].X = 200.0;
5975 ptf[1].Y = 200.0;
5976 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5977 expect(Ok, status);
5978 if (fabs(ptf[0].X - 75.0) < 0.001)
5979 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5980 "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);
5981 else /* before Win7 */
5983 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5984 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5985 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5986 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5989 status = GdipCreateMatrix(&matrix);
5990 expect(Ok, status);
5991 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5992 expect(Ok, status);
5993 status = GdipSetWorldTransform(graphics, matrix);
5994 expect(Ok, status);
5995 GdipDeleteMatrix(matrix);
5997 status = GdipGetClip(graphics, region);
5998 expect(Ok, status);
5999 status = GdipGetRegionHRgn(region, NULL, &hrgn);
6000 expect(Ok, status);
6001 ret = GetRgnBox(hrgn, &rc);
6002 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6003 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
6004 "expected 65,65-140,140, got %s\n", wine_dbgstr_rect(&rc));
6005 DeleteObject(hrgn);
6006 status = GdipGetRegionHRgn(region, graphics, &hrgn);
6007 expect(Ok, status);
6008 ret = GetRgnBox(hrgn, &rc);
6009 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6010 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
6011 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
6012 DeleteObject(hrgn);
6014 ptf[0].X = 100.0;
6015 ptf[0].Y = 100.0;
6016 ptf[1].X = 200.0;
6017 ptf[1].Y = 200.0;
6018 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
6019 expect(Ok, status);
6020 expectf(65.0, ptf[0].X);
6021 expectf(65.0, ptf[0].Y);
6022 expectf(140.0, ptf[1].X);
6023 expectf(140.0, ptf[1].X);
6025 status = GdipCreateMatrix(&matrix);
6026 expect(Ok, status);
6027 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
6028 expect(Ok, status);
6029 status = GdipSetWorldTransform(graphics, matrix);
6030 expect(Ok, status);
6031 GdipDeleteMatrix(matrix);
6033 status = GdipGetClip(graphics, region);
6034 expect(Ok, status);
6035 status = GdipGetRegionHRgn(region, NULL, &hrgn);
6036 expect(Ok, status);
6037 ret = GetRgnBox(hrgn, &rc);
6038 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6039 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
6040 "expected 300,150-600,300, got %s\n", wine_dbgstr_rect(&rc));
6041 DeleteObject(hrgn);
6042 status = GdipGetRegionHRgn(region, graphics, &hrgn);
6043 expect(Ok, status);
6044 ret = GetRgnBox(hrgn, &rc);
6045 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6046 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
6047 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
6048 DeleteObject(hrgn);
6050 ptf[0].X = 100.0;
6051 ptf[0].Y = 100.0;
6052 ptf[1].X = 200.0;
6053 ptf[1].Y = 200.0;
6054 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
6055 expect(Ok, status);
6056 expectf(300.0, ptf[0].X);
6057 expectf(150.0, ptf[0].Y);
6058 expectf(600.0, ptf[1].X);
6059 expectf(300.0, ptf[1].Y);
6061 status = GdipSetPageScale(graphics, 2.0);
6062 expect(Ok, status);
6064 status = GdipGetClip(graphics, region);
6065 expect(Ok, status);
6066 status = GdipGetRegionHRgn(region, NULL, &hrgn);
6067 expect(Ok, status);
6068 ret = GetRgnBox(hrgn, &rc);
6069 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6070 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
6071 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
6072 "expected 150,75-300,150, got %s\n", wine_dbgstr_rect(&rc));
6073 DeleteObject(hrgn);
6074 status = GdipGetRegionHRgn(region, graphics, &hrgn);
6075 expect(Ok, status);
6076 ret = GetRgnBox(hrgn, &rc);
6077 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6078 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
6079 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
6080 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
6081 DeleteObject(hrgn);
6083 ptf[0].X = 100.0;
6084 ptf[0].Y = 100.0;
6085 ptf[1].X = 200.0;
6086 ptf[1].Y = 200.0;
6087 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
6088 expect(Ok, status);
6089 if (fabs(ptf[0].X - 150.0) < 0.001)
6091 expectf(150.0, ptf[0].X);
6092 expectf(75.0, ptf[0].Y);
6093 expectf(300.0, ptf[1].X);
6094 expectf(150.0, ptf[1].Y);
6096 else /* before Win7 */
6098 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
6099 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
6100 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
6101 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
6104 status = GdipCreateMatrix(&matrix);
6105 expect(Ok, status);
6106 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
6107 expect(Ok, status);
6108 status = GdipSetWorldTransform(graphics, matrix);
6109 expect(Ok, status);
6110 GdipDeleteMatrix(matrix);
6112 status = GdipGetClip(graphics, region);
6113 expect(Ok, status);
6114 status = GdipGetRegionHRgn(region, NULL, &hrgn);
6115 expect(Ok, status);
6116 ret = GetRgnBox(hrgn, &rc);
6117 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
6118 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
6119 /* rounding under Wine is slightly different */
6120 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
6121 "expected 54,-26-107,27, got %s\n", wine_dbgstr_rect(&rc));
6122 DeleteObject(hrgn);
6123 status = GdipGetRegionHRgn(region, graphics, &hrgn);
6124 expect(Ok, status);
6125 ret = GetRgnBox(hrgn, &rc);
6126 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6127 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
6128 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
6129 DeleteObject(hrgn);
6131 ptf[0].X = 100.0;
6132 ptf[0].Y = 100.0;
6133 ptf[1].X = 200.0;
6134 ptf[1].Y = 200.0;
6135 ptf[2].X = 200.0;
6136 ptf[2].Y = 100.0;
6137 ptf[3].X = 100.0;
6138 ptf[3].Y = 200.0;
6139 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
6140 expect(Ok, status);
6141 expectf(53.033016, ptf[0].X);
6142 expectf(0.0, ptf[0].Y);
6143 expectf(106.066032, ptf[1].X);
6144 expectf(0.0, ptf[1].Y);
6145 expectf(79.549522, ptf[2].X);
6146 expectf(-26.516510, ptf[2].Y);
6147 expectf(79.549522, ptf[3].X);
6148 expectf(26.516508, ptf[3].Y);
6150 status = GdipCreateMatrix(&matrix);
6151 expect(Ok, status);
6152 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
6153 expect(Ok, status);
6154 status = GdipSetWorldTransform(graphics, matrix);
6155 expect(Ok, status);
6156 GdipDeleteMatrix(matrix);
6158 status = GdipGetClip(graphics, region);
6159 expect(Ok, status);
6160 status = GdipGetRegionHRgn(region, NULL, &hrgn);
6161 expect(Ok, status);
6162 ret = GetRgnBox(hrgn, &rc);
6163 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
6164 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
6165 /* rounding under Wine is slightly different */
6166 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
6167 "expected -26,54-27,107, got %s\n", wine_dbgstr_rect(&rc));
6168 DeleteObject(hrgn);
6169 status = GdipGetRegionHRgn(region, graphics, &hrgn);
6170 expect(Ok, status);
6171 ret = GetRgnBox(hrgn, &rc);
6172 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6173 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
6174 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
6175 DeleteObject(hrgn);
6177 ptf[0].X = 100.0;
6178 ptf[0].Y = 100.0;
6179 ptf[1].X = 200.0;
6180 ptf[1].Y = 200.0;
6181 ptf[2].X = 200.0;
6182 ptf[2].Y = 100.0;
6183 ptf[3].X = 100.0;
6184 ptf[3].Y = 200.0;
6185 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
6186 expect(Ok, status);
6187 expectf(0.0, ptf[0].X);
6188 expectf(53.033005, ptf[0].Y);
6189 expectf(0.0, ptf[1].X);
6190 expectf(106.066010, ptf[1].Y);
6191 expectf(26.516491, ptf[2].X);
6192 expectf(79.549507, ptf[2].Y);
6193 expectf(-26.516520, ptf[3].X);
6194 expectf(79.549500, ptf[3].Y);
6196 GdipDeleteRegion(region);
6197 GdipDeleteGraphics(graphics);
6198 DeleteDC(hdc);
6202 static void test_GdipFillRectangles(void)
6204 GpStatus status;
6205 GpGraphics *graphics = NULL;
6206 GpBrush *brush = NULL;
6207 HDC hdc = GetDC( hwnd );
6208 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
6210 ok(hdc != NULL, "Expected HDC to be initialized\n");
6212 status = GdipCreateFromHDC(hdc, &graphics);
6213 expect(Ok, status);
6214 ok(graphics != NULL, "Expected graphics to be initialized\n");
6216 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
6217 expect(Ok, status);
6218 ok(brush != NULL, "Expected brush to be initialized\n");
6220 status = GdipFillRectangles(NULL, brush, rects, 2);
6221 expect(InvalidParameter, status);
6223 status = GdipFillRectangles(graphics, NULL, rects, 2);
6224 expect(InvalidParameter, status);
6226 status = GdipFillRectangles(graphics, brush, NULL, 2);
6227 expect(InvalidParameter, status);
6229 status = GdipFillRectangles(graphics, brush, rects, 0);
6230 expect(InvalidParameter, status);
6232 status = GdipFillRectangles(graphics, brush, rects, -1);
6233 expect(InvalidParameter, status);
6235 status = GdipFillRectangles(graphics, brush, rects, 1);
6236 expect(Ok, status);
6238 status = GdipFillRectangles(graphics, brush, rects, 2);
6239 expect(Ok, status);
6241 GdipDeleteBrush(brush);
6242 GdipDeleteGraphics(graphics);
6244 ReleaseDC(hwnd, hdc);
6247 static void test_GdipGetVisibleClipBounds_memoryDC(void)
6249 HDC hdc,dc;
6250 HBITMAP bmp;
6251 HGDIOBJ old;
6252 RECT rect;
6253 POINT pt;
6254 int width = 0;
6255 int height = 0;
6256 GpGraphics* graphics = NULL;
6257 GpRect boundRect;
6258 GpStatus status;
6260 ok(GetClientRect(hwnd, &rect), "GetClientRect should have succeeded\n");
6261 width = rect.right - rect.left;
6262 height = rect.bottom - rect.top;
6264 dc = GetDC(hwnd);
6265 hdc = CreateCompatibleDC ( dc );
6266 bmp = CreateCompatibleBitmap ( dc, width, height );
6267 old = SelectObject (hdc, bmp);
6269 /*change the window origin is the key test point*/
6270 SetWindowOrgEx (hdc, rect.left+10, rect.top+10, &pt);
6272 status = GdipCreateFromHDC(hdc, &graphics);
6273 expect(Ok, status);
6275 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
6276 expect(Ok, status);
6278 ok(boundRect.X==rect.left+10 &&
6279 boundRect.Y==rect.top+10 &&
6280 boundRect.Width==width &&
6281 boundRect.Height==height, "Expected GdipGetVisibleClipBoundsI ok\n");
6283 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
6284 expect(Ok, status);
6286 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
6287 expect(Ok, status);
6289 ok(boundRect.X==rect.left+10 &&
6290 boundRect.Y==rect.top+10 &&
6291 boundRect.Width==width-10 &&
6292 boundRect.Height==height-10, "Expected GdipGetVisibleClipBoundsI ok\n");
6294 GdipDeleteGraphics(graphics);
6296 SelectObject (hdc, old);
6297 DeleteObject (bmp);
6298 DeleteDC (hdc);
6299 ReleaseDC(hwnd, dc);
6302 static void test_container_rects(void)
6304 GpStatus status;
6305 GpGraphics *graphics;
6306 HDC hdc = GetDC( hwnd );
6307 GpRectF dstrect, srcrect;
6308 GraphicsContainer state;
6309 static const GpPointF test_points[3] = {{0.0,0.0}, {1.0,0.0}, {0.0,1.0}};
6310 GpPointF points[3];
6311 REAL dpix, dpiy;
6313 status = GdipCreateFromHDC(hdc, &graphics);
6314 expect(Ok, status);
6316 dstrect.X = 0.0;
6317 dstrect.Y = 0.0;
6318 dstrect.Width = 1.0;
6319 dstrect.Height = 1.0;
6320 srcrect = dstrect;
6322 status = GdipGetDpiX(graphics, &dpix);
6323 expect(Ok, status);
6325 status = GdipGetDpiY(graphics, &dpiy);
6326 expect(Ok, status);
6328 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitWorld, &state);
6329 expect(InvalidParameter, status);
6331 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitDisplay, &state);
6332 expect(InvalidParameter, status);
6334 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitMillimeter+1, &state);
6335 expect(InvalidParameter, status);
6337 status = GdipBeginContainer(NULL, &dstrect, &srcrect, UnitPixel, &state);
6338 expect(InvalidParameter, status);
6340 status = GdipBeginContainer(graphics, NULL, &srcrect, UnitPixel, &state);
6341 expect(InvalidParameter, status);
6343 status = GdipBeginContainer(graphics, &dstrect, NULL, UnitPixel, &state);
6344 expect(InvalidParameter, status);
6346 status = GdipBeginContainer(graphics, &dstrect, &srcrect, -1, &state);
6347 expect(InvalidParameter, status);
6349 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, NULL);
6350 expect(InvalidParameter, status);
6352 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6353 expect(Ok, status);
6355 memcpy(points, test_points, sizeof(points));
6356 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6357 expect(Ok, status);
6358 expectf(0.0, points[0].X);
6359 expectf(0.0, points[0].Y);
6360 expectf(1.0, points[1].X);
6361 expectf(0.0, points[1].Y);
6362 expectf(0.0, points[2].X);
6363 expectf(1.0, points[2].Y);
6365 status = GdipEndContainer(graphics, state);
6366 expect(Ok, status);
6368 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6369 expect(Ok, status);
6371 memcpy(points, test_points, sizeof(points));
6372 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6373 expect(Ok, status);
6374 expectf(0.0, points[0].X);
6375 expectf(0.0, points[0].Y);
6376 expectf(1.0/dpix, points[1].X);
6377 expectf(0.0, points[1].Y);
6378 expectf(0.0, points[2].X);
6379 expectf(1.0/dpiy, points[2].Y);
6381 status = GdipEndContainer(graphics, state);
6382 expect(Ok, status);
6384 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
6385 expect(Ok, status);
6387 dstrect.X = 1.0;
6388 dstrect.Height = 3.0;
6389 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6390 expect(Ok, status);
6392 memcpy(points, test_points, sizeof(points));
6393 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6394 expect(Ok, status);
6395 expectf(2.0, points[0].X);
6396 expectf(0.0, points[0].Y);
6397 expectf(4.0, points[1].X);
6398 expectf(0.0, points[1].Y);
6399 expectf(2.0, points[2].X);
6400 expectf(6.0, points[2].Y);
6402 status = GdipEndContainer(graphics, state);
6403 expect(Ok, status);
6405 memcpy(points, test_points, sizeof(points));
6406 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6407 expect(Ok, status);
6408 expectf(0.0, points[0].X);
6409 expectf(0.0, points[0].Y);
6410 expectf(2.0, points[1].X);
6411 expectf(0.0, points[1].Y);
6412 expectf(0.0, points[2].X);
6413 expectf(2.0, points[2].Y);
6415 status = GdipResetWorldTransform(graphics);
6416 expect(Ok, status);
6418 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6419 expect(Ok, status);
6421 memcpy(points, test_points, sizeof(points));
6422 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6423 expect(Ok, status);
6424 expectf(1.0, points[0].X);
6425 expectf(0.0, points[0].Y);
6426 expectf((dpix+1.0)/dpix, points[1].X);
6427 expectf(0.0, points[1].Y);
6428 expectf(1.0, points[2].X);
6429 expectf(3.0/dpiy, points[2].Y);
6431 status = GdipEndContainer(graphics, state);
6432 expect(Ok, status);
6434 status = GdipSetPageUnit(graphics, UnitInch);
6435 expect(Ok, status);
6437 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6438 expect(Ok, status);
6440 memcpy(points, test_points, sizeof(points));
6441 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6442 expect(Ok, status);
6443 expectf(dpix, points[0].X);
6444 expectf(0.0, points[0].Y);
6445 expectf(dpix*2, points[1].X);
6446 expectf(0.0, points[1].Y);
6447 expectf(dpix, points[2].X);
6448 expectf(dpiy*3, points[2].Y);
6450 status = GdipEndContainer(graphics, state);
6451 expect(Ok, status);
6453 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6454 expect(Ok, status);
6456 memcpy(points, test_points, sizeof(points));
6457 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6458 expect(Ok, status);
6459 expectf(dpix, points[0].X);
6460 expectf(0.0, points[0].Y);
6461 expectf(dpix+1.0, points[1].X);
6462 expectf(0.0, points[1].Y);
6463 expectf(dpix, points[2].X);
6464 expectf(3.0, points[2].Y);
6466 status = GdipEndContainer(graphics, state);
6467 expect(Ok, status);
6469 GdipDeleteGraphics(graphics);
6471 ReleaseDC(hwnd, hdc);
6474 static void test_GdipGraphicsSetAbort(void)
6476 HDC hdc;
6477 GpStatus status;
6478 GpGraphics *graphics;
6480 if (!pGdipGraphicsSetAbort)
6482 win_skip("GdipGraphicsSetAbort() is not supported.\n");
6483 return;
6486 hdc = GetDC(hwnd);
6488 status = GdipCreateFromHDC(hdc, &graphics);
6489 expect(Ok, status);
6491 status = pGdipGraphicsSetAbort(NULL, NULL);
6492 expect(InvalidParameter, status);
6494 status = pGdipGraphicsSetAbort(graphics, NULL);
6495 expect(Ok, status);
6497 GdipDeleteGraphics(graphics);
6499 ReleaseDC(hwnd, hdc);
6502 #define BLUE_COLOR (0xff0000ff)
6503 #define is_blue_color(color) ( ((color) & 0x00ffffff) == 0xff )
6504 #define get_bitmap_pixel(x,y) pixel[(y)*(width) + (x)]
6505 static DWORD* GetBitmapPixelBuffer(HDC hdc, HBITMAP hbmp, int width, int height)
6507 BITMAPINFOHEADER bi;
6508 UINT lines = 0;
6509 DWORD *buffer = (DWORD *)GdipAlloc(width*height*4);
6511 bi.biSize = sizeof(BITMAPINFOHEADER);
6512 bi.biWidth = width;
6513 bi.biHeight = -height; /*very Important, set negative, indicating a top-down DIB*/
6514 bi.biPlanes = 1;
6515 bi.biBitCount = 32;
6516 bi.biCompression = BI_RGB;
6517 bi.biSizeImage = 0;
6518 bi.biXPelsPerMeter = 0;
6519 bi.biYPelsPerMeter = 0;
6520 bi.biClrUsed = 0;
6521 bi.biClrImportant = 0;
6523 lines = GetDIBits(hdc, hbmp, 0, height, buffer, (BITMAPINFO *)&bi, DIB_RGB_COLORS);
6524 ok(lines == height, "Expected GetDIBits:%p,%d->%d,%ld\n", buffer, height, lines, GetLastError());
6526 return buffer;
6529 static void test_GdipFillRectanglesOnMemoryDCSolidBrush(void)
6531 ARGB color[6] = {0,0,0,0,0,0};
6532 POINT pt = {0,0};
6533 RECT rect = {100, 100, 180, 180};
6534 UINT width = rect.right - rect.left;
6535 UINT height = rect.bottom - rect.top;
6536 GpStatus status = 0;
6537 GpSolidFill *brush = NULL;
6538 GpGraphics *graphics = NULL;
6539 HDC dc = GetDC( hwnd);
6540 HDC hdc = CreateCompatibleDC(dc);
6541 HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
6542 HGDIOBJ old = SelectObject(hdc, bmp);
6543 DWORD* pixel = NULL;
6545 /*Change the window origin is the key test point*/
6546 SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
6548 status = GdipCreateSolidFill(BLUE_COLOR, &brush);
6549 expect(Ok, status);
6551 status = GdipCreateFromHDC(hdc, &graphics);
6552 expect(Ok, status);
6554 status = GdipSetClipRectI(graphics, rect.left+width/2, rect.top+height/2,
6555 width, height, CombineModeReplace);
6556 expect(Ok, status);
6558 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, rect.right, rect.bottom);
6559 expect(Ok, status);
6561 GdipDeleteBrush((GpBrush*)brush);
6562 GdipDeleteGraphics(graphics);
6564 pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
6565 if (pixel)
6567 color[0] = get_bitmap_pixel(width/2, height/2);
6568 color[1] = get_bitmap_pixel(width/2+1, height/2);
6569 color[2] = get_bitmap_pixel(width/2, height/2+1);
6570 color[3] = get_bitmap_pixel(width/2-1, height/2-1);
6571 color[4] = get_bitmap_pixel(width/2-1, height-1);
6572 color[5] = get_bitmap_pixel(width-1, height/2-1);
6575 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6576 color[3] == 0 && color[4] == 0 && color[5] == 0,
6577 "Expected GdipFillRectangleI take effect!\n" );
6578 GdipFree(pixel);
6580 SelectObject(hdc, old);
6581 DeleteObject(bmp);
6582 DeleteDC(hdc);
6583 ReleaseDC(hwnd, dc);
6586 static void test_GdipFillRectanglesOnMemoryDCTextureBrush(void)
6588 ARGB color[6] = {0,0,0,0,0,0};
6589 POINT pt = {0,0};
6590 RECT rect = {100, 100, 180, 180};
6591 UINT width = rect.right - rect.left;
6592 UINT height = rect.bottom - rect.top;
6593 GpStatus status = 0;
6594 union
6596 GpBitmap *bitmap;
6597 GpImage *image;
6598 } src_img;
6599 GpTexture *brush = NULL;
6600 GpGraphics *graphics = NULL;
6601 HDC dc = GetDC( hwnd);
6602 HDC hdc = CreateCompatibleDC(dc);
6603 HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
6604 HGDIOBJ old = SelectObject(hdc, bmp);
6606 UINT x = 0;
6607 UINT y = 0;
6608 UINT src_img_width = width/2;
6609 UINT src_img_height = height/2;
6610 BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
6611 DWORD *pixel = (DWORD *)src_img_data;
6612 ok(pixel != NULL, "Expected src_img_data is valid\n");
6614 /*Change the window origin is the key test point*/
6615 SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
6617 /*build a blue solid image!*/
6618 for(y = 0; y < src_img_height; ++y)
6620 for(x = 0; x < src_img_width; ++x)
6622 pixel[x] = BLUE_COLOR;
6625 pixel += src_img_width;
6628 status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
6629 PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
6630 expect(Ok, status);
6632 status = GdipCreateTexture(src_img.image, 0, &brush);
6633 expect(Ok, status);
6635 status = GdipCreateFromHDC(hdc, &graphics);
6636 expect(Ok, status);
6638 status = GdipSetClipRectI(graphics, rect.left+width/2, rect.top+height/2,
6639 width, height, CombineModeReplace);
6640 expect(Ok, status);
6642 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, rect.right, rect.bottom);
6643 expect(Ok, status);
6645 GdipDisposeImage(src_img.image);
6646 GdipDeleteBrush((GpBrush*)brush);
6647 GdipDeleteGraphics(graphics);
6648 GdipFree(src_img_data);
6650 pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
6651 if (pixel)
6653 color[0] = get_bitmap_pixel(width/2, height/2);
6654 color[1] = get_bitmap_pixel(width/2+1, height/2);
6655 color[2] = get_bitmap_pixel(width/2, height/2+1);
6656 color[3] = get_bitmap_pixel(width/2-1, height/2-1);
6657 color[4] = get_bitmap_pixel(width/2-1, height-1);
6658 color[5] = get_bitmap_pixel(width-1, height/2-1);
6660 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6661 color[3] == 0 && color[4] == 0 && color[5] == 0,
6662 "Expected GdipFillRectangleI take effect!\n" );
6663 GdipFree(pixel);
6665 SelectObject(hdc, old);
6666 DeleteObject(bmp);
6667 DeleteDC(hdc);
6668 ReleaseDC(hwnd, dc);
6671 static void test_GdipFillRectanglesOnBitmapTextureBrush(void)
6673 ARGB color[6] = {0,0,0,0,0,0};
6674 UINT x = 0;
6675 UINT y = 0;
6676 RECT rect = {100, 100, 180, 180};
6677 UINT width = rect.right - rect.left;
6678 UINT height = rect.bottom - rect.top;
6679 UINT src_img_width = width/2;
6680 UINT src_img_height = height/2;
6682 GpStatus status = 0;
6683 union
6685 GpBitmap *bitmap;
6686 GpImage *image;
6687 } src_img;
6688 union
6690 GpBitmap *bitmap;
6691 GpImage *image;
6692 } dst_img;
6694 GpTexture *brush = NULL;
6695 GpGraphics *graphics = NULL;
6696 BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
6697 DWORD *pixel = (DWORD *)src_img_data;
6698 ok(pixel != NULL, "Expected src_img_data is valid\n");
6700 status = GdipCreateBitmapFromScan0(width, height, width*4,
6701 PixelFormat32bppARGB, NULL, &dst_img.bitmap);
6702 expect(Ok, status);
6704 /*build a blue solid image!*/
6705 for(y = 0; y < src_img_height; ++y)
6707 for(x = 0; x < src_img_width; ++x)
6709 pixel[x] = BLUE_COLOR;
6712 pixel += src_img_width;
6715 status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
6716 PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
6717 expect(Ok, status);
6719 status = GdipCreateTexture(src_img.image, 0, &brush);
6720 expect(Ok, status);
6722 status = GdipGetImageGraphicsContext(dst_img.image, &graphics);
6723 expect(Ok, status);
6725 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
6726 expect(Ok, status);
6728 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, width/2, height/2);
6729 expect(Ok, status);
6731 GdipDeleteBrush((GpBrush*)brush);
6732 GdipDeleteGraphics(graphics);
6734 status = GdipBitmapGetPixel(dst_img.bitmap, 0, 0, &color[0]);
6735 expect(Ok, status);
6736 status = GdipBitmapGetPixel(dst_img.bitmap, 0, 1, &color[1]);
6737 expect(Ok, status);
6738 status = GdipBitmapGetPixel(dst_img.bitmap, 1, 0, &color[2]);
6739 expect(Ok, status);
6740 status = GdipBitmapGetPixel(dst_img.bitmap, width/2, 0, &color[3]);
6741 expect(Ok, status);
6742 status = GdipBitmapGetPixel(dst_img.bitmap, width/2, height/2, &color[4]);
6743 expect(Ok, status);
6744 status = GdipBitmapGetPixel(dst_img.bitmap, 0, height/2, &color[5]);
6745 expect(Ok, status);
6747 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6748 color[3] == 0 && color[4] == 0 && color[5] == 0,
6749 "Expected GdipFillRectangleI take effect!\n" );
6751 GdipDisposeImage(src_img.image);
6752 GdipDisposeImage(dst_img.image);
6753 GdipFree(src_img_data);
6756 static void test_GdipDrawImagePointsRectOnMemoryDC(void)
6758 ARGB color[6] = {0,0,0,0,0,0};
6759 POINT pt = {0,0};
6760 RECT rect = {100, 100, 180, 180};
6761 UINT width = rect.right - rect.left;
6762 UINT height = rect.bottom - rect.top;
6763 GpStatus status = 0;
6764 union
6766 GpBitmap *bitmap;
6767 GpImage *image;
6768 } src_img;
6769 GpGraphics *graphics = NULL;
6770 HDC dc = GetDC( hwnd);
6771 HDC hdc = CreateCompatibleDC(dc);
6772 HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
6773 HGDIOBJ old = SelectObject(hdc, bmp);
6775 UINT x = 0;
6776 UINT y = 0;
6777 UINT src_img_width = width/2;
6778 UINT src_img_height = height/2;
6779 BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
6780 DWORD *pixel = (DWORD *)src_img_data;
6781 ok(pixel != NULL, "Expected src_img_data is valid\n");
6783 /*Change the window origin is the key test point*/
6784 SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
6786 /*build a blue solid image!*/
6787 for(y = 0; y < src_img_height; ++y)
6789 for(x = 0; x < src_img_width; ++x)
6791 pixel[x] = BLUE_COLOR;
6794 pixel += src_img_width;
6797 status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
6798 PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
6799 expect(Ok, status);
6801 status = GdipCreateFromHDC(hdc, &graphics);
6802 expect(Ok, status);
6804 status = GdipDrawImageRectRectI(graphics, src_img.image,
6805 rect.left+width/2, rect.top+height/2, width/2, height/2,
6806 0, 0, src_img_width, src_img_height, UnitPixel, NULL, NULL, NULL);
6807 expect(Ok, status);
6809 GdipDisposeImage(src_img.image);
6810 GdipDeleteGraphics(graphics);
6811 GdipFree(src_img_data);
6813 pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
6814 if (pixel)
6816 color[0] = get_bitmap_pixel(width/2, height/2);
6817 color[1] = get_bitmap_pixel(width/2+1, height/2);
6818 color[2] = get_bitmap_pixel(width/2, height/2+1);
6819 color[3] = get_bitmap_pixel(width/2-1, height/2-1);
6820 color[4] = get_bitmap_pixel(width/2-1, height-1);
6821 color[5] = get_bitmap_pixel(width-1, height/2-1);
6823 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6824 color[3] == 0 && color[4] == 0 && color[5] == 0,
6825 "Expected GdipDrawImageRectRectI take effect!\n" );
6826 GdipFree(pixel);
6828 SelectObject(hdc, old);
6829 DeleteObject(bmp);
6830 DeleteDC(hdc);
6831 ReleaseDC(hwnd, dc);
6834 static void test_cliphrgn_transform(void)
6836 HDC hdc;
6837 GpStatus status;
6838 GpGraphics *graphics;
6839 HRGN rgn;
6840 RectF rectf;
6841 BOOL res;
6843 hdc = GetDC(hwnd);
6845 SetViewportOrgEx(hdc, 10, 10, NULL);
6847 status = GdipCreateFromHDC(hdc, &graphics);
6848 expect(Ok, status);
6850 rgn = CreateRectRgn(0, 0, 100, 100);
6852 status = GdipSetClipHrgn(graphics, rgn, CombineModeReplace);
6853 expect(Ok, status);
6855 status = GdipGetVisibleClipBounds(graphics, &rectf);
6856 expect(Ok, status);
6857 expectf(-10.0, rectf.X);
6858 expectf(-10.0, rectf.Y);
6859 expectf(100.0, rectf.Width);
6860 expectf(100.0, rectf.Height);
6862 status = GdipIsVisiblePoint(graphics, 95, 95, &res);
6863 expect(Ok, status);
6864 expect(FALSE, res);
6866 status = GdipIsVisiblePoint(graphics, -5, -5, &res);
6867 expect(Ok, status);
6868 expect(TRUE, res);
6870 DeleteObject(rgn);
6872 GdipDeleteGraphics(graphics);
6874 SetViewportOrgEx(hdc, 0, 0, NULL);
6876 ReleaseDC(hwnd, hdc);
6879 static void test_hdc_caching(void)
6881 GpStatus status;
6882 HDC hdc;
6883 HBITMAP hbm;
6884 GpGraphics *graphics;
6885 ULONG *bits;
6886 BITMAPINFO bmi;
6887 HRGN hrgn;
6888 GpBrush *brush;
6890 hdc = CreateCompatibleDC(0);
6891 ok(hdc != NULL, "CreateCompatibleDC failed\n");
6892 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
6893 bmi.bmiHeader.biHeight = -5;
6894 bmi.bmiHeader.biWidth = 5;
6895 bmi.bmiHeader.biBitCount = 32;
6896 bmi.bmiHeader.biPlanes = 1;
6897 bmi.bmiHeader.biCompression = BI_RGB;
6898 bmi.bmiHeader.biClrUsed = 0;
6900 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
6901 ok(hbm != NULL, "CreateDIBSection failed\n");
6903 SelectObject(hdc, hbm);
6905 SetViewportOrgEx(hdc, 1, 1, NULL);
6907 hrgn = CreateRectRgn(0, 0, 3, 3);
6908 SelectClipRgn(hdc, hrgn);
6909 DeleteObject(hrgn);
6911 status = GdipCreateSolidFill((ARGB)0xffaaaaaa, (GpSolidFill**)&brush);
6912 expect(Ok, status);
6914 status = GdipCreateFromHDC(hdc, &graphics);
6915 expect(Ok, status);
6917 memset(bits, 0, sizeof(*bits) * 25);
6918 status = GdipFillRectangleI(graphics, brush, 0, 0, 4, 4);
6919 expect(Ok, status);
6921 expect(0, bits[0]);
6922 expect(0xffaaaaaa, bits[6]);
6923 expect(0xffaaaaaa, bits[12]);
6924 expect(0, bits[18]);
6925 expect(0, bits[24]);
6927 SetViewportOrgEx(hdc, 0, 0, NULL);
6928 OffsetClipRgn(hdc, 2, 2);
6930 memset(bits, 0, sizeof(*bits) * 25);
6931 status = GdipFillRectangleI(graphics, brush, 0, 0, 4, 4);
6932 expect(Ok, status);
6934 expect(0, bits[0]);
6935 expect(0xffaaaaaa, bits[6]);
6936 expect(0xffaaaaaa, bits[12]);
6937 expect(0, bits[18]);
6938 expect(0, bits[24]);
6940 GdipDeleteGraphics(graphics);
6942 GdipDeleteBrush(brush);
6944 DeleteDC(hdc);
6945 DeleteObject(hbm);
6948 static void test_gdi_interop_bitmap(void)
6950 GpBitmap *bitmap;
6951 GpGraphics *graphics;
6952 GpMatrix *transform;
6953 GpBrush *brush;
6954 GpStatus stat;
6955 HDC hdc;
6956 HBRUSH hbrush, holdbrush;
6957 ARGB color;
6959 stat = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB, NULL, &bitmap);
6960 expect(Ok, stat);
6962 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
6963 expect(Ok, stat);
6965 stat = GdipCreateMatrix(&transform);
6966 expect(Ok, stat);
6968 stat = GdipSetMatrixElements(transform, 1.0, 0.0, 0.0, 1.0, 50.0, 50.0);
6969 expect(Ok, stat);
6971 /* GDI+: Set world transform. Should not matter to GDI. */
6972 stat = GdipSetWorldTransform(graphics, transform);
6973 expect(Ok, stat);
6975 stat = GdipGetDC(graphics, &hdc);
6976 expect(Ok, stat);
6978 hbrush = CreateSolidBrush(0xff0000);
6980 holdbrush = SelectObject(hdc, hbrush);
6982 /* GDI: Draw a rectangle at physical coords (5, 5) to (12, 10). */
6983 Rectangle(hdc, 5, 5, 12, 10);
6985 holdbrush = SelectObject(hdc, holdbrush);
6987 /* GDI: Set view port origin. Should not matter to GDI+. */
6988 SetViewportOrgEx(hdc, 20, 20, NULL);
6990 GdipReleaseDC(graphics, hdc);
6992 stat = GdipCreateSolidFill((ARGB)0xff0000ff, (GpSolidFill**)&brush);
6993 expect(Ok, stat);
6995 /* GDI+: Draw a rectangle at physical coords (85, 85) to (88, 95). */
6996 stat = GdipFillRectangleI(graphics, brush, 35, 35, 3, 10);
6997 expect(Ok, stat);
6999 stat = GdipDeleteBrush(brush);
7000 expect(Ok, stat);
7002 stat = GdipGetDC(graphics, &hdc);
7003 expect(Ok, stat);
7005 holdbrush = SelectObject(hdc, hbrush);
7007 /* GDI: Draw a rectangle at physical coords (25, 25) to (30, 34).
7008 Updated view port origin should still be in effect. */
7009 Rectangle(hdc, 5, 5, 10, 14);
7011 SelectObject(hdc, holdbrush);
7013 DeleteObject(hbrush);
7014 stat = GdipReleaseDC(graphics, hdc);
7015 expect(Ok, stat);
7017 stat = GdipDeleteMatrix(transform);
7018 expect(Ok, stat);
7020 stat = GdipBitmapGetPixel(bitmap, 6, 6, &color);
7021 expect(Ok, stat);
7022 expect(0xff0000ff, color);
7024 stat = GdipBitmapGetPixel(bitmap, 26, 26, &color);
7025 expect(Ok, stat);
7026 expect(0xff0000ff, color);
7028 stat = GdipBitmapGetPixel(bitmap, 86, 86, &color);
7029 expect(Ok, stat);
7030 expect(0xff0000ff, color);
7032 stat = GdipDeleteGraphics(graphics);
7033 expect(Ok, stat);
7035 stat = GdipDisposeImage((GpImage*)bitmap);
7036 expect(Ok, stat);
7039 static void test_gdi_interop_hdc(void)
7041 BITMAPINFO bmi;
7042 GpBrush *brush;
7043 GpGraphics *graphics;
7044 GpMatrix *transform;
7045 GpStatus stat;
7046 HBITMAP hbm;
7047 HBRUSH hbrush, holdbrush;
7048 HDC gdi_hdc;
7049 HDC src_hdc;
7050 ULONG *bits;
7051 XFORM xform = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
7053 src_hdc = CreateCompatibleDC(0);
7054 ok(src_hdc != NULL, "CreateCompatibleDC failed\n");
7056 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
7057 bmi.bmiHeader.biHeight = -100;
7058 bmi.bmiHeader.biWidth = 100;
7059 bmi.bmiHeader.biBitCount = 32;
7060 bmi.bmiHeader.biPlanes = 1;
7061 bmi.bmiHeader.biCompression = BI_RGB;
7062 bmi.bmiHeader.biClrUsed = 0;
7063 bmi.bmiHeader.biClrImportant = 0;
7065 hbm = CreateDIBSection(src_hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
7066 ok(hbm != NULL, "CreateDIBSection failed\n");
7068 SelectObject(src_hdc, hbm);
7070 SetGraphicsMode(src_hdc, GM_ADVANCED);
7072 xform.eDx = 10.0;
7073 xform.eDy = 10.0;
7074 SetWorldTransform(src_hdc, &xform);
7076 stat = GdipCreateFromHDC(src_hdc, &graphics);
7077 expect(Ok, stat);
7079 stat = GdipCreateMatrix(&transform);
7080 expect(Ok, stat);
7082 stat = GdipSetMatrixElements(transform, 1.0, 0.0, 0.0, 1.0, 40.0, 40.0);
7083 expect(Ok, stat);
7085 /* GDI+: Set world transform. Should not matter to GDI. */
7086 stat = GdipSetWorldTransform(graphics, transform);
7087 expect(Ok, stat);
7089 stat = GdipGetDC(graphics, &gdi_hdc);
7090 expect(Ok, stat);
7091 ok( gdi_hdc == src_hdc, "wrong dc\n" );
7093 /* GDI: Set GDI transform back to (0, 0).
7094 Should not matter to GDI+. */
7095 xform.eDx = 0.0;
7096 xform.eDy = 0.0;
7097 SetWorldTransform(gdi_hdc, &xform);
7099 hbrush = CreateSolidBrush(0xff00aa);
7101 holdbrush = SelectObject(gdi_hdc, hbrush);
7103 /* GDI: Draw a rectangle at physical coords (5, 5) to (12, 10). */
7104 Rectangle(gdi_hdc, 5, 5, 12, 10);
7106 holdbrush = SelectObject(gdi_hdc, holdbrush);
7108 /* GDI: Set GDI transform to translate (+20, +20).
7109 Should not matter to GDI+. */
7110 xform.eDx = 20.0;
7111 xform.eDy = 20.0;
7112 SetWorldTransform(gdi_hdc, &xform);
7114 GdipReleaseDC(graphics, gdi_hdc);
7116 /* GDI world transform should still be intact, even when back
7117 in GDI+ mode. */
7118 stat = GetWorldTransform(src_hdc, &xform);
7119 expect(TRUE, stat);
7120 expect(20.0, xform.eDx);
7121 expect(20.0, xform.eDy);
7123 stat = GdipCreateSolidFill((ARGB)0xffaa00ff, (GpSolidFill**)&brush);
7124 expect(Ok, stat);
7126 /* GDI+: Draw a rectangle at physical coords (85, 85) to (88, 95).
7127 The fact that the GDI world transform has been updated should
7128 not influence the GDI+ world transform. GDI+ should still apply
7129 the world transform from the when HDC backed graphics object was
7130 instantiated. */
7131 stat = GdipFillRectangleI(graphics, brush, 35, 35, 3, 10);
7132 expect(Ok, stat);
7134 stat = GdipDeleteBrush(brush);
7135 expect(Ok, stat);
7137 stat = GdipGetDC(graphics, &gdi_hdc);
7138 expect(Ok, stat);
7140 holdbrush = SelectObject(gdi_hdc, hbrush);
7142 /* GDI: Draw a rectangle at physical coords (25, 25) to (30, 34).
7143 Updated transform should still be in effect. */
7144 Rectangle(gdi_hdc, 5, 5, 10, 14);
7146 SelectObject(gdi_hdc, holdbrush);
7148 stat = GdipReleaseDC(graphics, gdi_hdc);
7149 expect(Ok, stat);
7151 GdipDeleteGraphics(graphics);
7152 stat = GdipDeleteMatrix(transform);
7153 expect(Ok, stat);
7155 holdbrush = SelectObject(src_hdc, hbrush);
7157 /* GDI: Draw a rectangle at physical coords (35, 35) to (40, 38).
7158 Updated transform should still be in effect on src_hdc. */
7159 Rectangle(gdi_hdc, 15, 15, 20, 18);
7161 SelectObject(gdi_hdc, holdbrush);
7163 DeleteObject(hbrush);
7165 expect(0x00aa00ff, bits[6 * 100 + 6]);
7166 expect(0x00aa00ff, bits[26 * 100 + 26]);
7167 expect(0x00aa00ff, bits[36 * 100 + 36]);
7168 expect(0xffaa00ff, bits[86 * 100 + 86]);
7170 DeleteDC(src_hdc);
7171 DeleteObject(hbm);
7174 static HDC create_printer_dc(void)
7176 char buffer[260];
7177 DWORD len;
7178 PRINTER_INFO_2A *pbuf = NULL;
7179 DRIVER_INFO_3A *dbuf = NULL;
7180 HANDLE hprn = 0;
7181 HDC hdc = 0;
7182 HMODULE winspool = LoadLibraryA("winspool.drv");
7183 BOOL (WINAPI *pOpenPrinterA)(LPSTR, HANDLE *, LPPRINTER_DEFAULTSA);
7184 BOOL (WINAPI *pGetDefaultPrinterA)(LPSTR, LPDWORD);
7185 BOOL (WINAPI *pGetPrinterA)(HANDLE, DWORD, LPBYTE, DWORD, LPDWORD);
7186 BOOL (WINAPI *pGetPrinterDriverA)(HANDLE, LPSTR, DWORD, LPBYTE, DWORD, LPDWORD);
7187 BOOL (WINAPI *pClosePrinter)(HANDLE);
7189 pGetDefaultPrinterA = (void *)GetProcAddress(winspool, "GetDefaultPrinterA");
7190 pOpenPrinterA = (void *)GetProcAddress(winspool, "OpenPrinterA");
7191 pGetPrinterA = (void *)GetProcAddress(winspool, "GetPrinterA");
7192 pGetPrinterDriverA = (void *)GetProcAddress(winspool, "GetPrinterDriverA");
7193 pClosePrinter = (void *)GetProcAddress(winspool, "ClosePrinter");
7195 if (!pGetDefaultPrinterA || !pOpenPrinterA || !pGetPrinterA || !pGetPrinterDriverA || !pClosePrinter)
7196 goto done;
7198 len = sizeof(buffer);
7199 if (!pGetDefaultPrinterA(buffer, &len)) goto done;
7200 if (!pOpenPrinterA(buffer, &hprn, NULL)) goto done;
7202 pGetPrinterA(hprn, 2, NULL, 0, &len);
7203 pbuf = HeapAlloc(GetProcessHeap(), 0, len);
7204 if (!pGetPrinterA(hprn, 2, (LPBYTE)pbuf, len, &len)) goto done;
7206 pGetPrinterDriverA(hprn, NULL, 3, NULL, 0, &len);
7207 dbuf = HeapAlloc(GetProcessHeap(), 0, len);
7208 if (!pGetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, len, &len)) goto done;
7210 hdc = CreateDCA(dbuf->pDriverPath, pbuf->pPrinterName, pbuf->pPortName, pbuf->pDevMode);
7211 trace("hdc %p for driver '%s' printer '%s' port '%s'\n", hdc,
7212 dbuf->pDriverPath, pbuf->pPrinterName, pbuf->pPortName);
7213 done:
7214 HeapFree(GetProcessHeap(), 0, dbuf);
7215 HeapFree(GetProcessHeap(), 0, pbuf);
7216 if (hprn) pClosePrinter(hprn);
7217 if (winspool) FreeLibrary(winspool);
7218 return hdc;
7221 static BOOL check_rect_pixels(const DWORD *pixel, const RectF *rect, UINT width, DWORD expected, Point *failed)
7223 UINT x, y;
7224 BOOL ret = TRUE;
7226 for (y = (UINT)rect->Y; y < (UINT)(rect->Y + rect->Height); y++)
7228 for (x = (UINT)rect->X; x < (UINT)(rect->X + rect->Width); x++)
7230 if (pixel[x + y * width] != expected)
7232 ret = FALSE;
7233 goto done;
7238 done:
7239 if (!ret)
7241 failed->X = x;
7242 failed->Y = y;
7244 else
7246 failed->X = 0;
7247 failed->Y = 0;
7249 return ret;
7252 static void test_printer_dc(void)
7254 HDC hdc_printer, hdc;
7255 Status status;
7256 GpGraphics *graphics;
7257 REAL dpi_x, dpi_y, pixel_per_unit_x, pixel_per_unit_y;
7258 HBITMAP bitmap;
7259 UINT width = 16, height = 16;
7260 GpUnit unit;
7261 GpSolidFill *brush;
7262 DWORD *pixel;
7263 BOOL match;
7264 RectF rect;
7265 Point pt;
7267 hdc_printer = create_printer_dc();
7268 if (!hdc_printer)
7270 skip("could not create a DC for the default printer\n");
7271 return;
7274 hdc = CreateCompatibleDC(hdc_printer);
7275 bitmap = CreateCompatibleBitmap(hdc, width, height);
7276 SelectObject(hdc, bitmap);
7278 status = GdipCreateFromHDC(hdc, &graphics);
7279 expect(Ok, status);
7281 GdipGetPageUnit(graphics, &unit);
7282 expect(UnitDisplay, unit);
7284 GdipGetDpiX(graphics, &dpi_x);
7285 GdipGetDpiY(graphics, &dpi_y);
7286 expectf((REAL)GetDeviceCaps(hdc, LOGPIXELSX), dpi_x);
7287 expectf((REAL)GetDeviceCaps(hdc, LOGPIXELSY), dpi_y);
7289 /* For graphics created from printer DC, UnitDisplay specifies that a unit is 1/100 inch */
7290 pixel_per_unit_x = dpi_x / 100.0;
7291 pixel_per_unit_y = dpi_y / 100.0;
7293 status = GdipCreateSolidFill((ARGB)0xffffffff, &brush);
7294 expect(Ok, status);
7296 status = GdipFillRectangleI(graphics, (GpBrush *)brush, 1, 1, 1, 1);
7297 expect(Ok, status);
7299 pixel = GetBitmapPixelBuffer(hdc, bitmap, width, height);
7301 /* pixels at (0, 0) should all be 0 */
7302 rect.X = 0;
7303 rect.Y = 0;
7304 rect.Width = pixel_per_unit_x;
7305 rect.Height = pixel_per_unit_y;
7306 match = check_rect_pixels(pixel, &rect, width, 0, &pt);
7307 ok(match, "Expected pixel (%u, %u) to be %08x, got %08lx\n",
7308 pt.X, pt.Y, 0, pixel[pt.X + pt.Y * width]);
7310 /* pixels at (1, 1) should all be 0x00ffffff */
7311 rect.X = pixel_per_unit_x;
7312 rect.Y = pixel_per_unit_y;
7313 rect.Width = pixel_per_unit_x;
7314 rect.Height = pixel_per_unit_y;
7315 match = check_rect_pixels(pixel, &rect, width, 0x00ffffff, &pt);
7316 ok(match, "Expected pixel (%u, %u) to be %08x, got %08lx\n",
7317 pt.X, pt.Y, 0x00ffffff, pixel[pt.X + pt.Y * width]);
7319 GdipFree(pixel);
7320 GdipDeleteBrush((GpBrush *)brush);
7321 GdipDeleteGraphics(graphics);
7322 DeleteObject(bitmap);
7323 DeleteDC(hdc);
7324 DeleteDC(hdc_printer);
7327 START_TEST(graphics)
7329 struct GdiplusStartupInput gdiplusStartupInput;
7330 ULONG_PTR gdiplusToken;
7331 WNDCLASSA class;
7332 HMODULE gdiplus_mod = GetModuleHandleA("gdiplus.dll");
7333 HMODULE hmsvcrt;
7334 int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask);
7336 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
7337 hmsvcrt = LoadLibraryA("msvcrt");
7338 _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s");
7339 if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e);
7341 pGdipGraphicsSetAbort = (void*)GetProcAddress(gdiplus_mod, "GdipGraphicsSetAbort");
7343 memset( &class, 0, sizeof(class) );
7344 class.lpszClassName = "gdiplus_test";
7345 class.style = CS_HREDRAW | CS_VREDRAW;
7346 class.lpfnWndProc = DefWindowProcA;
7347 class.hInstance = GetModuleHandleA(0);
7348 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
7349 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7350 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
7351 RegisterClassA( &class );
7352 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7353 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
7354 ok(hwnd != NULL, "Expected window to be created\n");
7356 gdiplusStartupInput.GdiplusVersion = 1;
7357 gdiplusStartupInput.DebugEventCallback = NULL;
7358 gdiplusStartupInput.SuppressBackgroundThread = 0;
7359 gdiplusStartupInput.SuppressExternalCodecs = 0;
7361 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
7363 test_clipping();
7364 test_clipping_2();
7365 test_measured_extra_space();
7366 test_measure_string();
7367 test_font_height_scaling();
7368 test_transform();
7369 test_set_page_transform();
7370 test_pen_thickness();
7371 test_GdipMeasureString();
7372 test_constructor_destructor();
7373 test_save_restore();
7374 test_GdipFillClosedCurve2();
7375 test_GdipFillClosedCurve2I();
7376 test_GdipDrawBezierI();
7377 test_GdipDrawArc();
7378 test_GdipDrawArcI();
7379 test_GdipDrawCurve();
7380 test_GdipDrawCurveI();
7381 test_GdipDrawCurve2();
7382 test_GdipDrawCurve2I();
7383 test_GdipDrawCurve3();
7384 test_GdipDrawCurve3I();
7385 test_GdipDrawLineI();
7386 test_GdipDrawLinesI();
7387 test_GdipDrawImagePointsRect();
7388 test_GdipFillClosedCurve();
7389 test_GdipFillClosedCurveI();
7390 test_GdipFillPath();
7391 test_GdipDrawString();
7392 test_GdipGetNearestColor();
7393 test_GdipGetVisibleClipBounds();
7394 test_GdipIsVisiblePoint();
7395 test_GdipIsVisibleRect();
7396 test_Get_Release_DC();
7397 test_BeginContainer2();
7398 test_transformpoints();
7399 test_get_set_clip();
7400 test_clip_xform();
7401 test_isempty();
7402 test_clear();
7403 test_textcontrast();
7404 test_fromMemoryBitmap();
7405 test_string_functions();
7406 test_get_set_interpolation();
7407 test_get_set_textrenderinghint();
7408 test_getdc_scaled();
7409 test_alpha_hdc();
7410 test_bitmapfromgraphics();
7411 test_GdipFillRectangles();
7412 test_GdipGetVisibleClipBounds_memoryDC();
7413 test_GdipFillRectanglesOnMemoryDCSolidBrush();
7414 test_GdipFillRectanglesOnMemoryDCTextureBrush();
7415 test_GdipFillRectanglesOnBitmapTextureBrush();
7416 test_GdipDrawImagePointsRectOnMemoryDC();
7417 test_container_rects();
7418 test_GdipGraphicsSetAbort();
7419 test_cliphrgn_transform();
7420 test_hdc_caching();
7421 test_gdi_interop_bitmap();
7422 test_gdi_interop_hdc();
7423 test_printer_dc();
7425 GdiplusShutdown(gdiplusToken);
7426 DestroyWindow( hwnd );