ntdll: Add stub for RtlSetHeapInformation.
[wine.git] / dlls / gdiplus / tests / graphics.c
blobc9cc4633e976c21ab221fa371b7a5accc8ab9347
1 /*
2 * Unit test suite for graphics objects
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <math.h>
24 #include "objbase.h"
25 #include "gdiplus.h"
26 #include "wine/test.h"
28 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
29 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
30 #define expectf(expected, got) expectf_((expected), (got), 0.001)
32 static const REAL mm_per_inch = 25.4;
33 static const REAL point_per_inch = 72.0;
34 static HWND hwnd;
36 static void set_rect_empty(RectF *rc)
38 rc->X = 0.0;
39 rc->Y = 0.0;
40 rc->Width = 0.0;
41 rc->Height = 0.0;
44 /* converts a given unit to its value in pixels */
45 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
47 switch (unit)
49 case UnitPixel:
50 case UnitDisplay:
51 return units;
52 case UnitPoint:
53 return units * dpi / point_per_inch;
54 case UnitInch:
55 return units * dpi;
56 case UnitDocument:
57 return units * dpi / 300.0; /* Per MSDN */
58 case UnitMillimeter:
59 return units * dpi / mm_per_inch;
60 default:
61 ok(0, "Unsupported unit: %d\n", unit);
62 return 0;
66 /* converts value in pixels to a given unit */
67 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
69 switch (unit)
71 case UnitPixel:
72 case UnitDisplay:
73 return pixels;
74 case UnitPoint:
75 return pixels * point_per_inch / dpi;
76 case UnitInch:
77 return pixels / dpi;
78 case UnitDocument:
79 return pixels * 300.0 / dpi;
80 case UnitMillimeter:
81 return pixels * mm_per_inch / dpi;
82 default:
83 ok(0, "Unsupported unit: %d\n", unit);
84 return 0;
88 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
90 REAL pixels = units_to_pixels(1.0, from, dpi);
91 return pixels_to_units(pixels, to, dpi);
94 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale, GpImage **image)
96 GpStatus status;
97 union
99 GpBitmap *bitmap;
100 GpImage *image;
101 } u;
102 GpGraphics *graphics = NULL;
103 REAL res;
105 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
106 expect(Ok, status);
108 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
109 expect(Ok, status);
110 status = GdipGetImageHorizontalResolution(u.image, &res);
111 expect(Ok, status);
112 expectf(res_x, res);
113 status = GdipGetImageVerticalResolution(u.image, &res);
114 expect(Ok, status);
115 expectf(res_y, res);
117 status = GdipGetImageGraphicsContext(u.image, &graphics);
118 expect(Ok, status);
120 *image = u.image;
122 status = GdipGetDpiX(graphics, &res);
123 expect(Ok, status);
124 expectf(res_x, res);
125 status = GdipGetDpiY(graphics, &res);
126 expect(Ok, status);
127 expectf(res_y, res);
129 status = GdipSetPageUnit(graphics, unit);
130 expect(Ok, status);
131 status = GdipSetPageScale(graphics, scale);
132 expect(Ok, status);
134 return graphics;
137 static void test_constructor_destructor(void)
139 GpStatus stat;
140 GpGraphics *graphics = NULL;
141 HDC hdc = GetDC( hwnd );
143 stat = GdipCreateFromHDC(NULL, &graphics);
144 expect(OutOfMemory, stat);
145 stat = GdipDeleteGraphics(graphics);
146 expect(InvalidParameter, stat);
148 stat = GdipCreateFromHDC(hdc, &graphics);
149 expect(Ok, stat);
150 stat = GdipDeleteGraphics(graphics);
151 expect(Ok, stat);
153 stat = GdipCreateFromHWND(NULL, &graphics);
154 expect(Ok, stat);
155 stat = GdipDeleteGraphics(graphics);
156 expect(Ok, stat);
158 stat = GdipCreateFromHWNDICM(NULL, &graphics);
159 expect(Ok, stat);
160 stat = GdipDeleteGraphics(graphics);
161 expect(Ok, stat);
163 stat = GdipDeleteGraphics(NULL);
164 expect(InvalidParameter, stat);
165 ReleaseDC(hwnd, hdc);
168 typedef struct node{
169 GraphicsState data;
170 struct node * next;
171 } node;
173 /* Linked list prepend function. */
174 static void log_state(GraphicsState data, node ** log)
176 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
178 new_entry->data = data;
179 new_entry->next = *log;
180 *log = new_entry;
183 /* Checks if there are duplicates in the list, and frees it. */
184 static void check_no_duplicates(node * log)
186 INT dups = 0;
187 node * temp = NULL;
188 node * temp2 = NULL;
189 node * orig = log;
191 if(!log)
192 goto end;
195 temp = log;
196 while((temp = temp->next)){
197 if(log->data == temp->data){
198 dups++;
199 break;
201 if(dups > 0)
202 break;
204 }while((log = log->next));
206 temp = orig;
208 temp2 = temp->next;
209 HeapFree(GetProcessHeap(), 0, temp);
210 temp = temp2;
211 }while(temp);
213 end:
214 expect(0, dups);
217 static void test_save_restore(void)
219 GpStatus stat;
220 GraphicsState state_a, state_b, state_c;
221 InterpolationMode mode;
222 GpGraphics *graphics1, *graphics2;
223 node * state_log = NULL;
224 HDC hdc = GetDC( hwnd );
225 state_a = state_b = state_c = 0xdeadbeef;
227 /* Invalid saving. */
228 GdipCreateFromHDC(hdc, &graphics1);
229 stat = GdipSaveGraphics(graphics1, NULL);
230 expect(InvalidParameter, stat);
231 stat = GdipSaveGraphics(NULL, &state_a);
232 expect(InvalidParameter, stat);
233 GdipDeleteGraphics(graphics1);
235 log_state(state_a, &state_log);
237 /* Basic save/restore. */
238 GdipCreateFromHDC(hdc, &graphics1);
239 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
240 stat = GdipSaveGraphics(graphics1, &state_a);
241 expect(Ok, stat);
242 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
243 stat = GdipRestoreGraphics(graphics1, state_a);
244 expect(Ok, stat);
245 GdipGetInterpolationMode(graphics1, &mode);
246 expect(InterpolationModeBilinear, mode);
247 GdipDeleteGraphics(graphics1);
249 log_state(state_a, &state_log);
251 /* Restoring garbage doesn't affect saves. */
252 GdipCreateFromHDC(hdc, &graphics1);
253 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
254 GdipSaveGraphics(graphics1, &state_a);
255 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
256 GdipSaveGraphics(graphics1, &state_b);
257 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
258 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
259 expect(Ok, stat);
260 GdipRestoreGraphics(graphics1, state_b);
261 GdipGetInterpolationMode(graphics1, &mode);
262 expect(InterpolationModeBicubic, mode);
263 GdipRestoreGraphics(graphics1, state_a);
264 GdipGetInterpolationMode(graphics1, &mode);
265 expect(InterpolationModeBilinear, mode);
266 GdipDeleteGraphics(graphics1);
268 log_state(state_a, &state_log);
269 log_state(state_b, &state_log);
271 /* Restoring older state invalidates newer saves (but not older saves). */
272 GdipCreateFromHDC(hdc, &graphics1);
273 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
274 GdipSaveGraphics(graphics1, &state_a);
275 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
276 GdipSaveGraphics(graphics1, &state_b);
277 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
278 GdipSaveGraphics(graphics1, &state_c);
279 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
280 GdipRestoreGraphics(graphics1, state_b);
281 GdipGetInterpolationMode(graphics1, &mode);
282 expect(InterpolationModeBicubic, mode);
283 GdipRestoreGraphics(graphics1, state_c);
284 GdipGetInterpolationMode(graphics1, &mode);
285 expect(InterpolationModeBicubic, mode);
286 GdipRestoreGraphics(graphics1, state_a);
287 GdipGetInterpolationMode(graphics1, &mode);
288 expect(InterpolationModeBilinear, mode);
289 GdipDeleteGraphics(graphics1);
291 log_state(state_a, &state_log);
292 log_state(state_b, &state_log);
293 log_state(state_c, &state_log);
295 /* Restoring older save from one graphics object does not invalidate
296 * newer save from other graphics object. */
297 GdipCreateFromHDC(hdc, &graphics1);
298 GdipCreateFromHDC(hdc, &graphics2);
299 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
300 GdipSaveGraphics(graphics1, &state_a);
301 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
302 GdipSaveGraphics(graphics2, &state_b);
303 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
304 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
305 GdipRestoreGraphics(graphics1, state_a);
306 GdipGetInterpolationMode(graphics1, &mode);
307 expect(InterpolationModeBilinear, mode);
308 GdipRestoreGraphics(graphics2, state_b);
309 GdipGetInterpolationMode(graphics2, &mode);
310 expect(InterpolationModeBicubic, mode);
311 GdipDeleteGraphics(graphics1);
312 GdipDeleteGraphics(graphics2);
314 /* You can't restore a state to a graphics object that didn't save it. */
315 GdipCreateFromHDC(hdc, &graphics1);
316 GdipCreateFromHDC(hdc, &graphics2);
317 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
318 GdipSaveGraphics(graphics1, &state_a);
319 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
320 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
321 GdipRestoreGraphics(graphics2, state_a);
322 GdipGetInterpolationMode(graphics2, &mode);
323 expect(InterpolationModeNearestNeighbor, mode);
324 GdipDeleteGraphics(graphics1);
325 GdipDeleteGraphics(graphics2);
327 log_state(state_a, &state_log);
329 /* The same state value should never be returned twice. */
330 todo_wine
331 check_no_duplicates(state_log);
333 ReleaseDC(hwnd, hdc);
336 static void test_GdipFillClosedCurve2(void)
338 GpStatus status;
339 GpGraphics *graphics = NULL;
340 GpSolidFill *brush = NULL;
341 HDC hdc = GetDC( hwnd );
342 GpPointF points[3];
344 points[0].X = 0;
345 points[0].Y = 0;
347 points[1].X = 40;
348 points[1].Y = 20;
350 points[2].X = 10;
351 points[2].Y = 40;
353 /* make a graphics object and brush object */
354 ok(hdc != NULL, "Expected HDC to be initialized\n");
356 status = GdipCreateFromHDC(hdc, &graphics);
357 expect(Ok, status);
358 ok(graphics != NULL, "Expected graphics to be initialized\n");
360 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
362 /* InvalidParameter cases: null graphics, null brush, null points */
363 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
364 expect(InvalidParameter, status);
366 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
367 expect(InvalidParameter, status);
369 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
370 expect(InvalidParameter, status);
372 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
373 expect(InvalidParameter, status);
375 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
376 expect(InvalidParameter, status);
378 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
379 expect(InvalidParameter, status);
381 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
382 expect(InvalidParameter, status);
384 /* InvalidParameter cases: invalid count */
385 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
386 expect(InvalidParameter, status);
388 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
389 expect(InvalidParameter, status);
391 /* Valid test cases */
392 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
393 expect(Ok, status);
395 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
396 expect(Ok, status);
398 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
399 expect(Ok, status);
401 GdipDeleteGraphics(graphics);
402 GdipDeleteBrush((GpBrush*)brush);
404 ReleaseDC(hwnd, hdc);
407 static void test_GdipFillClosedCurve2I(void)
409 GpStatus status;
410 GpGraphics *graphics = NULL;
411 GpSolidFill *brush = NULL;
412 HDC hdc = GetDC( hwnd );
413 GpPoint points[3];
415 points[0].X = 0;
416 points[0].Y = 0;
418 points[1].X = 40;
419 points[1].Y = 20;
421 points[2].X = 10;
422 points[2].Y = 40;
424 /* make a graphics object and brush object */
425 ok(hdc != NULL, "Expected HDC to be initialized\n");
427 status = GdipCreateFromHDC(hdc, &graphics);
428 expect(Ok, status);
429 ok(graphics != NULL, "Expected graphics to be initialized\n");
431 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
433 /* InvalidParameter cases: null graphics, null brush */
434 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
435 when points == NULL, so don't test this condition */
436 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
437 expect(InvalidParameter, status);
439 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
440 expect(InvalidParameter, status);
442 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
443 expect(InvalidParameter, status);
445 /* InvalidParameter cases: invalid count */
446 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
447 expect(InvalidParameter, status);
449 /* OutOfMemory cases: large (unsigned) int */
450 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
451 expect(OutOfMemory, status);
453 /* Valid test cases */
454 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
455 expect(Ok, status);
457 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
458 expect(Ok, status);
460 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
461 expect(Ok, status);
463 GdipDeleteGraphics(graphics);
464 GdipDeleteBrush((GpBrush*)brush);
466 ReleaseDC(hwnd, hdc);
469 static void test_GdipDrawArc(void)
471 GpStatus status;
472 GpGraphics *graphics = NULL;
473 GpPen *pen = NULL;
474 HDC hdc = GetDC( hwnd );
476 /* make a graphics object and pen object */
477 ok(hdc != NULL, "Expected HDC to be initialized\n");
479 status = GdipCreateFromHDC(hdc, &graphics);
480 expect(Ok, status);
481 ok(graphics != NULL, "Expected graphics to be initialized\n");
483 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
484 expect(Ok, status);
485 ok(pen != NULL, "Expected pen to be initialized\n");
487 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
488 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
489 expect(InvalidParameter, status);
491 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
492 expect(InvalidParameter, status);
494 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
495 expect(InvalidParameter, status);
497 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
498 expect(InvalidParameter, status);
500 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
501 expect(InvalidParameter, status);
503 /* successful case */
504 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
505 expect(Ok, status);
507 GdipDeletePen(pen);
508 GdipDeleteGraphics(graphics);
510 ReleaseDC(hwnd, hdc);
513 static void test_GdipDrawArcI(void)
515 GpStatus status;
516 GpGraphics *graphics = NULL;
517 GpPen *pen = NULL;
518 HDC hdc = GetDC( hwnd );
520 /* make a graphics object and pen object */
521 ok(hdc != NULL, "Expected HDC to be initialized\n");
523 status = GdipCreateFromHDC(hdc, &graphics);
524 expect(Ok, status);
525 ok(graphics != NULL, "Expected graphics to be initialized\n");
527 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
528 expect(Ok, status);
529 ok(pen != NULL, "Expected pen to be initialized\n");
531 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
532 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
533 expect(InvalidParameter, status);
535 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
536 expect(InvalidParameter, status);
538 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
539 expect(InvalidParameter, status);
541 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
542 expect(InvalidParameter, status);
544 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
545 expect(InvalidParameter, status);
547 /* successful case */
548 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
549 expect(Ok, status);
551 GdipDeletePen(pen);
552 GdipDeleteGraphics(graphics);
554 ReleaseDC(hwnd, hdc);
557 static void test_BeginContainer2(void)
559 GpMatrix *transform;
560 GpRectF clip;
561 REAL defClip[] = {5, 10, 15, 20};
562 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
563 GraphicsContainer cont1, cont2, cont3, cont4;
564 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
565 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
566 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
567 REAL scale, defScale = 17;
568 GpUnit unit, defUnit = UnitPixel;
569 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
570 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
571 UINT contrast, defContrast = 5;
572 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
574 GpStatus status;
575 GpGraphics *graphics = NULL;
576 HDC hdc = GetDC( hwnd );
578 ok(hdc != NULL, "Expected HDC to be initialized\n");
580 status = GdipCreateFromHDC(hdc, &graphics);
581 expect(Ok, status);
582 ok(graphics != NULL, "Expected graphics to be initialized\n");
584 /* null graphics, null container */
585 status = GdipBeginContainer2(NULL, &cont1);
586 expect(InvalidParameter, status);
588 status = GdipBeginContainer2(graphics, NULL);
589 expect(InvalidParameter, status);
591 status = GdipEndContainer(NULL, cont1);
592 expect(InvalidParameter, status);
594 /* test all quality-related values */
595 GdipSetCompositingMode(graphics, defCompmode);
596 GdipSetCompositingQuality(graphics, defCompqual);
597 GdipSetInterpolationMode(graphics, defInterp);
598 GdipSetPageScale(graphics, defScale);
599 GdipSetPageUnit(graphics, defUnit);
600 GdipSetPixelOffsetMode(graphics, defOffsetmode);
601 GdipSetSmoothingMode(graphics, defSmoothmode);
602 GdipSetTextContrast(graphics, defContrast);
603 GdipSetTextRenderingHint(graphics, defTexthint);
605 status = GdipBeginContainer2(graphics, &cont1);
606 expect(Ok, status);
608 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
609 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
610 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
611 GdipSetPageScale(graphics, 10);
612 GdipSetPageUnit(graphics, UnitDocument);
613 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
614 GdipSetSmoothingMode(graphics, SmoothingModeNone);
615 GdipSetTextContrast(graphics, 7);
616 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
618 status = GdipEndContainer(graphics, cont1);
619 expect(Ok, status);
621 GdipGetCompositingMode(graphics, &compmode);
622 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
624 GdipGetCompositingQuality(graphics, &compqual);
625 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
627 GdipGetInterpolationMode(graphics, &interp);
628 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
630 GdipGetPageScale(graphics, &scale);
631 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
633 GdipGetPageUnit(graphics, &unit);
634 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
636 GdipGetPixelOffsetMode(graphics, &offsetmode);
637 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
639 GdipGetSmoothingMode(graphics, &smoothmode);
640 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
642 GdipGetTextContrast(graphics, &contrast);
643 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
645 GdipGetTextRenderingHint(graphics, &texthint);
646 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
648 /* test world transform */
649 status = GdipBeginContainer2(graphics, &cont1);
650 expect(Ok, status);
652 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
653 defTrans[4], defTrans[5], &transform);
654 expect(Ok, status);
655 GdipSetWorldTransform(graphics, transform);
656 GdipDeleteMatrix(transform);
657 transform = NULL;
659 status = GdipBeginContainer2(graphics, &cont2);
660 expect(Ok, status);
662 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
663 expect(Ok, status);
664 GdipSetWorldTransform(graphics, transform);
665 GdipDeleteMatrix(transform);
666 transform = NULL;
668 status = GdipEndContainer(graphics, cont2);
669 expect(Ok, status);
671 status = GdipCreateMatrix(&transform);
672 expect(Ok, status);
673 GdipGetWorldTransform(graphics, transform);
674 GdipGetMatrixElements(transform, elems);
675 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
676 fabs(defTrans[1] - elems[1]) < 0.0001 &&
677 fabs(defTrans[2] - elems[2]) < 0.0001 &&
678 fabs(defTrans[3] - elems[3]) < 0.0001 &&
679 fabs(defTrans[4] - elems[4]) < 0.0001 &&
680 fabs(defTrans[5] - elems[5]) < 0.0001,
681 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
682 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
683 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
684 GdipDeleteMatrix(transform);
685 transform = NULL;
687 status = GdipEndContainer(graphics, cont1);
688 expect(Ok, status);
690 /* test clipping */
691 status = GdipBeginContainer2(graphics, &cont1);
692 expect(Ok, status);
694 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
696 status = GdipBeginContainer2(graphics, &cont2);
697 expect(Ok, status);
699 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
701 status = GdipEndContainer(graphics, cont2);
702 expect(Ok, status);
704 status = GdipGetClipBounds(graphics, &clip);
705 expect(Ok, status);
707 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
708 fabs(defClip[1] - clip.Y) < 0.0001 &&
709 fabs(defClip[2] - clip.Width) < 0.0001 &&
710 fabs(defClip[3] - clip.Height) < 0.0001,
711 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
712 defClip[0], defClip[1], defClip[2], defClip[3],
713 clip.X, clip.Y, clip.Width, clip.Height);
715 status = GdipEndContainer(graphics, cont1);
716 expect(Ok, status);
718 /* nesting */
719 status = GdipBeginContainer2(graphics, &cont1);
720 expect(Ok, status);
722 status = GdipBeginContainer2(graphics, &cont2);
723 expect(Ok, status);
725 status = GdipBeginContainer2(graphics, &cont3);
726 expect(Ok, status);
728 status = GdipEndContainer(graphics, cont3);
729 expect(Ok, status);
731 status = GdipBeginContainer2(graphics, &cont4);
732 expect(Ok, status);
734 status = GdipEndContainer(graphics, cont4);
735 expect(Ok, status);
737 /* skip cont2 */
738 status = GdipEndContainer(graphics, cont1);
739 expect(Ok, status);
741 /* end an already-ended container */
742 status = GdipEndContainer(graphics, cont1);
743 expect(Ok, status);
745 GdipDeleteGraphics(graphics);
746 ReleaseDC(hwnd, hdc);
749 static void test_GdipDrawBezierI(void)
751 GpStatus status;
752 GpGraphics *graphics = NULL;
753 GpPen *pen = NULL;
754 HDC hdc = GetDC( hwnd );
756 /* make a graphics object and pen object */
757 ok(hdc != NULL, "Expected HDC to be initialized\n");
759 status = GdipCreateFromHDC(hdc, &graphics);
760 expect(Ok, status);
761 ok(graphics != NULL, "Expected graphics to be initialized\n");
763 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
764 expect(Ok, status);
765 ok(pen != NULL, "Expected pen to be initialized\n");
767 /* InvalidParameter cases: null graphics, null pen */
768 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
769 expect(InvalidParameter, status);
771 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
772 expect(InvalidParameter, status);
774 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
775 expect(InvalidParameter, status);
777 /* successful case */
778 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
779 expect(Ok, status);
781 GdipDeletePen(pen);
782 GdipDeleteGraphics(graphics);
784 ReleaseDC(hwnd, hdc);
787 static void test_GdipDrawCurve3(void)
789 GpStatus status;
790 GpGraphics *graphics = NULL;
791 GpPen *pen = NULL;
792 HDC hdc = GetDC( hwnd );
793 GpPointF points[3];
795 points[0].X = 0;
796 points[0].Y = 0;
798 points[1].X = 40;
799 points[1].Y = 20;
801 points[2].X = 10;
802 points[2].Y = 40;
804 /* make a graphics object and pen object */
805 ok(hdc != NULL, "Expected HDC to be initialized\n");
807 status = GdipCreateFromHDC(hdc, &graphics);
808 expect(Ok, status);
809 ok(graphics != NULL, "Expected graphics to be initialized\n");
811 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
812 expect(Ok, status);
813 ok(pen != NULL, "Expected pen to be initialized\n");
815 /* InvalidParameter cases: null graphics, null pen */
816 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
817 expect(InvalidParameter, status);
819 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
820 expect(InvalidParameter, status);
822 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
823 expect(InvalidParameter, status);
825 /* InvalidParameter cases: invalid count */
826 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
827 expect(InvalidParameter, status);
829 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
830 expect(InvalidParameter, status);
832 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
833 expect(InvalidParameter, status);
835 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
836 expect(InvalidParameter, status);
838 /* InvalidParameter cases: invalid number of segments */
839 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
840 expect(InvalidParameter, status);
842 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
843 expect(InvalidParameter, status);
845 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
846 expect(InvalidParameter, status);
848 /* Valid test cases */
849 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
850 expect(Ok, status);
852 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
853 expect(Ok, status);
855 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
856 expect(Ok, status);
858 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
859 expect(Ok, status);
861 GdipDeletePen(pen);
862 GdipDeleteGraphics(graphics);
864 ReleaseDC(hwnd, hdc);
867 static void test_GdipDrawCurve3I(void)
869 GpStatus status;
870 GpGraphics *graphics = NULL;
871 GpPen *pen = NULL;
872 HDC hdc = GetDC( hwnd );
873 GpPoint points[3];
875 points[0].X = 0;
876 points[0].Y = 0;
878 points[1].X = 40;
879 points[1].Y = 20;
881 points[2].X = 10;
882 points[2].Y = 40;
884 /* make a graphics object and pen object */
885 ok(hdc != NULL, "Expected HDC to be initialized\n");
887 status = GdipCreateFromHDC(hdc, &graphics);
888 expect(Ok, status);
889 ok(graphics != NULL, "Expected graphics to be initialized\n");
891 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
892 expect(Ok, status);
893 ok(pen != NULL, "Expected pen to be initialized\n");
895 /* InvalidParameter cases: null graphics, null pen */
896 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
897 expect(InvalidParameter, status);
899 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
900 expect(InvalidParameter, status);
902 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
903 expect(InvalidParameter, status);
905 /* InvalidParameter cases: invalid count */
906 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
907 expect(OutOfMemory, status);
909 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
910 expect(InvalidParameter, status);
912 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
913 expect(InvalidParameter, status);
915 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
916 expect(InvalidParameter, status);
918 /* InvalidParameter cases: invalid number of segments */
919 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
920 expect(InvalidParameter, status);
922 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
923 expect(InvalidParameter, status);
925 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
926 expect(InvalidParameter, status);
928 /* Valid test cases */
929 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
930 expect(Ok, status);
932 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
933 expect(Ok, status);
935 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
936 expect(Ok, status);
938 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
939 expect(Ok, status);
941 GdipDeletePen(pen);
942 GdipDeleteGraphics(graphics);
944 ReleaseDC(hwnd, hdc);
947 static void test_GdipDrawCurve2(void)
949 GpStatus status;
950 GpGraphics *graphics = NULL;
951 GpPen *pen = NULL;
952 HDC hdc = GetDC( hwnd );
953 GpPointF points[3];
955 points[0].X = 0;
956 points[0].Y = 0;
958 points[1].X = 40;
959 points[1].Y = 20;
961 points[2].X = 10;
962 points[2].Y = 40;
964 /* make a graphics object and pen object */
965 ok(hdc != NULL, "Expected HDC to be initialized\n");
967 status = GdipCreateFromHDC(hdc, &graphics);
968 expect(Ok, status);
969 ok(graphics != NULL, "Expected graphics to be initialized\n");
971 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
972 expect(Ok, status);
973 ok(pen != NULL, "Expected pen to be initialized\n");
975 /* InvalidParameter cases: null graphics, null pen */
976 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
977 expect(InvalidParameter, status);
979 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
980 expect(InvalidParameter, status);
982 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
983 expect(InvalidParameter, status);
985 /* InvalidParameter cases: invalid count */
986 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
987 expect(InvalidParameter, status);
989 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
990 expect(InvalidParameter, status);
992 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
993 expect(InvalidParameter, status);
995 /* Valid test cases */
996 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
997 expect(Ok, status);
999 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1000 expect(Ok, status);
1002 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1003 expect(Ok, status);
1005 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1006 expect(Ok, status);
1008 GdipDeletePen(pen);
1009 GdipDeleteGraphics(graphics);
1011 ReleaseDC(hwnd, hdc);
1014 static void test_GdipDrawCurve2I(void)
1016 GpStatus status;
1017 GpGraphics *graphics = NULL;
1018 GpPen *pen = NULL;
1019 HDC hdc = GetDC( hwnd );
1020 GpPoint points[3];
1022 points[0].X = 0;
1023 points[0].Y = 0;
1025 points[1].X = 40;
1026 points[1].Y = 20;
1028 points[2].X = 10;
1029 points[2].Y = 40;
1031 /* make a graphics object and pen object */
1032 ok(hdc != NULL, "Expected HDC to be initialized\n");
1034 status = GdipCreateFromHDC(hdc, &graphics);
1035 expect(Ok, status);
1036 ok(graphics != NULL, "Expected graphics to be initialized\n");
1038 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1039 expect(Ok, status);
1040 ok(pen != NULL, "Expected pen to be initialized\n");
1042 /* InvalidParameter cases: null graphics, null pen */
1043 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1044 expect(InvalidParameter, status);
1046 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1047 expect(InvalidParameter, status);
1049 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1050 expect(InvalidParameter, status);
1052 /* InvalidParameter cases: invalid count */
1053 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1054 expect(OutOfMemory, status);
1056 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1057 expect(InvalidParameter, status);
1059 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1060 expect(InvalidParameter, status);
1062 /* Valid test cases */
1063 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1064 expect(Ok, status);
1066 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1067 expect(Ok, status);
1069 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1070 expect(Ok, status);
1072 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1073 expect(Ok, status);
1075 GdipDeletePen(pen);
1076 GdipDeleteGraphics(graphics);
1078 ReleaseDC(hwnd, hdc);
1081 static void test_GdipDrawCurve(void)
1083 GpStatus status;
1084 GpGraphics *graphics = NULL;
1085 GpPen *pen = NULL;
1086 HDC hdc = GetDC( hwnd );
1087 GpPointF points[3];
1089 points[0].X = 0;
1090 points[0].Y = 0;
1092 points[1].X = 40;
1093 points[1].Y = 20;
1095 points[2].X = 10;
1096 points[2].Y = 40;
1098 /* make a graphics object and pen object */
1099 ok(hdc != NULL, "Expected HDC to be initialized\n");
1101 status = GdipCreateFromHDC(hdc, &graphics);
1102 expect(Ok, status);
1103 ok(graphics != NULL, "Expected graphics to be initialized\n");
1105 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1106 expect(Ok, status);
1107 ok(pen != NULL, "Expected pen to be initialized\n");
1109 /* InvalidParameter cases: null graphics, null pen */
1110 status = GdipDrawCurve(NULL, NULL, points, 3);
1111 expect(InvalidParameter, status);
1113 status = GdipDrawCurve(graphics, NULL, points, 3);
1114 expect(InvalidParameter, status);
1116 status = GdipDrawCurve(NULL, pen, points, 3);
1117 expect(InvalidParameter, status);
1119 /* InvalidParameter cases: invalid count */
1120 status = GdipDrawCurve(graphics, pen, points, -1);
1121 expect(InvalidParameter, status);
1123 status = GdipDrawCurve(graphics, pen, points, 0);
1124 expect(InvalidParameter, status);
1126 status = GdipDrawCurve(graphics, pen, points, 1);
1127 expect(InvalidParameter, status);
1129 /* Valid test cases */
1130 status = GdipDrawCurve(graphics, pen, points, 2);
1131 expect(Ok, status);
1133 status = GdipDrawCurve(graphics, pen, points, 3);
1134 expect(Ok, status);
1136 GdipDeletePen(pen);
1137 GdipDeleteGraphics(graphics);
1139 ReleaseDC(hwnd, hdc);
1142 static void test_GdipDrawCurveI(void)
1144 GpStatus status;
1145 GpGraphics *graphics = NULL;
1146 GpPen *pen = NULL;
1147 HDC hdc = GetDC( hwnd );
1148 GpPoint points[3];
1150 points[0].X = 0;
1151 points[0].Y = 0;
1153 points[1].X = 40;
1154 points[1].Y = 20;
1156 points[2].X = 10;
1157 points[2].Y = 40;
1159 /* make a graphics object and pen object */
1160 ok(hdc != NULL, "Expected HDC to be initialized\n");
1162 status = GdipCreateFromHDC(hdc, &graphics);
1163 expect(Ok, status);
1164 ok(graphics != NULL, "Expected graphics to be initialized\n");
1166 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1167 expect(Ok, status);
1168 ok(pen != NULL, "Expected pen to be initialized\n");
1170 /* InvalidParameter cases: null graphics, null pen */
1171 status = GdipDrawCurveI(NULL, NULL, points, 3);
1172 expect(InvalidParameter, status);
1174 status = GdipDrawCurveI(graphics, NULL, points, 3);
1175 expect(InvalidParameter, status);
1177 status = GdipDrawCurveI(NULL, pen, points, 3);
1178 expect(InvalidParameter, status);
1180 /* InvalidParameter cases: invalid count */
1181 status = GdipDrawCurveI(graphics, pen, points, -1);
1182 expect(OutOfMemory, status);
1184 status = GdipDrawCurveI(graphics, pen, points, 0);
1185 expect(InvalidParameter, status);
1187 status = GdipDrawCurveI(graphics, pen, points, 1);
1188 expect(InvalidParameter, status);
1190 /* Valid test cases */
1191 status = GdipDrawCurveI(graphics, pen, points, 2);
1192 expect(Ok, status);
1194 status = GdipDrawCurveI(graphics, pen, points, 3);
1195 expect(Ok, status);
1197 GdipDeletePen(pen);
1198 GdipDeleteGraphics(graphics);
1200 ReleaseDC(hwnd, hdc);
1203 static void test_GdipDrawLineI(void)
1205 GpStatus status;
1206 GpGraphics *graphics = NULL;
1207 GpPen *pen = NULL;
1208 HDC hdc = GetDC( hwnd );
1210 /* make a graphics object and pen object */
1211 ok(hdc != NULL, "Expected HDC to be initialized\n");
1213 status = GdipCreateFromHDC(hdc, &graphics);
1214 expect(Ok, status);
1215 ok(graphics != NULL, "Expected graphics to be initialized\n");
1217 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1218 expect(Ok, status);
1219 ok(pen != NULL, "Expected pen to be initialized\n");
1221 /* InvalidParameter cases: null graphics, null pen */
1222 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1223 expect(InvalidParameter, status);
1225 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1226 expect(InvalidParameter, status);
1228 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1229 expect(InvalidParameter, status);
1231 /* successful case */
1232 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1233 expect(Ok, status);
1235 GdipDeletePen(pen);
1236 GdipDeleteGraphics(graphics);
1238 ReleaseDC(hwnd, hdc);
1241 static void test_GdipDrawImagePointsRect(void)
1243 GpStatus status;
1244 GpGraphics *graphics = NULL;
1245 GpPointF ptf[4];
1246 GpBitmap *bm = NULL;
1247 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1248 BYTE buff[400];
1249 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1250 HDC hdc = GetDC( hwnd );
1251 if (!hdc)
1252 return;
1254 memset(rbmi, 0, sizeof(rbmi));
1255 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1256 bmi->bmiHeader.biWidth = 10;
1257 bmi->bmiHeader.biHeight = 10;
1258 bmi->bmiHeader.biPlanes = 1;
1259 bmi->bmiHeader.biBitCount = 32;
1260 bmi->bmiHeader.biCompression = BI_RGB;
1261 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1262 expect(Ok, status);
1263 ok(NULL != bm, "Expected bitmap to be initialized\n");
1264 status = GdipCreateFromHDC(hdc, &graphics);
1265 expect(Ok, status);
1266 ptf[0].X = 0;
1267 ptf[0].Y = 0;
1268 ptf[1].X = 10;
1269 ptf[1].Y = 0;
1270 ptf[2].X = 0;
1271 ptf[2].Y = 10;
1272 ptf[3].X = 10;
1273 ptf[3].Y = 10;
1274 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1275 expect(NotImplemented, status);
1276 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1277 expect(InvalidParameter, status);
1278 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1279 expect(Ok, status);
1280 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1281 expect(InvalidParameter, status);
1282 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1283 expect(InvalidParameter, status);
1284 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1285 expect(Ok, status);
1286 memset(ptf, 0, sizeof(ptf));
1287 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1288 expect(Ok, status);
1290 GdipDisposeImage((GpImage*)bm);
1291 GdipDeleteGraphics(graphics);
1292 ReleaseDC(hwnd, hdc);
1295 static void test_GdipDrawLinesI(void)
1297 GpStatus status;
1298 GpGraphics *graphics = NULL;
1299 GpPen *pen = NULL;
1300 GpPoint *ptf = NULL;
1301 HDC hdc = GetDC( hwnd );
1303 /* make a graphics object and pen object */
1304 ok(hdc != NULL, "Expected HDC to be initialized\n");
1306 status = GdipCreateFromHDC(hdc, &graphics);
1307 expect(Ok, status);
1308 ok(graphics != NULL, "Expected graphics to be initialized\n");
1310 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1311 expect(Ok, status);
1312 ok(pen != NULL, "Expected pen to be initialized\n");
1314 /* make some arbitrary valid points*/
1315 ptf = GdipAlloc(2 * sizeof(GpPointF));
1317 ptf[0].X = 1;
1318 ptf[0].Y = 1;
1320 ptf[1].X = 2;
1321 ptf[1].Y = 2;
1323 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1324 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1325 expect(InvalidParameter, status);
1327 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1328 expect(InvalidParameter, status);
1330 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1331 expect(InvalidParameter, status);
1333 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1334 expect(InvalidParameter, status);
1336 /* successful case */
1337 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1338 expect(Ok, status);
1340 GdipFree(ptf);
1341 GdipDeletePen(pen);
1342 GdipDeleteGraphics(graphics);
1344 ReleaseDC(hwnd, hdc);
1347 static void test_GdipFillClosedCurve(void)
1349 GpStatus status;
1350 GpGraphics *graphics = NULL;
1351 GpSolidFill *brush = NULL;
1352 HDC hdc = GetDC( hwnd );
1353 GpPointF points[3];
1355 points[0].X = 0;
1356 points[0].Y = 0;
1358 points[1].X = 40;
1359 points[1].Y = 20;
1361 points[2].X = 10;
1362 points[2].Y = 40;
1364 /* make a graphics object and brush object */
1365 ok(hdc != NULL, "Expected HDC to be initialized\n");
1367 status = GdipCreateFromHDC(hdc, &graphics);
1368 expect(Ok, status);
1369 ok(graphics != NULL, "Expected graphics to be initialized\n");
1371 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1373 /* InvalidParameter cases: null graphics, null brush, null points */
1374 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1375 expect(InvalidParameter, status);
1377 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1378 expect(InvalidParameter, status);
1380 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1381 expect(InvalidParameter, status);
1383 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1384 expect(InvalidParameter, status);
1386 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1387 expect(InvalidParameter, status);
1389 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1390 expect(InvalidParameter, status);
1392 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1393 expect(InvalidParameter, status);
1395 /* InvalidParameter cases: invalid count */
1396 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1397 expect(InvalidParameter, status);
1399 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1400 expect(InvalidParameter, status);
1402 /* Valid test cases */
1403 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1404 expect(Ok, status);
1406 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1407 expect(Ok, status);
1409 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1410 expect(Ok, status);
1412 GdipDeleteGraphics(graphics);
1413 GdipDeleteBrush((GpBrush*)brush);
1415 ReleaseDC(hwnd, hdc);
1418 static void test_GdipFillClosedCurveI(void)
1420 GpStatus status;
1421 GpGraphics *graphics = NULL;
1422 GpSolidFill *brush = NULL;
1423 HDC hdc = GetDC( hwnd );
1424 GpPoint points[3];
1426 points[0].X = 0;
1427 points[0].Y = 0;
1429 points[1].X = 40;
1430 points[1].Y = 20;
1432 points[2].X = 10;
1433 points[2].Y = 40;
1435 /* make a graphics object and brush object */
1436 ok(hdc != NULL, "Expected HDC to be initialized\n");
1438 status = GdipCreateFromHDC(hdc, &graphics);
1439 expect(Ok, status);
1440 ok(graphics != NULL, "Expected graphics to be initialized\n");
1442 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1444 /* InvalidParameter cases: null graphics, null brush */
1445 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1446 when points == NULL, so don't test this condition */
1447 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1448 expect(InvalidParameter, status);
1450 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1451 expect(InvalidParameter, status);
1453 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1454 expect(InvalidParameter, status);
1456 /* InvalidParameter cases: invalid count */
1457 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1458 expect(InvalidParameter, status);
1460 /* OutOfMemory cases: large (unsigned) int */
1461 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1462 expect(OutOfMemory, status);
1464 /* Valid test cases */
1465 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1466 expect(Ok, status);
1468 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1469 expect(Ok, status);
1471 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1472 expect(Ok, status);
1474 GdipDeleteGraphics(graphics);
1475 GdipDeleteBrush((GpBrush*)brush);
1477 ReleaseDC(hwnd, hdc);
1480 static void test_Get_Release_DC(void)
1482 GpStatus status;
1483 GpGraphics *graphics = NULL;
1484 GpPen *pen;
1485 GpSolidFill *brush;
1486 GpPath *path;
1487 HDC hdc = GetDC( hwnd );
1488 HDC retdc;
1489 REAL r;
1490 CompositingQuality quality;
1491 CompositingMode compmode;
1492 InterpolationMode intmode;
1493 GpMatrix *m;
1494 GpRegion *region;
1495 GpUnit unit;
1496 PixelOffsetMode offsetmode;
1497 SmoothingMode smoothmode;
1498 TextRenderingHint texthint;
1499 GpPointF ptf[5];
1500 GpPoint pt[5];
1501 GpRectF rectf[2];
1502 GpRect rect[2];
1503 GpRegion *clip;
1504 INT i;
1505 BOOL res;
1506 ARGB color = 0x00000000;
1507 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1509 pt[0].X = 10;
1510 pt[0].Y = 10;
1511 pt[1].X = 20;
1512 pt[1].Y = 15;
1513 pt[2].X = 40;
1514 pt[2].Y = 80;
1515 pt[3].X = -20;
1516 pt[3].Y = 20;
1517 pt[4].X = 50;
1518 pt[4].Y = 110;
1520 for(i = 0; i < 5;i++){
1521 ptf[i].X = (REAL)pt[i].X;
1522 ptf[i].Y = (REAL)pt[i].Y;
1525 rect[0].X = 0;
1526 rect[0].Y = 0;
1527 rect[0].Width = 50;
1528 rect[0].Height = 70;
1529 rect[1].X = 0;
1530 rect[1].Y = 0;
1531 rect[1].Width = 10;
1532 rect[1].Height = 20;
1534 for(i = 0; i < 2;i++){
1535 rectf[i].X = (REAL)rect[i].X;
1536 rectf[i].Y = (REAL)rect[i].Y;
1537 rectf[i].Height = (REAL)rect[i].Height;
1538 rectf[i].Width = (REAL)rect[i].Width;
1541 status = GdipCreateMatrix(&m);
1542 expect(Ok, status);
1543 GdipCreateRegion(&region);
1544 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1545 GdipCreatePath(FillModeAlternate, &path);
1546 GdipCreateRegion(&clip);
1548 status = GdipCreateFromHDC(hdc, &graphics);
1549 expect(Ok, status);
1550 ok(graphics != NULL, "Expected graphics to be initialized\n");
1551 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1552 expect(Ok, status);
1554 /* NULL arguments */
1555 status = GdipGetDC(NULL, NULL);
1556 expect(InvalidParameter, status);
1557 status = GdipGetDC(graphics, NULL);
1558 expect(InvalidParameter, status);
1559 status = GdipGetDC(NULL, &retdc);
1560 expect(InvalidParameter, status);
1562 status = GdipReleaseDC(NULL, NULL);
1563 expect(InvalidParameter, status);
1564 status = GdipReleaseDC(graphics, NULL);
1565 expect(InvalidParameter, status);
1566 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1567 expect(InvalidParameter, status);
1569 /* Release without Get */
1570 status = GdipReleaseDC(graphics, hdc);
1571 expect(InvalidParameter, status);
1573 retdc = NULL;
1574 status = GdipGetDC(graphics, &retdc);
1575 expect(Ok, status);
1576 ok(retdc == hdc, "Invalid HDC returned\n");
1577 /* call it once more */
1578 status = GdipGetDC(graphics, &retdc);
1579 expect(ObjectBusy, status);
1581 /* try all Graphics calls here */
1582 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1583 expect(ObjectBusy, status);
1584 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1585 expect(ObjectBusy, status);
1586 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1587 expect(ObjectBusy, status);
1588 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1589 expect(ObjectBusy, status);
1590 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1591 expect(ObjectBusy, status);
1592 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1593 expect(ObjectBusy, status);
1594 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1595 expect(ObjectBusy, status);
1596 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1597 expect(ObjectBusy, status);
1598 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1599 expect(ObjectBusy, status);
1600 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1601 expect(ObjectBusy, status);
1602 status = GdipDrawCurve(graphics, pen, ptf, 5);
1603 expect(ObjectBusy, status);
1604 status = GdipDrawCurveI(graphics, pen, pt, 5);
1605 expect(ObjectBusy, status);
1606 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1607 expect(ObjectBusy, status);
1608 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1609 expect(ObjectBusy, status);
1610 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1611 expect(ObjectBusy, status);
1612 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1613 expect(ObjectBusy, status);
1614 /* GdipDrawImage/GdipDrawImageI */
1615 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1616 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1617 /* GdipDrawImageRect/GdipDrawImageRectI */
1618 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1619 expect(ObjectBusy, status);
1620 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1621 expect(ObjectBusy, status);
1622 status = GdipDrawLines(graphics, pen, ptf, 5);
1623 expect(ObjectBusy, status);
1624 status = GdipDrawLinesI(graphics, pen, pt, 5);
1625 expect(ObjectBusy, status);
1626 status = GdipDrawPath(graphics, pen, path);
1627 expect(ObjectBusy, status);
1628 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1629 expect(ObjectBusy, status);
1630 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1631 expect(ObjectBusy, status);
1632 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1633 expect(ObjectBusy, status);
1634 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1635 expect(ObjectBusy, status);
1636 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1637 expect(ObjectBusy, status);
1638 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1639 expect(ObjectBusy, status);
1640 /* GdipDrawString */
1641 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1642 expect(ObjectBusy, status);
1643 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1644 expect(ObjectBusy, status);
1645 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1646 expect(ObjectBusy, status);
1647 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1648 expect(ObjectBusy, status);
1649 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1650 expect(ObjectBusy, status);
1651 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1652 expect(ObjectBusy, status);
1653 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1654 expect(ObjectBusy, status);
1655 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1656 expect(ObjectBusy, status);
1657 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1658 expect(ObjectBusy, status);
1659 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1660 expect(ObjectBusy, status);
1661 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1662 expect(ObjectBusy, status);
1663 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1664 expect(ObjectBusy, status);
1665 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1666 expect(ObjectBusy, status);
1667 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1668 expect(ObjectBusy, status);
1669 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1670 expect(ObjectBusy, status);
1671 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1672 expect(ObjectBusy, status);
1673 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1674 expect(ObjectBusy, status);
1675 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1676 expect(ObjectBusy, status);
1677 status = GdipFlush(graphics, FlushIntentionFlush);
1678 expect(ObjectBusy, status);
1679 status = GdipGetClipBounds(graphics, rectf);
1680 expect(ObjectBusy, status);
1681 status = GdipGetClipBoundsI(graphics, rect);
1682 expect(ObjectBusy, status);
1683 status = GdipGetCompositingMode(graphics, &compmode);
1684 expect(ObjectBusy, status);
1685 status = GdipGetCompositingQuality(graphics, &quality);
1686 expect(ObjectBusy, status);
1687 status = GdipGetInterpolationMode(graphics, &intmode);
1688 expect(ObjectBusy, status);
1689 status = GdipGetNearestColor(graphics, &color);
1690 expect(ObjectBusy, status);
1691 status = GdipGetPageScale(graphics, &r);
1692 expect(ObjectBusy, status);
1693 status = GdipGetPageUnit(graphics, &unit);
1694 expect(ObjectBusy, status);
1695 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1696 expect(ObjectBusy, status);
1697 status = GdipGetSmoothingMode(graphics, &smoothmode);
1698 expect(ObjectBusy, status);
1699 status = GdipGetTextRenderingHint(graphics, &texthint);
1700 expect(ObjectBusy, status);
1701 status = GdipGetWorldTransform(graphics, m);
1702 expect(ObjectBusy, status);
1703 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1704 expect(ObjectBusy, status);
1705 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1706 expect(ObjectBusy, status);
1707 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1708 expect(ObjectBusy, status);
1709 /* GdipMeasureCharacterRanges */
1710 /* GdipMeasureString */
1711 status = GdipResetClip(graphics);
1712 expect(ObjectBusy, status);
1713 status = GdipResetWorldTransform(graphics);
1714 expect(ObjectBusy, status);
1715 /* GdipRestoreGraphics */
1716 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1717 expect(ObjectBusy, status);
1718 /* GdipSaveGraphics */
1719 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1720 expect(ObjectBusy, status);
1721 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1722 expect(ObjectBusy, status);
1723 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1724 expect(ObjectBusy, status);
1725 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1726 expect(ObjectBusy, status);
1727 status = GdipSetPageScale(graphics, 1.0);
1728 expect(ObjectBusy, status);
1729 status = GdipSetPageUnit(graphics, UnitWorld);
1730 expect(ObjectBusy, status);
1731 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1732 expect(ObjectBusy, status);
1733 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1734 expect(ObjectBusy, status);
1735 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1736 expect(ObjectBusy, status);
1737 status = GdipSetWorldTransform(graphics, m);
1738 expect(ObjectBusy, status);
1739 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1740 expect(ObjectBusy, status);
1741 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1742 expect(ObjectBusy, status);
1743 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1744 expect(ObjectBusy, status);
1745 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1746 expect(ObjectBusy, status);
1747 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1748 expect(ObjectBusy, status);
1749 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1750 expect(ObjectBusy, status);
1751 status = GdipTranslateClip(graphics, 0.0, 0.0);
1752 expect(ObjectBusy, status);
1753 status = GdipTranslateClipI(graphics, 0, 0);
1754 expect(ObjectBusy, status);
1755 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1756 expect(ObjectBusy, status);
1757 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1758 expect(ObjectBusy, status);
1759 status = GdipGetDpiX(graphics, &r);
1760 expect(ObjectBusy, status);
1761 status = GdipGetDpiY(graphics, &r);
1762 expect(ObjectBusy, status);
1763 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1764 expect(ObjectBusy, status);
1765 status = GdipGetClip(graphics, region);
1766 expect(ObjectBusy, status);
1767 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1768 expect(ObjectBusy, status);
1770 /* try to delete before release */
1771 status = GdipDeleteGraphics(graphics);
1772 expect(ObjectBusy, status);
1774 status = GdipReleaseDC(graphics, retdc);
1775 expect(Ok, status);
1777 GdipDeletePen(pen);
1778 GdipDeleteGraphics(graphics);
1780 GdipDeleteRegion(clip);
1781 GdipDeletePath(path);
1782 GdipDeleteBrush((GpBrush*)brush);
1783 GdipDeleteRegion(region);
1784 GdipDeleteMatrix(m);
1785 DeleteObject(hrgn);
1787 ReleaseDC(hwnd, hdc);
1790 static void test_transformpoints(void)
1792 GpStatus status;
1793 GpGraphics *graphics = NULL;
1794 HDC hdc = GetDC( hwnd );
1795 GpPointF ptf[2];
1796 GpPoint pt[2];
1798 status = GdipCreateFromHDC(hdc, &graphics);
1799 expect(Ok, status);
1801 /* NULL arguments */
1802 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1803 expect(InvalidParameter, status);
1804 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1805 expect(InvalidParameter, status);
1806 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1807 expect(InvalidParameter, status);
1808 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1809 expect(InvalidParameter, status);
1811 ptf[0].X = 1.0;
1812 ptf[0].Y = 0.0;
1813 ptf[1].X = 0.0;
1814 ptf[1].Y = 1.0;
1815 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1816 expect(Ok, status);
1817 expectf(1.0, ptf[0].X);
1818 expectf(0.0, ptf[0].Y);
1819 expectf(0.0, ptf[1].X);
1820 expectf(1.0, ptf[1].Y);
1822 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1823 expect(Ok, status);
1824 status = GdipSetPageUnit(graphics, UnitPixel);
1825 expect(Ok, status);
1826 status = GdipSetPageScale(graphics, 3.0);
1827 expect(Ok, status);
1829 ptf[0].X = 1.0;
1830 ptf[0].Y = 0.0;
1831 ptf[1].X = 0.0;
1832 ptf[1].Y = 1.0;
1833 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1834 expect(Ok, status);
1835 expectf(18.0, ptf[0].X);
1836 expectf(15.0, ptf[0].Y);
1837 expectf(15.0, ptf[1].X);
1838 expectf(18.0, ptf[1].Y);
1840 ptf[0].X = 1.0;
1841 ptf[0].Y = 0.0;
1842 ptf[1].X = 0.0;
1843 ptf[1].Y = 1.0;
1844 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1845 expect(Ok, status);
1846 expectf(6.0, ptf[0].X);
1847 expectf(5.0, ptf[0].Y);
1848 expectf(5.0, ptf[1].X);
1849 expectf(6.0, ptf[1].Y);
1851 ptf[0].X = 1.0;
1852 ptf[0].Y = 0.0;
1853 ptf[1].X = 0.0;
1854 ptf[1].Y = 1.0;
1855 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1856 expect(Ok, status);
1857 expectf(3.0, ptf[0].X);
1858 expectf(0.0, ptf[0].Y);
1859 expectf(0.0, ptf[1].X);
1860 expectf(3.0, ptf[1].Y);
1862 ptf[0].X = 18.0;
1863 ptf[0].Y = 15.0;
1864 ptf[1].X = 15.0;
1865 ptf[1].Y = 18.0;
1866 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1867 expect(Ok, status);
1868 expectf(1.0, ptf[0].X);
1869 expectf(0.0, ptf[0].Y);
1870 expectf(0.0, ptf[1].X);
1871 expectf(1.0, ptf[1].Y);
1873 ptf[0].X = 6.0;
1874 ptf[0].Y = 5.0;
1875 ptf[1].X = 5.0;
1876 ptf[1].Y = 6.0;
1877 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1878 expect(Ok, status);
1879 expectf(1.0, ptf[0].X);
1880 expectf(0.0, ptf[0].Y);
1881 expectf(0.0, ptf[1].X);
1882 expectf(1.0, ptf[1].Y);
1884 ptf[0].X = 3.0;
1885 ptf[0].Y = 0.0;
1886 ptf[1].X = 0.0;
1887 ptf[1].Y = 3.0;
1888 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1889 expect(Ok, status);
1890 expectf(1.0, ptf[0].X);
1891 expectf(0.0, ptf[0].Y);
1892 expectf(0.0, ptf[1].X);
1893 expectf(1.0, ptf[1].Y);
1895 pt[0].X = 1;
1896 pt[0].Y = 0;
1897 pt[1].X = 0;
1898 pt[1].Y = 1;
1899 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1900 expect(Ok, status);
1901 expect(18, pt[0].X);
1902 expect(15, pt[0].Y);
1903 expect(15, pt[1].X);
1904 expect(18, pt[1].Y);
1906 GdipDeleteGraphics(graphics);
1907 ReleaseDC(hwnd, hdc);
1910 static void test_get_set_clip(void)
1912 GpStatus status;
1913 GpGraphics *graphics = NULL;
1914 HDC hdc = GetDC( hwnd );
1915 GpRegion *clip;
1916 GpRectF rect;
1917 BOOL res;
1919 status = GdipCreateFromHDC(hdc, &graphics);
1920 expect(Ok, status);
1922 rect.X = rect.Y = 0.0;
1923 rect.Height = rect.Width = 100.0;
1925 status = GdipCreateRegionRect(&rect, &clip);
1926 expect(Ok, status);
1928 /* NULL arguments */
1929 status = GdipGetClip(NULL, NULL);
1930 expect(InvalidParameter, status);
1931 status = GdipGetClip(graphics, NULL);
1932 expect(InvalidParameter, status);
1933 status = GdipGetClip(NULL, clip);
1934 expect(InvalidParameter, status);
1936 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1937 expect(InvalidParameter, status);
1938 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1939 expect(InvalidParameter, status);
1941 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1942 expect(InvalidParameter, status);
1943 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1944 expect(InvalidParameter, status);
1946 res = FALSE;
1947 status = GdipGetClip(graphics, clip);
1948 expect(Ok, status);
1949 status = GdipIsInfiniteRegion(clip, graphics, &res);
1950 expect(Ok, status);
1951 expect(TRUE, res);
1953 /* remains infinite after reset */
1954 res = FALSE;
1955 status = GdipResetClip(graphics);
1956 expect(Ok, status);
1957 status = GdipGetClip(graphics, clip);
1958 expect(Ok, status);
1959 status = GdipIsInfiniteRegion(clip, graphics, &res);
1960 expect(Ok, status);
1961 expect(TRUE, res);
1963 /* set to empty and then reset to infinite */
1964 status = GdipSetEmpty(clip);
1965 expect(Ok, status);
1966 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1967 expect(Ok, status);
1969 status = GdipGetClip(graphics, clip);
1970 expect(Ok, status);
1971 res = FALSE;
1972 status = GdipIsEmptyRegion(clip, graphics, &res);
1973 expect(Ok, status);
1974 expect(TRUE, res);
1975 status = GdipResetClip(graphics);
1976 expect(Ok, status);
1977 status = GdipGetClip(graphics, clip);
1978 expect(Ok, status);
1979 res = FALSE;
1980 status = GdipIsInfiniteRegion(clip, graphics, &res);
1981 expect(Ok, status);
1982 expect(TRUE, res);
1984 GdipDeleteRegion(clip);
1986 GdipDeleteGraphics(graphics);
1987 ReleaseDC(hwnd, hdc);
1990 static void test_isempty(void)
1992 GpStatus status;
1993 GpGraphics *graphics = NULL;
1994 HDC hdc = GetDC( hwnd );
1995 GpRegion *clip;
1996 BOOL res;
1998 status = GdipCreateFromHDC(hdc, &graphics);
1999 expect(Ok, status);
2001 status = GdipCreateRegion(&clip);
2002 expect(Ok, status);
2004 /* NULL */
2005 status = GdipIsClipEmpty(NULL, NULL);
2006 expect(InvalidParameter, status);
2007 status = GdipIsClipEmpty(graphics, NULL);
2008 expect(InvalidParameter, status);
2009 status = GdipIsClipEmpty(NULL, &res);
2010 expect(InvalidParameter, status);
2012 /* default is infinite */
2013 res = TRUE;
2014 status = GdipIsClipEmpty(graphics, &res);
2015 expect(Ok, status);
2016 expect(FALSE, res);
2018 GdipDeleteRegion(clip);
2020 GdipDeleteGraphics(graphics);
2021 ReleaseDC(hwnd, hdc);
2024 static void test_clear(void)
2026 GpStatus status;
2028 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2029 expect(InvalidParameter, status);
2032 static void test_textcontrast(void)
2034 GpStatus status;
2035 HDC hdc = GetDC( hwnd );
2036 GpGraphics *graphics;
2037 UINT contrast;
2039 status = GdipGetTextContrast(NULL, NULL);
2040 expect(InvalidParameter, status);
2042 status = GdipCreateFromHDC(hdc, &graphics);
2043 expect(Ok, status);
2045 status = GdipGetTextContrast(graphics, NULL);
2046 expect(InvalidParameter, status);
2047 status = GdipGetTextContrast(graphics, &contrast);
2048 expect(Ok, status);
2049 expect(4, contrast);
2051 GdipDeleteGraphics(graphics);
2052 ReleaseDC(hwnd, hdc);
2055 static void test_GdipDrawString(void)
2057 GpStatus status;
2058 GpGraphics *graphics = NULL;
2059 GpFont *fnt = NULL;
2060 RectF rect;
2061 GpStringFormat *format;
2062 GpBrush *brush;
2063 LOGFONTA logfont;
2064 HDC hdc = GetDC( hwnd );
2065 static const WCHAR string[] = {'T','e','s','t',0};
2066 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2067 GpMatrix *matrix;
2069 memset(&logfont,0,sizeof(logfont));
2070 strcpy(logfont.lfFaceName,"Arial");
2071 logfont.lfHeight = 12;
2072 logfont.lfCharSet = DEFAULT_CHARSET;
2074 status = GdipCreateFromHDC(hdc, &graphics);
2075 expect(Ok, status);
2077 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2078 if (status == NotTrueTypeFont || status == FileNotFound)
2080 skip("Arial not installed.\n");
2081 return;
2083 expect(Ok, status);
2085 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2086 expect(Ok, status);
2088 status = GdipCreateStringFormat(0,0,&format);
2089 expect(Ok, status);
2091 rect.X = 0;
2092 rect.Y = 0;
2093 rect.Width = 0;
2094 rect.Height = 12;
2096 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2097 expect(Ok, status);
2099 status = GdipCreateMatrix(&matrix);
2100 expect(Ok, status);
2102 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2103 expect(InvalidParameter, status);
2105 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2106 expect(InvalidParameter, status);
2108 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2109 expect(InvalidParameter, status);
2111 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2112 expect(InvalidParameter, status);
2114 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2115 expect(InvalidParameter, status);
2117 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2118 expect(Ok, status);
2120 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2121 expect(Ok, status);
2123 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2124 expect(Ok, status);
2126 GdipDeleteMatrix(matrix);
2127 GdipDeleteGraphics(graphics);
2128 GdipDeleteBrush(brush);
2129 GdipDeleteFont(fnt);
2130 GdipDeleteStringFormat(format);
2132 ReleaseDC(hwnd, hdc);
2135 static void test_GdipGetVisibleClipBounds_screen(void)
2137 GpStatus status;
2138 GpGraphics *graphics = NULL;
2139 HDC hdc = GetDC(0);
2140 GpRectF rectf, exp, clipr;
2141 GpRect recti;
2143 ok(hdc != NULL, "Expected HDC to be initialized\n");
2145 status = GdipCreateFromHDC(hdc, &graphics);
2146 expect(Ok, status);
2147 ok(graphics != NULL, "Expected graphics to be initialized\n");
2149 /* no clipping rect */
2150 exp.X = 0;
2151 exp.Y = 0;
2152 exp.Width = GetDeviceCaps(hdc, HORZRES);
2153 exp.Height = GetDeviceCaps(hdc, VERTRES);
2155 status = GdipGetVisibleClipBounds(graphics, &rectf);
2156 expect(Ok, status);
2157 ok(rectf.X == exp.X &&
2158 rectf.Y == exp.Y &&
2159 rectf.Width == exp.Width &&
2160 rectf.Height == exp.Height,
2161 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2162 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2163 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2164 exp.X, exp.Y, exp.Width, exp.Height);
2166 /* clipping rect entirely within window */
2167 exp.X = clipr.X = 10;
2168 exp.Y = clipr.Y = 12;
2169 exp.Width = clipr.Width = 14;
2170 exp.Height = clipr.Height = 16;
2172 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2173 expect(Ok, status);
2175 status = GdipGetVisibleClipBounds(graphics, &rectf);
2176 expect(Ok, status);
2177 ok(rectf.X == exp.X &&
2178 rectf.Y == exp.Y &&
2179 rectf.Width == exp.Width &&
2180 rectf.Height == exp.Height,
2181 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2182 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2183 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2184 exp.X, exp.Y, exp.Width, exp.Height);
2186 /* clipping rect partially outside of screen */
2187 clipr.X = -10;
2188 clipr.Y = -12;
2189 clipr.Width = 20;
2190 clipr.Height = 24;
2192 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2193 expect(Ok, status);
2195 exp.X = 0;
2196 exp.Y = 0;
2197 exp.Width = 10;
2198 exp.Height = 12;
2200 status = GdipGetVisibleClipBounds(graphics, &rectf);
2201 expect(Ok, status);
2202 ok(rectf.X == exp.X &&
2203 rectf.Y == exp.Y &&
2204 rectf.Width == exp.Width &&
2205 rectf.Height == exp.Height,
2206 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2207 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2208 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2209 exp.X, exp.Y, exp.Width, exp.Height);
2211 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2212 expect(Ok, status);
2213 ok(recti.X == exp.X &&
2214 recti.Y == exp.Y &&
2215 recti.Width == exp.Width &&
2216 recti.Height == exp.Height,
2217 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2218 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2219 recti.X, recti.Y, recti.Width, recti.Height,
2220 exp.X, exp.Y, exp.Width, exp.Height);
2222 GdipDeleteGraphics(graphics);
2223 ReleaseDC(0, hdc);
2226 static void test_GdipGetVisibleClipBounds_window(void)
2228 GpStatus status;
2229 GpGraphics *graphics = NULL;
2230 GpRectF rectf, window, exp, clipr;
2231 GpRect recti;
2232 HDC hdc;
2233 PAINTSTRUCT ps;
2234 RECT wnd_rect;
2236 /* get client area size */
2237 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2238 window.X = wnd_rect.left;
2239 window.Y = wnd_rect.top;
2240 window.Width = wnd_rect.right - wnd_rect.left;
2241 window.Height = wnd_rect.bottom - wnd_rect.top;
2243 hdc = BeginPaint(hwnd, &ps);
2245 status = GdipCreateFromHDC(hdc, &graphics);
2246 expect(Ok, status);
2247 ok(graphics != NULL, "Expected graphics to be initialized\n");
2249 status = GdipGetVisibleClipBounds(graphics, &rectf);
2250 expect(Ok, status);
2251 ok(rectf.X == window.X &&
2252 rectf.Y == window.Y &&
2253 rectf.Width == window.Width &&
2254 rectf.Height == window.Height,
2255 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2256 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2257 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2258 window.X, window.Y, window.Width, window.Height);
2260 /* clipping rect entirely within window */
2261 exp.X = clipr.X = 20;
2262 exp.Y = clipr.Y = 8;
2263 exp.Width = clipr.Width = 30;
2264 exp.Height = clipr.Height = 20;
2266 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2267 expect(Ok, status);
2269 status = GdipGetVisibleClipBounds(graphics, &rectf);
2270 expect(Ok, status);
2271 ok(rectf.X == exp.X &&
2272 rectf.Y == exp.Y &&
2273 rectf.Width == exp.Width &&
2274 rectf.Height == exp.Height,
2275 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2276 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2277 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2278 exp.X, exp.Y, exp.Width, exp.Height);
2280 /* clipping rect partially outside of window */
2281 clipr.X = window.Width - 10;
2282 clipr.Y = window.Height - 15;
2283 clipr.Width = 20;
2284 clipr.Height = 30;
2286 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2287 expect(Ok, status);
2289 exp.X = window.Width - 10;
2290 exp.Y = window.Height - 15;
2291 exp.Width = 10;
2292 exp.Height = 15;
2294 status = GdipGetVisibleClipBounds(graphics, &rectf);
2295 expect(Ok, status);
2296 ok(rectf.X == exp.X &&
2297 rectf.Y == exp.Y &&
2298 rectf.Width == exp.Width &&
2299 rectf.Height == exp.Height,
2300 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2301 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2302 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2303 exp.X, exp.Y, exp.Width, exp.Height);
2305 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2306 expect(Ok, status);
2307 ok(recti.X == exp.X &&
2308 recti.Y == exp.Y &&
2309 recti.Width == exp.Width &&
2310 recti.Height == exp.Height,
2311 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2312 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2313 recti.X, recti.Y, recti.Width, recti.Height,
2314 exp.X, exp.Y, exp.Width, exp.Height);
2316 GdipDeleteGraphics(graphics);
2317 EndPaint(hwnd, &ps);
2320 static void test_GdipGetVisibleClipBounds(void)
2322 GpGraphics* graphics = NULL;
2323 GpRectF rectf;
2324 GpRect rect;
2325 HDC hdc = GetDC( hwnd );
2326 GpStatus status;
2328 status = GdipCreateFromHDC(hdc, &graphics);
2329 expect(Ok, status);
2330 ok(graphics != NULL, "Expected graphics to be initialized\n");
2332 /* test null parameters */
2333 status = GdipGetVisibleClipBounds(graphics, NULL);
2334 expect(InvalidParameter, status);
2336 status = GdipGetVisibleClipBounds(NULL, &rectf);
2337 expect(InvalidParameter, status);
2339 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2340 expect(InvalidParameter, status);
2342 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2343 expect(InvalidParameter, status);
2345 GdipDeleteGraphics(graphics);
2346 ReleaseDC(hwnd, hdc);
2348 test_GdipGetVisibleClipBounds_screen();
2349 test_GdipGetVisibleClipBounds_window();
2352 static void test_fromMemoryBitmap(void)
2354 GpStatus status;
2355 GpGraphics *graphics = NULL;
2356 GpBitmap *bitmap = NULL;
2357 BYTE bits[48] = {0};
2358 HDC hdc=NULL;
2359 COLORREF color;
2361 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2362 expect(Ok, status);
2364 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2365 expect(Ok, status);
2367 status = GdipGraphicsClear(graphics, 0xff686868);
2368 expect(Ok, status);
2370 GdipDeleteGraphics(graphics);
2372 /* drawing writes to the memory provided */
2373 expect(0x68, bits[10]);
2375 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2376 expect(Ok, status);
2378 status = GdipGetDC(graphics, &hdc);
2379 expect(Ok, status);
2380 ok(hdc != NULL, "got NULL hdc\n");
2382 color = GetPixel(hdc, 0, 0);
2383 /* The HDC is write-only, and native fills with a solid color to figure out
2384 * which pixels have changed. */
2385 todo_wine expect(0x0c0b0d, color);
2387 SetPixel(hdc, 0, 0, 0x797979);
2388 SetPixel(hdc, 1, 0, 0x0c0b0d);
2390 status = GdipReleaseDC(graphics, hdc);
2391 expect(Ok, status);
2393 GdipDeleteGraphics(graphics);
2395 expect(0x79, bits[0]);
2396 todo_wine expect(0x68, bits[3]);
2398 GdipDisposeImage((GpImage*)bitmap);
2400 /* We get the same kind of write-only HDC for a "normal" bitmap */
2401 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2402 expect(Ok, status);
2404 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2405 expect(Ok, status);
2407 status = GdipGetDC(graphics, &hdc);
2408 expect(Ok, status);
2409 ok(hdc != NULL, "got NULL hdc\n");
2411 color = GetPixel(hdc, 0, 0);
2412 todo_wine expect(0x0c0b0d, color);
2414 status = GdipReleaseDC(graphics, hdc);
2415 expect(Ok, status);
2417 GdipDeleteGraphics(graphics);
2419 GdipDisposeImage((GpImage*)bitmap);
2422 static void test_GdipIsVisiblePoint(void)
2424 GpStatus status;
2425 GpGraphics *graphics = NULL;
2426 HDC hdc = GetDC( hwnd );
2427 REAL x, y;
2428 BOOL val;
2430 ok(hdc != NULL, "Expected HDC to be initialized\n");
2432 status = GdipCreateFromHDC(hdc, &graphics);
2433 expect(Ok, status);
2434 ok(graphics != NULL, "Expected graphics to be initialized\n");
2436 /* null parameters */
2437 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2438 expect(InvalidParameter, status);
2440 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2441 expect(InvalidParameter, status);
2443 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2444 expect(InvalidParameter, status);
2446 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2447 expect(InvalidParameter, status);
2449 x = 0;
2450 y = 0;
2451 status = GdipIsVisiblePoint(graphics, x, y, &val);
2452 expect(Ok, status);
2453 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2455 x = -10;
2456 y = 0;
2457 status = GdipIsVisiblePoint(graphics, x, y, &val);
2458 expect(Ok, status);
2459 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2461 x = 0;
2462 y = -5;
2463 status = GdipIsVisiblePoint(graphics, x, y, &val);
2464 expect(Ok, status);
2465 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2467 x = 1;
2468 y = 1;
2469 status = GdipIsVisiblePoint(graphics, x, y, &val);
2470 expect(Ok, status);
2471 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2473 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2474 expect(Ok, status);
2476 x = 1;
2477 y = 1;
2478 status = GdipIsVisiblePoint(graphics, x, y, &val);
2479 expect(Ok, status);
2480 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2482 x = 15.5;
2483 y = 40.5;
2484 status = GdipIsVisiblePoint(graphics, x, y, &val);
2485 expect(Ok, status);
2486 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2488 /* translate into the center of the rect */
2489 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2491 x = 0;
2492 y = 0;
2493 status = GdipIsVisiblePoint(graphics, x, y, &val);
2494 expect(Ok, status);
2495 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2497 x = 25;
2498 y = 40;
2499 status = GdipIsVisiblePoint(graphics, x, y, &val);
2500 expect(Ok, status);
2501 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2503 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2505 /* corner cases */
2506 x = 9;
2507 y = 19;
2508 status = GdipIsVisiblePoint(graphics, x, y, &val);
2509 expect(Ok, status);
2510 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2512 x = 9.25;
2513 y = 19.25;
2514 status = GdipIsVisiblePoint(graphics, x, y, &val);
2515 expect(Ok, status);
2516 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2518 x = 9.5;
2519 y = 19.5;
2520 status = GdipIsVisiblePoint(graphics, x, y, &val);
2521 expect(Ok, status);
2522 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2524 x = 9.75;
2525 y = 19.75;
2526 status = GdipIsVisiblePoint(graphics, x, y, &val);
2527 expect(Ok, status);
2528 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2530 x = 10;
2531 y = 20;
2532 status = GdipIsVisiblePoint(graphics, x, y, &val);
2533 expect(Ok, status);
2534 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2536 x = 40;
2537 y = 20;
2538 status = GdipIsVisiblePoint(graphics, x, y, &val);
2539 expect(Ok, status);
2540 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2542 x = 39;
2543 y = 59;
2544 status = GdipIsVisiblePoint(graphics, x, y, &val);
2545 expect(Ok, status);
2546 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2548 x = 39.25;
2549 y = 59.25;
2550 status = GdipIsVisiblePoint(graphics, x, y, &val);
2551 expect(Ok, status);
2552 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2554 x = 39.5;
2555 y = 39.5;
2556 status = GdipIsVisiblePoint(graphics, x, y, &val);
2557 expect(Ok, status);
2558 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2560 x = 39.75;
2561 y = 59.75;
2562 status = GdipIsVisiblePoint(graphics, x, y, &val);
2563 expect(Ok, status);
2564 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2566 x = 40;
2567 y = 60;
2568 status = GdipIsVisiblePoint(graphics, x, y, &val);
2569 expect(Ok, status);
2570 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2572 x = 40.15;
2573 y = 60.15;
2574 status = GdipIsVisiblePoint(graphics, x, y, &val);
2575 expect(Ok, status);
2576 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2578 x = 10;
2579 y = 60;
2580 status = GdipIsVisiblePoint(graphics, x, y, &val);
2581 expect(Ok, status);
2582 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2584 /* integer version */
2585 x = 25;
2586 y = 30;
2587 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2588 expect(Ok, status);
2589 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2591 x = 50;
2592 y = 100;
2593 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2594 expect(Ok, status);
2595 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2597 GdipDeleteGraphics(graphics);
2598 ReleaseDC(hwnd, hdc);
2601 static void test_GdipIsVisibleRect(void)
2603 GpStatus status;
2604 GpGraphics *graphics = NULL;
2605 HDC hdc = GetDC( hwnd );
2606 REAL x, y, width, height;
2607 BOOL val;
2609 ok(hdc != NULL, "Expected HDC to be initialized\n");
2611 status = GdipCreateFromHDC(hdc, &graphics);
2612 expect(Ok, status);
2613 ok(graphics != NULL, "Expected graphics to be initialized\n");
2615 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2616 expect(InvalidParameter, status);
2618 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2619 expect(InvalidParameter, status);
2621 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2622 expect(InvalidParameter, status);
2624 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2625 expect(InvalidParameter, status);
2627 /* entirely within the visible region */
2628 x = 0; width = 10;
2629 y = 0; height = 10;
2630 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2631 expect(Ok, status);
2632 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2634 /* partially outside */
2635 x = -10; width = 20;
2636 y = -10; height = 20;
2637 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2638 expect(Ok, status);
2639 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2641 /* entirely outside */
2642 x = -10; width = 5;
2643 y = -10; height = 5;
2644 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2645 expect(Ok, status);
2646 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2648 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2649 expect(Ok, status);
2651 /* entirely within the visible region */
2652 x = 12; width = 10;
2653 y = 22; height = 10;
2654 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2655 expect(Ok, status);
2656 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2658 /* partially outside */
2659 x = 35; width = 10;
2660 y = 55; height = 10;
2661 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2662 expect(Ok, status);
2663 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2665 /* entirely outside */
2666 x = 45; width = 5;
2667 y = 65; height = 5;
2668 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2669 expect(Ok, status);
2670 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2672 /* translate into center of clipping rect */
2673 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2675 x = 0; width = 10;
2676 y = 0; height = 10;
2677 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2678 expect(Ok, status);
2679 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2681 x = 25; width = 5;
2682 y = 40; height = 5;
2683 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2684 expect(Ok, status);
2685 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2687 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2689 /* corners entirely outside, but some intersections */
2690 x = 0; width = 70;
2691 y = 0; height = 90;
2692 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2693 expect(Ok, status);
2694 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2696 x = 0; width = 70;
2697 y = 0; height = 30;
2698 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2699 expect(Ok, status);
2700 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2702 x = 0; width = 30;
2703 y = 0; height = 90;
2704 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2705 expect(Ok, status);
2706 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2708 /* edge cases */
2709 x = 0; width = 10;
2710 y = 20; height = 40;
2711 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2712 expect(Ok, status);
2713 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2715 x = 10; width = 30;
2716 y = 0; height = 20;
2717 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2718 expect(Ok, status);
2719 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2721 x = 40; width = 10;
2722 y = 20; height = 40;
2723 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2724 expect(Ok, status);
2725 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2727 x = 10; width = 30;
2728 y = 60; height = 10;
2729 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2730 expect(Ok, status);
2731 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2733 /* rounding tests */
2734 x = 0.4; width = 10.4;
2735 y = 20; height = 40;
2736 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2737 expect(Ok, status);
2738 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2740 x = 10; width = 30;
2741 y = 0.4; height = 20.4;
2742 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2743 expect(Ok, status);
2744 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2746 /* integer version */
2747 x = 0; width = 30;
2748 y = 0; height = 90;
2749 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2750 expect(Ok, status);
2751 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2753 x = 12; width = 10;
2754 y = 22; height = 10;
2755 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2756 expect(Ok, status);
2757 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2759 GdipDeleteGraphics(graphics);
2760 ReleaseDC(hwnd, hdc);
2763 static void test_GdipGetNearestColor(void)
2765 GpStatus status;
2766 GpGraphics *graphics;
2767 GpBitmap *bitmap;
2768 ARGB color = 0xdeadbeef;
2769 HDC hdc = GetDC( hwnd );
2771 /* create a graphics object */
2772 ok(hdc != NULL, "Expected HDC to be initialized\n");
2774 status = GdipCreateFromHDC(hdc, &graphics);
2775 expect(Ok, status);
2776 ok(graphics != NULL, "Expected graphics to be initialized\n");
2778 status = GdipGetNearestColor(graphics, NULL);
2779 expect(InvalidParameter, status);
2781 status = GdipGetNearestColor(NULL, &color);
2782 expect(InvalidParameter, status);
2783 GdipDeleteGraphics(graphics);
2785 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2786 expect(Ok, status);
2787 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2788 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2789 if (status == Ok)
2791 status = GdipGetNearestColor(graphics, &color);
2792 expect(Ok, status);
2793 expect(0xdeadbeef, color);
2794 GdipDeleteGraphics(graphics);
2796 GdipDisposeImage((GpImage*)bitmap);
2798 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2799 expect(Ok, status);
2800 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2801 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2802 if (status == Ok)
2804 status = GdipGetNearestColor(graphics, &color);
2805 expect(Ok, status);
2806 expect(0xdeadbeef, color);
2807 GdipDeleteGraphics(graphics);
2809 GdipDisposeImage((GpImage*)bitmap);
2811 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2812 expect(Ok, status);
2813 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2814 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2815 if (status == Ok)
2817 status = GdipGetNearestColor(graphics, &color);
2818 expect(Ok, status);
2819 expect(0xdeadbeef, color);
2820 GdipDeleteGraphics(graphics);
2822 GdipDisposeImage((GpImage*)bitmap);
2824 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2825 expect(Ok, status);
2826 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2827 todo_wine expect(OutOfMemory, status);
2828 if (status == Ok)
2829 GdipDeleteGraphics(graphics);
2830 GdipDisposeImage((GpImage*)bitmap);
2832 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2833 expect(Ok, status);
2834 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2835 expect(Ok, status);
2836 status = GdipGetNearestColor(graphics, &color);
2837 expect(Ok, status);
2838 expect(0xdeadbeef, color);
2839 GdipDeleteGraphics(graphics);
2840 GdipDisposeImage((GpImage*)bitmap);
2842 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2843 expect(Ok, status);
2844 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2845 expect(Ok, status);
2846 status = GdipGetNearestColor(graphics, &color);
2847 expect(Ok, status);
2848 expect(0xdeadbeef, color);
2849 GdipDeleteGraphics(graphics);
2850 GdipDisposeImage((GpImage*)bitmap);
2852 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2853 expect(Ok, status);
2854 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2855 expect(Ok, status);
2856 status = GdipGetNearestColor(graphics, &color);
2857 expect(Ok, status);
2858 expect(0xdeadbeef, color);
2859 GdipDeleteGraphics(graphics);
2860 GdipDisposeImage((GpImage*)bitmap);
2862 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2863 expect(Ok, status);
2864 if (status == Ok)
2866 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2867 expect(Ok, status);
2868 status = GdipGetNearestColor(graphics, &color);
2869 expect(Ok, status);
2870 expect(0xdeadbeef, color);
2871 GdipDeleteGraphics(graphics);
2872 GdipDisposeImage((GpImage*)bitmap);
2875 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2876 expect(Ok, status);
2877 if (status == Ok)
2879 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2880 expect(Ok, status);
2881 status = GdipGetNearestColor(graphics, &color);
2882 expect(Ok, status);
2883 expect(0xdeadbeef, color);
2884 GdipDeleteGraphics(graphics);
2885 GdipDisposeImage((GpImage*)bitmap);
2888 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2889 expect(Ok, status);
2890 if (status == Ok)
2892 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2893 expect(Ok, status);
2894 status = GdipGetNearestColor(graphics, &color);
2895 expect(Ok, status);
2896 expect(0xdeadbeef, color);
2897 GdipDeleteGraphics(graphics);
2898 GdipDisposeImage((GpImage*)bitmap);
2901 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2902 expect(Ok, status);
2903 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2904 expect(Ok, status);
2905 status = GdipGetNearestColor(graphics, &color);
2906 expect(Ok, status);
2907 todo_wine expect(0xffa8bce8, color);
2908 GdipDeleteGraphics(graphics);
2909 GdipDisposeImage((GpImage*)bitmap);
2911 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2912 expect(Ok, status);
2913 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2914 expect(Ok, status);
2915 status = GdipGetNearestColor(graphics, &color);
2916 expect(Ok, status);
2917 todo_wine
2918 ok(color == 0xffa8b8e8 ||
2919 broken(color == 0xffa0b8e0), /* Win98/WinMe */
2920 "Expected ffa8b8e8, got %.8x\n", color);
2921 GdipDeleteGraphics(graphics);
2922 GdipDisposeImage((GpImage*)bitmap);
2924 ReleaseDC(hwnd, hdc);
2927 static void test_string_functions(void)
2929 GpStatus status;
2930 GpGraphics *graphics;
2931 GpFontFamily *family;
2932 GpFont *font;
2933 RectF rc, char_bounds, bounds;
2934 GpBrush *brush;
2935 ARGB color = 0xff000000;
2936 HDC hdc = GetDC( hwnd );
2937 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2938 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2939 const WCHAR teststring2[] = {'j',0};
2940 REAL char_width, char_height;
2941 INT codepointsfitted, linesfilled;
2942 GpStringFormat *format;
2943 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2944 GpRegion *regions[4];
2945 BOOL region_isempty[4];
2946 int i;
2947 PointF positions[8];
2948 GpMatrix *identity;
2950 ok(hdc != NULL, "Expected HDC to be initialized\n");
2951 status = GdipCreateFromHDC(hdc, &graphics);
2952 expect(Ok, status);
2953 ok(graphics != NULL, "Expected graphics to be initialized\n");
2955 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2956 expect(Ok, status);
2958 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2959 expect(Ok, status);
2961 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2962 expect(Ok, status);
2964 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2965 expect(Ok, status);
2967 rc.X = 0;
2968 rc.Y = 0;
2969 rc.Width = 100.0;
2970 rc.Height = 100.0;
2972 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2973 expect(InvalidParameter, status);
2975 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2976 expect(InvalidParameter, status);
2978 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2979 expect(InvalidParameter, status);
2981 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2982 expect(InvalidParameter, status);
2984 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2985 expect(InvalidParameter, status);
2987 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2988 expect(Ok, status);
2990 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2991 expect(InvalidParameter, status);
2993 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2994 expect(InvalidParameter, status);
2996 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2997 expect(InvalidParameter, status);
2999 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3000 expect(InvalidParameter, status);
3002 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3003 expect(InvalidParameter, status);
3005 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3006 expect(Ok, status);
3008 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3009 expect(Ok, status);
3011 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3012 expect(Ok, status);
3013 expectf(0.0, char_bounds.X);
3014 expectf(0.0, char_bounds.Y);
3015 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3016 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3017 expect(1, codepointsfitted);
3018 expect(1, linesfilled);
3020 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3021 expect(Ok, status);
3022 expectf(0.0, bounds.X);
3023 expectf(0.0, bounds.Y);
3024 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3025 expectf(char_bounds.Height, bounds.Height);
3026 expect(2, codepointsfitted);
3027 expect(1, linesfilled);
3028 char_width = bounds.Width - char_bounds.Width;
3030 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3031 expect(Ok, status);
3032 expectf(0.0, bounds.X);
3033 expectf(0.0, bounds.Y);
3034 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3035 bounds.Width, char_bounds.Width + char_width * 2);
3036 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3037 expect(6, codepointsfitted);
3038 expect(2, linesfilled);
3039 char_height = bounds.Height - char_bounds.Height;
3041 /* Measure the first line. */
3042 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3043 expect(Ok, status);
3044 expectf(0.0, bounds.X);
3045 expectf(0.0, bounds.Y);
3046 expect(4, codepointsfitted);
3047 expect(1, linesfilled);
3049 /* Give just enough space to fit the first line. */
3050 rc.Width = bounds.Width;
3051 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3052 expect(Ok, status);
3053 expectf(0.0, bounds.X);
3054 expectf(0.0, bounds.Y);
3055 todo_wine expect(5, codepointsfitted);
3056 todo_wine expect(1, linesfilled);
3058 /* Cut off everything after the first space. */
3059 rc.Width = char_bounds.Width + char_width * 2.1;
3061 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3062 expect(Ok, status);
3063 expectf(0.0, bounds.X);
3064 expectf(0.0, bounds.Y);
3065 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3066 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3067 expect(6, codepointsfitted);
3068 expect(3, linesfilled);
3070 /* Cut off everything including the first space. */
3071 rc.Width = char_bounds.Width + char_width * 1.7;
3073 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3074 expect(Ok, status);
3075 expectf(0.0, bounds.X);
3076 expectf(0.0, bounds.Y);
3077 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3078 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3079 expect(6, codepointsfitted);
3080 expect(3, linesfilled);
3082 /* Cut off everything after the first character. */
3083 rc.Width = char_bounds.Width + char_width * 0.8;
3085 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3086 expect(Ok, status);
3087 expectf(0.0, bounds.X);
3088 expectf(0.0, bounds.Y);
3089 expectf_(char_bounds.Width, bounds.Width, 0.01);
3090 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3091 expect(6, codepointsfitted);
3092 todo_wine expect(4, linesfilled);
3094 for (i = 0; i < 4; i++)
3095 regions[i] = (GpRegion *)0xdeadbeef;
3097 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3098 expect(Ok, status);
3100 for (i = 0; i < 4; i++)
3101 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3103 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3104 expect(Ok, status);
3106 for (i = 0; i < 4; i++)
3107 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3109 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3110 expect(Ok, status);
3112 set_rect_empty(&rc);
3114 for (i=0; i<4; i++)
3116 status = GdipCreateRegion(&regions[i]);
3117 expect(Ok, status);
3118 status = GdipSetEmpty(regions[i]);
3119 expect(Ok, status);
3122 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3123 expect(InvalidParameter, status);
3125 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3126 expect(InvalidParameter, status);
3128 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3129 expect(InvalidParameter, status);
3131 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3132 expect(InvalidParameter, status);
3134 if (0)
3136 /* Crashes on Windows XP */
3137 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3138 expect(InvalidParameter, status);
3141 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3142 expect(InvalidParameter, status);
3144 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3145 expect(InvalidParameter, status);
3147 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3148 expect(Ok, status);
3150 for (i = 0; i < 4; i++)
3152 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3153 expect(Ok, status);
3156 ok(region_isempty[0], "region should be empty\n");
3157 ok(region_isempty[1], "region should be empty\n");
3158 ok(region_isempty[2], "region should be empty\n");
3159 ok(region_isempty[3], "region should be empty\n");
3161 rc.Width = 100.0;
3162 rc.Height = 100.0;
3164 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3165 expect(Ok, status);
3167 for (i=0; i<4; i++)
3169 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3170 expect(Ok, status);
3173 ok(!region_isempty[0], "region shouldn't be empty\n");
3174 ok(!region_isempty[1], "region shouldn't be empty\n");
3175 ok(!region_isempty[2], "region shouldn't be empty\n");
3176 ok(region_isempty[3], "region should be empty\n");
3178 /* Cut off everything after the first space, and the second line. */
3179 rc.Width = char_bounds.Width + char_width * 2.1;
3180 rc.Height = char_bounds.Height + char_height * 0.5;
3182 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3183 expect(Ok, status);
3185 for (i=0; i<4; i++)
3187 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3188 expect(Ok, status);
3191 ok(!region_isempty[0], "region shouldn't be empty\n");
3192 ok(!region_isempty[1], "region shouldn't be empty\n");
3193 ok(region_isempty[2], "region should be empty\n");
3194 ok(region_isempty[3], "region should be empty\n");
3196 for (i=0; i<4; i++)
3197 GdipDeleteRegion(regions[i]);
3199 status = GdipCreateMatrix(&identity);
3200 expect(Ok, status);
3202 rc.X = 0;
3203 rc.Y = 0;
3204 rc.Width = 0;
3205 rc.Height = 0;
3206 memset(positions, 0, sizeof(positions));
3207 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3208 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3209 identity, &rc);
3210 expect(InvalidParameter, status);
3212 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3213 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3214 identity, &rc);
3215 expect(InvalidParameter, status);
3217 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3218 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3219 identity, &rc);
3220 expect(InvalidParameter, status);
3222 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3223 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3224 identity, &rc);
3225 expect(InvalidParameter, status);
3227 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3228 0x100, identity, &rc);
3229 expect(Ok, status);
3231 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3232 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3233 NULL, &rc);
3234 expect(Ok, status);
3236 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3237 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3238 identity, NULL);
3239 expect(InvalidParameter, status);
3241 rc.X = 0;
3242 rc.Y = 0;
3243 rc.Width = 0;
3244 rc.Height = 0;
3245 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3246 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3247 identity, &rc);
3248 expect(Ok, status);
3250 expectf(0.0, rc.X);
3251 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3252 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3253 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3255 char_width = rc.Width;
3256 char_height = rc.Height;
3258 rc.X = 0;
3259 rc.Y = 0;
3260 rc.Width = 0;
3261 rc.Height = 0;
3262 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3263 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3264 identity, &rc);
3265 expect(Ok, status);
3267 expectf(0.0, rc.X);
3268 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3269 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3270 expectf(char_height, rc.Height);
3272 rc.X = 0;
3273 rc.Y = 0;
3274 rc.Width = 0;
3275 rc.Height = 0;
3276 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3277 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3278 identity, &rc);
3279 expect(Ok, status);
3281 expectf(rc.X, 0.0);
3282 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3283 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3284 expectf(rc.Height, char_height);
3286 GdipDeleteMatrix(identity);
3287 GdipDeleteStringFormat(format);
3288 GdipDeleteBrush(brush);
3289 GdipDeleteFont(font);
3290 GdipDeleteFontFamily(family);
3291 GdipDeleteGraphics(graphics);
3293 ReleaseDC(hwnd, hdc);
3296 static void test_get_set_interpolation(void)
3298 GpGraphics *graphics;
3299 HDC hdc = GetDC( hwnd );
3300 GpStatus status;
3301 InterpolationMode mode;
3303 ok(hdc != NULL, "Expected HDC to be initialized\n");
3304 status = GdipCreateFromHDC(hdc, &graphics);
3305 expect(Ok, status);
3306 ok(graphics != NULL, "Expected graphics to be initialized\n");
3308 status = GdipGetInterpolationMode(NULL, &mode);
3309 expect(InvalidParameter, status);
3311 if (0)
3313 /* Crashes on Windows XP */
3314 status = GdipGetInterpolationMode(graphics, NULL);
3315 expect(InvalidParameter, status);
3318 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3319 expect(InvalidParameter, status);
3321 /* out of range */
3322 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3323 expect(InvalidParameter, status);
3325 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3326 expect(InvalidParameter, status);
3328 status = GdipGetInterpolationMode(graphics, &mode);
3329 expect(Ok, status);
3330 expect(InterpolationModeBilinear, mode);
3332 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3333 expect(Ok, status);
3335 status = GdipGetInterpolationMode(graphics, &mode);
3336 expect(Ok, status);
3337 expect(InterpolationModeNearestNeighbor, mode);
3339 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3340 expect(Ok, status);
3342 status = GdipGetInterpolationMode(graphics, &mode);
3343 expect(Ok, status);
3344 expect(InterpolationModeBilinear, mode);
3346 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3347 expect(Ok, status);
3349 status = GdipGetInterpolationMode(graphics, &mode);
3350 expect(Ok, status);
3351 expect(InterpolationModeBilinear, mode);
3353 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3354 expect(Ok, status);
3356 status = GdipGetInterpolationMode(graphics, &mode);
3357 expect(Ok, status);
3358 expect(InterpolationModeHighQualityBicubic, mode);
3360 GdipDeleteGraphics(graphics);
3362 ReleaseDC(hwnd, hdc);
3365 static void test_get_set_textrenderinghint(void)
3367 GpGraphics *graphics;
3368 HDC hdc = GetDC( hwnd );
3369 GpStatus status;
3370 TextRenderingHint hint;
3372 ok(hdc != NULL, "Expected HDC to be initialized\n");
3373 status = GdipCreateFromHDC(hdc, &graphics);
3374 expect(Ok, status);
3375 ok(graphics != NULL, "Expected graphics to be initialized\n");
3377 status = GdipGetTextRenderingHint(NULL, &hint);
3378 expect(InvalidParameter, status);
3380 status = GdipGetTextRenderingHint(graphics, NULL);
3381 expect(InvalidParameter, status);
3383 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3384 expect(InvalidParameter, status);
3386 /* out of range */
3387 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3388 expect(InvalidParameter, status);
3390 status = GdipGetTextRenderingHint(graphics, &hint);
3391 expect(Ok, status);
3392 expect(TextRenderingHintSystemDefault, hint);
3394 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3395 expect(Ok, status);
3397 status = GdipGetTextRenderingHint(graphics, &hint);
3398 expect(Ok, status);
3399 expect(TextRenderingHintSystemDefault, hint);
3401 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3402 expect(Ok, status);
3404 status = GdipGetTextRenderingHint(graphics, &hint);
3405 expect(Ok, status);
3406 expect(TextRenderingHintAntiAliasGridFit, hint);
3408 GdipDeleteGraphics(graphics);
3410 ReleaseDC(hwnd, hdc);
3413 static void test_getdc_scaled(void)
3415 GpStatus status;
3416 GpGraphics *graphics = NULL;
3417 GpBitmap *bitmap = NULL;
3418 HDC hdc=NULL;
3419 HBRUSH hbrush, holdbrush;
3420 ARGB color;
3422 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3423 expect(Ok, status);
3425 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3426 expect(Ok, status);
3428 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3429 expect(Ok, status);
3431 status = GdipGetDC(graphics, &hdc);
3432 expect(Ok, status);
3433 ok(hdc != NULL, "got NULL hdc\n");
3435 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3437 holdbrush = SelectObject(hdc, hbrush);
3439 Rectangle(hdc, 2, 2, 6, 6);
3441 SelectObject(hdc, holdbrush);
3443 DeleteObject(hbrush);
3445 status = GdipReleaseDC(graphics, hdc);
3446 expect(Ok, status);
3448 GdipDeleteGraphics(graphics);
3450 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3451 expect(Ok, status);
3452 expect(0xffff0000, color);
3454 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3455 expect(Ok, status);
3456 expect(0xff000000, color);
3458 GdipDisposeImage((GpImage*)bitmap);
3461 static void test_GdipMeasureString(void)
3463 static const struct test_data
3465 REAL res_x, res_y, page_scale;
3466 GpUnit unit;
3467 } td[] =
3469 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3470 { 200.0, 200.0, 2.0, UnitPixel },
3471 { 200.0, 200.0, 1.0, UnitDisplay },
3472 { 200.0, 200.0, 2.0, UnitDisplay },
3473 { 200.0, 200.0, 1.0, UnitInch },
3474 { 200.0, 200.0, 2.0, UnitInch },
3475 { 200.0, 600.0, 1.0, UnitPoint },
3476 { 200.0, 600.0, 2.0, UnitPoint },
3477 { 200.0, 600.0, 1.0, UnitDocument },
3478 { 200.0, 600.0, 2.0, UnitDocument },
3479 { 200.0, 600.0, 1.0, UnitMillimeter },
3480 { 200.0, 600.0, 2.0, UnitMillimeter },
3481 { 200.0, 600.0, 1.0, UnitDisplay },
3482 { 200.0, 600.0, 2.0, UnitDisplay },
3483 { 200.0, 600.0, 1.0, UnitPixel },
3484 { 200.0, 600.0, 2.0, UnitPixel },
3486 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3487 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3488 GpStatus status;
3489 GpGraphics *graphics;
3490 GpFontFamily *family;
3491 GpFont *font;
3492 GpStringFormat *format;
3493 RectF bounds, rc;
3494 REAL base_cx = 0, base_cy = 0, height;
3495 INT chars, lines;
3496 LOGFONTW lf;
3497 UINT i;
3498 REAL font_size;
3499 GpUnit font_unit, unit;
3501 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3502 expect(Ok, status);
3503 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3504 expect(Ok, status);
3506 /* font size in pixels */
3507 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3508 expect(Ok, status);
3509 status = GdipGetFontSize(font, &font_size);
3510 expect(Ok, status);
3511 expectf(100.0, font_size);
3512 status = GdipGetFontUnit(font, &font_unit);
3513 expect(Ok, status);
3514 expect(UnitPixel, font_unit);
3516 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3518 GpImage *image;
3520 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3522 lf.lfHeight = 0xdeadbeef;
3523 status = GdipGetLogFontW(font, graphics, &lf);
3524 expect(Ok, status);
3525 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3526 if (td[i].unit != UnitDisplay)
3527 height *= td[i].page_scale;
3528 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3529 i, (LONG)(height + 0.5), height, lf.lfHeight);
3531 height = font_size + 2.0 * font_size / 6.0;
3533 set_rect_empty(&rc);
3534 set_rect_empty(&bounds);
3535 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3536 expect(Ok, status);
3538 if (i == 0)
3540 base_cx = bounds.Width;
3541 base_cy = bounds.Height;
3544 expectf(0.0, bounds.X);
3545 expectf(0.0, bounds.Y);
3546 todo_wine
3547 expectf_(height, bounds.Height, height / 100.0);
3548 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3549 expect(7, chars);
3550 expect(1, lines);
3552 /* make sure it really fits */
3553 bounds.Width += 1.0;
3554 bounds.Height += 1.0;
3555 rc = bounds;
3556 rc.X = 50.0;
3557 rc.Y = 50.0;
3558 set_rect_empty(&bounds);
3559 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3560 expect(Ok, status);
3561 expectf(50.0, bounds.X);
3562 expectf(50.0, bounds.Y);
3563 todo_wine
3564 expectf_(height, bounds.Height, height / 100.0);
3565 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3566 expect(7, chars);
3567 expect(1, lines);
3569 status = GdipDeleteGraphics(graphics);
3570 expect(Ok, status);
3572 status = GdipDisposeImage(image);
3573 expect(Ok, status);
3576 GdipDeleteFont(font);
3578 /* font size in logical units */
3579 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3580 for (unit = 3; unit <= 6; unit++)
3582 /* create a font which final height is 100.0 pixels with 200 dpi device */
3583 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3584 height = pixels_to_units(75.0, unit, 200.0);
3585 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3586 expect(Ok, status);
3587 status = GdipGetFontSize(font, &font_size);
3588 expect(Ok, status);
3589 expectf(height, font_size);
3590 status = GdipGetFontUnit(font, &font_unit);
3591 expect(Ok, status);
3592 expect(unit, font_unit);
3594 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3596 REAL unit_scale;
3597 GpImage *image;
3599 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3601 lf.lfHeight = 0xdeadbeef;
3602 status = GdipGetLogFontW(font, graphics, &lf);
3603 expect(Ok, status);
3604 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3605 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3606 else
3607 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3608 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3609 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3610 i, (LONG)(height + 0.5), height, lf.lfHeight);
3612 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3613 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3614 else
3615 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3616 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3617 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3618 if (td[i].unit != UnitDisplay)
3619 height /= td[i].page_scale;
3620 /*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);*/
3622 set_rect_empty(&rc);
3623 set_rect_empty(&bounds);
3624 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3625 expect(Ok, status);
3627 if (i == 0)
3629 base_cx = bounds.Width;
3630 base_cy = bounds.Height;
3633 expectf(0.0, bounds.X);
3634 expectf(0.0, bounds.Y);
3635 todo_wine
3636 expectf_(height, bounds.Height, height / 85.0);
3637 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3638 expect(7, chars);
3639 expect(1, lines);
3641 /* make sure it really fits */
3642 bounds.Width += 1.0;
3643 bounds.Height += 1.0;
3644 rc = bounds;
3645 rc.X = 50.0;
3646 rc.Y = 50.0;
3647 set_rect_empty(&bounds);
3648 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3649 expect(Ok, status);
3650 expectf(50.0, bounds.X);
3651 expectf(50.0, bounds.Y);
3652 todo_wine
3653 expectf_(height, bounds.Height, height / 85.0);
3654 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3655 expect(7, chars);
3656 expect(1, lines);
3658 /* verify the result */
3659 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3660 if (td[i].unit != UnitDisplay)
3661 height *= td[i].page_scale;
3662 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3663 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3664 todo_wine
3665 expectf_(100.0, height, 1.1);
3667 status = GdipDeleteGraphics(graphics);
3668 expect(Ok, status);
3670 status = GdipDisposeImage(image);
3671 expect(Ok, status);
3674 GdipDeleteFont(font);
3677 GdipDeleteFontFamily(family);
3678 GdipDeleteStringFormat(format);
3681 static void test_transform(void)
3683 static const struct test_data
3685 REAL res_x, res_y, scale;
3686 GpUnit unit;
3687 GpPointF in[2], out[2];
3688 } td[] =
3690 { 96.0, 96.0, 1.0, UnitPixel,
3691 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3692 { 96.0, 96.0, 1.0, UnitDisplay,
3693 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3694 { 96.0, 96.0, 1.0, UnitInch,
3695 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
3696 { 123.0, 456.0, 1.0, UnitPoint,
3697 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
3698 { 123.0, 456.0, 1.0, UnitDocument,
3699 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
3700 { 123.0, 456.0, 2.0, UnitMillimeter,
3701 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
3702 { 196.0, 296.0, 1.0, UnitDisplay,
3703 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3704 { 196.0, 296.0, 1.0, UnitPixel,
3705 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3707 GpStatus status;
3708 GpGraphics *graphics;
3709 GpImage *image;
3710 GpPointF ptf[2];
3711 UINT i;
3713 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3715 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
3716 ptf[0].X = td[i].in[0].X;
3717 ptf[0].Y = td[i].in[0].Y;
3718 ptf[1].X = td[i].in[1].X;
3719 ptf[1].Y = td[i].in[1].Y;
3720 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
3721 expect(Ok, status);
3722 expectf(td[i].out[0].X, ptf[0].X);
3723 expectf(td[i].out[0].Y, ptf[0].Y);
3724 expectf(td[i].out[1].X, ptf[1].X);
3725 expectf(td[i].out[1].Y, ptf[1].Y);
3726 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
3727 expect(Ok, status);
3728 expectf(td[i].in[0].X, ptf[0].X);
3729 expectf(td[i].in[0].Y, ptf[0].Y);
3730 expectf(td[i].in[1].X, ptf[1].X);
3731 expectf(td[i].in[1].Y, ptf[1].Y);
3732 status = GdipDeleteGraphics(graphics);
3733 expect(Ok, status);
3734 status = GdipDisposeImage(image);
3735 expect(Ok, status);
3739 /* Many people on the net ask why there is so much difference in rendered
3740 * text height between gdiplus and gdi32, this test suggests an answer to
3741 * that question. Important: this test assumes that font dpi == device dpi.
3743 static void test_font_height_scaling(void)
3745 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3746 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3747 HDC hdc;
3748 GpStringFormat *format;
3749 CharacterRange range = { 0, 7 };
3750 GpRegion *region;
3751 GpGraphics *graphics;
3752 GpFontFamily *family;
3753 GpFont *font;
3754 GpStatus status;
3755 RectF bounds, rect;
3756 REAL height, dpi, scale;
3757 PointF ptf;
3758 GpUnit gfx_unit, font_unit;
3760 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3761 expect(Ok, status);
3762 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3763 expect(Ok, status);
3764 status = GdipCreateRegion(&region);
3765 expect(Ok, status);
3767 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3768 expect(Ok, status);
3770 hdc = CreateCompatibleDC(0);
3771 status = GdipCreateFromHDC(hdc, &graphics);
3773 status = GdipGetDpiY(graphics, &dpi);
3774 expect(Ok, status);
3776 /* First check if tested functionality works:
3777 * under XP if font and graphics units differ then GdipTransformPoints
3778 * followed by GdipSetPageUnit to change the graphics units breaks region
3779 * scaling in GdipMeasureCharacterRanges called later.
3781 status = GdipSetPageUnit(graphics, UnitDocument);
3782 expect(Ok, status);
3784 ptf.X = 0.0;
3785 ptf.Y = 0.0;
3786 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
3787 expect(Ok, status);
3789 status = GdipSetPageUnit(graphics, UnitInch);
3790 expect(Ok, status);
3792 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
3793 expect(Ok, status);
3795 set_rect_empty(&rect);
3796 set_rect_empty(&bounds);
3797 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
3798 expect(Ok, status);
3799 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
3801 set_rect_empty(&rect);
3802 rect.Width = 32000.0;
3803 rect.Height = 32000.0;
3804 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3805 expect(Ok, status);
3807 set_rect_empty(&rect);
3808 status = GdipGetRegionBounds(region, graphics, &rect);
3809 expect(Ok, status);
3810 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
3812 GdipDeleteFont(font);
3814 scale = rect.Height / bounds.Height;
3815 if (fabs(scale - 1.0) > 0.1)
3817 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
3818 goto cleanup;
3821 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
3822 expect(Ok, status);
3824 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3825 /* UnitPixel as a font base unit is not tested because it drastically
3826 differs in behaviour */
3827 for (font_unit = 3; font_unit <= 6; font_unit++)
3829 /* create a font for the final text height of 100 pixels */
3830 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3831 status = GdipSetPageUnit(graphics, font_unit);
3832 expect(Ok, status);
3833 ptf.X = 0;
3834 ptf.Y = 75.0;
3835 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
3836 expect(Ok, status);
3837 height = ptf.Y;
3838 /*trace("height %f units\n", height);*/
3839 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
3840 expect(Ok, status);
3842 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3843 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
3845 static const WCHAR doubleW[2] = { 'W','W' };
3846 RectF bounds_1, bounds_2;
3847 REAL margin, margin_y, font_height;
3848 int match;
3850 status = GdipSetPageUnit(graphics, gfx_unit);
3851 expect(Ok, status);
3853 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
3854 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
3856 status = GdipGetFontHeight(font, graphics, &font_height);
3857 expect(Ok, status);
3859 set_rect_empty(&rect);
3860 set_rect_empty(&bounds);
3861 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
3862 expect(Ok, status);
3863 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
3864 todo_wine
3865 expectf_(font_height + margin_y, bounds.Height, 0.005);
3867 ptf.X = 0;
3868 ptf.Y = bounds.Height;
3869 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
3870 expect(Ok, status);
3871 match = fabs(100.0 - ptf.Y) <= 1.0;
3872 todo_wine
3873 ok(match, "Expected 100.0, got %f\n", ptf.Y);
3875 /* verify the result */
3876 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
3877 ptf.Y /= 100.0;
3878 match = fabs(100.0 - ptf.Y) <= 1.0;
3879 todo_wine
3880 ok(match, "Expected 100.0, got %f\n", ptf.Y);
3882 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
3883 set_rect_empty(&rect);
3884 set_rect_empty(&bounds_1);
3885 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
3886 expect(Ok, status);
3887 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
3888 set_rect_empty(&rect);
3889 set_rect_empty(&bounds_2);
3890 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
3891 expect(Ok, status);
3893 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
3894 margin = bounds_1.Width - bounds_2.Width / 2.0;
3895 /*trace("margin %f\n", margin);*/
3896 ok(margin > 0.0, "wrong margin %f\n", margin);
3898 set_rect_empty(&rect);
3899 rect.Width = 320000.0;
3900 rect.Height = 320000.0;
3901 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3902 expect(Ok, status);
3903 set_rect_empty(&rect);
3904 status = GdipGetRegionBounds(region, graphics, &rect);
3905 expect(Ok, status);
3906 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
3907 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
3908 expectf(0.0, rect.Y);
3909 match = fabs(1.0 - margin / rect.X) <= 0.05;
3910 ok(match, "Expected %f, got %f\n", margin, rect.X);
3911 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
3912 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
3913 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
3914 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
3917 GdipDeleteFont(font);
3920 cleanup:
3921 status = GdipDeleteGraphics(graphics);
3922 expect(Ok, status);
3923 DeleteDC(hdc);
3925 GdipDeleteFontFamily(family);
3926 GdipDeleteRegion(region);
3927 GdipDeleteStringFormat(format);
3930 static void test_measure_string(void)
3932 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3933 static const WCHAR string[] = { 'A','0','1',0 };
3934 HDC hdc;
3935 GpStringFormat *format;
3936 CharacterRange range;
3937 GpRegion *region;
3938 GpGraphics *graphics;
3939 GpFontFamily *family;
3940 GpFont *font;
3941 GpStatus status;
3942 RectF bounds, rect;
3943 REAL width, height, width_1, width_2;
3944 REAL margin_x, margin_y, width_rgn, height_rgn;
3945 int lines, glyphs;
3947 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3948 expect(Ok, status);
3949 expect(Ok, status);
3951 status = GdipCreateRegion(&region);
3952 expect(Ok, status);
3954 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3955 expect(Ok, status);
3957 hdc = CreateCompatibleDC(0);
3958 status = GdipCreateFromHDC(hdc, &graphics);
3960 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
3961 expect(Ok, status);
3963 margin_x = 20.0 / 6.0;
3964 margin_y = 20.0 / 8.0;
3966 set_rect_empty(&rect);
3967 set_rect_empty(&bounds);
3968 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
3969 expect(Ok, status);
3970 expect(3, glyphs);
3971 expect(1, lines);
3972 expectf(0.0, bounds.X);
3973 expectf(0.0, bounds.Y);
3974 width = bounds.Width;
3975 height = bounds.Height;
3977 set_rect_empty(&rect);
3978 rect.Height = height / 2.0;
3979 set_rect_empty(&bounds);
3980 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
3981 expect(Ok, status);
3982 expect(3, glyphs);
3983 expect(1, lines);
3984 expectf(0.0, bounds.X);
3985 expectf(0.0, bounds.Y);
3986 expectf(width, bounds.Width);
3987 todo_wine
3988 expectf(height / 2.0, bounds.Height);
3990 range.First = 0;
3991 range.Length = lstrlenW(string);
3992 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3993 expect(Ok, status);
3995 rect.X = 5.0;
3996 rect.Y = 5.0;
3997 rect.Width = 32000.0;
3998 rect.Height = 32000.0;
3999 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4000 expect(Ok, status);
4001 set_rect_empty(&bounds);
4002 status = GdipGetRegionBounds(region, graphics, &bounds);
4003 expect(Ok, status);
4004 expectf_(5.0 + margin_x, bounds.X, 1.0);
4005 expectf(5.0, bounds.Y);
4006 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4007 todo_wine
4008 expectf_(height - margin_y, bounds.Height, 1.0);
4010 width_rgn = bounds.Width;
4011 height_rgn = bounds.Height;
4013 range.First = 0;
4014 range.Length = 1;
4015 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4016 expect(Ok, status);
4018 set_rect_empty(&rect);
4019 rect.Width = 32000.0;
4020 rect.Height = 32000.0;
4021 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4022 expect(Ok, status);
4023 set_rect_empty(&bounds);
4024 status = GdipGetRegionBounds(region, graphics, &bounds);
4025 expect(Ok, status);
4026 expectf_(margin_x, bounds.X, 1.0);
4027 expectf(0.0, bounds.Y);
4028 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4029 expectf(height_rgn, bounds.Height);
4030 width_1 = bounds.Width;
4032 range.First = 0;
4033 range.Length = lstrlenW(string);
4034 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4035 expect(Ok, status);
4037 rect.X = 5.0;
4038 rect.Y = 5.0;
4039 rect.Width = 0.0;
4040 rect.Height = 0.0;
4041 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4042 expect(Ok, status);
4043 set_rect_empty(&bounds);
4044 status = GdipGetRegionBounds(region, graphics, &bounds);
4045 expect(Ok, status);
4046 expectf(0.0, bounds.X);
4047 expectf(0.0, bounds.Y);
4048 expectf(0.0, bounds.Width);
4049 expectf(0.0, bounds.Height);
4051 rect.X = 5.0;
4052 rect.Y = 5.0;
4053 rect.Width = width_rgn / 2.0;
4054 rect.Height = 32000.0;
4055 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4056 expect(Ok, status);
4057 set_rect_empty(&bounds);
4058 status = GdipGetRegionBounds(region, graphics, &bounds);
4059 expect(Ok, status);
4060 expectf_(5.0 + margin_x, bounds.X, 1.0);
4061 expectf(5.0, bounds.Y);
4062 expectf_(width_1, bounds.Width, 1.0);
4063 todo_wine
4064 expectf_(height - margin_y, bounds.Height, 1.0);
4066 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4068 rect.X = 5.0;
4069 rect.Y = 5.0;
4070 rect.Width = 0.0;
4071 rect.Height = 0.0;
4072 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4073 expect(Ok, status);
4074 set_rect_empty(&bounds);
4075 status = GdipGetRegionBounds(region, graphics, &bounds);
4076 expect(Ok, status);
4077 expectf_(5.0 + margin_x, bounds.X, 1.0);
4078 expectf(5.0, bounds.Y);
4079 expectf(width_rgn, bounds.Width);
4080 expectf(height_rgn, bounds.Height);
4082 rect.X = 5.0;
4083 rect.Y = 5.0;
4084 rect.Width = width_rgn / 2.0;
4085 rect.Height = 32000.0;
4086 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4087 expect(Ok, status);
4088 set_rect_empty(&bounds);
4089 status = GdipGetRegionBounds(region, graphics, &bounds);
4090 expect(Ok, status);
4091 expectf_(5.0 + margin_x, bounds.X, 1.0);
4092 expectf(5.0, bounds.Y);
4093 expectf_(width_1, bounds.Width, 1.0);
4094 expectf(height_rgn, bounds.Height);
4096 set_rect_empty(&rect);
4097 rect.Height = height / 2.0;
4098 set_rect_empty(&bounds);
4099 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4100 expect(Ok, status);
4101 expect(3, glyphs);
4102 expect(1, lines);
4103 expectf(0.0, bounds.X);
4104 expectf(0.0, bounds.Y);
4105 expectf_(width, bounds.Width, 0.01);
4106 todo_wine
4107 expectf(height, bounds.Height);
4109 set_rect_empty(&rect);
4110 set_rect_empty(&bounds);
4111 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4112 expect(Ok, status);
4113 expect(1, glyphs);
4114 expect(1, lines);
4115 expectf(0.0, bounds.X);
4116 expectf(0.0, bounds.Y);
4117 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4118 expectf(height, bounds.Height);
4119 width_1 = bounds.Width;
4121 set_rect_empty(&rect);
4122 set_rect_empty(&bounds);
4123 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4124 expect(Ok, status);
4125 expect(2, glyphs);
4126 expect(1, lines);
4127 expectf(0.0, bounds.X);
4128 expectf(0.0, bounds.Y);
4129 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4130 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4131 expectf(height, bounds.Height);
4132 width_2 = bounds.Width;
4134 set_rect_empty(&rect);
4135 rect.Width = width / 2.0;
4136 set_rect_empty(&bounds);
4137 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4138 expect(Ok, status);
4139 expect(1, glyphs);
4140 expect(1, lines);
4141 expectf(0.0, bounds.X);
4142 expectf(0.0, bounds.Y);
4143 expectf_(width_1, bounds.Width, 0.01);
4144 expectf(height, bounds.Height);
4146 set_rect_empty(&rect);
4147 rect.Height = height;
4148 rect.Width = width - 0.05;
4149 set_rect_empty(&bounds);
4150 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4151 expect(Ok, status);
4152 expect(2, glyphs);
4153 expect(1, lines);
4154 expectf(0.0, bounds.X);
4155 expectf(0.0, bounds.Y);
4156 expectf_(width_2, bounds.Width, 0.01);
4157 expectf(height, bounds.Height);
4159 set_rect_empty(&rect);
4160 rect.Height = height;
4161 rect.Width = width_2 - 0.05;
4162 set_rect_empty(&bounds);
4163 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4164 expect(Ok, status);
4165 expect(1, glyphs);
4166 expect(1, lines);
4167 expectf(0.0, bounds.X);
4168 expectf(0.0, bounds.Y);
4169 expectf_(width_1, bounds.Width, 0.01);
4170 expectf(height, bounds.Height);
4172 /* Default (Near) alignment */
4173 rect.X = 5.0;
4174 rect.Y = 5.0;
4175 rect.Width = width * 2.0;
4176 rect.Height = height * 2.0;
4177 set_rect_empty(&bounds);
4178 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4179 expect(Ok, status);
4180 expect(3, glyphs);
4181 expect(1, lines);
4182 expectf(5.0, bounds.X);
4183 expectf(5.0, bounds.Y);
4184 expectf_(width, bounds.Width, 0.01);
4185 expectf(height, bounds.Height);
4187 rect.X = 5.0;
4188 rect.Y = 5.0;
4189 rect.Width = 32000.0;
4190 rect.Height = 32000.0;
4191 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4192 expect(Ok, status);
4193 set_rect_empty(&bounds);
4194 status = GdipGetRegionBounds(region, graphics, &bounds);
4195 expect(Ok, status);
4196 expectf_(5.0 + margin_x, bounds.X, 1.0);
4197 expectf(5.0, bounds.Y);
4198 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4199 todo_wine
4200 expectf_(height - margin_y, bounds.Height, 1.0);
4202 width_rgn = bounds.Width;
4203 height_rgn = bounds.Height;
4205 /* Center alignment */
4206 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4207 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4209 rect.X = 5.0;
4210 rect.Y = 5.0;
4211 rect.Width = width * 2.0;
4212 rect.Height = height * 2.0;
4213 set_rect_empty(&bounds);
4214 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4215 expect(Ok, status);
4216 expect(3, glyphs);
4217 expect(1, lines);
4218 todo_wine
4219 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4220 todo_wine
4221 expectf(5.0 + height/2.0, bounds.Y);
4222 expectf_(width, bounds.Width, 0.01);
4223 expectf(height, bounds.Height);
4225 rect.X = 5.0;
4226 rect.Y = 5.0;
4227 rect.Width = 0.0;
4228 rect.Height = 0.0;
4229 set_rect_empty(&bounds);
4230 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4231 expect(Ok, status);
4232 expect(3, glyphs);
4233 expect(1, lines);
4234 todo_wine
4235 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4236 todo_wine
4237 expectf(5.0 - height/2.0, bounds.Y);
4238 expectf_(width, bounds.Width, 0.01);
4239 expectf(height, bounds.Height);
4241 rect.X = 5.0;
4242 rect.Y = 5.0;
4243 rect.Width = width_rgn * 2.0;
4244 rect.Height = height_rgn * 2.0;
4245 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4246 expect(Ok, status);
4247 set_rect_empty(&bounds);
4248 status = GdipGetRegionBounds(region, graphics, &bounds);
4249 expect(Ok, status);
4250 todo_wine
4251 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4252 todo_wine
4253 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4254 expectf_(width_rgn, bounds.Width, 1.0);
4255 expectf_(height_rgn, bounds.Height, 1.0);
4257 rect.X = 5.0;
4258 rect.Y = 5.0;
4259 rect.Width = 0.0;
4260 rect.Height = 0.0;
4261 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4262 expect(Ok, status);
4263 set_rect_empty(&bounds);
4264 status = GdipGetRegionBounds(region, graphics, &bounds);
4265 expect(Ok, status);
4266 todo_wine
4267 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4268 todo_wine
4269 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4270 expectf_(width_rgn, bounds.Width, 1.0);
4271 expectf_(height_rgn, bounds.Height, 1.0);
4273 /* Far alignment */
4274 GdipSetStringFormatAlign(format, StringAlignmentFar);
4275 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4277 rect.X = 5.0;
4278 rect.Y = 5.0;
4279 rect.Width = width * 2.0;
4280 rect.Height = height * 2.0;
4281 set_rect_empty(&bounds);
4282 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4283 expect(Ok, status);
4284 expect(3, glyphs);
4285 expect(1, lines);
4286 todo_wine
4287 expectf_(5.0 + width, bounds.X, 0.01);
4288 todo_wine
4289 expectf(5.0 + height, bounds.Y);
4290 expectf_(width, bounds.Width, 0.01);
4291 expectf(height, bounds.Height);
4293 rect.X = 5.0;
4294 rect.Y = 5.0;
4295 rect.Width = 0.0;
4296 rect.Height = 0.0;
4297 set_rect_empty(&bounds);
4298 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4299 expect(Ok, status);
4300 expect(3, glyphs);
4301 expect(1, lines);
4302 todo_wine
4303 expectf_(5.0 - width, bounds.X, 0.01);
4304 todo_wine
4305 expectf(5.0 - height, bounds.Y);
4306 expectf_(width, bounds.Width, 0.01);
4307 expectf(height, bounds.Height);
4309 rect.X = 5.0;
4310 rect.Y = 5.0;
4311 rect.Width = width_rgn * 2.0;
4312 rect.Height = height_rgn * 2.0;
4313 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4314 expect(Ok, status);
4315 set_rect_empty(&bounds);
4316 status = GdipGetRegionBounds(region, graphics, &bounds);
4317 expect(Ok, status);
4318 todo_wine
4319 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4320 todo_wine
4321 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4322 expectf_(width_rgn, bounds.Width, 1.0);
4323 expectf_(height_rgn, bounds.Height, 1.0);
4325 rect.X = 5.0;
4326 rect.Y = 5.0;
4327 rect.Width = 0.0;
4328 rect.Height = 0.0;
4329 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4330 expect(Ok, status);
4331 set_rect_empty(&bounds);
4332 status = GdipGetRegionBounds(region, graphics, &bounds);
4333 expect(Ok, status);
4334 todo_wine
4335 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4336 todo_wine
4337 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4338 expectf_(width_rgn, bounds.Width, 1.0);
4339 expectf_(height_rgn, bounds.Height, 1.0);
4341 status = GdipDeleteFont(font);
4342 expect(Ok, status);
4344 status = GdipDeleteGraphics(graphics);
4345 expect(Ok, status);
4346 DeleteDC(hdc);
4348 GdipDeleteFontFamily(family);
4349 GdipDeleteRegion(region);
4350 GdipDeleteStringFormat(format);
4353 static void test_measured_extra_space(void)
4355 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4356 static const WCHAR string[2] = { 'W','W' };
4357 GpStringFormat *format;
4358 HDC hdc;
4359 GpGraphics *graphics;
4360 GpFontFamily *family;
4361 GpFont *font;
4362 GpStatus status;
4363 GpUnit gfx_unit, font_unit;
4364 RectF bounds_1, bounds_2, rect;
4365 REAL margin, font_size, dpi;
4367 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4368 expect(Ok, status);
4370 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4371 expect(Ok, status);
4372 hdc = CreateCompatibleDC(0);
4373 status = GdipCreateFromHDC(hdc, &graphics);
4374 expect(Ok, status);
4376 status = GdipGetDpiX(graphics, &dpi);
4377 expect(Ok, status);
4379 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4380 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4381 for (font_unit = 3; font_unit <= 6; font_unit++)
4383 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4384 expect(Ok, status);
4386 status = GdipGetFontSize(font, &font_size);
4387 expect(Ok, status);
4388 font_size = units_to_pixels(font_size, font_unit, dpi);
4389 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4391 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4392 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4394 status = GdipSetPageUnit(graphics, gfx_unit);
4395 expect(Ok, status);
4397 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4398 set_rect_empty(&rect);
4399 set_rect_empty(&bounds_1);
4400 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4401 expect(Ok, status);
4402 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4403 set_rect_empty(&rect);
4404 set_rect_empty(&bounds_2);
4405 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4406 expect(Ok, status);
4408 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4409 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4410 /*trace("margin %f pixels\n", margin);*/
4411 expectf_(font_size / 6.0, margin, font_size / 100.0);
4414 GdipDeleteFont(font);
4417 GdipDeleteGraphics(graphics);
4418 DeleteDC(hdc);
4419 GdipDeleteFontFamily(family);
4420 GdipDeleteStringFormat(format);
4423 static void test_alpha_hdc(void)
4425 GpStatus status;
4426 HDC hdc;
4427 HBITMAP hbm, old_hbm;
4428 GpGraphics *graphics;
4429 ULONG *bits;
4430 BITMAPINFO bmi;
4431 GpRectF bounds;
4433 hdc = CreateCompatibleDC(0);
4434 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4435 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4436 bmi.bmiHeader.biHeight = 5;
4437 bmi.bmiHeader.biWidth = 5;
4438 bmi.bmiHeader.biBitCount = 32;
4439 bmi.bmiHeader.biPlanes = 1;
4440 bmi.bmiHeader.biCompression = BI_RGB;
4441 bmi.bmiHeader.biClrUsed = 0;
4443 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4444 ok(hbm != NULL, "CreateDIBSection failed\n");
4446 old_hbm = SelectObject(hdc, hbm);
4448 status = GdipCreateFromHDC(hdc, &graphics);
4449 expect(Ok, status);
4451 status = GdipGetVisibleClipBounds(graphics, &bounds);
4452 expect(Ok, status);
4453 expectf(0.0, bounds.X);
4454 expectf(0.0, bounds.Y);
4455 expectf(5.0, bounds.Width);
4456 expectf(5.0, bounds.Height);
4458 bits[0] = 0xdeadbeef;
4460 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4461 expect(Ok, status);
4463 expect(0xffaaaaaa, bits[0]);
4465 SelectObject(hdc, old_hbm);
4467 bits[0] = 0xdeadbeef;
4469 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4470 expect(Ok, status);
4472 todo_wine expect(0xffbbbbbb, bits[0]);
4474 GdipDeleteGraphics(graphics);
4476 DeleteObject(hbm);
4477 DeleteDC(hdc);
4480 static void test_bitmapfromgraphics(void)
4482 GpStatus stat;
4483 GpGraphics *graphics = NULL;
4484 HDC hdc = GetDC( hwnd );
4485 GpBitmap *bitmap = NULL;
4486 PixelFormat format;
4487 REAL imageres, graphicsres;
4488 UINT width, height;
4490 stat = GdipCreateFromHDC(hdc, &graphics);
4491 expect(Ok, stat);
4493 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
4494 expect(InvalidParameter, stat);
4496 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
4497 expect(InvalidParameter, stat);
4499 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
4500 expect(Ok, stat);
4502 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
4503 expect(Ok, stat);
4504 expect(PixelFormat32bppPARGB, format);
4506 stat = GdipGetDpiX(graphics, &graphicsres);
4507 expect(Ok, stat);
4509 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
4510 expect(Ok, stat);
4511 expectf(graphicsres, imageres);
4513 stat = GdipGetDpiY(graphics, &graphicsres);
4514 expect(Ok, stat);
4516 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
4517 expect(Ok, stat);
4518 expectf(graphicsres, imageres);
4520 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
4521 expect(Ok, stat);
4522 expect(12, width);
4524 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
4525 expect(Ok, stat);
4526 expect(13, height);
4528 GdipDeleteGraphics(graphics);
4529 GdipDisposeImage((GpImage*)bitmap);
4532 static void test_clipping(void)
4534 HDC hdc;
4535 GpStatus status;
4536 GpGraphics *graphics;
4537 GpRegion *region, *region100x100;
4538 GpMatrix *matrix;
4539 GpRectF rect;
4540 GpPointF ptf[4];
4541 GpUnit unit;
4542 HRGN hrgn;
4543 int ret;
4544 RECT rc;
4546 hdc = CreateCompatibleDC(0);
4547 status = GdipCreateFromHDC(hdc, &graphics);
4548 expect(Ok, status);
4550 status = GdipGetPageUnit(graphics, &unit);
4551 expect(Ok, status);
4552 expect(UnitDisplay, unit);
4554 status = GdipCreateRegion(&region);
4555 expect(Ok, status);
4556 status = GdipSetEmpty(region);
4557 expect(Ok, status);
4559 status = GdipCreateRegion(&region100x100);
4560 expect(Ok, status);
4561 status = GdipSetEmpty(region100x100);
4562 expect(Ok, status);
4564 rect.X = rect.Y = 100.0;
4565 rect.Width = rect.Height = 100.0;
4566 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
4567 expect(Ok, status);
4568 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
4569 expect(Ok, status);
4571 status = GdipGetClipBounds(graphics, &rect);
4572 expect(Ok, status);
4573 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4574 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4576 status = GdipSetEmpty(region);
4577 expect(Ok, status);
4578 status = GdipGetClip(graphics, region);
4579 expect(Ok, status);
4580 status = GdipGetRegionBounds(region, graphics, &rect);
4581 expect(Ok, status);
4582 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4583 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4585 ptf[0].X = 100.0;
4586 ptf[0].Y = 100.0;
4587 ptf[1].X = 200.0;
4588 ptf[1].Y = 200.0;
4589 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4590 expect(Ok, status);
4591 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4592 "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);
4594 status = GdipCreateMatrix(&matrix);
4595 expect(Ok, status);
4596 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
4597 expect(Ok, status);
4598 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
4599 expect(Ok, status);
4600 status = GdipSetWorldTransform(graphics, matrix);
4601 expect(Ok, status);
4603 status = GdipGetClipBounds(graphics, &rect);
4604 expect(Ok, status);
4605 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4606 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4608 status = GdipSetEmpty(region);
4609 expect(Ok, status);
4610 status = GdipGetClip(graphics, region);
4611 expect(Ok, status);
4612 status = GdipGetRegionBounds(region, graphics, &rect);
4613 expect(Ok, status);
4614 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4615 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4617 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4618 expect(Ok, status);
4619 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4620 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4622 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4623 expect(Ok, status);
4624 ret = GetRgnBox(hrgn, &rc);
4625 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4626 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4627 "expected 45,20-95,45, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4628 DeleteObject(hrgn);
4630 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4631 expect(Ok, status);
4632 ret = GetRgnBox(hrgn, &rc);
4633 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4634 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4635 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4636 DeleteObject(hrgn);
4638 ptf[0].X = 100.0;
4639 ptf[0].Y = 100.0;
4640 ptf[1].X = 200.0;
4641 ptf[1].Y = 200.0;
4642 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4643 expect(Ok, status);
4644 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4645 "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);
4647 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4648 expect(Ok, status);
4649 ret = GetRgnBox(hrgn, &rc);
4650 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4651 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4652 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4653 DeleteObject(hrgn);
4655 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4656 expect(Ok, status);
4657 ret = GetRgnBox(hrgn, &rc);
4658 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4659 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4660 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4661 DeleteObject(hrgn);
4663 ptf[0].X = 210.0;
4664 ptf[0].Y = 420.0;
4665 ptf[1].X = 410.0;
4666 ptf[1].Y = 820.0;
4667 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4668 expect(Ok, status);
4669 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4670 "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);
4672 status = GdipSetPageScale(graphics, 2.0);
4673 expect(Ok, status);
4675 status = GdipGetClipBounds(graphics, &rect);
4676 expect(Ok, status);
4677 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4678 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4680 status = GdipSetEmpty(region);
4681 expect(Ok, status);
4682 status = GdipGetClip(graphics, region);
4683 expect(Ok, status);
4684 status = GdipGetRegionBounds(region, graphics, &rect);
4685 expect(Ok, status);
4686 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4687 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4689 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4690 expect(Ok, status);
4691 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4692 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4694 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4695 expect(Ok, status);
4696 ret = GetRgnBox(hrgn, &rc);
4697 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4698 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4699 "expected 45,20-95,45, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4700 DeleteObject(hrgn);
4702 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4703 expect(Ok, status);
4704 ret = GetRgnBox(hrgn, &rc);
4705 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4706 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4707 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4708 DeleteObject(hrgn);
4710 ptf[0].X = 100.0;
4711 ptf[0].Y = 100.0;
4712 ptf[1].X = 200.0;
4713 ptf[1].Y = 200.0;
4714 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4715 expect(Ok, status);
4716 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4717 "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);
4719 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4720 expect(Ok, status);
4721 ret = GetRgnBox(hrgn, &rc);
4722 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4723 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4724 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4725 DeleteObject(hrgn);
4727 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4728 expect(Ok, status);
4729 ret = GetRgnBox(hrgn, &rc);
4730 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4731 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4732 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4733 DeleteObject(hrgn);
4735 ptf[0].X = 210.0;
4736 ptf[0].Y = 420.0;
4737 ptf[1].X = 410.0;
4738 ptf[1].Y = 820.0;
4739 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4740 expect(Ok, status);
4741 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4742 "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);
4744 GdipSetPageUnit(graphics, UnitPoint);
4745 expect(Ok, status);
4747 status = GdipGetClipBounds(graphics, &rect);
4748 expect(Ok, status);
4749 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4750 /* rounding under Wine is slightly different */
4751 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4752 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4753 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4755 status = GdipSetEmpty(region);
4756 expect(Ok, status);
4757 status = GdipGetClip(graphics, region);
4758 expect(Ok, status);
4759 status = GdipGetRegionBounds(region, graphics, &rect);
4760 expect(Ok, status);
4761 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4762 /* rounding under Wine is slightly different */
4763 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4764 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4765 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4767 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4768 expect(Ok, status);
4769 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4770 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4772 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4773 expect(Ok, status);
4774 ret = GetRgnBox(hrgn, &rc);
4775 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4776 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
4777 /* rounding under Wine is slightly different */
4778 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
4779 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
4780 "expected 14,5-33,14, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4781 DeleteObject(hrgn);
4783 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4784 expect(Ok, status);
4785 ret = GetRgnBox(hrgn, &rc);
4786 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4787 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
4788 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
4789 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4790 DeleteObject(hrgn);
4792 ptf[0].X = 100.0;
4793 ptf[0].Y = 100.0;
4794 ptf[1].X = 200.0;
4795 ptf[1].Y = 200.0;
4796 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4797 expect(Ok, status);
4798 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
4799 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
4800 "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);
4802 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4803 expect(Ok, status);
4804 ret = GetRgnBox(hrgn, &rc);
4805 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4806 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4807 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4808 DeleteObject(hrgn);
4810 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4811 expect(Ok, status);
4812 ret = GetRgnBox(hrgn, &rc);
4813 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4814 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
4815 /* rounding under Wine is slightly different */
4816 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
4817 "expected 560,1120-1094,2187, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4818 DeleteObject(hrgn);
4820 ptf[0].X = 560.0;
4821 ptf[0].Y = 1120.0;
4822 ptf[1].X = 1094.0;
4823 ptf[1].Y = 2187.0;
4824 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4825 expect(Ok, status);
4826 if (fabs(ptf[0].X - 100.0) < 0.001)
4828 expectf(100.0, ptf[0].X);
4829 expectf(100.0, ptf[0].Y);
4830 expectf(200.125, ptf[1].X);
4831 expectf(200.03125, ptf[1].Y);
4833 else /* before Win7 */
4835 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
4836 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
4837 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
4838 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
4841 status = GdipTransformRegion(region100x100, matrix);
4842 expect(Ok, status);
4844 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4845 expect(Ok, status);
4846 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
4847 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4849 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4850 expect(Ok, status);
4851 ret = GetRgnBox(hrgn, &rc);
4852 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4853 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4854 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4855 DeleteObject(hrgn);
4857 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4858 expect(Ok, status);
4859 ret = GetRgnBox(hrgn, &rc);
4860 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4861 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
4862 /* rounding under Wine is slightly different */
4863 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
4864 "expected 1147,4534-2214,8800, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4865 DeleteObject(hrgn);
4867 ptf[0].X = 1147.0;
4868 ptf[0].Y = 4534.0;
4869 ptf[1].X = 2214.0;
4870 ptf[1].Y = 8800.0;
4871 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4872 expect(Ok, status);
4873 if (fabs(ptf[0].X - 210.0625) < 0.001)
4875 expectf(210.0625, ptf[0].X);
4876 expectf(420.0625, ptf[0].Y);
4877 expectf(410.125, ptf[1].X);
4878 expectf(820.0, ptf[1].Y);
4880 else /* before Win7 */
4882 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
4883 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
4884 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
4885 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
4888 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
4889 expect(Ok, status);
4890 status = GdipSetWorldTransform(graphics, matrix);
4891 expect(Ok, status);
4893 status = GdipGetClipBounds(graphics, &rect);
4894 expect(Ok, status);
4895 expectf_(20.612978, rect.X, 1.0);
4896 expectf_(-6.256012, rect.Y, 1.5);
4897 expectf_(25.612978, rect.Width, 1.0);
4898 expectf_(12.806489, rect.Height, 1.0);
4900 status = GdipSetEmpty(region);
4901 expect(Ok, status);
4902 status = GdipGetClip(graphics, region);
4903 expect(Ok, status);
4904 status = GdipGetRegionBounds(region, graphics, &rect);
4905 expect(Ok, status);
4906 /* rounding under Wine is slightly different */
4907 expectf_(20.612978, rect.X, 1.0);
4908 expectf_(-6.256012, rect.Y, 1.5);
4909 expectf_(25.612978, rect.Width, 1.0);
4910 expectf_(12.806489, rect.Height, 1.0);
4912 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4913 expect(Ok, status);
4914 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
4915 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4917 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4918 expect(Ok, status);
4919 ret = GetRgnBox(hrgn, &rc);
4920 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
4921 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
4922 /* rounding under Wine is slightly different */
4923 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
4924 "expected (22,-6)-(46,7), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4925 DeleteObject(hrgn);
4927 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4928 expect(Ok, status);
4929 ret = GetRgnBox(hrgn, &rc);
4930 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4931 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4932 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4933 DeleteObject(hrgn);
4935 ptf[0].X = 100.0;
4936 ptf[0].Y = 100.0;
4937 ptf[1].X = 200.0;
4938 ptf[1].Y = 200.0;
4939 ptf[2].X = 200.0;
4940 ptf[2].Y = 100.0;
4941 ptf[3].X = 100.0;
4942 ptf[3].Y = 200.0;
4943 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
4944 expect(Ok, status);
4945 expectf(20.612978, ptf[0].X);
4946 expectf(-1.568512, ptf[0].Y);
4947 expectf(46.225956, ptf[1].X);
4948 expectf(1.862977, ptf[1].Y);
4949 expectf(36.850956, ptf[2].X);
4950 expectf(-6.256012, ptf[2].Y);
4951 expectf(29.987980, ptf[3].X);
4952 expectf(6.550478, ptf[3].Y);
4954 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4955 expect(Ok, status);
4956 ret = GetRgnBox(hrgn, &rc);
4957 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4958 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4959 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4960 DeleteObject(hrgn);
4962 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4963 expect(Ok, status);
4964 ret = GetRgnBox(hrgn, &rc);
4965 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
4966 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
4967 /* rounding under Wine is slightly different */
4968 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
4969 "expected (-3406,4500)-(-350,8728), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4970 DeleteObject(hrgn);
4972 ptf[0].X = -3406.0;
4973 ptf[0].Y = 4500.0;
4974 ptf[1].X = -350.0;
4975 ptf[1].Y = 8728.0;
4976 ptf[2].X = -350.0;
4977 ptf[2].Y = 4500.0;
4978 ptf[3].X = -3406.0;
4979 ptf[3].Y = 8728.0;
4980 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
4981 expect(Ok, status);
4982 expectf(-136.190491, ptf[0].X);
4983 expectf(520.010742, ptf[0].Y);
4984 expectf(756.417175, ptf[1].X);
4985 expectf(720.031616, ptf[1].Y);
4986 expectf(360.042114, ptf[2].X);
4987 expectf(376.760742, ptf[2].Y);
4988 expectf(260.184570, ptf[3].X);
4989 expectf(863.281616, ptf[3].Y);
4991 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
4992 expect(Ok, status);
4993 status = GdipSetWorldTransform(graphics, matrix);
4994 expect(Ok, status);
4996 status = GdipGetClipBounds(graphics, &rect);
4997 expect(Ok, status);
4998 expectf_(-28.100956, rect.X, 1.0);
4999 expectf_(7.806488, rect.Y, 1.5);
5000 expectf_(25.612978, rect.Width, 1.0);
5001 expectf_(12.806489, rect.Height, 1.0);
5003 status = GdipSetEmpty(region);
5004 expect(Ok, status);
5005 status = GdipGetClip(graphics, region);
5006 expect(Ok, status);
5007 status = GdipGetRegionBounds(region, graphics, &rect);
5008 expect(Ok, status);
5009 /* rounding under Wine is slightly different */
5010 expectf_(-28.100956, rect.X, 1.0);
5011 expectf_(7.806488, rect.Y, 1.5);
5012 expectf_(25.612978, rect.Width, 1.0);
5013 expectf_(12.806489, rect.Height, 1.0);
5015 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5016 expect(Ok, status);
5017 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5018 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5020 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5021 expect(Ok, status);
5022 ret = GetRgnBox(hrgn, &rc);
5023 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5024 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5025 /* rounding under Wine is slightly different */
5026 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5027 "expected (-27,8)-(-2,21), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5028 DeleteObject(hrgn);
5030 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5031 expect(Ok, status);
5032 ret = GetRgnBox(hrgn, &rc);
5033 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5034 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5035 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5036 DeleteObject(hrgn);
5038 ptf[0].X = 100.0;
5039 ptf[0].Y = 100.0;
5040 ptf[1].X = 200.0;
5041 ptf[1].Y = 200.0;
5042 ptf[2].X = 200.0;
5043 ptf[2].Y = 100.0;
5044 ptf[3].X = 100.0;
5045 ptf[3].Y = 200.0;
5046 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5047 expect(Ok, status);
5048 expectf(-11.862979, ptf[0].X);
5049 expectf(7.806488, ptf[0].Y);
5050 expectf(-18.725958, ptf[1].X);
5051 expectf(20.612976, ptf[1].Y);
5052 expectf(-2.487981, ptf[2].X);
5053 expectf(15.925477, ptf[2].Y);
5054 expectf(-28.100956, ptf[3].X);
5055 expectf(12.493987, ptf[3].Y);
5057 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5058 expect(Ok, status);
5059 ret = GetRgnBox(hrgn, &rc);
5060 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5061 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5062 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5063 DeleteObject(hrgn);
5065 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5066 expect(Ok, status);
5067 ret = GetRgnBox(hrgn, &rc);
5068 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5069 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5070 /* rounding under Wine is slightly different */
5071 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5072 "expected (4500,351)-(8728,3407), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5073 DeleteObject(hrgn);
5075 ptf[0].X = -3406.0;
5076 ptf[0].Y = 4500.0;
5077 ptf[1].X = -350.0;
5078 ptf[1].Y = 8728.0;
5079 ptf[2].X = -350.0;
5080 ptf[2].Y = 4500.0;
5081 ptf[3].X = -3406.0;
5082 ptf[3].Y = 8728.0;
5083 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5084 expect(Ok, status);
5085 expectf(-1055.021484, ptf[0].X);
5086 expectf(-70.595329, ptf[0].Y);
5087 expectf(-1455.063232, ptf[1].X);
5088 expectf(375.708435, ptf[1].Y);
5089 expectf(-768.521484, ptf[2].X);
5090 expectf(177.520981, ptf[2].Y);
5091 expectf(-1741.563110, ptf[3].X);
5092 expectf(127.592125, ptf[3].Y);
5094 GdipDeleteMatrix(matrix);
5095 GdipDeleteRegion(region);
5096 GdipDeleteRegion(region100x100);
5097 GdipDeleteGraphics(graphics);
5098 DeleteDC(hdc);
5101 static void test_clipping_2(void)
5104 HDC hdc;
5105 GpStatus status;
5106 GpGraphics *graphics;
5107 GpRegion *region;
5108 GpMatrix *matrix;
5109 GpRectF rect;
5110 GpPointF ptf[4];
5111 GpUnit unit;
5112 HRGN hrgn;
5113 int ret;
5114 RECT rc;
5116 hdc = CreateCompatibleDC(0);
5117 status = GdipCreateFromHDC(hdc, &graphics);
5118 expect(Ok, status);
5120 status = GdipGetPageUnit(graphics, &unit);
5121 expect(Ok, status);
5122 expect(UnitDisplay, unit);
5124 GdipSetPageUnit(graphics, UnitInch);
5126 status = GdipCreateRegion(&region);
5127 expect(Ok, status);
5128 status = GdipSetEmpty(region);
5129 expect(Ok, status);
5130 rect.X = rect.Y = 100.0;
5131 rect.Width = rect.Height = 100.0;
5132 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5133 expect(Ok, status);
5134 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5135 expect(Ok, status);
5137 status = GdipGetClip(graphics, region);
5138 expect(Ok, status);
5139 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5140 expect(Ok, status);
5141 ret = GetRgnBox(hrgn, &rc);
5142 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5143 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5144 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5145 DeleteObject(hrgn);
5146 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5147 expect(Ok, status);
5148 ret = GetRgnBox(hrgn, &rc);
5149 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5150 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5151 "expected 9600,9600-19200,19200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5152 DeleteObject(hrgn);
5154 ptf[0].X = 9600.0;
5155 ptf[0].Y = 9600.0;
5156 ptf[1].X = 19200.0;
5157 ptf[1].Y = 19200.0;
5158 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5159 expect(Ok, status);
5160 expectf(100.0, ptf[0].X);
5161 expectf(100.0, ptf[0].Y);
5162 expectf(200.0, ptf[1].X);
5163 expectf(200.0, ptf[1].X);
5165 GdipSetPageUnit(graphics, UnitPoint);
5167 status = GdipGetClip(graphics, region);
5168 expect(Ok, status);
5169 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5170 expect(Ok, status);
5171 ret = GetRgnBox(hrgn, &rc);
5172 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5173 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5174 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5175 "expected 7200,7200-14400,14400, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5176 DeleteObject(hrgn);
5177 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5178 expect(Ok, status);
5179 ret = GetRgnBox(hrgn, &rc);
5180 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5181 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5182 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5183 "expected 9600,9600-19200,19200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5184 DeleteObject(hrgn);
5186 ptf[0].X = 9600.0;
5187 ptf[0].Y = 9600.0;
5188 ptf[1].X = 19200.0;
5189 ptf[1].Y = 19200.0;
5190 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5191 expect(Ok, status);
5192 if (fabs(ptf[0].X - 7200.0) < 0.001)
5193 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5194 "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);
5195 else /* before Win7 */
5197 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5198 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5199 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5200 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5203 GdipDeleteRegion(region);
5205 GdipSetPageUnit(graphics, UnitPixel);
5207 status = GdipCreateRegion(&region);
5208 expect(Ok, status);
5209 status = GdipSetEmpty(region);
5210 expect(Ok, status);
5211 rect.X = rect.Y = 100.0;
5212 rect.Width = rect.Height = 100.0;
5213 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5214 expect(Ok, status);
5215 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5216 expect(Ok, status);
5218 status = GdipGetClip(graphics, region);
5219 expect(Ok, status);
5220 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5221 expect(Ok, status);
5222 ret = GetRgnBox(hrgn, &rc);
5223 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5224 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5225 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5226 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5227 DeleteObject(hrgn);
5228 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5229 expect(Ok, status);
5230 ret = GetRgnBox(hrgn, &rc);
5231 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5232 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5233 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5234 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5235 DeleteObject(hrgn);
5237 ptf[0].X = 100.0;
5238 ptf[0].Y = 100.0;
5239 ptf[1].X = 200.0;
5240 ptf[1].Y = 200.0;
5241 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5242 expect(Ok, status);
5243 if (fabs(ptf[0].X - 100.0) < 0.001)
5244 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5245 "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);
5246 else /* before Win7 */
5248 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5249 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5250 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5251 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5254 GdipSetPageUnit(graphics, UnitPoint);
5256 status = GdipGetClip(graphics, region);
5257 expect(Ok, status);
5258 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5259 expect(Ok, status);
5260 ret = GetRgnBox(hrgn, &rc);
5261 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5262 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5263 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5264 "expected 75,75-150,150, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5265 DeleteObject(hrgn);
5266 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5267 expect(Ok, status);
5268 ret = GetRgnBox(hrgn, &rc);
5269 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5270 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5271 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5272 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5273 DeleteObject(hrgn);
5275 ptf[0].X = 100.0;
5276 ptf[0].Y = 100.0;
5277 ptf[1].X = 200.0;
5278 ptf[1].Y = 200.0;
5279 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5280 expect(Ok, status);
5281 if (fabs(ptf[0].X - 75.0) < 0.001)
5282 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5283 "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);
5284 else /* before Win7 */
5286 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5287 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5288 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5289 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5292 status = GdipCreateMatrix(&matrix);
5293 expect(Ok, status);
5294 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5295 expect(Ok, status);
5296 status = GdipSetWorldTransform(graphics, matrix);
5297 expect(Ok, status);
5298 GdipDeleteMatrix(matrix);
5300 status = GdipGetClip(graphics, region);
5301 expect(Ok, status);
5302 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5303 expect(Ok, status);
5304 ret = GetRgnBox(hrgn, &rc);
5305 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5306 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5307 "expected 65,65-140,140, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5308 DeleteObject(hrgn);
5309 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5310 expect(Ok, status);
5311 ret = GetRgnBox(hrgn, &rc);
5312 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5313 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5314 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5315 DeleteObject(hrgn);
5317 ptf[0].X = 100.0;
5318 ptf[0].Y = 100.0;
5319 ptf[1].X = 200.0;
5320 ptf[1].Y = 200.0;
5321 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5322 expect(Ok, status);
5323 expectf(65.0, ptf[0].X);
5324 expectf(65.0, ptf[0].Y);
5325 expectf(140.0, ptf[1].X);
5326 expectf(140.0, ptf[1].X);
5328 status = GdipCreateMatrix(&matrix);
5329 expect(Ok, status);
5330 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5331 expect(Ok, status);
5332 status = GdipSetWorldTransform(graphics, matrix);
5333 expect(Ok, status);
5334 GdipDeleteMatrix(matrix);
5336 status = GdipGetClip(graphics, region);
5337 expect(Ok, status);
5338 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5339 expect(Ok, status);
5340 ret = GetRgnBox(hrgn, &rc);
5341 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5342 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5343 "expected 300,150-600,300, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5344 DeleteObject(hrgn);
5345 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5346 expect(Ok, status);
5347 ret = GetRgnBox(hrgn, &rc);
5348 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5349 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5350 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5351 DeleteObject(hrgn);
5353 ptf[0].X = 100.0;
5354 ptf[0].Y = 100.0;
5355 ptf[1].X = 200.0;
5356 ptf[1].Y = 200.0;
5357 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5358 expect(Ok, status);
5359 expectf(300.0, ptf[0].X);
5360 expectf(150.0, ptf[0].Y);
5361 expectf(600.0, ptf[1].X);
5362 expectf(300.0, ptf[1].Y);
5364 status = GdipSetPageScale(graphics, 2.0);
5365 expect(Ok, status);
5367 status = GdipGetClip(graphics, region);
5368 expect(Ok, status);
5369 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5370 expect(Ok, status);
5371 ret = GetRgnBox(hrgn, &rc);
5372 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5373 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5374 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5375 "expected 150,75-300,150, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5376 DeleteObject(hrgn);
5377 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5378 expect(Ok, status);
5379 ret = GetRgnBox(hrgn, &rc);
5380 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5381 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5382 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5383 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5384 DeleteObject(hrgn);
5386 ptf[0].X = 100.0;
5387 ptf[0].Y = 100.0;
5388 ptf[1].X = 200.0;
5389 ptf[1].Y = 200.0;
5390 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5391 expect(Ok, status);
5392 if (fabs(ptf[0].X - 150.0) < 0.001)
5394 expectf(150.0, ptf[0].X);
5395 expectf(75.0, ptf[0].Y);
5396 expectf(300.0, ptf[1].X);
5397 expectf(150.0, ptf[1].Y);
5399 else /* before Win7 */
5401 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5402 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5403 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5404 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5407 status = GdipCreateMatrix(&matrix);
5408 expect(Ok, status);
5409 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5410 expect(Ok, status);
5411 status = GdipSetWorldTransform(graphics, matrix);
5412 expect(Ok, status);
5413 GdipDeleteMatrix(matrix);
5415 status = GdipGetClip(graphics, region);
5416 expect(Ok, status);
5417 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5418 expect(Ok, status);
5419 ret = GetRgnBox(hrgn, &rc);
5420 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5421 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5422 /* rounding under Wine is slightly different */
5423 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5424 "expected 54,-26-107,27, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5425 DeleteObject(hrgn);
5426 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5427 expect(Ok, status);
5428 ret = GetRgnBox(hrgn, &rc);
5429 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5430 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5431 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5432 DeleteObject(hrgn);
5434 ptf[0].X = 100.0;
5435 ptf[0].Y = 100.0;
5436 ptf[1].X = 200.0;
5437 ptf[1].Y = 200.0;
5438 ptf[2].X = 200.0;
5439 ptf[2].Y = 100.0;
5440 ptf[3].X = 100.0;
5441 ptf[3].Y = 200.0;
5442 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5443 expect(Ok, status);
5444 expectf(53.033016, ptf[0].X);
5445 expectf(0.0, ptf[0].Y);
5446 expectf(106.066032, ptf[1].X);
5447 expectf(0.0, ptf[1].Y);
5448 expectf(79.549522, ptf[2].X);
5449 expectf(-26.516510, ptf[2].Y);
5450 expectf(79.549522, ptf[3].X);
5451 expectf(26.516508, ptf[3].Y);
5453 status = GdipCreateMatrix(&matrix);
5454 expect(Ok, status);
5455 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5456 expect(Ok, status);
5457 status = GdipSetWorldTransform(graphics, matrix);
5458 expect(Ok, status);
5459 GdipDeleteMatrix(matrix);
5461 status = GdipGetClip(graphics, region);
5462 expect(Ok, status);
5463 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5464 expect(Ok, status);
5465 ret = GetRgnBox(hrgn, &rc);
5466 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5467 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
5468 /* rounding under Wine is slightly different */
5469 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
5470 "expected -26,54-27,107, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5471 DeleteObject(hrgn);
5472 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5473 expect(Ok, status);
5474 ret = GetRgnBox(hrgn, &rc);
5475 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5476 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5477 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5478 DeleteObject(hrgn);
5480 ptf[0].X = 100.0;
5481 ptf[0].Y = 100.0;
5482 ptf[1].X = 200.0;
5483 ptf[1].Y = 200.0;
5484 ptf[2].X = 200.0;
5485 ptf[2].Y = 100.0;
5486 ptf[3].X = 100.0;
5487 ptf[3].Y = 200.0;
5488 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5489 expect(Ok, status);
5490 expectf(0.0, ptf[0].X);
5491 expectf(53.033005, ptf[0].Y);
5492 expectf(0.0, ptf[1].X);
5493 expectf(106.066010, ptf[1].Y);
5494 expectf(26.516491, ptf[2].X);
5495 expectf(79.549507, ptf[2].Y);
5496 expectf(-26.516520, ptf[3].X);
5497 expectf(79.549500, ptf[3].Y);
5499 GdipDeleteRegion(region);
5500 GdipDeleteGraphics(graphics);
5501 DeleteDC(hdc);
5505 static void test_GdipFillRectangles(void)
5507 GpStatus status;
5508 GpGraphics *graphics = NULL;
5509 GpBrush *brush = NULL;
5510 HDC hdc = GetDC( hwnd );
5511 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
5513 ok(hdc != NULL, "Expected HDC to be initialized\n");
5515 status = GdipCreateFromHDC(hdc, &graphics);
5516 expect(Ok, status);
5517 ok(graphics != NULL, "Expected graphics to be initialized\n");
5519 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
5520 expect(Ok, status);
5521 ok(brush != NULL, "Expected brush to be initialized\n");
5523 status = GdipFillRectangles(NULL, brush, rects, 2);
5524 expect(InvalidParameter, status);
5526 status = GdipFillRectangles(graphics, NULL, rects, 2);
5527 expect(InvalidParameter, status);
5529 status = GdipFillRectangles(graphics, brush, NULL, 2);
5530 expect(InvalidParameter, status);
5532 status = GdipFillRectangles(graphics, brush, rects, 0);
5533 expect(InvalidParameter, status);
5535 status = GdipFillRectangles(graphics, brush, rects, -1);
5536 expect(InvalidParameter, status);
5538 status = GdipFillRectangles(graphics, brush, rects, 1);
5539 expect(Ok, status);
5541 status = GdipFillRectangles(graphics, brush, rects, 2);
5542 expect(Ok, status);
5544 GdipDeleteBrush(brush);
5545 GdipDeleteGraphics(graphics);
5547 ReleaseDC(hwnd, hdc);
5550 START_TEST(graphics)
5552 struct GdiplusStartupInput gdiplusStartupInput;
5553 ULONG_PTR gdiplusToken;
5554 WNDCLASSA class;
5556 memset( &class, 0, sizeof(class) );
5557 class.lpszClassName = "gdiplus_test";
5558 class.style = CS_HREDRAW | CS_VREDRAW;
5559 class.lpfnWndProc = DefWindowProcA;
5560 class.hInstance = GetModuleHandleA(0);
5561 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5562 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5563 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
5564 RegisterClassA( &class );
5565 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5566 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
5567 ok(hwnd != NULL, "Expected window to be created\n");
5569 gdiplusStartupInput.GdiplusVersion = 1;
5570 gdiplusStartupInput.DebugEventCallback = NULL;
5571 gdiplusStartupInput.SuppressBackgroundThread = 0;
5572 gdiplusStartupInput.SuppressExternalCodecs = 0;
5574 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
5576 test_clipping();
5577 test_clipping_2();
5578 test_measured_extra_space();
5579 test_measure_string();
5580 test_font_height_scaling();
5581 test_transform();
5582 test_GdipMeasureString();
5583 test_constructor_destructor();
5584 test_save_restore();
5585 test_GdipFillClosedCurve2();
5586 test_GdipFillClosedCurve2I();
5587 test_GdipDrawBezierI();
5588 test_GdipDrawArc();
5589 test_GdipDrawArcI();
5590 test_GdipDrawCurve();
5591 test_GdipDrawCurveI();
5592 test_GdipDrawCurve2();
5593 test_GdipDrawCurve2I();
5594 test_GdipDrawCurve3();
5595 test_GdipDrawCurve3I();
5596 test_GdipDrawLineI();
5597 test_GdipDrawLinesI();
5598 test_GdipDrawImagePointsRect();
5599 test_GdipFillClosedCurve();
5600 test_GdipFillClosedCurveI();
5601 test_GdipDrawString();
5602 test_GdipGetNearestColor();
5603 test_GdipGetVisibleClipBounds();
5604 test_GdipIsVisiblePoint();
5605 test_GdipIsVisibleRect();
5606 test_Get_Release_DC();
5607 test_BeginContainer2();
5608 test_transformpoints();
5609 test_get_set_clip();
5610 test_isempty();
5611 test_clear();
5612 test_textcontrast();
5613 test_fromMemoryBitmap();
5614 test_string_functions();
5615 test_get_set_interpolation();
5616 test_get_set_textrenderinghint();
5617 test_getdc_scaled();
5618 test_alpha_hdc();
5619 test_bitmapfromgraphics();
5620 test_GdipFillRectangles();
5622 GdiplusShutdown(gdiplusToken);
5623 DestroyWindow( hwnd );