gdiplus: Improve GdipFillRectangles parameter validation.
[wine/multimedia.git] / dlls / gdiplus / tests / graphics.c
blob9fb13479ea1e08cd726bd784b0b1b8ff5bbd56d2
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)
31 #define TABLE_LEN (23)
33 static const REAL mm_per_inch = 25.4;
34 static const REAL point_per_inch = 72.0;
35 static HWND hwnd;
37 static void set_rect_empty(RectF *rc)
39 rc->X = 0.0;
40 rc->Y = 0.0;
41 rc->Width = 0.0;
42 rc->Height = 0.0;
45 /* converts a given unit to its value in pixels */
46 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
48 switch (unit)
50 case UnitPixel:
51 case UnitDisplay:
52 return units;
53 case UnitPoint:
54 return units * dpi / point_per_inch;
55 case UnitInch:
56 return units * dpi;
57 case UnitDocument:
58 return units * dpi / 300.0; /* Per MSDN */
59 case UnitMillimeter:
60 return units * dpi / mm_per_inch;
61 default:
62 ok(0, "Unsupported unit: %d\n", unit);
63 return 0;
67 /* converts value in pixels to a given unit */
68 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
70 switch (unit)
72 case UnitPixel:
73 case UnitDisplay:
74 return pixels;
75 case UnitPoint:
76 return pixels * point_per_inch / dpi;
77 case UnitInch:
78 return pixels / dpi;
79 case UnitDocument:
80 return pixels * 300.0 / dpi;
81 case UnitMillimeter:
82 return pixels * mm_per_inch / dpi;
83 default:
84 ok(0, "Unsupported unit: %d\n", unit);
85 return 0;
89 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
91 REAL pixels = units_to_pixels(1.0, from, dpi);
92 return pixels_to_units(pixels, to, dpi);
95 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale)
97 GpStatus status;
98 union
100 GpBitmap *bitmap;
101 GpImage *image;
102 } u;
103 GpGraphics *graphics = NULL;
104 REAL res;
106 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
107 expect(Ok, status);
109 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
110 expect(Ok, status);
111 status = GdipGetImageHorizontalResolution(u.image, &res);
112 expect(Ok, status);
113 expectf(res_x, res);
114 status = GdipGetImageVerticalResolution(u.image, &res);
115 expect(Ok, status);
116 expectf(res_y, res);
118 status = GdipGetImageGraphicsContext(u.image, &graphics);
119 expect(Ok, status);
120 /* image is intentionally leaked to make sure that there is no
121 side effects after its destruction.
122 status = GdipDisposeImage(u.image);
123 expect(Ok, status);
126 status = GdipGetDpiX(graphics, &res);
127 expect(Ok, status);
128 expectf(res_x, res);
129 status = GdipGetDpiY(graphics, &res);
130 expect(Ok, status);
131 expectf(res_y, res);
133 status = GdipSetPageUnit(graphics, unit);
134 expect(Ok, status);
135 status = GdipSetPageScale(graphics, scale);
136 expect(Ok, status);
138 return graphics;
141 static void test_constructor_destructor(void)
143 GpStatus stat;
144 GpGraphics *graphics = NULL;
145 HDC hdc = GetDC( hwnd );
147 stat = GdipCreateFromHDC(NULL, &graphics);
148 expect(OutOfMemory, stat);
149 stat = GdipDeleteGraphics(graphics);
150 expect(InvalidParameter, stat);
152 stat = GdipCreateFromHDC(hdc, &graphics);
153 expect(Ok, stat);
154 stat = GdipDeleteGraphics(graphics);
155 expect(Ok, stat);
157 stat = GdipCreateFromHWND(NULL, &graphics);
158 expect(Ok, stat);
159 stat = GdipDeleteGraphics(graphics);
160 expect(Ok, stat);
162 stat = GdipCreateFromHWNDICM(NULL, &graphics);
163 expect(Ok, stat);
164 stat = GdipDeleteGraphics(graphics);
165 expect(Ok, stat);
167 stat = GdipDeleteGraphics(NULL);
168 expect(InvalidParameter, stat);
169 ReleaseDC(hwnd, hdc);
172 typedef struct node{
173 GraphicsState data;
174 struct node * next;
175 } node;
177 /* Linked list prepend function. */
178 static void log_state(GraphicsState data, node ** log)
180 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
182 new_entry->data = data;
183 new_entry->next = *log;
184 *log = new_entry;
187 /* Checks if there are duplicates in the list, and frees it. */
188 static void check_no_duplicates(node * log)
190 INT dups = 0;
191 node * temp = NULL;
192 node * temp2 = NULL;
193 node * orig = log;
195 if(!log)
196 goto end;
199 temp = log;
200 while((temp = temp->next)){
201 if(log->data == temp->data){
202 dups++;
203 break;
205 if(dups > 0)
206 break;
208 }while((log = log->next));
210 temp = orig;
212 temp2 = temp->next;
213 HeapFree(GetProcessHeap(), 0, temp);
214 temp = temp2;
215 }while(temp);
217 end:
218 expect(0, dups);
221 static void test_save_restore(void)
223 GpStatus stat;
224 GraphicsState state_a, state_b, state_c;
225 InterpolationMode mode;
226 GpGraphics *graphics1, *graphics2;
227 node * state_log = NULL;
228 HDC hdc = GetDC( hwnd );
229 state_a = state_b = state_c = 0xdeadbeef;
231 /* Invalid saving. */
232 GdipCreateFromHDC(hdc, &graphics1);
233 stat = GdipSaveGraphics(graphics1, NULL);
234 expect(InvalidParameter, stat);
235 stat = GdipSaveGraphics(NULL, &state_a);
236 expect(InvalidParameter, stat);
237 GdipDeleteGraphics(graphics1);
239 log_state(state_a, &state_log);
241 /* Basic save/restore. */
242 GdipCreateFromHDC(hdc, &graphics1);
243 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
244 stat = GdipSaveGraphics(graphics1, &state_a);
245 expect(Ok, stat);
246 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
247 stat = GdipRestoreGraphics(graphics1, state_a);
248 expect(Ok, stat);
249 GdipGetInterpolationMode(graphics1, &mode);
250 expect(InterpolationModeBilinear, mode);
251 GdipDeleteGraphics(graphics1);
253 log_state(state_a, &state_log);
255 /* Restoring garbage doesn't affect saves. */
256 GdipCreateFromHDC(hdc, &graphics1);
257 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
258 GdipSaveGraphics(graphics1, &state_a);
259 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
260 GdipSaveGraphics(graphics1, &state_b);
261 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
262 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
263 expect(Ok, stat);
264 GdipRestoreGraphics(graphics1, state_b);
265 GdipGetInterpolationMode(graphics1, &mode);
266 expect(InterpolationModeBicubic, mode);
267 GdipRestoreGraphics(graphics1, state_a);
268 GdipGetInterpolationMode(graphics1, &mode);
269 expect(InterpolationModeBilinear, mode);
270 GdipDeleteGraphics(graphics1);
272 log_state(state_a, &state_log);
273 log_state(state_b, &state_log);
275 /* Restoring older state invalidates newer saves (but not older saves). */
276 GdipCreateFromHDC(hdc, &graphics1);
277 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
278 GdipSaveGraphics(graphics1, &state_a);
279 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
280 GdipSaveGraphics(graphics1, &state_b);
281 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
282 GdipSaveGraphics(graphics1, &state_c);
283 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
284 GdipRestoreGraphics(graphics1, state_b);
285 GdipGetInterpolationMode(graphics1, &mode);
286 expect(InterpolationModeBicubic, mode);
287 GdipRestoreGraphics(graphics1, state_c);
288 GdipGetInterpolationMode(graphics1, &mode);
289 expect(InterpolationModeBicubic, mode);
290 GdipRestoreGraphics(graphics1, state_a);
291 GdipGetInterpolationMode(graphics1, &mode);
292 expect(InterpolationModeBilinear, mode);
293 GdipDeleteGraphics(graphics1);
295 log_state(state_a, &state_log);
296 log_state(state_b, &state_log);
297 log_state(state_c, &state_log);
299 /* Restoring older save from one graphics object does not invalidate
300 * newer save from other graphics object. */
301 GdipCreateFromHDC(hdc, &graphics1);
302 GdipCreateFromHDC(hdc, &graphics2);
303 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
304 GdipSaveGraphics(graphics1, &state_a);
305 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
306 GdipSaveGraphics(graphics2, &state_b);
307 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
308 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
309 GdipRestoreGraphics(graphics1, state_a);
310 GdipGetInterpolationMode(graphics1, &mode);
311 expect(InterpolationModeBilinear, mode);
312 GdipRestoreGraphics(graphics2, state_b);
313 GdipGetInterpolationMode(graphics2, &mode);
314 expect(InterpolationModeBicubic, mode);
315 GdipDeleteGraphics(graphics1);
316 GdipDeleteGraphics(graphics2);
318 /* You can't restore a state to a graphics object that didn't save it. */
319 GdipCreateFromHDC(hdc, &graphics1);
320 GdipCreateFromHDC(hdc, &graphics2);
321 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
322 GdipSaveGraphics(graphics1, &state_a);
323 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
324 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
325 GdipRestoreGraphics(graphics2, state_a);
326 GdipGetInterpolationMode(graphics2, &mode);
327 expect(InterpolationModeNearestNeighbor, mode);
328 GdipDeleteGraphics(graphics1);
329 GdipDeleteGraphics(graphics2);
331 log_state(state_a, &state_log);
333 /* The same state value should never be returned twice. */
334 todo_wine
335 check_no_duplicates(state_log);
337 ReleaseDC(hwnd, hdc);
340 static void test_GdipFillClosedCurve2(void)
342 GpStatus status;
343 GpGraphics *graphics = NULL;
344 GpSolidFill *brush = NULL;
345 HDC hdc = GetDC( hwnd );
346 GpPointF points[3];
348 points[0].X = 0;
349 points[0].Y = 0;
351 points[1].X = 40;
352 points[1].Y = 20;
354 points[2].X = 10;
355 points[2].Y = 40;
357 /* make a graphics object and brush object */
358 ok(hdc != NULL, "Expected HDC to be initialized\n");
360 status = GdipCreateFromHDC(hdc, &graphics);
361 expect(Ok, status);
362 ok(graphics != NULL, "Expected graphics to be initialized\n");
364 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
366 /* InvalidParameter cases: null graphics, null brush, null points */
367 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
368 expect(InvalidParameter, status);
370 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
371 expect(InvalidParameter, status);
373 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
374 expect(InvalidParameter, status);
376 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
377 expect(InvalidParameter, status);
379 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
380 expect(InvalidParameter, status);
382 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
383 expect(InvalidParameter, status);
385 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
386 expect(InvalidParameter, status);
388 /* InvalidParameter cases: invalid count */
389 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
390 expect(InvalidParameter, status);
392 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
393 expect(InvalidParameter, status);
395 /* Valid test cases */
396 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
397 expect(Ok, status);
399 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
400 expect(Ok, status);
402 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
403 expect(Ok, status);
405 GdipDeleteGraphics(graphics);
406 GdipDeleteBrush((GpBrush*)brush);
408 ReleaseDC(hwnd, hdc);
411 static void test_GdipFillClosedCurve2I(void)
413 GpStatus status;
414 GpGraphics *graphics = NULL;
415 GpSolidFill *brush = NULL;
416 HDC hdc = GetDC( hwnd );
417 GpPoint points[3];
419 points[0].X = 0;
420 points[0].Y = 0;
422 points[1].X = 40;
423 points[1].Y = 20;
425 points[2].X = 10;
426 points[2].Y = 40;
428 /* make a graphics object and brush object */
429 ok(hdc != NULL, "Expected HDC to be initialized\n");
431 status = GdipCreateFromHDC(hdc, &graphics);
432 expect(Ok, status);
433 ok(graphics != NULL, "Expected graphics to be initialized\n");
435 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
437 /* InvalidParameter cases: null graphics, null brush */
438 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
439 when points == NULL, so don't test this condition */
440 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
441 expect(InvalidParameter, status);
443 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
444 expect(InvalidParameter, status);
446 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
447 expect(InvalidParameter, status);
449 /* InvalidParameter cases: invalid count */
450 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
451 expect(InvalidParameter, status);
453 /* OutOfMemory cases: large (unsigned) int */
454 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
455 expect(OutOfMemory, status);
457 /* Valid test cases */
458 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
459 expect(Ok, status);
461 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
462 expect(Ok, status);
464 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
465 expect(Ok, status);
467 GdipDeleteGraphics(graphics);
468 GdipDeleteBrush((GpBrush*)brush);
470 ReleaseDC(hwnd, hdc);
473 static void test_GdipDrawArc(void)
475 GpStatus status;
476 GpGraphics *graphics = NULL;
477 GpPen *pen = NULL;
478 HDC hdc = GetDC( hwnd );
480 /* make a graphics object and pen object */
481 ok(hdc != NULL, "Expected HDC to be initialized\n");
483 status = GdipCreateFromHDC(hdc, &graphics);
484 expect(Ok, status);
485 ok(graphics != NULL, "Expected graphics to be initialized\n");
487 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
488 expect(Ok, status);
489 ok(pen != NULL, "Expected pen to be initialized\n");
491 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
492 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
493 expect(InvalidParameter, status);
495 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
496 expect(InvalidParameter, status);
498 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
499 expect(InvalidParameter, status);
501 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
502 expect(InvalidParameter, status);
504 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
505 expect(InvalidParameter, status);
507 /* successful case */
508 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
509 expect(Ok, status);
511 GdipDeletePen(pen);
512 GdipDeleteGraphics(graphics);
514 ReleaseDC(hwnd, hdc);
517 static void test_GdipDrawArcI(void)
519 GpStatus status;
520 GpGraphics *graphics = NULL;
521 GpPen *pen = NULL;
522 HDC hdc = GetDC( hwnd );
524 /* make a graphics object and pen object */
525 ok(hdc != NULL, "Expected HDC to be initialized\n");
527 status = GdipCreateFromHDC(hdc, &graphics);
528 expect(Ok, status);
529 ok(graphics != NULL, "Expected graphics to be initialized\n");
531 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
532 expect(Ok, status);
533 ok(pen != NULL, "Expected pen to be initialized\n");
535 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
536 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
537 expect(InvalidParameter, status);
539 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
540 expect(InvalidParameter, status);
542 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
543 expect(InvalidParameter, status);
545 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
546 expect(InvalidParameter, status);
548 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
549 expect(InvalidParameter, status);
551 /* successful case */
552 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
553 expect(Ok, status);
555 GdipDeletePen(pen);
556 GdipDeleteGraphics(graphics);
558 ReleaseDC(hwnd, hdc);
561 static void test_BeginContainer2(void)
563 GpMatrix *transform;
564 GpRectF clip;
565 REAL defClip[] = {5, 10, 15, 20};
566 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
567 GraphicsContainer cont1, cont2, cont3, cont4;
568 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
569 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
570 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
571 REAL scale, defScale = 17;
572 GpUnit unit, defUnit = UnitPixel;
573 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
574 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
575 UINT contrast, defContrast = 5;
576 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
578 GpStatus status;
579 GpGraphics *graphics = NULL;
580 HDC hdc = GetDC( hwnd );
582 ok(hdc != NULL, "Expected HDC to be initialized\n");
584 status = GdipCreateFromHDC(hdc, &graphics);
585 expect(Ok, status);
586 ok(graphics != NULL, "Expected graphics to be initialized\n");
588 /* null graphics, null container */
589 status = GdipBeginContainer2(NULL, &cont1);
590 expect(InvalidParameter, status);
592 status = GdipBeginContainer2(graphics, NULL);
593 expect(InvalidParameter, status);
595 status = GdipEndContainer(NULL, cont1);
596 expect(InvalidParameter, status);
598 /* test all quality-related values */
599 GdipSetCompositingMode(graphics, defCompmode);
600 GdipSetCompositingQuality(graphics, defCompqual);
601 GdipSetInterpolationMode(graphics, defInterp);
602 GdipSetPageScale(graphics, defScale);
603 GdipSetPageUnit(graphics, defUnit);
604 GdipSetPixelOffsetMode(graphics, defOffsetmode);
605 GdipSetSmoothingMode(graphics, defSmoothmode);
606 GdipSetTextContrast(graphics, defContrast);
607 GdipSetTextRenderingHint(graphics, defTexthint);
609 status = GdipBeginContainer2(graphics, &cont1);
610 expect(Ok, status);
612 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
613 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
614 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
615 GdipSetPageScale(graphics, 10);
616 GdipSetPageUnit(graphics, UnitDocument);
617 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
618 GdipSetSmoothingMode(graphics, SmoothingModeNone);
619 GdipSetTextContrast(graphics, 7);
620 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
622 status = GdipEndContainer(graphics, cont1);
623 expect(Ok, status);
625 GdipGetCompositingMode(graphics, &compmode);
626 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
628 GdipGetCompositingQuality(graphics, &compqual);
629 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
631 GdipGetInterpolationMode(graphics, &interp);
632 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
634 GdipGetPageScale(graphics, &scale);
635 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
637 GdipGetPageUnit(graphics, &unit);
638 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
640 GdipGetPixelOffsetMode(graphics, &offsetmode);
641 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
643 GdipGetSmoothingMode(graphics, &smoothmode);
644 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
646 GdipGetTextContrast(graphics, &contrast);
647 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
649 GdipGetTextRenderingHint(graphics, &texthint);
650 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
652 /* test world transform */
653 status = GdipBeginContainer2(graphics, &cont1);
654 expect(Ok, status);
656 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
657 defTrans[4], defTrans[5], &transform);
658 expect(Ok, status);
659 GdipSetWorldTransform(graphics, transform);
660 GdipDeleteMatrix(transform);
661 transform = NULL;
663 status = GdipBeginContainer2(graphics, &cont2);
664 expect(Ok, status);
666 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
667 expect(Ok, status);
668 GdipSetWorldTransform(graphics, transform);
669 GdipDeleteMatrix(transform);
670 transform = NULL;
672 status = GdipEndContainer(graphics, cont2);
673 expect(Ok, status);
675 status = GdipCreateMatrix(&transform);
676 expect(Ok, status);
677 GdipGetWorldTransform(graphics, transform);
678 GdipGetMatrixElements(transform, elems);
679 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
680 fabs(defTrans[1] - elems[1]) < 0.0001 &&
681 fabs(defTrans[2] - elems[2]) < 0.0001 &&
682 fabs(defTrans[3] - elems[3]) < 0.0001 &&
683 fabs(defTrans[4] - elems[4]) < 0.0001 &&
684 fabs(defTrans[5] - elems[5]) < 0.0001,
685 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
686 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
687 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
688 GdipDeleteMatrix(transform);
689 transform = NULL;
691 status = GdipEndContainer(graphics, cont1);
692 expect(Ok, status);
694 /* test clipping */
695 status = GdipBeginContainer2(graphics, &cont1);
696 expect(Ok, status);
698 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
700 status = GdipBeginContainer2(graphics, &cont2);
701 expect(Ok, status);
703 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
705 status = GdipEndContainer(graphics, cont2);
706 expect(Ok, status);
708 status = GdipGetClipBounds(graphics, &clip);
709 expect(Ok, status);
711 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
712 fabs(defClip[1] - clip.Y) < 0.0001 &&
713 fabs(defClip[2] - clip.Width) < 0.0001 &&
714 fabs(defClip[3] - clip.Height) < 0.0001,
715 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
716 defClip[0], defClip[1], defClip[2], defClip[3],
717 clip.X, clip.Y, clip.Width, clip.Height);
719 status = GdipEndContainer(graphics, cont1);
720 expect(Ok, status);
722 /* nesting */
723 status = GdipBeginContainer2(graphics, &cont1);
724 expect(Ok, status);
726 status = GdipBeginContainer2(graphics, &cont2);
727 expect(Ok, status);
729 status = GdipBeginContainer2(graphics, &cont3);
730 expect(Ok, status);
732 status = GdipEndContainer(graphics, cont3);
733 expect(Ok, status);
735 status = GdipBeginContainer2(graphics, &cont4);
736 expect(Ok, status);
738 status = GdipEndContainer(graphics, cont4);
739 expect(Ok, status);
741 /* skip cont2 */
742 status = GdipEndContainer(graphics, cont1);
743 expect(Ok, status);
745 /* end an already-ended container */
746 status = GdipEndContainer(graphics, cont1);
747 expect(Ok, status);
749 GdipDeleteGraphics(graphics);
750 ReleaseDC(hwnd, hdc);
753 static void test_GdipDrawBezierI(void)
755 GpStatus status;
756 GpGraphics *graphics = NULL;
757 GpPen *pen = NULL;
758 HDC hdc = GetDC( hwnd );
760 /* make a graphics object and pen object */
761 ok(hdc != NULL, "Expected HDC to be initialized\n");
763 status = GdipCreateFromHDC(hdc, &graphics);
764 expect(Ok, status);
765 ok(graphics != NULL, "Expected graphics to be initialized\n");
767 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
768 expect(Ok, status);
769 ok(pen != NULL, "Expected pen to be initialized\n");
771 /* InvalidParameter cases: null graphics, null pen */
772 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
773 expect(InvalidParameter, status);
775 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
776 expect(InvalidParameter, status);
778 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
779 expect(InvalidParameter, status);
781 /* successful case */
782 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
783 expect(Ok, status);
785 GdipDeletePen(pen);
786 GdipDeleteGraphics(graphics);
788 ReleaseDC(hwnd, hdc);
791 static void test_GdipDrawCurve3(void)
793 GpStatus status;
794 GpGraphics *graphics = NULL;
795 GpPen *pen = NULL;
796 HDC hdc = GetDC( hwnd );
797 GpPointF points[3];
799 points[0].X = 0;
800 points[0].Y = 0;
802 points[1].X = 40;
803 points[1].Y = 20;
805 points[2].X = 10;
806 points[2].Y = 40;
808 /* make a graphics object and pen object */
809 ok(hdc != NULL, "Expected HDC to be initialized\n");
811 status = GdipCreateFromHDC(hdc, &graphics);
812 expect(Ok, status);
813 ok(graphics != NULL, "Expected graphics to be initialized\n");
815 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
816 expect(Ok, status);
817 ok(pen != NULL, "Expected pen to be initialized\n");
819 /* InvalidParameter cases: null graphics, null pen */
820 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
821 expect(InvalidParameter, status);
823 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
824 expect(InvalidParameter, status);
826 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
827 expect(InvalidParameter, status);
829 /* InvalidParameter cases: invalid count */
830 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
831 expect(InvalidParameter, status);
833 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
834 expect(InvalidParameter, status);
836 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
837 expect(InvalidParameter, status);
839 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
840 expect(InvalidParameter, status);
842 /* InvalidParameter cases: invalid number of segments */
843 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
844 expect(InvalidParameter, status);
846 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
847 expect(InvalidParameter, status);
849 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
850 expect(InvalidParameter, status);
852 /* Valid test cases */
853 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
854 expect(Ok, status);
856 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
857 expect(Ok, status);
859 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
860 expect(Ok, status);
862 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
863 expect(Ok, status);
865 GdipDeletePen(pen);
866 GdipDeleteGraphics(graphics);
868 ReleaseDC(hwnd, hdc);
871 static void test_GdipDrawCurve3I(void)
873 GpStatus status;
874 GpGraphics *graphics = NULL;
875 GpPen *pen = NULL;
876 HDC hdc = GetDC( hwnd );
877 GpPoint points[3];
879 points[0].X = 0;
880 points[0].Y = 0;
882 points[1].X = 40;
883 points[1].Y = 20;
885 points[2].X = 10;
886 points[2].Y = 40;
888 /* make a graphics object and pen object */
889 ok(hdc != NULL, "Expected HDC to be initialized\n");
891 status = GdipCreateFromHDC(hdc, &graphics);
892 expect(Ok, status);
893 ok(graphics != NULL, "Expected graphics to be initialized\n");
895 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
896 expect(Ok, status);
897 ok(pen != NULL, "Expected pen to be initialized\n");
899 /* InvalidParameter cases: null graphics, null pen */
900 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
901 expect(InvalidParameter, status);
903 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
904 expect(InvalidParameter, status);
906 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
907 expect(InvalidParameter, status);
909 /* InvalidParameter cases: invalid count */
910 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
911 expect(OutOfMemory, status);
913 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
914 expect(InvalidParameter, status);
916 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
917 expect(InvalidParameter, status);
919 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
920 expect(InvalidParameter, status);
922 /* InvalidParameter cases: invalid number of segments */
923 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
924 expect(InvalidParameter, status);
926 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
927 expect(InvalidParameter, status);
929 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
930 expect(InvalidParameter, status);
932 /* Valid test cases */
933 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
934 expect(Ok, status);
936 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
937 expect(Ok, status);
939 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
940 expect(Ok, status);
942 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
943 expect(Ok, status);
945 GdipDeletePen(pen);
946 GdipDeleteGraphics(graphics);
948 ReleaseDC(hwnd, hdc);
951 static void test_GdipDrawCurve2(void)
953 GpStatus status;
954 GpGraphics *graphics = NULL;
955 GpPen *pen = NULL;
956 HDC hdc = GetDC( hwnd );
957 GpPointF points[3];
959 points[0].X = 0;
960 points[0].Y = 0;
962 points[1].X = 40;
963 points[1].Y = 20;
965 points[2].X = 10;
966 points[2].Y = 40;
968 /* make a graphics object and pen object */
969 ok(hdc != NULL, "Expected HDC to be initialized\n");
971 status = GdipCreateFromHDC(hdc, &graphics);
972 expect(Ok, status);
973 ok(graphics != NULL, "Expected graphics to be initialized\n");
975 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
976 expect(Ok, status);
977 ok(pen != NULL, "Expected pen to be initialized\n");
979 /* InvalidParameter cases: null graphics, null pen */
980 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
981 expect(InvalidParameter, status);
983 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
984 expect(InvalidParameter, status);
986 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
987 expect(InvalidParameter, status);
989 /* InvalidParameter cases: invalid count */
990 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
991 expect(InvalidParameter, status);
993 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
994 expect(InvalidParameter, status);
996 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
997 expect(InvalidParameter, status);
999 /* Valid test cases */
1000 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1001 expect(Ok, status);
1003 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1004 expect(Ok, status);
1006 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1007 expect(Ok, status);
1009 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1010 expect(Ok, status);
1012 GdipDeletePen(pen);
1013 GdipDeleteGraphics(graphics);
1015 ReleaseDC(hwnd, hdc);
1018 static void test_GdipDrawCurve2I(void)
1020 GpStatus status;
1021 GpGraphics *graphics = NULL;
1022 GpPen *pen = NULL;
1023 HDC hdc = GetDC( hwnd );
1024 GpPoint points[3];
1026 points[0].X = 0;
1027 points[0].Y = 0;
1029 points[1].X = 40;
1030 points[1].Y = 20;
1032 points[2].X = 10;
1033 points[2].Y = 40;
1035 /* make a graphics object and pen object */
1036 ok(hdc != NULL, "Expected HDC to be initialized\n");
1038 status = GdipCreateFromHDC(hdc, &graphics);
1039 expect(Ok, status);
1040 ok(graphics != NULL, "Expected graphics to be initialized\n");
1042 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1043 expect(Ok, status);
1044 ok(pen != NULL, "Expected pen to be initialized\n");
1046 /* InvalidParameter cases: null graphics, null pen */
1047 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1048 expect(InvalidParameter, status);
1050 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1051 expect(InvalidParameter, status);
1053 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1054 expect(InvalidParameter, status);
1056 /* InvalidParameter cases: invalid count */
1057 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1058 expect(OutOfMemory, status);
1060 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1061 expect(InvalidParameter, status);
1063 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1064 expect(InvalidParameter, status);
1066 /* Valid test cases */
1067 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1068 expect(Ok, status);
1070 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1071 expect(Ok, status);
1073 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1074 expect(Ok, status);
1076 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1077 expect(Ok, status);
1079 GdipDeletePen(pen);
1080 GdipDeleteGraphics(graphics);
1082 ReleaseDC(hwnd, hdc);
1085 static void test_GdipDrawCurve(void)
1087 GpStatus status;
1088 GpGraphics *graphics = NULL;
1089 GpPen *pen = NULL;
1090 HDC hdc = GetDC( hwnd );
1091 GpPointF points[3];
1093 points[0].X = 0;
1094 points[0].Y = 0;
1096 points[1].X = 40;
1097 points[1].Y = 20;
1099 points[2].X = 10;
1100 points[2].Y = 40;
1102 /* make a graphics object and pen object */
1103 ok(hdc != NULL, "Expected HDC to be initialized\n");
1105 status = GdipCreateFromHDC(hdc, &graphics);
1106 expect(Ok, status);
1107 ok(graphics != NULL, "Expected graphics to be initialized\n");
1109 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1110 expect(Ok, status);
1111 ok(pen != NULL, "Expected pen to be initialized\n");
1113 /* InvalidParameter cases: null graphics, null pen */
1114 status = GdipDrawCurve(NULL, NULL, points, 3);
1115 expect(InvalidParameter, status);
1117 status = GdipDrawCurve(graphics, NULL, points, 3);
1118 expect(InvalidParameter, status);
1120 status = GdipDrawCurve(NULL, pen, points, 3);
1121 expect(InvalidParameter, status);
1123 /* InvalidParameter cases: invalid count */
1124 status = GdipDrawCurve(graphics, pen, points, -1);
1125 expect(InvalidParameter, status);
1127 status = GdipDrawCurve(graphics, pen, points, 0);
1128 expect(InvalidParameter, status);
1130 status = GdipDrawCurve(graphics, pen, points, 1);
1131 expect(InvalidParameter, status);
1133 /* Valid test cases */
1134 status = GdipDrawCurve(graphics, pen, points, 2);
1135 expect(Ok, status);
1137 status = GdipDrawCurve(graphics, pen, points, 3);
1138 expect(Ok, status);
1140 GdipDeletePen(pen);
1141 GdipDeleteGraphics(graphics);
1143 ReleaseDC(hwnd, hdc);
1146 static void test_GdipDrawCurveI(void)
1148 GpStatus status;
1149 GpGraphics *graphics = NULL;
1150 GpPen *pen = NULL;
1151 HDC hdc = GetDC( hwnd );
1152 GpPoint points[3];
1154 points[0].X = 0;
1155 points[0].Y = 0;
1157 points[1].X = 40;
1158 points[1].Y = 20;
1160 points[2].X = 10;
1161 points[2].Y = 40;
1163 /* make a graphics object and pen object */
1164 ok(hdc != NULL, "Expected HDC to be initialized\n");
1166 status = GdipCreateFromHDC(hdc, &graphics);
1167 expect(Ok, status);
1168 ok(graphics != NULL, "Expected graphics to be initialized\n");
1170 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1171 expect(Ok, status);
1172 ok(pen != NULL, "Expected pen to be initialized\n");
1174 /* InvalidParameter cases: null graphics, null pen */
1175 status = GdipDrawCurveI(NULL, NULL, points, 3);
1176 expect(InvalidParameter, status);
1178 status = GdipDrawCurveI(graphics, NULL, points, 3);
1179 expect(InvalidParameter, status);
1181 status = GdipDrawCurveI(NULL, pen, points, 3);
1182 expect(InvalidParameter, status);
1184 /* InvalidParameter cases: invalid count */
1185 status = GdipDrawCurveI(graphics, pen, points, -1);
1186 expect(OutOfMemory, status);
1188 status = GdipDrawCurveI(graphics, pen, points, 0);
1189 expect(InvalidParameter, status);
1191 status = GdipDrawCurveI(graphics, pen, points, 1);
1192 expect(InvalidParameter, status);
1194 /* Valid test cases */
1195 status = GdipDrawCurveI(graphics, pen, points, 2);
1196 expect(Ok, status);
1198 status = GdipDrawCurveI(graphics, pen, points, 3);
1199 expect(Ok, status);
1201 GdipDeletePen(pen);
1202 GdipDeleteGraphics(graphics);
1204 ReleaseDC(hwnd, hdc);
1207 static void test_GdipDrawLineI(void)
1209 GpStatus status;
1210 GpGraphics *graphics = NULL;
1211 GpPen *pen = NULL;
1212 HDC hdc = GetDC( hwnd );
1214 /* make a graphics object and pen object */
1215 ok(hdc != NULL, "Expected HDC to be initialized\n");
1217 status = GdipCreateFromHDC(hdc, &graphics);
1218 expect(Ok, status);
1219 ok(graphics != NULL, "Expected graphics to be initialized\n");
1221 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1222 expect(Ok, status);
1223 ok(pen != NULL, "Expected pen to be initialized\n");
1225 /* InvalidParameter cases: null graphics, null pen */
1226 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1227 expect(InvalidParameter, status);
1229 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1230 expect(InvalidParameter, status);
1232 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1233 expect(InvalidParameter, status);
1235 /* successful case */
1236 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1237 expect(Ok, status);
1239 GdipDeletePen(pen);
1240 GdipDeleteGraphics(graphics);
1242 ReleaseDC(hwnd, hdc);
1245 static void test_GdipDrawImagePointsRect(void)
1247 GpStatus status;
1248 GpGraphics *graphics = NULL;
1249 GpPointF ptf[4];
1250 GpBitmap *bm = NULL;
1251 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1252 BYTE buff[400];
1253 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1254 HDC hdc = GetDC( hwnd );
1255 if (!hdc)
1256 return;
1258 memset(rbmi, 0, sizeof(rbmi));
1259 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1260 bmi->bmiHeader.biWidth = 10;
1261 bmi->bmiHeader.biHeight = 10;
1262 bmi->bmiHeader.biPlanes = 1;
1263 bmi->bmiHeader.biBitCount = 32;
1264 bmi->bmiHeader.biCompression = BI_RGB;
1265 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1266 expect(Ok, status);
1267 ok(NULL != bm, "Expected bitmap to be initialized\n");
1268 status = GdipCreateFromHDC(hdc, &graphics);
1269 expect(Ok, status);
1270 ptf[0].X = 0;
1271 ptf[0].Y = 0;
1272 ptf[1].X = 10;
1273 ptf[1].Y = 0;
1274 ptf[2].X = 0;
1275 ptf[2].Y = 10;
1276 ptf[3].X = 10;
1277 ptf[3].Y = 10;
1278 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1279 expect(NotImplemented, status);
1280 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1281 expect(InvalidParameter, status);
1282 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1283 expect(Ok, status);
1284 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1285 expect(InvalidParameter, status);
1286 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1287 expect(InvalidParameter, status);
1288 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1289 expect(Ok, status);
1290 memset(ptf, 0, sizeof(ptf));
1291 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1292 expect(Ok, status);
1294 GdipDisposeImage((GpImage*)bm);
1295 GdipDeleteGraphics(graphics);
1296 ReleaseDC(hwnd, hdc);
1299 static void test_GdipDrawLinesI(void)
1301 GpStatus status;
1302 GpGraphics *graphics = NULL;
1303 GpPen *pen = NULL;
1304 GpPoint *ptf = NULL;
1305 HDC hdc = GetDC( hwnd );
1307 /* make a graphics object and pen object */
1308 ok(hdc != NULL, "Expected HDC to be initialized\n");
1310 status = GdipCreateFromHDC(hdc, &graphics);
1311 expect(Ok, status);
1312 ok(graphics != NULL, "Expected graphics to be initialized\n");
1314 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1315 expect(Ok, status);
1316 ok(pen != NULL, "Expected pen to be initialized\n");
1318 /* make some arbitrary valid points*/
1319 ptf = GdipAlloc(2 * sizeof(GpPointF));
1321 ptf[0].X = 1;
1322 ptf[0].Y = 1;
1324 ptf[1].X = 2;
1325 ptf[1].Y = 2;
1327 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1328 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1329 expect(InvalidParameter, status);
1331 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1332 expect(InvalidParameter, status);
1334 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1335 expect(InvalidParameter, status);
1337 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1338 expect(InvalidParameter, status);
1340 /* successful case */
1341 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1342 expect(Ok, status);
1344 GdipFree(ptf);
1345 GdipDeletePen(pen);
1346 GdipDeleteGraphics(graphics);
1348 ReleaseDC(hwnd, hdc);
1351 static void test_GdipFillClosedCurve(void)
1353 GpStatus status;
1354 GpGraphics *graphics = NULL;
1355 GpSolidFill *brush = NULL;
1356 HDC hdc = GetDC( hwnd );
1357 GpPointF points[3];
1359 points[0].X = 0;
1360 points[0].Y = 0;
1362 points[1].X = 40;
1363 points[1].Y = 20;
1365 points[2].X = 10;
1366 points[2].Y = 40;
1368 /* make a graphics object and brush object */
1369 ok(hdc != NULL, "Expected HDC to be initialized\n");
1371 status = GdipCreateFromHDC(hdc, &graphics);
1372 expect(Ok, status);
1373 ok(graphics != NULL, "Expected graphics to be initialized\n");
1375 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1377 /* InvalidParameter cases: null graphics, null brush, null points */
1378 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1379 expect(InvalidParameter, status);
1381 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1382 expect(InvalidParameter, status);
1384 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1385 expect(InvalidParameter, status);
1387 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1388 expect(InvalidParameter, status);
1390 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1391 expect(InvalidParameter, status);
1393 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1394 expect(InvalidParameter, status);
1396 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1397 expect(InvalidParameter, status);
1399 /* InvalidParameter cases: invalid count */
1400 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1401 expect(InvalidParameter, status);
1403 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1404 expect(InvalidParameter, status);
1406 /* Valid test cases */
1407 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1408 expect(Ok, status);
1410 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1411 expect(Ok, status);
1413 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1414 expect(Ok, status);
1416 GdipDeleteGraphics(graphics);
1417 GdipDeleteBrush((GpBrush*)brush);
1419 ReleaseDC(hwnd, hdc);
1422 static void test_GdipFillClosedCurveI(void)
1424 GpStatus status;
1425 GpGraphics *graphics = NULL;
1426 GpSolidFill *brush = NULL;
1427 HDC hdc = GetDC( hwnd );
1428 GpPoint points[3];
1430 points[0].X = 0;
1431 points[0].Y = 0;
1433 points[1].X = 40;
1434 points[1].Y = 20;
1436 points[2].X = 10;
1437 points[2].Y = 40;
1439 /* make a graphics object and brush object */
1440 ok(hdc != NULL, "Expected HDC to be initialized\n");
1442 status = GdipCreateFromHDC(hdc, &graphics);
1443 expect(Ok, status);
1444 ok(graphics != NULL, "Expected graphics to be initialized\n");
1446 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1448 /* InvalidParameter cases: null graphics, null brush */
1449 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1450 when points == NULL, so don't test this condition */
1451 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1452 expect(InvalidParameter, status);
1454 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1455 expect(InvalidParameter, status);
1457 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1458 expect(InvalidParameter, status);
1460 /* InvalidParameter cases: invalid count */
1461 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1462 expect(InvalidParameter, status);
1464 /* OutOfMemory cases: large (unsigned) int */
1465 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1466 expect(OutOfMemory, status);
1468 /* Valid test cases */
1469 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1470 expect(Ok, status);
1472 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1473 expect(Ok, status);
1475 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1476 expect(Ok, status);
1478 GdipDeleteGraphics(graphics);
1479 GdipDeleteBrush((GpBrush*)brush);
1481 ReleaseDC(hwnd, hdc);
1484 static void test_Get_Release_DC(void)
1486 GpStatus status;
1487 GpGraphics *graphics = NULL;
1488 GpPen *pen;
1489 GpSolidFill *brush;
1490 GpPath *path;
1491 HDC hdc = GetDC( hwnd );
1492 HDC retdc;
1493 REAL r;
1494 CompositingQuality quality;
1495 CompositingMode compmode;
1496 InterpolationMode intmode;
1497 GpMatrix *m;
1498 GpRegion *region;
1499 GpUnit unit;
1500 PixelOffsetMode offsetmode;
1501 SmoothingMode smoothmode;
1502 TextRenderingHint texthint;
1503 GpPointF ptf[5];
1504 GpPoint pt[5];
1505 GpRectF rectf[2];
1506 GpRect rect[2];
1507 GpRegion *clip;
1508 INT i;
1509 BOOL res;
1510 ARGB color = 0x00000000;
1511 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1513 pt[0].X = 10;
1514 pt[0].Y = 10;
1515 pt[1].X = 20;
1516 pt[1].Y = 15;
1517 pt[2].X = 40;
1518 pt[2].Y = 80;
1519 pt[3].X = -20;
1520 pt[3].Y = 20;
1521 pt[4].X = 50;
1522 pt[4].Y = 110;
1524 for(i = 0; i < 5;i++){
1525 ptf[i].X = (REAL)pt[i].X;
1526 ptf[i].Y = (REAL)pt[i].Y;
1529 rect[0].X = 0;
1530 rect[0].Y = 0;
1531 rect[0].Width = 50;
1532 rect[0].Height = 70;
1533 rect[1].X = 0;
1534 rect[1].Y = 0;
1535 rect[1].Width = 10;
1536 rect[1].Height = 20;
1538 for(i = 0; i < 2;i++){
1539 rectf[i].X = (REAL)rect[i].X;
1540 rectf[i].Y = (REAL)rect[i].Y;
1541 rectf[i].Height = (REAL)rect[i].Height;
1542 rectf[i].Width = (REAL)rect[i].Width;
1545 status = GdipCreateMatrix(&m);
1546 expect(Ok, status);
1547 GdipCreateRegion(&region);
1548 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1549 GdipCreatePath(FillModeAlternate, &path);
1550 GdipCreateRegion(&clip);
1552 status = GdipCreateFromHDC(hdc, &graphics);
1553 expect(Ok, status);
1554 ok(graphics != NULL, "Expected graphics to be initialized\n");
1555 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1556 expect(Ok, status);
1558 /* NULL arguments */
1559 status = GdipGetDC(NULL, NULL);
1560 expect(InvalidParameter, status);
1561 status = GdipGetDC(graphics, NULL);
1562 expect(InvalidParameter, status);
1563 status = GdipGetDC(NULL, &retdc);
1564 expect(InvalidParameter, status);
1566 status = GdipReleaseDC(NULL, NULL);
1567 expect(InvalidParameter, status);
1568 status = GdipReleaseDC(graphics, NULL);
1569 expect(InvalidParameter, status);
1570 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1571 expect(InvalidParameter, status);
1573 /* Release without Get */
1574 status = GdipReleaseDC(graphics, hdc);
1575 expect(InvalidParameter, status);
1577 retdc = NULL;
1578 status = GdipGetDC(graphics, &retdc);
1579 expect(Ok, status);
1580 ok(retdc == hdc, "Invalid HDC returned\n");
1581 /* call it once more */
1582 status = GdipGetDC(graphics, &retdc);
1583 expect(ObjectBusy, status);
1585 /* try all Graphics calls here */
1586 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1587 expect(ObjectBusy, status);
1588 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1589 expect(ObjectBusy, status);
1590 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1591 expect(ObjectBusy, status);
1592 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1593 expect(ObjectBusy, status);
1594 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1595 expect(ObjectBusy, status);
1596 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1597 expect(ObjectBusy, status);
1598 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1599 expect(ObjectBusy, status);
1600 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1601 expect(ObjectBusy, status);
1602 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1603 expect(ObjectBusy, status);
1604 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1605 expect(ObjectBusy, status);
1606 status = GdipDrawCurve(graphics, pen, ptf, 5);
1607 expect(ObjectBusy, status);
1608 status = GdipDrawCurveI(graphics, pen, pt, 5);
1609 expect(ObjectBusy, status);
1610 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1611 expect(ObjectBusy, status);
1612 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1613 expect(ObjectBusy, status);
1614 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1615 expect(ObjectBusy, status);
1616 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1617 expect(ObjectBusy, status);
1618 /* GdipDrawImage/GdipDrawImageI */
1619 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1620 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1621 /* GdipDrawImageRect/GdipDrawImageRectI */
1622 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1623 expect(ObjectBusy, status);
1624 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1625 expect(ObjectBusy, status);
1626 status = GdipDrawLines(graphics, pen, ptf, 5);
1627 expect(ObjectBusy, status);
1628 status = GdipDrawLinesI(graphics, pen, pt, 5);
1629 expect(ObjectBusy, status);
1630 status = GdipDrawPath(graphics, pen, path);
1631 expect(ObjectBusy, status);
1632 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1633 expect(ObjectBusy, status);
1634 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1635 expect(ObjectBusy, status);
1636 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1637 expect(ObjectBusy, status);
1638 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1639 expect(ObjectBusy, status);
1640 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1641 expect(ObjectBusy, status);
1642 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1643 expect(ObjectBusy, status);
1644 /* GdipDrawString */
1645 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1646 expect(ObjectBusy, status);
1647 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1648 expect(ObjectBusy, status);
1649 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1650 expect(ObjectBusy, status);
1651 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1652 expect(ObjectBusy, status);
1653 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1654 expect(ObjectBusy, status);
1655 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1656 expect(ObjectBusy, status);
1657 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1658 expect(ObjectBusy, status);
1659 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1660 expect(ObjectBusy, status);
1661 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1662 expect(ObjectBusy, status);
1663 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1664 expect(ObjectBusy, status);
1665 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1666 expect(ObjectBusy, status);
1667 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1668 expect(ObjectBusy, status);
1669 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1670 expect(ObjectBusy, status);
1671 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1672 expect(ObjectBusy, status);
1673 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1674 expect(ObjectBusy, status);
1675 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1676 expect(ObjectBusy, status);
1677 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1678 expect(ObjectBusy, status);
1679 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1680 expect(ObjectBusy, status);
1681 status = GdipFlush(graphics, FlushIntentionFlush);
1682 expect(ObjectBusy, status);
1683 status = GdipGetClipBounds(graphics, rectf);
1684 expect(ObjectBusy, status);
1685 status = GdipGetClipBoundsI(graphics, rect);
1686 expect(ObjectBusy, status);
1687 status = GdipGetCompositingMode(graphics, &compmode);
1688 expect(ObjectBusy, status);
1689 status = GdipGetCompositingQuality(graphics, &quality);
1690 expect(ObjectBusy, status);
1691 status = GdipGetInterpolationMode(graphics, &intmode);
1692 expect(ObjectBusy, status);
1693 status = GdipGetNearestColor(graphics, &color);
1694 expect(ObjectBusy, status);
1695 status = GdipGetPageScale(graphics, &r);
1696 expect(ObjectBusy, status);
1697 status = GdipGetPageUnit(graphics, &unit);
1698 expect(ObjectBusy, status);
1699 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1700 expect(ObjectBusy, status);
1701 status = GdipGetSmoothingMode(graphics, &smoothmode);
1702 expect(ObjectBusy, status);
1703 status = GdipGetTextRenderingHint(graphics, &texthint);
1704 expect(ObjectBusy, status);
1705 status = GdipGetWorldTransform(graphics, m);
1706 expect(ObjectBusy, status);
1707 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1708 expect(ObjectBusy, status);
1709 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1710 expect(ObjectBusy, status);
1711 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1712 expect(ObjectBusy, status);
1713 /* GdipMeasureCharacterRanges */
1714 /* GdipMeasureString */
1715 status = GdipResetClip(graphics);
1716 expect(ObjectBusy, status);
1717 status = GdipResetWorldTransform(graphics);
1718 expect(ObjectBusy, status);
1719 /* GdipRestoreGraphics */
1720 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1721 expect(ObjectBusy, status);
1722 /* GdipSaveGraphics */
1723 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1724 expect(ObjectBusy, status);
1725 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1726 expect(ObjectBusy, status);
1727 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1728 expect(ObjectBusy, status);
1729 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1730 expect(ObjectBusy, status);
1731 status = GdipSetPageScale(graphics, 1.0);
1732 expect(ObjectBusy, status);
1733 status = GdipSetPageUnit(graphics, UnitWorld);
1734 expect(ObjectBusy, status);
1735 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1736 expect(ObjectBusy, status);
1737 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1738 expect(ObjectBusy, status);
1739 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1740 expect(ObjectBusy, status);
1741 status = GdipSetWorldTransform(graphics, m);
1742 expect(ObjectBusy, status);
1743 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1744 expect(ObjectBusy, status);
1745 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1746 expect(ObjectBusy, status);
1747 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1748 expect(ObjectBusy, status);
1749 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1750 expect(ObjectBusy, status);
1751 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1752 expect(ObjectBusy, status);
1753 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1754 expect(ObjectBusy, status);
1755 status = GdipTranslateClip(graphics, 0.0, 0.0);
1756 expect(ObjectBusy, status);
1757 status = GdipTranslateClipI(graphics, 0, 0);
1758 expect(ObjectBusy, status);
1759 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1760 expect(ObjectBusy, status);
1761 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1762 expect(ObjectBusy, status);
1763 status = GdipGetDpiX(graphics, &r);
1764 expect(ObjectBusy, status);
1765 status = GdipGetDpiY(graphics, &r);
1766 expect(ObjectBusy, status);
1767 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1768 expect(ObjectBusy, status);
1769 status = GdipGetClip(graphics, region);
1770 expect(ObjectBusy, status);
1771 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1772 expect(ObjectBusy, status);
1774 /* try to delete before release */
1775 status = GdipDeleteGraphics(graphics);
1776 expect(ObjectBusy, status);
1778 status = GdipReleaseDC(graphics, retdc);
1779 expect(Ok, status);
1781 GdipDeletePen(pen);
1782 GdipDeleteGraphics(graphics);
1784 GdipDeleteRegion(clip);
1785 GdipDeletePath(path);
1786 GdipDeleteBrush((GpBrush*)brush);
1787 GdipDeleteRegion(region);
1788 GdipDeleteMatrix(m);
1789 DeleteObject(hrgn);
1791 ReleaseDC(hwnd, hdc);
1794 static void test_transformpoints(void)
1796 GpStatus status;
1797 GpGraphics *graphics = NULL;
1798 HDC hdc = GetDC( hwnd );
1799 GpPointF ptf[2];
1800 GpPoint pt[2];
1802 status = GdipCreateFromHDC(hdc, &graphics);
1803 expect(Ok, status);
1805 /* NULL arguments */
1806 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1807 expect(InvalidParameter, status);
1808 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1809 expect(InvalidParameter, status);
1810 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1811 expect(InvalidParameter, status);
1812 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1813 expect(InvalidParameter, status);
1815 ptf[0].X = 1.0;
1816 ptf[0].Y = 0.0;
1817 ptf[1].X = 0.0;
1818 ptf[1].Y = 1.0;
1819 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1820 expect(Ok, status);
1821 expectf(1.0, ptf[0].X);
1822 expectf(0.0, ptf[0].Y);
1823 expectf(0.0, ptf[1].X);
1824 expectf(1.0, ptf[1].Y);
1826 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1827 expect(Ok, status);
1828 status = GdipSetPageUnit(graphics, UnitPixel);
1829 expect(Ok, status);
1830 status = GdipSetPageScale(graphics, 3.0);
1831 expect(Ok, status);
1833 ptf[0].X = 1.0;
1834 ptf[0].Y = 0.0;
1835 ptf[1].X = 0.0;
1836 ptf[1].Y = 1.0;
1837 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1838 expect(Ok, status);
1839 expectf(18.0, ptf[0].X);
1840 expectf(15.0, ptf[0].Y);
1841 expectf(15.0, ptf[1].X);
1842 expectf(18.0, ptf[1].Y);
1844 ptf[0].X = 1.0;
1845 ptf[0].Y = 0.0;
1846 ptf[1].X = 0.0;
1847 ptf[1].Y = 1.0;
1848 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1849 expect(Ok, status);
1850 expectf(6.0, ptf[0].X);
1851 expectf(5.0, ptf[0].Y);
1852 expectf(5.0, ptf[1].X);
1853 expectf(6.0, ptf[1].Y);
1855 ptf[0].X = 1.0;
1856 ptf[0].Y = 0.0;
1857 ptf[1].X = 0.0;
1858 ptf[1].Y = 1.0;
1859 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1860 expect(Ok, status);
1861 expectf(3.0, ptf[0].X);
1862 expectf(0.0, ptf[0].Y);
1863 expectf(0.0, ptf[1].X);
1864 expectf(3.0, ptf[1].Y);
1866 ptf[0].X = 18.0;
1867 ptf[0].Y = 15.0;
1868 ptf[1].X = 15.0;
1869 ptf[1].Y = 18.0;
1870 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1871 expect(Ok, status);
1872 expectf(1.0, ptf[0].X);
1873 expectf(0.0, ptf[0].Y);
1874 expectf(0.0, ptf[1].X);
1875 expectf(1.0, ptf[1].Y);
1877 ptf[0].X = 6.0;
1878 ptf[0].Y = 5.0;
1879 ptf[1].X = 5.0;
1880 ptf[1].Y = 6.0;
1881 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1882 expect(Ok, status);
1883 expectf(1.0, ptf[0].X);
1884 expectf(0.0, ptf[0].Y);
1885 expectf(0.0, ptf[1].X);
1886 expectf(1.0, ptf[1].Y);
1888 ptf[0].X = 3.0;
1889 ptf[0].Y = 0.0;
1890 ptf[1].X = 0.0;
1891 ptf[1].Y = 3.0;
1892 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1893 expect(Ok, status);
1894 expectf(1.0, ptf[0].X);
1895 expectf(0.0, ptf[0].Y);
1896 expectf(0.0, ptf[1].X);
1897 expectf(1.0, ptf[1].Y);
1899 pt[0].X = 1;
1900 pt[0].Y = 0;
1901 pt[1].X = 0;
1902 pt[1].Y = 1;
1903 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1904 expect(Ok, status);
1905 expect(18, pt[0].X);
1906 expect(15, pt[0].Y);
1907 expect(15, pt[1].X);
1908 expect(18, pt[1].Y);
1910 GdipDeleteGraphics(graphics);
1911 ReleaseDC(hwnd, hdc);
1914 static void test_get_set_clip(void)
1916 GpStatus status;
1917 GpGraphics *graphics = NULL;
1918 HDC hdc = GetDC( hwnd );
1919 GpRegion *clip;
1920 GpRectF rect;
1921 BOOL res;
1923 status = GdipCreateFromHDC(hdc, &graphics);
1924 expect(Ok, status);
1926 rect.X = rect.Y = 0.0;
1927 rect.Height = rect.Width = 100.0;
1929 status = GdipCreateRegionRect(&rect, &clip);
1930 expect(Ok, status);
1932 /* NULL arguments */
1933 status = GdipGetClip(NULL, NULL);
1934 expect(InvalidParameter, status);
1935 status = GdipGetClip(graphics, NULL);
1936 expect(InvalidParameter, status);
1937 status = GdipGetClip(NULL, clip);
1938 expect(InvalidParameter, status);
1940 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1941 expect(InvalidParameter, status);
1942 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1943 expect(InvalidParameter, status);
1945 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1946 expect(InvalidParameter, status);
1947 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1948 expect(InvalidParameter, status);
1950 res = FALSE;
1951 status = GdipGetClip(graphics, clip);
1952 expect(Ok, status);
1953 status = GdipIsInfiniteRegion(clip, graphics, &res);
1954 expect(Ok, status);
1955 expect(TRUE, res);
1957 /* remains infinite after reset */
1958 res = FALSE;
1959 status = GdipResetClip(graphics);
1960 expect(Ok, status);
1961 status = GdipGetClip(graphics, clip);
1962 expect(Ok, status);
1963 status = GdipIsInfiniteRegion(clip, graphics, &res);
1964 expect(Ok, status);
1965 expect(TRUE, res);
1967 /* set to empty and then reset to infinite */
1968 status = GdipSetEmpty(clip);
1969 expect(Ok, status);
1970 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1971 expect(Ok, status);
1973 status = GdipGetClip(graphics, clip);
1974 expect(Ok, status);
1975 res = FALSE;
1976 status = GdipIsEmptyRegion(clip, graphics, &res);
1977 expect(Ok, status);
1978 expect(TRUE, res);
1979 status = GdipResetClip(graphics);
1980 expect(Ok, status);
1981 status = GdipGetClip(graphics, clip);
1982 expect(Ok, status);
1983 res = FALSE;
1984 status = GdipIsInfiniteRegion(clip, graphics, &res);
1985 expect(Ok, status);
1986 expect(TRUE, res);
1988 GdipDeleteRegion(clip);
1990 GdipDeleteGraphics(graphics);
1991 ReleaseDC(hwnd, hdc);
1994 static void test_isempty(void)
1996 GpStatus status;
1997 GpGraphics *graphics = NULL;
1998 HDC hdc = GetDC( hwnd );
1999 GpRegion *clip;
2000 BOOL res;
2002 status = GdipCreateFromHDC(hdc, &graphics);
2003 expect(Ok, status);
2005 status = GdipCreateRegion(&clip);
2006 expect(Ok, status);
2008 /* NULL */
2009 status = GdipIsClipEmpty(NULL, NULL);
2010 expect(InvalidParameter, status);
2011 status = GdipIsClipEmpty(graphics, NULL);
2012 expect(InvalidParameter, status);
2013 status = GdipIsClipEmpty(NULL, &res);
2014 expect(InvalidParameter, status);
2016 /* default is infinite */
2017 res = TRUE;
2018 status = GdipIsClipEmpty(graphics, &res);
2019 expect(Ok, status);
2020 expect(FALSE, res);
2022 GdipDeleteRegion(clip);
2024 GdipDeleteGraphics(graphics);
2025 ReleaseDC(hwnd, hdc);
2028 static void test_clear(void)
2030 GpStatus status;
2032 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2033 expect(InvalidParameter, status);
2036 static void test_textcontrast(void)
2038 GpStatus status;
2039 HDC hdc = GetDC( hwnd );
2040 GpGraphics *graphics;
2041 UINT contrast;
2043 status = GdipGetTextContrast(NULL, NULL);
2044 expect(InvalidParameter, status);
2046 status = GdipCreateFromHDC(hdc, &graphics);
2047 expect(Ok, status);
2049 status = GdipGetTextContrast(graphics, NULL);
2050 expect(InvalidParameter, status);
2051 status = GdipGetTextContrast(graphics, &contrast);
2052 expect(Ok, status);
2053 expect(4, contrast);
2055 GdipDeleteGraphics(graphics);
2056 ReleaseDC(hwnd, hdc);
2059 static void test_GdipDrawString(void)
2061 GpStatus status;
2062 GpGraphics *graphics = NULL;
2063 GpFont *fnt = NULL;
2064 RectF rect;
2065 GpStringFormat *format;
2066 GpBrush *brush;
2067 LOGFONTA logfont;
2068 HDC hdc = GetDC( hwnd );
2069 static const WCHAR string[] = {'T','e','s','t',0};
2070 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2071 GpMatrix *matrix;
2073 memset(&logfont,0,sizeof(logfont));
2074 strcpy(logfont.lfFaceName,"Arial");
2075 logfont.lfHeight = 12;
2076 logfont.lfCharSet = DEFAULT_CHARSET;
2078 status = GdipCreateFromHDC(hdc, &graphics);
2079 expect(Ok, status);
2081 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2082 if (status == NotTrueTypeFont || status == FileNotFound)
2084 skip("Arial not installed.\n");
2085 return;
2087 expect(Ok, status);
2089 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2090 expect(Ok, status);
2092 status = GdipCreateStringFormat(0,0,&format);
2093 expect(Ok, status);
2095 rect.X = 0;
2096 rect.Y = 0;
2097 rect.Width = 0;
2098 rect.Height = 12;
2100 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2101 expect(Ok, status);
2103 status = GdipCreateMatrix(&matrix);
2104 expect(Ok, status);
2106 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2107 expect(InvalidParameter, status);
2109 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2110 expect(InvalidParameter, status);
2112 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2113 expect(InvalidParameter, status);
2115 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2116 expect(InvalidParameter, status);
2118 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2119 expect(InvalidParameter, status);
2121 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2122 expect(Ok, status);
2124 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2125 expect(Ok, status);
2127 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2128 expect(Ok, status);
2130 GdipDeleteMatrix(matrix);
2131 GdipDeleteGraphics(graphics);
2132 GdipDeleteBrush(brush);
2133 GdipDeleteFont(fnt);
2134 GdipDeleteStringFormat(format);
2136 ReleaseDC(hwnd, hdc);
2139 static void test_GdipGetVisibleClipBounds_screen(void)
2141 GpStatus status;
2142 GpGraphics *graphics = NULL;
2143 HDC hdc = GetDC(0);
2144 GpRectF rectf, exp, clipr;
2145 GpRect recti;
2147 ok(hdc != NULL, "Expected HDC to be initialized\n");
2149 status = GdipCreateFromHDC(hdc, &graphics);
2150 expect(Ok, status);
2151 ok(graphics != NULL, "Expected graphics to be initialized\n");
2153 /* no clipping rect */
2154 exp.X = 0;
2155 exp.Y = 0;
2156 exp.Width = GetDeviceCaps(hdc, HORZRES);
2157 exp.Height = GetDeviceCaps(hdc, VERTRES);
2159 status = GdipGetVisibleClipBounds(graphics, &rectf);
2160 expect(Ok, status);
2161 ok(rectf.X == exp.X &&
2162 rectf.Y == exp.Y &&
2163 rectf.Width == exp.Width &&
2164 rectf.Height == exp.Height,
2165 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2166 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2167 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2168 exp.X, exp.Y, exp.Width, exp.Height);
2170 /* clipping rect entirely within window */
2171 exp.X = clipr.X = 10;
2172 exp.Y = clipr.Y = 12;
2173 exp.Width = clipr.Width = 14;
2174 exp.Height = clipr.Height = 16;
2176 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2177 expect(Ok, status);
2179 status = GdipGetVisibleClipBounds(graphics, &rectf);
2180 expect(Ok, status);
2181 ok(rectf.X == exp.X &&
2182 rectf.Y == exp.Y &&
2183 rectf.Width == exp.Width &&
2184 rectf.Height == exp.Height,
2185 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2186 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2187 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2188 exp.X, exp.Y, exp.Width, exp.Height);
2190 /* clipping rect partially outside of screen */
2191 clipr.X = -10;
2192 clipr.Y = -12;
2193 clipr.Width = 20;
2194 clipr.Height = 24;
2196 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2197 expect(Ok, status);
2199 exp.X = 0;
2200 exp.Y = 0;
2201 exp.Width = 10;
2202 exp.Height = 12;
2204 status = GdipGetVisibleClipBounds(graphics, &rectf);
2205 expect(Ok, status);
2206 ok(rectf.X == exp.X &&
2207 rectf.Y == exp.Y &&
2208 rectf.Width == exp.Width &&
2209 rectf.Height == exp.Height,
2210 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2211 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2212 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2213 exp.X, exp.Y, exp.Width, exp.Height);
2215 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2216 expect(Ok, status);
2217 ok(recti.X == exp.X &&
2218 recti.Y == exp.Y &&
2219 recti.Width == exp.Width &&
2220 recti.Height == exp.Height,
2221 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2222 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2223 recti.X, recti.Y, recti.Width, recti.Height,
2224 exp.X, exp.Y, exp.Width, exp.Height);
2226 GdipDeleteGraphics(graphics);
2227 ReleaseDC(0, hdc);
2230 static void test_GdipGetVisibleClipBounds_window(void)
2232 GpStatus status;
2233 GpGraphics *graphics = NULL;
2234 GpRectF rectf, window, exp, clipr;
2235 GpRect recti;
2236 HDC hdc;
2237 PAINTSTRUCT ps;
2238 RECT wnd_rect;
2240 /* get client area size */
2241 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2242 window.X = wnd_rect.left;
2243 window.Y = wnd_rect.top;
2244 window.Width = wnd_rect.right - wnd_rect.left;
2245 window.Height = wnd_rect.bottom - wnd_rect.top;
2247 hdc = BeginPaint(hwnd, &ps);
2249 status = GdipCreateFromHDC(hdc, &graphics);
2250 expect(Ok, status);
2251 ok(graphics != NULL, "Expected graphics to be initialized\n");
2253 status = GdipGetVisibleClipBounds(graphics, &rectf);
2254 expect(Ok, status);
2255 ok(rectf.X == window.X &&
2256 rectf.Y == window.Y &&
2257 rectf.Width == window.Width &&
2258 rectf.Height == window.Height,
2259 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2260 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2261 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2262 window.X, window.Y, window.Width, window.Height);
2264 /* clipping rect entirely within window */
2265 exp.X = clipr.X = 20;
2266 exp.Y = clipr.Y = 8;
2267 exp.Width = clipr.Width = 30;
2268 exp.Height = clipr.Height = 20;
2270 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2271 expect(Ok, status);
2273 status = GdipGetVisibleClipBounds(graphics, &rectf);
2274 expect(Ok, status);
2275 ok(rectf.X == exp.X &&
2276 rectf.Y == exp.Y &&
2277 rectf.Width == exp.Width &&
2278 rectf.Height == exp.Height,
2279 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2280 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2281 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2282 exp.X, exp.Y, exp.Width, exp.Height);
2284 /* clipping rect partially outside of window */
2285 clipr.X = window.Width - 10;
2286 clipr.Y = window.Height - 15;
2287 clipr.Width = 20;
2288 clipr.Height = 30;
2290 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2291 expect(Ok, status);
2293 exp.X = window.Width - 10;
2294 exp.Y = window.Height - 15;
2295 exp.Width = 10;
2296 exp.Height = 15;
2298 status = GdipGetVisibleClipBounds(graphics, &rectf);
2299 expect(Ok, status);
2300 ok(rectf.X == exp.X &&
2301 rectf.Y == exp.Y &&
2302 rectf.Width == exp.Width &&
2303 rectf.Height == exp.Height,
2304 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2305 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2306 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2307 exp.X, exp.Y, exp.Width, exp.Height);
2309 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2310 expect(Ok, status);
2311 ok(recti.X == exp.X &&
2312 recti.Y == exp.Y &&
2313 recti.Width == exp.Width &&
2314 recti.Height == exp.Height,
2315 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2316 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2317 recti.X, recti.Y, recti.Width, recti.Height,
2318 exp.X, exp.Y, exp.Width, exp.Height);
2320 GdipDeleteGraphics(graphics);
2321 EndPaint(hwnd, &ps);
2324 static void test_GdipGetVisibleClipBounds(void)
2326 GpGraphics* graphics = NULL;
2327 GpRectF rectf;
2328 GpRect rect;
2329 HDC hdc = GetDC( hwnd );
2330 GpStatus status;
2332 status = GdipCreateFromHDC(hdc, &graphics);
2333 expect(Ok, status);
2334 ok(graphics != NULL, "Expected graphics to be initialized\n");
2336 /* test null parameters */
2337 status = GdipGetVisibleClipBounds(graphics, NULL);
2338 expect(InvalidParameter, status);
2340 status = GdipGetVisibleClipBounds(NULL, &rectf);
2341 expect(InvalidParameter, status);
2343 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2344 expect(InvalidParameter, status);
2346 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2347 expect(InvalidParameter, status);
2349 GdipDeleteGraphics(graphics);
2350 ReleaseDC(hwnd, hdc);
2352 test_GdipGetVisibleClipBounds_screen();
2353 test_GdipGetVisibleClipBounds_window();
2356 static void test_fromMemoryBitmap(void)
2358 GpStatus status;
2359 GpGraphics *graphics = NULL;
2360 GpBitmap *bitmap = NULL;
2361 BYTE bits[48] = {0};
2362 HDC hdc=NULL;
2363 COLORREF color;
2365 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2366 expect(Ok, status);
2368 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2369 expect(Ok, status);
2371 status = GdipGraphicsClear(graphics, 0xff686868);
2372 expect(Ok, status);
2374 GdipDeleteGraphics(graphics);
2376 /* drawing writes to the memory provided */
2377 expect(0x68, bits[10]);
2379 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2380 expect(Ok, status);
2382 status = GdipGetDC(graphics, &hdc);
2383 expect(Ok, status);
2384 ok(hdc != NULL, "got NULL hdc\n");
2386 color = GetPixel(hdc, 0, 0);
2387 /* The HDC is write-only, and native fills with a solid color to figure out
2388 * which pixels have changed. */
2389 todo_wine expect(0x0c0b0d, color);
2391 SetPixel(hdc, 0, 0, 0x797979);
2392 SetPixel(hdc, 1, 0, 0x0c0b0d);
2394 status = GdipReleaseDC(graphics, hdc);
2395 expect(Ok, status);
2397 GdipDeleteGraphics(graphics);
2399 expect(0x79, bits[0]);
2400 todo_wine expect(0x68, bits[3]);
2402 GdipDisposeImage((GpImage*)bitmap);
2404 /* We get the same kind of write-only HDC for a "normal" bitmap */
2405 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2406 expect(Ok, status);
2408 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2409 expect(Ok, status);
2411 status = GdipGetDC(graphics, &hdc);
2412 expect(Ok, status);
2413 ok(hdc != NULL, "got NULL hdc\n");
2415 color = GetPixel(hdc, 0, 0);
2416 todo_wine expect(0x0c0b0d, color);
2418 status = GdipReleaseDC(graphics, hdc);
2419 expect(Ok, status);
2421 GdipDeleteGraphics(graphics);
2423 GdipDisposeImage((GpImage*)bitmap);
2426 static void test_GdipIsVisiblePoint(void)
2428 GpStatus status;
2429 GpGraphics *graphics = NULL;
2430 HDC hdc = GetDC( hwnd );
2431 REAL x, y;
2432 BOOL val;
2434 ok(hdc != NULL, "Expected HDC to be initialized\n");
2436 status = GdipCreateFromHDC(hdc, &graphics);
2437 expect(Ok, status);
2438 ok(graphics != NULL, "Expected graphics to be initialized\n");
2440 /* null parameters */
2441 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2442 expect(InvalidParameter, status);
2444 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2445 expect(InvalidParameter, status);
2447 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2448 expect(InvalidParameter, status);
2450 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2451 expect(InvalidParameter, status);
2453 x = 0;
2454 y = 0;
2455 status = GdipIsVisiblePoint(graphics, x, y, &val);
2456 expect(Ok, status);
2457 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2459 x = -10;
2460 y = 0;
2461 status = GdipIsVisiblePoint(graphics, x, y, &val);
2462 expect(Ok, status);
2463 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2465 x = 0;
2466 y = -5;
2467 status = GdipIsVisiblePoint(graphics, x, y, &val);
2468 expect(Ok, status);
2469 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2471 x = 1;
2472 y = 1;
2473 status = GdipIsVisiblePoint(graphics, x, y, &val);
2474 expect(Ok, status);
2475 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2477 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2478 expect(Ok, status);
2480 x = 1;
2481 y = 1;
2482 status = GdipIsVisiblePoint(graphics, x, y, &val);
2483 expect(Ok, status);
2484 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2486 x = 15.5;
2487 y = 40.5;
2488 status = GdipIsVisiblePoint(graphics, x, y, &val);
2489 expect(Ok, status);
2490 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2492 /* translate into the center of the rect */
2493 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2495 x = 0;
2496 y = 0;
2497 status = GdipIsVisiblePoint(graphics, x, y, &val);
2498 expect(Ok, status);
2499 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2501 x = 25;
2502 y = 40;
2503 status = GdipIsVisiblePoint(graphics, x, y, &val);
2504 expect(Ok, status);
2505 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2507 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2509 /* corner cases */
2510 x = 9;
2511 y = 19;
2512 status = GdipIsVisiblePoint(graphics, x, y, &val);
2513 expect(Ok, status);
2514 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2516 x = 9.25;
2517 y = 19.25;
2518 status = GdipIsVisiblePoint(graphics, x, y, &val);
2519 expect(Ok, status);
2520 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2522 x = 9.5;
2523 y = 19.5;
2524 status = GdipIsVisiblePoint(graphics, x, y, &val);
2525 expect(Ok, status);
2526 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2528 x = 9.75;
2529 y = 19.75;
2530 status = GdipIsVisiblePoint(graphics, x, y, &val);
2531 expect(Ok, status);
2532 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2534 x = 10;
2535 y = 20;
2536 status = GdipIsVisiblePoint(graphics, x, y, &val);
2537 expect(Ok, status);
2538 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2540 x = 40;
2541 y = 20;
2542 status = GdipIsVisiblePoint(graphics, x, y, &val);
2543 expect(Ok, status);
2544 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2546 x = 39;
2547 y = 59;
2548 status = GdipIsVisiblePoint(graphics, x, y, &val);
2549 expect(Ok, status);
2550 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2552 x = 39.25;
2553 y = 59.25;
2554 status = GdipIsVisiblePoint(graphics, x, y, &val);
2555 expect(Ok, status);
2556 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2558 x = 39.5;
2559 y = 39.5;
2560 status = GdipIsVisiblePoint(graphics, x, y, &val);
2561 expect(Ok, status);
2562 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2564 x = 39.75;
2565 y = 59.75;
2566 status = GdipIsVisiblePoint(graphics, x, y, &val);
2567 expect(Ok, status);
2568 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2570 x = 40;
2571 y = 60;
2572 status = GdipIsVisiblePoint(graphics, x, y, &val);
2573 expect(Ok, status);
2574 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2576 x = 40.15;
2577 y = 60.15;
2578 status = GdipIsVisiblePoint(graphics, x, y, &val);
2579 expect(Ok, status);
2580 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2582 x = 10;
2583 y = 60;
2584 status = GdipIsVisiblePoint(graphics, x, y, &val);
2585 expect(Ok, status);
2586 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2588 /* integer version */
2589 x = 25;
2590 y = 30;
2591 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2592 expect(Ok, status);
2593 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2595 x = 50;
2596 y = 100;
2597 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2598 expect(Ok, status);
2599 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2601 GdipDeleteGraphics(graphics);
2602 ReleaseDC(hwnd, hdc);
2605 static void test_GdipIsVisibleRect(void)
2607 GpStatus status;
2608 GpGraphics *graphics = NULL;
2609 HDC hdc = GetDC( hwnd );
2610 REAL x, y, width, height;
2611 BOOL val;
2613 ok(hdc != NULL, "Expected HDC to be initialized\n");
2615 status = GdipCreateFromHDC(hdc, &graphics);
2616 expect(Ok, status);
2617 ok(graphics != NULL, "Expected graphics to be initialized\n");
2619 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2620 expect(InvalidParameter, status);
2622 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2623 expect(InvalidParameter, status);
2625 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2626 expect(InvalidParameter, status);
2628 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2629 expect(InvalidParameter, status);
2631 /* entirely within the visible region */
2632 x = 0; width = 10;
2633 y = 0; height = 10;
2634 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2635 expect(Ok, status);
2636 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2638 /* partially outside */
2639 x = -10; width = 20;
2640 y = -10; height = 20;
2641 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2642 expect(Ok, status);
2643 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2645 /* entirely outside */
2646 x = -10; width = 5;
2647 y = -10; height = 5;
2648 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2649 expect(Ok, status);
2650 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2652 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2653 expect(Ok, status);
2655 /* entirely within the visible region */
2656 x = 12; width = 10;
2657 y = 22; height = 10;
2658 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2659 expect(Ok, status);
2660 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2662 /* partially outside */
2663 x = 35; width = 10;
2664 y = 55; height = 10;
2665 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2666 expect(Ok, status);
2667 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2669 /* entirely outside */
2670 x = 45; width = 5;
2671 y = 65; height = 5;
2672 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2673 expect(Ok, status);
2674 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2676 /* translate into center of clipping rect */
2677 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2679 x = 0; width = 10;
2680 y = 0; height = 10;
2681 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2682 expect(Ok, status);
2683 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2685 x = 25; width = 5;
2686 y = 40; height = 5;
2687 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2688 expect(Ok, status);
2689 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2691 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2693 /* corners entirely outside, but some intersections */
2694 x = 0; width = 70;
2695 y = 0; height = 90;
2696 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2697 expect(Ok, status);
2698 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2700 x = 0; width = 70;
2701 y = 0; height = 30;
2702 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2703 expect(Ok, status);
2704 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2706 x = 0; width = 30;
2707 y = 0; height = 90;
2708 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2709 expect(Ok, status);
2710 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2712 /* edge cases */
2713 x = 0; width = 10;
2714 y = 20; height = 40;
2715 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2716 expect(Ok, status);
2717 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2719 x = 10; width = 30;
2720 y = 0; height = 20;
2721 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2722 expect(Ok, status);
2723 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2725 x = 40; width = 10;
2726 y = 20; height = 40;
2727 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2728 expect(Ok, status);
2729 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2731 x = 10; width = 30;
2732 y = 60; height = 10;
2733 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2734 expect(Ok, status);
2735 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2737 /* rounding tests */
2738 x = 0.4; width = 10.4;
2739 y = 20; height = 40;
2740 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2741 expect(Ok, status);
2742 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2744 x = 10; width = 30;
2745 y = 0.4; height = 20.4;
2746 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2747 expect(Ok, status);
2748 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2750 /* integer version */
2751 x = 0; width = 30;
2752 y = 0; height = 90;
2753 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2754 expect(Ok, status);
2755 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2757 x = 12; width = 10;
2758 y = 22; height = 10;
2759 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2760 expect(Ok, status);
2761 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2763 GdipDeleteGraphics(graphics);
2764 ReleaseDC(hwnd, hdc);
2767 static void test_GdipGetNearestColor(void)
2769 GpStatus status;
2770 GpGraphics *graphics;
2771 GpBitmap *bitmap;
2772 ARGB color = 0xdeadbeef;
2773 HDC hdc = GetDC( hwnd );
2775 /* create a graphics object */
2776 ok(hdc != NULL, "Expected HDC to be initialized\n");
2778 status = GdipCreateFromHDC(hdc, &graphics);
2779 expect(Ok, status);
2780 ok(graphics != NULL, "Expected graphics to be initialized\n");
2782 status = GdipGetNearestColor(graphics, NULL);
2783 expect(InvalidParameter, status);
2785 status = GdipGetNearestColor(NULL, &color);
2786 expect(InvalidParameter, status);
2787 GdipDeleteGraphics(graphics);
2789 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2790 expect(Ok, status);
2791 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2792 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2793 if (status == Ok)
2795 status = GdipGetNearestColor(graphics, &color);
2796 expect(Ok, status);
2797 expect(0xdeadbeef, color);
2798 GdipDeleteGraphics(graphics);
2800 GdipDisposeImage((GpImage*)bitmap);
2802 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2803 expect(Ok, status);
2804 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2805 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2806 if (status == Ok)
2808 status = GdipGetNearestColor(graphics, &color);
2809 expect(Ok, status);
2810 expect(0xdeadbeef, color);
2811 GdipDeleteGraphics(graphics);
2813 GdipDisposeImage((GpImage*)bitmap);
2815 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2816 expect(Ok, status);
2817 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2818 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2819 if (status == Ok)
2821 status = GdipGetNearestColor(graphics, &color);
2822 expect(Ok, status);
2823 expect(0xdeadbeef, color);
2824 GdipDeleteGraphics(graphics);
2826 GdipDisposeImage((GpImage*)bitmap);
2828 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2829 expect(Ok, status);
2830 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2831 todo_wine expect(OutOfMemory, status);
2832 if (status == Ok)
2833 GdipDeleteGraphics(graphics);
2834 GdipDisposeImage((GpImage*)bitmap);
2836 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2837 expect(Ok, status);
2838 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2839 expect(Ok, status);
2840 status = GdipGetNearestColor(graphics, &color);
2841 expect(Ok, status);
2842 expect(0xdeadbeef, color);
2843 GdipDeleteGraphics(graphics);
2844 GdipDisposeImage((GpImage*)bitmap);
2846 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2847 expect(Ok, status);
2848 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2849 expect(Ok, status);
2850 status = GdipGetNearestColor(graphics, &color);
2851 expect(Ok, status);
2852 expect(0xdeadbeef, color);
2853 GdipDeleteGraphics(graphics);
2854 GdipDisposeImage((GpImage*)bitmap);
2856 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2857 expect(Ok, status);
2858 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2859 expect(Ok, status);
2860 status = GdipGetNearestColor(graphics, &color);
2861 expect(Ok, status);
2862 expect(0xdeadbeef, color);
2863 GdipDeleteGraphics(graphics);
2864 GdipDisposeImage((GpImage*)bitmap);
2866 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2867 expect(Ok, status);
2868 if (status == Ok)
2870 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2871 expect(Ok, status);
2872 status = GdipGetNearestColor(graphics, &color);
2873 expect(Ok, status);
2874 expect(0xdeadbeef, color);
2875 GdipDeleteGraphics(graphics);
2876 GdipDisposeImage((GpImage*)bitmap);
2879 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2880 expect(Ok, status);
2881 if (status == Ok)
2883 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2884 expect(Ok, status);
2885 status = GdipGetNearestColor(graphics, &color);
2886 expect(Ok, status);
2887 expect(0xdeadbeef, color);
2888 GdipDeleteGraphics(graphics);
2889 GdipDisposeImage((GpImage*)bitmap);
2892 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2893 expect(Ok, status);
2894 if (status == Ok)
2896 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2897 expect(Ok, status);
2898 status = GdipGetNearestColor(graphics, &color);
2899 expect(Ok, status);
2900 expect(0xdeadbeef, color);
2901 GdipDeleteGraphics(graphics);
2902 GdipDisposeImage((GpImage*)bitmap);
2905 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2906 expect(Ok, status);
2907 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2908 expect(Ok, status);
2909 status = GdipGetNearestColor(graphics, &color);
2910 expect(Ok, status);
2911 todo_wine expect(0xffa8bce8, color);
2912 GdipDeleteGraphics(graphics);
2913 GdipDisposeImage((GpImage*)bitmap);
2915 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2916 expect(Ok, status);
2917 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2918 expect(Ok, status);
2919 status = GdipGetNearestColor(graphics, &color);
2920 expect(Ok, status);
2921 todo_wine
2922 ok(color == 0xffa8b8e8 ||
2923 broken(color == 0xffa0b8e0), /* Win98/WinMe */
2924 "Expected ffa8b8e8, got %.8x\n", color);
2925 GdipDeleteGraphics(graphics);
2926 GdipDisposeImage((GpImage*)bitmap);
2928 ReleaseDC(hwnd, hdc);
2931 static void test_string_functions(void)
2933 GpStatus status;
2934 GpGraphics *graphics;
2935 GpFontFamily *family;
2936 GpFont *font;
2937 RectF rc, char_bounds, bounds;
2938 GpBrush *brush;
2939 ARGB color = 0xff000000;
2940 HDC hdc = GetDC( hwnd );
2941 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2942 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2943 const WCHAR teststring2[] = {'j',0};
2944 REAL char_width, char_height;
2945 INT codepointsfitted, linesfilled;
2946 GpStringFormat *format;
2947 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2948 GpRegion *regions[4];
2949 BOOL region_isempty[4];
2950 int i;
2951 PointF positions[8];
2952 GpMatrix *identity;
2954 ok(hdc != NULL, "Expected HDC to be initialized\n");
2955 status = GdipCreateFromHDC(hdc, &graphics);
2956 expect(Ok, status);
2957 ok(graphics != NULL, "Expected graphics to be initialized\n");
2959 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2960 expect(Ok, status);
2962 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2963 expect(Ok, status);
2965 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2966 expect(Ok, status);
2968 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2969 expect(Ok, status);
2971 rc.X = 0;
2972 rc.Y = 0;
2973 rc.Width = 100.0;
2974 rc.Height = 100.0;
2976 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2977 expect(InvalidParameter, status);
2979 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2980 expect(InvalidParameter, status);
2982 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2983 expect(InvalidParameter, status);
2985 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2986 expect(InvalidParameter, status);
2988 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2989 expect(InvalidParameter, status);
2991 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2992 expect(Ok, status);
2994 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2995 expect(InvalidParameter, status);
2997 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2998 expect(InvalidParameter, status);
3000 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3001 expect(InvalidParameter, status);
3003 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3004 expect(InvalidParameter, status);
3006 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3007 expect(InvalidParameter, status);
3009 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3010 expect(Ok, status);
3012 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3013 expect(Ok, status);
3015 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3016 expect(Ok, status);
3017 expectf(0.0, char_bounds.X);
3018 expectf(0.0, char_bounds.Y);
3019 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3020 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3021 expect(1, codepointsfitted);
3022 expect(1, linesfilled);
3024 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3025 expect(Ok, status);
3026 expectf(0.0, bounds.X);
3027 expectf(0.0, bounds.Y);
3028 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3029 expectf(char_bounds.Height, bounds.Height);
3030 expect(2, codepointsfitted);
3031 expect(1, linesfilled);
3032 char_width = bounds.Width - char_bounds.Width;
3034 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3035 expect(Ok, status);
3036 expectf(0.0, bounds.X);
3037 expectf(0.0, bounds.Y);
3038 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3039 bounds.Width, char_bounds.Width + char_width * 2);
3040 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3041 expect(6, codepointsfitted);
3042 expect(2, linesfilled);
3043 char_height = bounds.Height - char_bounds.Height;
3045 /* Measure the first line. */
3046 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3047 expect(Ok, status);
3048 expectf(0.0, bounds.X);
3049 expectf(0.0, bounds.Y);
3050 expect(4, codepointsfitted);
3051 expect(1, linesfilled);
3053 /* Give just enough space to fit the first line. */
3054 rc.Width = bounds.Width;
3055 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3056 expect(Ok, status);
3057 expectf(0.0, bounds.X);
3058 expectf(0.0, bounds.Y);
3059 todo_wine expect(5, codepointsfitted);
3060 todo_wine expect(1, linesfilled);
3062 /* Cut off everything after the first space. */
3063 rc.Width = char_bounds.Width + char_width * 2.1;
3065 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3066 expect(Ok, status);
3067 expectf(0.0, bounds.X);
3068 expectf(0.0, bounds.Y);
3069 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3070 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3071 expect(6, codepointsfitted);
3072 expect(3, linesfilled);
3074 /* Cut off everything including the first space. */
3075 rc.Width = char_bounds.Width + char_width * 1.7;
3077 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3078 expect(Ok, status);
3079 expectf(0.0, bounds.X);
3080 expectf(0.0, bounds.Y);
3081 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3082 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3083 expect(6, codepointsfitted);
3084 expect(3, linesfilled);
3086 /* Cut off everything after the first character. */
3087 rc.Width = char_bounds.Width + char_width * 0.8;
3089 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3090 expect(Ok, status);
3091 expectf(0.0, bounds.X);
3092 expectf(0.0, bounds.Y);
3093 expectf_(char_bounds.Width, bounds.Width, 0.01);
3094 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3095 expect(6, codepointsfitted);
3096 todo_wine expect(4, linesfilled);
3098 for (i = 0; i < 4; i++)
3099 regions[i] = (GpRegion *)0xdeadbeef;
3101 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3102 expect(Ok, status);
3104 for (i = 0; i < 4; i++)
3105 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3107 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3108 expect(Ok, status);
3110 for (i = 0; i < 4; i++)
3111 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3113 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3114 expect(Ok, status);
3116 set_rect_empty(&rc);
3118 for (i=0; i<4; i++)
3120 status = GdipCreateRegion(&regions[i]);
3121 expect(Ok, status);
3122 status = GdipSetEmpty(regions[i]);
3123 expect(Ok, status);
3126 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3127 expect(InvalidParameter, status);
3129 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3130 expect(InvalidParameter, status);
3132 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3133 expect(InvalidParameter, status);
3135 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3136 expect(InvalidParameter, status);
3138 if (0)
3140 /* Crashes on Windows XP */
3141 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3142 expect(InvalidParameter, status);
3145 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3146 expect(InvalidParameter, status);
3148 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3149 expect(InvalidParameter, status);
3151 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3152 expect(Ok, status);
3154 for (i = 0; i < 4; i++)
3156 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3157 expect(Ok, status);
3160 ok(region_isempty[0], "region should be empty\n");
3161 ok(region_isempty[1], "region should be empty\n");
3162 ok(region_isempty[2], "region should be empty\n");
3163 ok(region_isempty[3], "region should be empty\n");
3165 rc.Width = 100.0;
3166 rc.Height = 100.0;
3168 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3169 expect(Ok, status);
3171 for (i=0; i<4; i++)
3173 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3174 expect(Ok, status);
3177 ok(!region_isempty[0], "region shouldn't be empty\n");
3178 ok(!region_isempty[1], "region shouldn't be empty\n");
3179 ok(!region_isempty[2], "region shouldn't be empty\n");
3180 ok(region_isempty[3], "region should be empty\n");
3182 /* Cut off everything after the first space, and the second line. */
3183 rc.Width = char_bounds.Width + char_width * 2.1;
3184 rc.Height = char_bounds.Height + char_height * 0.5;
3186 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3187 expect(Ok, status);
3189 for (i=0; i<4; i++)
3191 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3192 expect(Ok, status);
3195 ok(!region_isempty[0], "region shouldn't be empty\n");
3196 ok(!region_isempty[1], "region shouldn't be empty\n");
3197 ok(region_isempty[2], "region should be empty\n");
3198 ok(region_isempty[3], "region should be empty\n");
3200 for (i=0; i<4; i++)
3201 GdipDeleteRegion(regions[i]);
3203 status = GdipCreateMatrix(&identity);
3204 expect(Ok, status);
3206 rc.X = 0;
3207 rc.Y = 0;
3208 rc.Width = 0;
3209 rc.Height = 0;
3210 memset(positions, 0, sizeof(positions));
3211 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3212 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3213 identity, &rc);
3214 expect(InvalidParameter, status);
3216 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3217 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3218 identity, &rc);
3219 expect(InvalidParameter, status);
3221 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3222 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3223 identity, &rc);
3224 expect(InvalidParameter, status);
3226 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3227 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3228 identity, &rc);
3229 expect(InvalidParameter, status);
3231 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3232 0x100, identity, &rc);
3233 expect(Ok, status);
3235 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3236 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3237 NULL, &rc);
3238 expect(Ok, status);
3240 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3241 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3242 identity, NULL);
3243 expect(InvalidParameter, status);
3245 rc.X = 0;
3246 rc.Y = 0;
3247 rc.Width = 0;
3248 rc.Height = 0;
3249 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3250 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3251 identity, &rc);
3252 expect(Ok, status);
3254 expectf(0.0, rc.X);
3255 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3256 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3257 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3259 char_width = rc.Width;
3260 char_height = rc.Height;
3262 rc.X = 0;
3263 rc.Y = 0;
3264 rc.Width = 0;
3265 rc.Height = 0;
3266 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3267 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3268 identity, &rc);
3269 expect(Ok, status);
3271 expectf(0.0, rc.X);
3272 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3273 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3274 expectf(char_height, rc.Height);
3276 rc.X = 0;
3277 rc.Y = 0;
3278 rc.Width = 0;
3279 rc.Height = 0;
3280 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3281 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3282 identity, &rc);
3283 expect(Ok, status);
3285 expectf(rc.X, 0.0);
3286 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3287 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3288 expectf(rc.Height, char_height);
3290 GdipDeleteMatrix(identity);
3291 GdipDeleteStringFormat(format);
3292 GdipDeleteBrush(brush);
3293 GdipDeleteFont(font);
3294 GdipDeleteFontFamily(family);
3295 GdipDeleteGraphics(graphics);
3297 ReleaseDC(hwnd, hdc);
3300 static void test_get_set_interpolation(void)
3302 GpGraphics *graphics;
3303 HDC hdc = GetDC( hwnd );
3304 GpStatus status;
3305 InterpolationMode mode;
3307 ok(hdc != NULL, "Expected HDC to be initialized\n");
3308 status = GdipCreateFromHDC(hdc, &graphics);
3309 expect(Ok, status);
3310 ok(graphics != NULL, "Expected graphics to be initialized\n");
3312 status = GdipGetInterpolationMode(NULL, &mode);
3313 expect(InvalidParameter, status);
3315 if (0)
3317 /* Crashes on Windows XP */
3318 status = GdipGetInterpolationMode(graphics, NULL);
3319 expect(InvalidParameter, status);
3322 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3323 expect(InvalidParameter, status);
3325 /* out of range */
3326 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3327 expect(InvalidParameter, status);
3329 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3330 expect(InvalidParameter, status);
3332 status = GdipGetInterpolationMode(graphics, &mode);
3333 expect(Ok, status);
3334 expect(InterpolationModeBilinear, mode);
3336 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3337 expect(Ok, status);
3339 status = GdipGetInterpolationMode(graphics, &mode);
3340 expect(Ok, status);
3341 expect(InterpolationModeNearestNeighbor, mode);
3343 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3344 expect(Ok, status);
3346 status = GdipGetInterpolationMode(graphics, &mode);
3347 expect(Ok, status);
3348 expect(InterpolationModeBilinear, mode);
3350 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3351 expect(Ok, status);
3353 status = GdipGetInterpolationMode(graphics, &mode);
3354 expect(Ok, status);
3355 expect(InterpolationModeBilinear, mode);
3357 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3358 expect(Ok, status);
3360 status = GdipGetInterpolationMode(graphics, &mode);
3361 expect(Ok, status);
3362 expect(InterpolationModeHighQualityBicubic, mode);
3364 GdipDeleteGraphics(graphics);
3366 ReleaseDC(hwnd, hdc);
3369 static void test_get_set_textrenderinghint(void)
3371 GpGraphics *graphics;
3372 HDC hdc = GetDC( hwnd );
3373 GpStatus status;
3374 TextRenderingHint hint;
3376 ok(hdc != NULL, "Expected HDC to be initialized\n");
3377 status = GdipCreateFromHDC(hdc, &graphics);
3378 expect(Ok, status);
3379 ok(graphics != NULL, "Expected graphics to be initialized\n");
3381 status = GdipGetTextRenderingHint(NULL, &hint);
3382 expect(InvalidParameter, status);
3384 status = GdipGetTextRenderingHint(graphics, NULL);
3385 expect(InvalidParameter, status);
3387 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3388 expect(InvalidParameter, status);
3390 /* out of range */
3391 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3392 expect(InvalidParameter, status);
3394 status = GdipGetTextRenderingHint(graphics, &hint);
3395 expect(Ok, status);
3396 expect(TextRenderingHintSystemDefault, hint);
3398 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3399 expect(Ok, status);
3401 status = GdipGetTextRenderingHint(graphics, &hint);
3402 expect(Ok, status);
3403 expect(TextRenderingHintSystemDefault, hint);
3405 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3406 expect(Ok, status);
3408 status = GdipGetTextRenderingHint(graphics, &hint);
3409 expect(Ok, status);
3410 expect(TextRenderingHintAntiAliasGridFit, hint);
3412 GdipDeleteGraphics(graphics);
3414 ReleaseDC(hwnd, hdc);
3417 static void test_getdc_scaled(void)
3419 GpStatus status;
3420 GpGraphics *graphics = NULL;
3421 GpBitmap *bitmap = NULL;
3422 HDC hdc=NULL;
3423 HBRUSH hbrush, holdbrush;
3424 ARGB color;
3426 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3427 expect(Ok, status);
3429 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3430 expect(Ok, status);
3432 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3433 expect(Ok, status);
3435 status = GdipGetDC(graphics, &hdc);
3436 expect(Ok, status);
3437 ok(hdc != NULL, "got NULL hdc\n");
3439 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3441 holdbrush = SelectObject(hdc, hbrush);
3443 Rectangle(hdc, 2, 2, 6, 6);
3445 SelectObject(hdc, holdbrush);
3447 DeleteObject(hbrush);
3449 status = GdipReleaseDC(graphics, hdc);
3450 expect(Ok, status);
3452 GdipDeleteGraphics(graphics);
3454 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3455 expect(Ok, status);
3456 expect(0xffff0000, color);
3458 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3459 expect(Ok, status);
3460 expect(0xff000000, color);
3462 GdipDisposeImage((GpImage*)bitmap);
3465 static void test_GdipMeasureString(void)
3467 static const struct test_data
3469 REAL res_x, res_y, page_scale;
3470 GpUnit unit;
3471 } td[] =
3473 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3474 { 200.0, 200.0, 2.0, UnitPixel },
3475 { 200.0, 200.0, 1.0, UnitDisplay },
3476 { 200.0, 200.0, 2.0, UnitDisplay },
3477 { 200.0, 200.0, 1.0, UnitInch },
3478 { 200.0, 200.0, 2.0, UnitInch },
3479 { 200.0, 600.0, 1.0, UnitPoint },
3480 { 200.0, 600.0, 2.0, UnitPoint },
3481 { 200.0, 600.0, 1.0, UnitDocument },
3482 { 200.0, 600.0, 2.0, UnitDocument },
3483 { 200.0, 600.0, 1.0, UnitMillimeter },
3484 { 200.0, 600.0, 2.0, UnitMillimeter },
3485 { 200.0, 600.0, 1.0, UnitDisplay },
3486 { 200.0, 600.0, 2.0, UnitDisplay },
3487 { 200.0, 600.0, 1.0, UnitPixel },
3488 { 200.0, 600.0, 2.0, UnitPixel },
3490 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3491 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3492 GpStatus status;
3493 GpGraphics *graphics;
3494 GpFontFamily *family;
3495 GpFont *font;
3496 GpStringFormat *format;
3497 RectF bounds, rc;
3498 REAL base_cx = 0, base_cy = 0, height;
3499 INT chars, lines;
3500 LOGFONTW lf;
3501 UINT i;
3502 REAL font_size;
3503 GpUnit font_unit, unit;
3505 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3506 expect(Ok, status);
3507 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3508 expect(Ok, status);
3510 /* font size in pixels */
3511 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3512 expect(Ok, status);
3513 status = GdipGetFontSize(font, &font_size);
3514 expect(Ok, status);
3515 expectf(100.0, font_size);
3516 status = GdipGetFontUnit(font, &font_unit);
3517 expect(Ok, status);
3518 expect(UnitPixel, font_unit);
3520 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3522 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale);
3524 lf.lfHeight = 0xdeadbeef;
3525 status = GdipGetLogFontW(font, graphics, &lf);
3526 expect(Ok, status);
3527 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3528 if (td[i].unit != UnitDisplay)
3529 height *= td[i].page_scale;
3530 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3531 i, (LONG)(height + 0.5), height, lf.lfHeight);
3533 height = font_size + 2.0 * font_size / 6.0;
3535 set_rect_empty(&rc);
3536 set_rect_empty(&bounds);
3537 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3538 expect(Ok, status);
3540 if (i == 0)
3542 base_cx = bounds.Width;
3543 base_cy = bounds.Height;
3546 expectf(0.0, bounds.X);
3547 expectf(0.0, bounds.Y);
3548 todo_wine
3549 expectf_(height, bounds.Height, height / 100.0);
3550 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3551 expect(7, chars);
3552 expect(1, lines);
3554 /* make sure it really fits */
3555 bounds.Width += 1.0;
3556 bounds.Height += 1.0;
3557 rc = bounds;
3558 rc.X = 50.0;
3559 rc.Y = 50.0;
3560 set_rect_empty(&bounds);
3561 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3562 expect(Ok, status);
3563 expectf(50.0, bounds.X);
3564 expectf(50.0, bounds.Y);
3565 todo_wine
3566 expectf_(height, bounds.Height, height / 100.0);
3567 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3568 expect(7, chars);
3569 expect(1, lines);
3571 status = GdipDeleteGraphics(graphics);
3572 expect(Ok, status);
3575 GdipDeleteFont(font);
3577 /* font size in logical units */
3578 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3579 for (unit = 3; unit <= 6; unit++)
3581 /* create a font which final height is 100.0 pixels with 200 dpi device */
3582 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3583 height = pixels_to_units(75.0, unit, 200.0);
3584 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3585 expect(Ok, status);
3586 status = GdipGetFontSize(font, &font_size);
3587 expect(Ok, status);
3588 expectf(height, font_size);
3589 status = GdipGetFontUnit(font, &font_unit);
3590 expect(Ok, status);
3591 expect(unit, font_unit);
3593 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3595 REAL unit_scale;
3597 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale);
3599 lf.lfHeight = 0xdeadbeef;
3600 status = GdipGetLogFontW(font, graphics, &lf);
3601 expect(Ok, status);
3602 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3603 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3604 else
3605 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3606 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3607 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3608 i, (LONG)(height + 0.5), height, lf.lfHeight);
3610 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3611 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3612 else
3613 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3614 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3615 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3616 if (td[i].unit != UnitDisplay)
3617 height /= td[i].page_scale;
3618 /*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);*/
3620 set_rect_empty(&rc);
3621 set_rect_empty(&bounds);
3622 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3623 expect(Ok, status);
3625 if (i == 0)
3627 base_cx = bounds.Width;
3628 base_cy = bounds.Height;
3631 expectf(0.0, bounds.X);
3632 expectf(0.0, bounds.Y);
3633 todo_wine
3634 expectf_(height, bounds.Height, height / 85.0);
3635 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3636 expect(7, chars);
3637 expect(1, lines);
3639 /* make sure it really fits */
3640 bounds.Width += 1.0;
3641 bounds.Height += 1.0;
3642 rc = bounds;
3643 rc.X = 50.0;
3644 rc.Y = 50.0;
3645 set_rect_empty(&bounds);
3646 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3647 expect(Ok, status);
3648 expectf(50.0, bounds.X);
3649 expectf(50.0, bounds.Y);
3650 todo_wine
3651 expectf_(height, bounds.Height, height / 85.0);
3652 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3653 expect(7, chars);
3654 expect(1, lines);
3656 /* verify the result */
3657 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3658 if (td[i].unit != UnitDisplay)
3659 height *= td[i].page_scale;
3660 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3661 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3662 todo_wine
3663 expectf_(100.0, height, 1.1);
3665 status = GdipDeleteGraphics(graphics);
3666 expect(Ok, status);
3669 GdipDeleteFont(font);
3672 GdipDeleteFontFamily(family);
3673 GdipDeleteStringFormat(format);
3676 static void test_transform(void)
3678 static const struct test_data
3680 REAL res_x, res_y, scale;
3681 GpUnit unit;
3682 GpPointF in[2], out[2];
3683 } td[] =
3685 { 96.0, 96.0, 1.0, UnitPixel,
3686 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3687 { 96.0, 96.0, 1.0, UnitDisplay,
3688 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3689 { 96.0, 96.0, 1.0, UnitInch,
3690 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
3691 { 123.0, 456.0, 1.0, UnitPoint,
3692 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
3693 { 123.0, 456.0, 1.0, UnitDocument,
3694 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
3695 { 123.0, 456.0, 2.0, UnitMillimeter,
3696 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
3697 { 196.0, 296.0, 1.0, UnitDisplay,
3698 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3699 { 196.0, 296.0, 1.0, UnitPixel,
3700 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3702 GpStatus status;
3703 GpGraphics *graphics;
3704 GpPointF ptf[2];
3705 UINT i;
3707 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3709 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale);
3710 ptf[0].X = td[i].in[0].X;
3711 ptf[0].Y = td[i].in[0].Y;
3712 ptf[1].X = td[i].in[1].X;
3713 ptf[1].Y = td[i].in[1].Y;
3714 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
3715 expect(Ok, status);
3716 expectf(td[i].out[0].X, ptf[0].X);
3717 expectf(td[i].out[0].Y, ptf[0].Y);
3718 expectf(td[i].out[1].X, ptf[1].X);
3719 expectf(td[i].out[1].Y, ptf[1].Y);
3720 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
3721 expect(Ok, status);
3722 expectf(td[i].in[0].X, ptf[0].X);
3723 expectf(td[i].in[0].Y, ptf[0].Y);
3724 expectf(td[i].in[1].X, ptf[1].X);
3725 expectf(td[i].in[1].Y, ptf[1].Y);
3726 status = GdipDeleteGraphics(graphics);
3727 expect(Ok, status);
3731 /* Many people on the net ask why there is so much difference in rendered
3732 * text height between gdiplus and gdi32, this test suggests an answer to
3733 * that question. Important: this test assumes that font dpi == device dpi.
3735 static void test_font_height_scaling(void)
3737 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3738 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3739 HDC hdc;
3740 GpStringFormat *format;
3741 CharacterRange range = { 0, 7 };
3742 GpRegion *region;
3743 GpGraphics *graphics;
3744 GpFontFamily *family;
3745 GpFont *font;
3746 GpStatus status;
3747 RectF bounds, rect;
3748 REAL height, dpi, scale;
3749 PointF ptf;
3750 GpUnit gfx_unit, font_unit;
3752 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3753 expect(Ok, status);
3754 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3755 expect(Ok, status);
3756 status = GdipCreateRegion(&region);
3757 expect(Ok, status);
3759 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3760 expect(Ok, status);
3762 hdc = CreateCompatibleDC(0);
3763 status = GdipCreateFromHDC(hdc, &graphics);
3765 status = GdipGetDpiY(graphics, &dpi);
3766 expect(Ok, status);
3768 /* First check if tested functionality works:
3769 * under XP if font and graphics units differ then GdipTransformPoints
3770 * followed by GdipSetPageUnit to change the graphics units breaks region
3771 * scaling in GdipMeasureCharacterRanges called later.
3773 status = GdipSetPageUnit(graphics, UnitDocument);
3774 expect(Ok, status);
3776 ptf.X = 0.0;
3777 ptf.Y = 0.0;
3778 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
3779 expect(Ok, status);
3781 status = GdipSetPageUnit(graphics, UnitInch);
3782 expect(Ok, status);
3784 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
3785 expect(Ok, status);
3787 set_rect_empty(&rect);
3788 set_rect_empty(&bounds);
3789 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
3790 expect(Ok, status);
3791 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
3793 set_rect_empty(&rect);
3794 rect.Width = 32000.0;
3795 rect.Height = 32000.0;
3796 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3797 expect(Ok, status);
3799 set_rect_empty(&rect);
3800 status = GdipGetRegionBounds(region, graphics, &rect);
3801 expect(Ok, status);
3802 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
3804 GdipDeleteFont(font);
3806 scale = rect.Height / bounds.Height;
3807 if (fabs(scale - 1.0) > 0.1)
3809 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
3810 goto cleanup;
3813 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
3814 expect(Ok, status);
3816 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3817 /* UnitPixel as a font base unit is not tested because it drastically
3818 differs in behaviour */
3819 for (font_unit = 3; font_unit <= 6; font_unit++)
3821 /* create a font for the final text height of 100 pixels */
3822 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3823 status = GdipSetPageUnit(graphics, font_unit);
3824 expect(Ok, status);
3825 ptf.X = 0;
3826 ptf.Y = 75.0;
3827 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
3828 expect(Ok, status);
3829 height = ptf.Y;
3830 /*trace("height %f units\n", height);*/
3831 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
3832 expect(Ok, status);
3834 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3835 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
3837 static const WCHAR doubleW[2] = { 'W','W' };
3838 RectF bounds_1, bounds_2;
3839 REAL margin, margin_y, font_height;
3840 int match;
3842 status = GdipSetPageUnit(graphics, gfx_unit);
3843 expect(Ok, status);
3845 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
3846 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
3848 status = GdipGetFontHeight(font, graphics, &font_height);
3849 expect(Ok, status);
3851 set_rect_empty(&rect);
3852 set_rect_empty(&bounds);
3853 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
3854 expect(Ok, status);
3855 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
3856 todo_wine
3857 expectf_(font_height + margin_y, bounds.Height, 0.005);
3859 ptf.X = 0;
3860 ptf.Y = bounds.Height;
3861 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
3862 expect(Ok, status);
3863 match = fabs(100.0 - ptf.Y) <= 1.0;
3864 todo_wine
3865 ok(match, "Expected 100.0, got %f\n", ptf.Y);
3867 /* verify the result */
3868 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
3869 ptf.Y /= 100.0;
3870 match = fabs(100.0 - ptf.Y) <= 1.0;
3871 todo_wine
3872 ok(match, "Expected 100.0, got %f\n", ptf.Y);
3874 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
3875 set_rect_empty(&rect);
3876 set_rect_empty(&bounds_1);
3877 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
3878 expect(Ok, status);
3879 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
3880 set_rect_empty(&rect);
3881 set_rect_empty(&bounds_2);
3882 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
3883 expect(Ok, status);
3885 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
3886 margin = bounds_1.Width - bounds_2.Width / 2.0;
3887 /*trace("margin %f\n", margin);*/
3888 ok(margin > 0.0, "wrong margin %f\n", margin);
3890 set_rect_empty(&rect);
3891 rect.Width = 320000.0;
3892 rect.Height = 320000.0;
3893 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3894 expect(Ok, status);
3895 set_rect_empty(&rect);
3896 status = GdipGetRegionBounds(region, graphics, &rect);
3897 expect(Ok, status);
3898 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
3899 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
3900 expectf(0.0, rect.Y);
3901 match = fabs(1.0 - margin / rect.X) <= 0.05;
3902 ok(match, "Expected %f, got %f\n", margin, rect.X);
3903 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
3904 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
3905 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
3906 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
3909 GdipDeleteFont(font);
3912 cleanup:
3913 status = GdipDeleteGraphics(graphics);
3914 expect(Ok, status);
3915 DeleteDC(hdc);
3917 GdipDeleteFontFamily(family);
3918 GdipDeleteRegion(region);
3919 GdipDeleteStringFormat(format);
3922 static void test_measure_string(void)
3924 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3925 static const WCHAR string[] = { 'A','0','1',0 };
3926 HDC hdc;
3927 GpStringFormat *format;
3928 CharacterRange range;
3929 GpRegion *region;
3930 GpGraphics *graphics;
3931 GpFontFamily *family;
3932 GpFont *font;
3933 GpStatus status;
3934 RectF bounds, rect;
3935 REAL width, height, width_1, width_2;
3936 REAL margin_x, margin_y, width_rgn, height_rgn;
3937 int lines, glyphs;
3939 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3940 expect(Ok, status);
3941 expect(Ok, status);
3943 status = GdipCreateRegion(&region);
3944 expect(Ok, status);
3946 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3947 expect(Ok, status);
3949 hdc = CreateCompatibleDC(0);
3950 status = GdipCreateFromHDC(hdc, &graphics);
3952 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
3953 expect(Ok, status);
3955 margin_x = 20.0 / 6.0;
3956 margin_y = 20.0 / 8.0;
3958 set_rect_empty(&rect);
3959 set_rect_empty(&bounds);
3960 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
3961 expect(Ok, status);
3962 expect(3, glyphs);
3963 expect(1, lines);
3964 expectf(0.0, bounds.X);
3965 expectf(0.0, bounds.Y);
3966 width = bounds.Width;
3967 height = bounds.Height;
3969 set_rect_empty(&rect);
3970 rect.Height = height / 2.0;
3971 set_rect_empty(&bounds);
3972 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
3973 expect(Ok, status);
3974 expect(3, glyphs);
3975 expect(1, lines);
3976 expectf(0.0, bounds.X);
3977 expectf(0.0, bounds.Y);
3978 expectf(width, bounds.Width);
3979 todo_wine
3980 expectf(height / 2.0, bounds.Height);
3982 range.First = 0;
3983 range.Length = lstrlenW(string);
3984 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3985 expect(Ok, status);
3987 rect.X = 5.0;
3988 rect.Y = 5.0;
3989 rect.Width = 32000.0;
3990 rect.Height = 32000.0;
3991 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3992 expect(Ok, status);
3993 set_rect_empty(&bounds);
3994 status = GdipGetRegionBounds(region, graphics, &bounds);
3995 expect(Ok, status);
3996 expectf_(5.0 + margin_x, bounds.X, 1.0);
3997 expectf(5.0, bounds.Y);
3998 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
3999 todo_wine
4000 expectf_(height - margin_y, bounds.Height, 1.0);
4002 width_rgn = bounds.Width;
4003 height_rgn = bounds.Height;
4005 range.First = 0;
4006 range.Length = 1;
4007 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4008 expect(Ok, status);
4010 set_rect_empty(&rect);
4011 rect.Width = 32000.0;
4012 rect.Height = 32000.0;
4013 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4014 expect(Ok, status);
4015 set_rect_empty(&bounds);
4016 status = GdipGetRegionBounds(region, graphics, &bounds);
4017 expect(Ok, status);
4018 expectf_(margin_x, bounds.X, 1.0);
4019 expectf(0.0, bounds.Y);
4020 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4021 expectf(height_rgn, bounds.Height);
4022 width_1 = bounds.Width;
4024 range.First = 0;
4025 range.Length = lstrlenW(string);
4026 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4027 expect(Ok, status);
4029 rect.X = 5.0;
4030 rect.Y = 5.0;
4031 rect.Width = 0.0;
4032 rect.Height = 0.0;
4033 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4034 expect(Ok, status);
4035 set_rect_empty(&bounds);
4036 status = GdipGetRegionBounds(region, graphics, &bounds);
4037 expect(Ok, status);
4038 expectf(0.0, bounds.X);
4039 expectf(0.0, bounds.Y);
4040 expectf(0.0, bounds.Width);
4041 expectf(0.0, bounds.Height);
4043 rect.X = 5.0;
4044 rect.Y = 5.0;
4045 rect.Width = width_rgn / 2.0;
4046 rect.Height = 32000.0;
4047 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4048 expect(Ok, status);
4049 set_rect_empty(&bounds);
4050 status = GdipGetRegionBounds(region, graphics, &bounds);
4051 expect(Ok, status);
4052 expectf_(5.0 + margin_x, bounds.X, 1.0);
4053 expectf(5.0, bounds.Y);
4054 expectf_(width_1, bounds.Width, 1.0);
4055 todo_wine
4056 expectf_(height - margin_y, bounds.Height, 1.0);
4058 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4060 rect.X = 5.0;
4061 rect.Y = 5.0;
4062 rect.Width = 0.0;
4063 rect.Height = 0.0;
4064 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4065 expect(Ok, status);
4066 set_rect_empty(&bounds);
4067 status = GdipGetRegionBounds(region, graphics, &bounds);
4068 expect(Ok, status);
4069 expectf_(5.0 + margin_x, bounds.X, 1.0);
4070 expectf(5.0, bounds.Y);
4071 expectf(width_rgn, bounds.Width);
4072 expectf(height_rgn, bounds.Height);
4074 rect.X = 5.0;
4075 rect.Y = 5.0;
4076 rect.Width = width_rgn / 2.0;
4077 rect.Height = 32000.0;
4078 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4079 expect(Ok, status);
4080 set_rect_empty(&bounds);
4081 status = GdipGetRegionBounds(region, graphics, &bounds);
4082 expect(Ok, status);
4083 expectf_(5.0 + margin_x, bounds.X, 1.0);
4084 expectf(5.0, bounds.Y);
4085 expectf_(width_1, bounds.Width, 1.0);
4086 expectf(height_rgn, bounds.Height);
4088 set_rect_empty(&rect);
4089 rect.Height = height / 2.0;
4090 set_rect_empty(&bounds);
4091 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4092 expect(Ok, status);
4093 expect(3, glyphs);
4094 expect(1, lines);
4095 expectf(0.0, bounds.X);
4096 expectf(0.0, bounds.Y);
4097 expectf_(width, bounds.Width, 0.01);
4098 todo_wine
4099 expectf(height, bounds.Height);
4101 set_rect_empty(&rect);
4102 set_rect_empty(&bounds);
4103 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4104 expect(Ok, status);
4105 expect(1, glyphs);
4106 expect(1, lines);
4107 expectf(0.0, bounds.X);
4108 expectf(0.0, bounds.Y);
4109 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4110 expectf(height, bounds.Height);
4111 width_1 = bounds.Width;
4113 set_rect_empty(&rect);
4114 set_rect_empty(&bounds);
4115 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4116 expect(Ok, status);
4117 expect(2, glyphs);
4118 expect(1, lines);
4119 expectf(0.0, bounds.X);
4120 expectf(0.0, bounds.Y);
4121 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4122 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4123 expectf(height, bounds.Height);
4124 width_2 = bounds.Width;
4126 set_rect_empty(&rect);
4127 rect.Width = width / 2.0;
4128 set_rect_empty(&bounds);
4129 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4130 expect(Ok, status);
4131 expect(1, glyphs);
4132 expect(1, lines);
4133 expectf(0.0, bounds.X);
4134 expectf(0.0, bounds.Y);
4135 expectf_(width_1, bounds.Width, 0.01);
4136 expectf(height, bounds.Height);
4138 set_rect_empty(&rect);
4139 rect.Height = height;
4140 rect.Width = width - 0.05;
4141 set_rect_empty(&bounds);
4142 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4143 expect(Ok, status);
4144 expect(2, glyphs);
4145 expect(1, lines);
4146 expectf(0.0, bounds.X);
4147 expectf(0.0, bounds.Y);
4148 expectf_(width_2, bounds.Width, 0.01);
4149 expectf(height, bounds.Height);
4151 set_rect_empty(&rect);
4152 rect.Height = height;
4153 rect.Width = width_2 - 0.05;
4154 set_rect_empty(&bounds);
4155 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4156 expect(Ok, status);
4157 expect(1, glyphs);
4158 expect(1, lines);
4159 expectf(0.0, bounds.X);
4160 expectf(0.0, bounds.Y);
4161 expectf_(width_1, bounds.Width, 0.01);
4162 expectf(height, bounds.Height);
4164 /* Default (Near) alignment */
4165 rect.X = 5.0;
4166 rect.Y = 5.0;
4167 rect.Width = width * 2.0;
4168 rect.Height = height * 2.0;
4169 set_rect_empty(&bounds);
4170 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4171 expect(Ok, status);
4172 expect(3, glyphs);
4173 expect(1, lines);
4174 expectf(5.0, bounds.X);
4175 expectf(5.0, bounds.Y);
4176 expectf_(width, bounds.Width, 0.01);
4177 expectf(height, bounds.Height);
4179 rect.X = 5.0;
4180 rect.Y = 5.0;
4181 rect.Width = 32000.0;
4182 rect.Height = 32000.0;
4183 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4184 expect(Ok, status);
4185 set_rect_empty(&bounds);
4186 status = GdipGetRegionBounds(region, graphics, &bounds);
4187 expect(Ok, status);
4188 expectf_(5.0 + margin_x, bounds.X, 1.0);
4189 expectf(5.0, bounds.Y);
4190 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4191 todo_wine
4192 expectf_(height - margin_y, bounds.Height, 1.0);
4194 width_rgn = bounds.Width;
4195 height_rgn = bounds.Height;
4197 /* Center alignment */
4198 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4199 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4201 rect.X = 5.0;
4202 rect.Y = 5.0;
4203 rect.Width = width * 2.0;
4204 rect.Height = height * 2.0;
4205 set_rect_empty(&bounds);
4206 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4207 expect(Ok, status);
4208 expect(3, glyphs);
4209 expect(1, lines);
4210 todo_wine
4211 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4212 todo_wine
4213 expectf(5.0 + height/2.0, bounds.Y);
4214 expectf_(width, bounds.Width, 0.01);
4215 expectf(height, bounds.Height);
4217 rect.X = 5.0;
4218 rect.Y = 5.0;
4219 rect.Width = 0.0;
4220 rect.Height = 0.0;
4221 set_rect_empty(&bounds);
4222 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4223 expect(Ok, status);
4224 expect(3, glyphs);
4225 expect(1, lines);
4226 todo_wine
4227 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4228 todo_wine
4229 expectf(5.0 - height/2.0, bounds.Y);
4230 expectf_(width, bounds.Width, 0.01);
4231 expectf(height, bounds.Height);
4233 rect.X = 5.0;
4234 rect.Y = 5.0;
4235 rect.Width = width_rgn * 2.0;
4236 rect.Height = height_rgn * 2.0;
4237 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4238 expect(Ok, status);
4239 set_rect_empty(&bounds);
4240 status = GdipGetRegionBounds(region, graphics, &bounds);
4241 expect(Ok, status);
4242 todo_wine
4243 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4244 todo_wine
4245 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4246 expectf_(width_rgn, bounds.Width, 1.0);
4247 expectf_(height_rgn, bounds.Height, 1.0);
4249 rect.X = 5.0;
4250 rect.Y = 5.0;
4251 rect.Width = 0.0;
4252 rect.Height = 0.0;
4253 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4254 expect(Ok, status);
4255 set_rect_empty(&bounds);
4256 status = GdipGetRegionBounds(region, graphics, &bounds);
4257 expect(Ok, status);
4258 todo_wine
4259 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4260 todo_wine
4261 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4262 expectf_(width_rgn, bounds.Width, 1.0);
4263 expectf_(height_rgn, bounds.Height, 1.0);
4265 /* Far alignment */
4266 GdipSetStringFormatAlign(format, StringAlignmentFar);
4267 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4269 rect.X = 5.0;
4270 rect.Y = 5.0;
4271 rect.Width = width * 2.0;
4272 rect.Height = height * 2.0;
4273 set_rect_empty(&bounds);
4274 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4275 expect(Ok, status);
4276 expect(3, glyphs);
4277 expect(1, lines);
4278 todo_wine
4279 expectf_(5.0 + width, bounds.X, 0.01);
4280 todo_wine
4281 expectf(5.0 + height, bounds.Y);
4282 expectf_(width, bounds.Width, 0.01);
4283 expectf(height, bounds.Height);
4285 rect.X = 5.0;
4286 rect.Y = 5.0;
4287 rect.Width = 0.0;
4288 rect.Height = 0.0;
4289 set_rect_empty(&bounds);
4290 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4291 expect(Ok, status);
4292 expect(3, glyphs);
4293 expect(1, lines);
4294 todo_wine
4295 expectf_(5.0 - width, bounds.X, 0.01);
4296 todo_wine
4297 expectf(5.0 - height, bounds.Y);
4298 expectf_(width, bounds.Width, 0.01);
4299 expectf(height, bounds.Height);
4301 rect.X = 5.0;
4302 rect.Y = 5.0;
4303 rect.Width = width_rgn * 2.0;
4304 rect.Height = height_rgn * 2.0;
4305 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4306 expect(Ok, status);
4307 set_rect_empty(&bounds);
4308 status = GdipGetRegionBounds(region, graphics, &bounds);
4309 expect(Ok, status);
4310 todo_wine
4311 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4312 todo_wine
4313 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4314 expectf_(width_rgn, bounds.Width, 1.0);
4315 expectf_(height_rgn, bounds.Height, 1.0);
4317 rect.X = 5.0;
4318 rect.Y = 5.0;
4319 rect.Width = 0.0;
4320 rect.Height = 0.0;
4321 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4322 expect(Ok, status);
4323 set_rect_empty(&bounds);
4324 status = GdipGetRegionBounds(region, graphics, &bounds);
4325 expect(Ok, status);
4326 todo_wine
4327 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4328 todo_wine
4329 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4330 expectf_(width_rgn, bounds.Width, 1.0);
4331 expectf_(height_rgn, bounds.Height, 1.0);
4333 status = GdipDeleteFont(font);
4334 expect(Ok, status);
4336 status = GdipDeleteGraphics(graphics);
4337 expect(Ok, status);
4338 DeleteDC(hdc);
4340 GdipDeleteFontFamily(family);
4341 GdipDeleteRegion(region);
4342 GdipDeleteStringFormat(format);
4345 static void test_measured_extra_space(void)
4347 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4348 static const WCHAR string[2] = { 'W','W' };
4349 GpStringFormat *format;
4350 HDC hdc;
4351 GpGraphics *graphics;
4352 GpFontFamily *family;
4353 GpFont *font;
4354 GpStatus status;
4355 GpUnit gfx_unit, font_unit;
4356 RectF bounds_1, bounds_2, rect;
4357 REAL margin, font_size, dpi;
4359 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4360 expect(Ok, status);
4362 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4363 expect(Ok, status);
4364 hdc = CreateCompatibleDC(0);
4365 status = GdipCreateFromHDC(hdc, &graphics);
4366 expect(Ok, status);
4368 status = GdipGetDpiX(graphics, &dpi);
4369 expect(Ok, status);
4371 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4372 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4373 for (font_unit = 3; font_unit <= 6; font_unit++)
4375 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4376 expect(Ok, status);
4378 status = GdipGetFontSize(font, &font_size);
4379 expect(Ok, status);
4380 font_size = units_to_pixels(font_size, font_unit, dpi);
4381 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4383 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4384 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4386 status = GdipSetPageUnit(graphics, gfx_unit);
4387 expect(Ok, status);
4389 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4390 set_rect_empty(&rect);
4391 set_rect_empty(&bounds_1);
4392 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4393 expect(Ok, status);
4394 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4395 set_rect_empty(&rect);
4396 set_rect_empty(&bounds_2);
4397 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4398 expect(Ok, status);
4400 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4401 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4402 /*trace("margin %f pixels\n", margin);*/
4403 expectf_(font_size / 6.0, margin, font_size / 100.0);
4406 GdipDeleteFont(font);
4409 GdipDeleteGraphics(graphics);
4410 DeleteDC(hdc);
4411 GdipDeleteFontFamily(family);
4412 GdipDeleteStringFormat(format);
4415 static void test_alpha_hdc(void)
4417 GpStatus status;
4418 HDC hdc;
4419 HBITMAP hbm, old_hbm;
4420 GpGraphics *graphics;
4421 ULONG *bits;
4422 BITMAPINFO bmi;
4423 GpRectF bounds;
4425 hdc = CreateCompatibleDC(0);
4426 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4427 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4428 bmi.bmiHeader.biHeight = 5;
4429 bmi.bmiHeader.biWidth = 5;
4430 bmi.bmiHeader.biBitCount = 32;
4431 bmi.bmiHeader.biPlanes = 1;
4432 bmi.bmiHeader.biCompression = BI_RGB;
4433 bmi.bmiHeader.biClrUsed = 0;
4435 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4436 ok(hbm != NULL, "CreateDIBSection failed\n");
4438 old_hbm = SelectObject(hdc, hbm);
4440 status = GdipCreateFromHDC(hdc, &graphics);
4441 expect(Ok, status);
4443 status = GdipGetVisibleClipBounds(graphics, &bounds);
4444 expect(Ok, status);
4445 expectf(0.0, bounds.X);
4446 expectf(0.0, bounds.Y);
4447 expectf(5.0, bounds.Width);
4448 expectf(5.0, bounds.Height);
4450 bits[0] = 0xdeadbeef;
4452 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4453 expect(Ok, status);
4455 expect(0xffaaaaaa, bits[0]);
4457 SelectObject(hdc, old_hbm);
4459 bits[0] = 0xdeadbeef;
4461 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4462 expect(Ok, status);
4464 todo_wine expect(0xffbbbbbb, bits[0]);
4466 GdipDeleteGraphics(graphics);
4468 DeleteObject(hbm);
4469 DeleteDC(hdc);
4472 static void test_bitmapfromgraphics(void)
4474 GpStatus stat;
4475 GpGraphics *graphics = NULL;
4476 HDC hdc = GetDC( hwnd );
4477 GpBitmap *bitmap = NULL;
4478 PixelFormat format;
4479 REAL imageres, graphicsres;
4480 UINT width, height;
4482 stat = GdipCreateFromHDC(hdc, &graphics);
4483 expect(Ok, stat);
4485 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
4486 expect(InvalidParameter, stat);
4488 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
4489 expect(InvalidParameter, stat);
4491 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
4492 expect(Ok, stat);
4494 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
4495 expect(Ok, stat);
4496 expect(PixelFormat32bppPARGB, format);
4498 stat = GdipGetDpiX(graphics, &graphicsres);
4499 expect(Ok, stat);
4501 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
4502 expect(Ok, stat);
4503 expectf(graphicsres, imageres);
4505 stat = GdipGetDpiY(graphics, &graphicsres);
4506 expect(Ok, stat);
4508 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
4509 expect(Ok, stat);
4510 expectf(graphicsres, imageres);
4512 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
4513 expect(Ok, stat);
4514 expect(12, width);
4516 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
4517 expect(Ok, stat);
4518 expect(13, height);
4520 GdipDeleteGraphics(graphics);
4521 GdipDisposeImage((GpImage*)bitmap);
4524 static void test_clipping(void)
4526 HDC hdc;
4527 GpStatus status;
4528 GpGraphics *graphics;
4529 GpRegion *region, *region100x100;
4530 GpMatrix *matrix;
4531 GpRectF rect;
4532 GpPointF ptf[4];
4533 GpUnit unit;
4534 HRGN hrgn;
4535 int ret;
4536 RECT rc;
4538 hdc = CreateCompatibleDC(0);
4539 status = GdipCreateFromHDC(hdc, &graphics);
4540 expect(Ok, status);
4542 status = GdipGetPageUnit(graphics, &unit);
4543 expect(Ok, status);
4544 expect(UnitDisplay, unit);
4546 status = GdipCreateRegion(&region);
4547 expect(Ok, status);
4548 status = GdipSetEmpty(region);
4549 expect(Ok, status);
4551 status = GdipCreateRegion(&region100x100);
4552 expect(Ok, status);
4553 status = GdipSetEmpty(region100x100);
4554 expect(Ok, status);
4556 rect.X = rect.Y = 100.0;
4557 rect.Width = rect.Height = 100.0;
4558 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
4559 expect(Ok, status);
4560 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
4561 expect(Ok, status);
4563 status = GdipGetClipBounds(graphics, &rect);
4564 expect(Ok, status);
4565 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4566 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4568 status = GdipSetEmpty(region);
4569 expect(Ok, status);
4570 status = GdipGetClip(graphics, region);
4571 expect(Ok, status);
4572 status = GdipGetRegionBounds(region, graphics, &rect);
4573 expect(Ok, status);
4574 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4575 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4577 ptf[0].X = 100.0;
4578 ptf[0].Y = 100.0;
4579 ptf[1].X = 200.0;
4580 ptf[1].Y = 200.0;
4581 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4582 expect(Ok, status);
4583 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4584 "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);
4586 status = GdipCreateMatrix(&matrix);
4587 expect(Ok, status);
4588 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
4589 expect(Ok, status);
4590 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
4591 expect(Ok, status);
4592 status = GdipSetWorldTransform(graphics, matrix);
4593 expect(Ok, status);
4595 status = GdipGetClipBounds(graphics, &rect);
4596 expect(Ok, status);
4597 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4598 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4600 status = GdipSetEmpty(region);
4601 expect(Ok, status);
4602 status = GdipGetClip(graphics, region);
4603 expect(Ok, status);
4604 status = GdipGetRegionBounds(region, graphics, &rect);
4605 expect(Ok, status);
4606 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4607 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4609 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4610 expect(Ok, status);
4611 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4612 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4614 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4615 expect(Ok, status);
4616 ret = GetRgnBox(hrgn, &rc);
4617 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4618 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4619 "expected 45,20-95,45, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4620 DeleteObject(hrgn);
4622 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4623 expect(Ok, status);
4624 ret = GetRgnBox(hrgn, &rc);
4625 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4626 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4627 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4628 DeleteObject(hrgn);
4630 ptf[0].X = 100.0;
4631 ptf[0].Y = 100.0;
4632 ptf[1].X = 200.0;
4633 ptf[1].Y = 200.0;
4634 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4635 expect(Ok, status);
4636 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4637 "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);
4639 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4640 expect(Ok, status);
4641 ret = GetRgnBox(hrgn, &rc);
4642 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4643 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4644 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4645 DeleteObject(hrgn);
4647 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4648 expect(Ok, status);
4649 ret = GetRgnBox(hrgn, &rc);
4650 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4651 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4652 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4653 DeleteObject(hrgn);
4655 ptf[0].X = 210.0;
4656 ptf[0].Y = 420.0;
4657 ptf[1].X = 410.0;
4658 ptf[1].Y = 820.0;
4659 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4660 expect(Ok, status);
4661 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4662 "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);
4664 status = GdipSetPageScale(graphics, 2.0);
4665 expect(Ok, status);
4667 status = GdipGetClipBounds(graphics, &rect);
4668 expect(Ok, status);
4669 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4670 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4672 status = GdipSetEmpty(region);
4673 expect(Ok, status);
4674 status = GdipGetClip(graphics, region);
4675 expect(Ok, status);
4676 status = GdipGetRegionBounds(region, graphics, &rect);
4677 expect(Ok, status);
4678 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4679 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4681 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4682 expect(Ok, status);
4683 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4684 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4686 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4687 expect(Ok, status);
4688 ret = GetRgnBox(hrgn, &rc);
4689 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4690 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4691 "expected 45,20-95,45, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4692 DeleteObject(hrgn);
4694 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4695 expect(Ok, status);
4696 ret = GetRgnBox(hrgn, &rc);
4697 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4698 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4699 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4700 DeleteObject(hrgn);
4702 ptf[0].X = 100.0;
4703 ptf[0].Y = 100.0;
4704 ptf[1].X = 200.0;
4705 ptf[1].Y = 200.0;
4706 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4707 expect(Ok, status);
4708 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4709 "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);
4711 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4712 expect(Ok, status);
4713 ret = GetRgnBox(hrgn, &rc);
4714 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4715 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4716 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4717 DeleteObject(hrgn);
4719 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4720 expect(Ok, status);
4721 ret = GetRgnBox(hrgn, &rc);
4722 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4723 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4724 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4725 DeleteObject(hrgn);
4727 ptf[0].X = 210.0;
4728 ptf[0].Y = 420.0;
4729 ptf[1].X = 410.0;
4730 ptf[1].Y = 820.0;
4731 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4732 expect(Ok, status);
4733 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4734 "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);
4736 GdipSetPageUnit(graphics, UnitPoint);
4737 expect(Ok, status);
4739 status = GdipGetClipBounds(graphics, &rect);
4740 expect(Ok, status);
4741 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4742 /* rounding under Wine is slightly different */
4743 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4744 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4745 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4747 status = GdipSetEmpty(region);
4748 expect(Ok, status);
4749 status = GdipGetClip(graphics, region);
4750 expect(Ok, status);
4751 status = GdipGetRegionBounds(region, graphics, &rect);
4752 expect(Ok, status);
4753 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4754 /* rounding under Wine is slightly different */
4755 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4756 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4757 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4759 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4760 expect(Ok, status);
4761 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4762 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4764 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4765 expect(Ok, status);
4766 ret = GetRgnBox(hrgn, &rc);
4767 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4768 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
4769 /* rounding under Wine is slightly different */
4770 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
4771 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
4772 "expected 14,5-33,14, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4773 DeleteObject(hrgn);
4775 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4776 expect(Ok, status);
4777 ret = GetRgnBox(hrgn, &rc);
4778 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4779 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
4780 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
4781 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4782 DeleteObject(hrgn);
4784 ptf[0].X = 100.0;
4785 ptf[0].Y = 100.0;
4786 ptf[1].X = 200.0;
4787 ptf[1].Y = 200.0;
4788 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4789 expect(Ok, status);
4790 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
4791 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
4792 "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);
4794 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4795 expect(Ok, status);
4796 ret = GetRgnBox(hrgn, &rc);
4797 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4798 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4799 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4800 DeleteObject(hrgn);
4802 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4803 expect(Ok, status);
4804 ret = GetRgnBox(hrgn, &rc);
4805 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4806 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
4807 /* rounding under Wine is slightly different */
4808 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
4809 "expected 560,1120-1094,2187, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4810 DeleteObject(hrgn);
4812 ptf[0].X = 560.0;
4813 ptf[0].Y = 1120.0;
4814 ptf[1].X = 1094.0;
4815 ptf[1].Y = 2187.0;
4816 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4817 expect(Ok, status);
4818 if (fabs(ptf[0].X - 100.0) < 0.001)
4820 expectf(100.0, ptf[0].X);
4821 expectf(100.0, ptf[0].Y);
4822 expectf(200.125, ptf[1].X);
4823 expectf(200.03125, ptf[1].Y);
4825 else /* before Win7 */
4827 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
4828 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
4829 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
4830 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
4833 status = GdipTransformRegion(region100x100, matrix);
4834 expect(Ok, status);
4836 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4837 expect(Ok, status);
4838 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
4839 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4841 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4842 expect(Ok, status);
4843 ret = GetRgnBox(hrgn, &rc);
4844 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4845 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4846 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4847 DeleteObject(hrgn);
4849 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4850 expect(Ok, status);
4851 ret = GetRgnBox(hrgn, &rc);
4852 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4853 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
4854 /* rounding under Wine is slightly different */
4855 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
4856 "expected 1147,4534-2214,8800, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4857 DeleteObject(hrgn);
4859 ptf[0].X = 1147.0;
4860 ptf[0].Y = 4534.0;
4861 ptf[1].X = 2214.0;
4862 ptf[1].Y = 8800.0;
4863 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4864 expect(Ok, status);
4865 if (fabs(ptf[0].X - 210.0625) < 0.001)
4867 expectf(210.0625, ptf[0].X);
4868 expectf(420.0625, ptf[0].Y);
4869 expectf(410.125, ptf[1].X);
4870 expectf(820.0, ptf[1].Y);
4872 else /* before Win7 */
4874 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
4875 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
4876 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
4877 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
4880 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
4881 expect(Ok, status);
4882 status = GdipSetWorldTransform(graphics, matrix);
4883 expect(Ok, status);
4885 status = GdipGetClipBounds(graphics, &rect);
4886 expect(Ok, status);
4887 expectf_(20.612978, rect.X, 1.0);
4888 expectf_(-6.256012, rect.Y, 1.5);
4889 expectf_(25.612978, rect.Width, 1.0);
4890 expectf_(12.806489, rect.Height, 1.0);
4892 status = GdipSetEmpty(region);
4893 expect(Ok, status);
4894 status = GdipGetClip(graphics, region);
4895 expect(Ok, status);
4896 status = GdipGetRegionBounds(region, graphics, &rect);
4897 expect(Ok, status);
4898 /* rounding under Wine is slightly different */
4899 expectf_(20.612978, rect.X, 1.0);
4900 expectf_(-6.256012, rect.Y, 1.5);
4901 expectf_(25.612978, rect.Width, 1.0);
4902 expectf_(12.806489, rect.Height, 1.0);
4904 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4905 expect(Ok, status);
4906 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
4907 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4909 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4910 expect(Ok, status);
4911 ret = GetRgnBox(hrgn, &rc);
4912 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
4913 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
4914 /* rounding under Wine is slightly different */
4915 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
4916 "expected (22,-6)-(46,7), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4917 DeleteObject(hrgn);
4919 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4920 expect(Ok, status);
4921 ret = GetRgnBox(hrgn, &rc);
4922 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4923 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4924 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4925 DeleteObject(hrgn);
4927 ptf[0].X = 100.0;
4928 ptf[0].Y = 100.0;
4929 ptf[1].X = 200.0;
4930 ptf[1].Y = 200.0;
4931 ptf[2].X = 200.0;
4932 ptf[2].Y = 100.0;
4933 ptf[3].X = 100.0;
4934 ptf[3].Y = 200.0;
4935 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
4936 expect(Ok, status);
4937 expectf(20.612978, ptf[0].X);
4938 expectf(-1.568512, ptf[0].Y);
4939 expectf(46.225956, ptf[1].X);
4940 expectf(1.862977, ptf[1].Y);
4941 expectf(36.850956, ptf[2].X);
4942 expectf(-6.256012, ptf[2].Y);
4943 expectf(29.987980, ptf[3].X);
4944 expectf(6.550478, ptf[3].Y);
4946 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4947 expect(Ok, status);
4948 ret = GetRgnBox(hrgn, &rc);
4949 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4950 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4951 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4952 DeleteObject(hrgn);
4954 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4955 expect(Ok, status);
4956 ret = GetRgnBox(hrgn, &rc);
4957 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
4958 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
4959 /* rounding under Wine is slightly different */
4960 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
4961 "expected (-3406,4500)-(-350,8728), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4962 DeleteObject(hrgn);
4964 ptf[0].X = -3406.0;
4965 ptf[0].Y = 4500.0;
4966 ptf[1].X = -350.0;
4967 ptf[1].Y = 8728.0;
4968 ptf[2].X = -350.0;
4969 ptf[2].Y = 4500.0;
4970 ptf[3].X = -3406.0;
4971 ptf[3].Y = 8728.0;
4972 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
4973 expect(Ok, status);
4974 expectf(-136.190491, ptf[0].X);
4975 expectf(520.010742, ptf[0].Y);
4976 expectf(756.417175, ptf[1].X);
4977 expectf(720.031616, ptf[1].Y);
4978 expectf(360.042114, ptf[2].X);
4979 expectf(376.760742, ptf[2].Y);
4980 expectf(260.184570, ptf[3].X);
4981 expectf(863.281616, ptf[3].Y);
4983 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
4984 expect(Ok, status);
4985 status = GdipSetWorldTransform(graphics, matrix);
4986 expect(Ok, status);
4988 status = GdipGetClipBounds(graphics, &rect);
4989 expect(Ok, status);
4990 expectf_(-28.100956, rect.X, 1.0);
4991 expectf_(7.806488, rect.Y, 1.5);
4992 expectf_(25.612978, rect.Width, 1.0);
4993 expectf_(12.806489, rect.Height, 1.0);
4995 status = GdipSetEmpty(region);
4996 expect(Ok, status);
4997 status = GdipGetClip(graphics, region);
4998 expect(Ok, status);
4999 status = GdipGetRegionBounds(region, graphics, &rect);
5000 expect(Ok, status);
5001 /* rounding under Wine is slightly different */
5002 expectf_(-28.100956, rect.X, 1.0);
5003 expectf_(7.806488, rect.Y, 1.5);
5004 expectf_(25.612978, rect.Width, 1.0);
5005 expectf_(12.806489, rect.Height, 1.0);
5007 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5008 expect(Ok, status);
5009 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5010 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5012 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5013 expect(Ok, status);
5014 ret = GetRgnBox(hrgn, &rc);
5015 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5016 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5017 /* rounding under Wine is slightly different */
5018 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5019 "expected (-27,8)-(-2,21), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5020 DeleteObject(hrgn);
5022 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5023 expect(Ok, status);
5024 ret = GetRgnBox(hrgn, &rc);
5025 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5026 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5027 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5028 DeleteObject(hrgn);
5030 ptf[0].X = 100.0;
5031 ptf[0].Y = 100.0;
5032 ptf[1].X = 200.0;
5033 ptf[1].Y = 200.0;
5034 ptf[2].X = 200.0;
5035 ptf[2].Y = 100.0;
5036 ptf[3].X = 100.0;
5037 ptf[3].Y = 200.0;
5038 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5039 expect(Ok, status);
5040 expectf(-11.862979, ptf[0].X);
5041 expectf(7.806488, ptf[0].Y);
5042 expectf(-18.725958, ptf[1].X);
5043 expectf(20.612976, ptf[1].Y);
5044 expectf(-2.487981, ptf[2].X);
5045 expectf(15.925477, ptf[2].Y);
5046 expectf(-28.100956, ptf[3].X);
5047 expectf(12.493987, ptf[3].Y);
5049 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5050 expect(Ok, status);
5051 ret = GetRgnBox(hrgn, &rc);
5052 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5053 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5054 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5055 DeleteObject(hrgn);
5057 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5058 expect(Ok, status);
5059 ret = GetRgnBox(hrgn, &rc);
5060 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5061 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5062 /* rounding under Wine is slightly different */
5063 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5064 "expected (4500,351)-(8728,3407), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5065 DeleteObject(hrgn);
5067 ptf[0].X = -3406.0;
5068 ptf[0].Y = 4500.0;
5069 ptf[1].X = -350.0;
5070 ptf[1].Y = 8728.0;
5071 ptf[2].X = -350.0;
5072 ptf[2].Y = 4500.0;
5073 ptf[3].X = -3406.0;
5074 ptf[3].Y = 8728.0;
5075 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5076 expect(Ok, status);
5077 expectf(-1055.021484, ptf[0].X);
5078 expectf(-70.595329, ptf[0].Y);
5079 expectf(-1455.063232, ptf[1].X);
5080 expectf(375.708435, ptf[1].Y);
5081 expectf(-768.521484, ptf[2].X);
5082 expectf(177.520981, ptf[2].Y);
5083 expectf(-1741.563110, ptf[3].X);
5084 expectf(127.592125, ptf[3].Y);
5086 GdipDeleteMatrix(matrix);
5087 GdipDeleteRegion(region);
5088 GdipDeleteRegion(region100x100);
5089 GdipDeleteGraphics(graphics);
5090 DeleteDC(hdc);
5093 static void test_clipping_2(void)
5096 HDC hdc;
5097 GpStatus status;
5098 GpGraphics *graphics;
5099 GpRegion *region;
5100 GpMatrix *matrix;
5101 GpRectF rect;
5102 GpPointF ptf[4];
5103 GpUnit unit;
5104 HRGN hrgn;
5105 int ret;
5106 RECT rc;
5108 hdc = CreateCompatibleDC(0);
5109 status = GdipCreateFromHDC(hdc, &graphics);
5110 expect(Ok, status);
5112 status = GdipGetPageUnit(graphics, &unit);
5113 expect(Ok, status);
5114 expect(UnitDisplay, unit);
5116 GdipSetPageUnit(graphics, UnitInch);
5118 status = GdipCreateRegion(&region);
5119 expect(Ok, status);
5120 status = GdipSetEmpty(region);
5121 expect(Ok, status);
5122 rect.X = rect.Y = 100.0;
5123 rect.Width = rect.Height = 100.0;
5124 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5125 expect(Ok, status);
5126 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5127 expect(Ok, status);
5129 status = GdipGetClip(graphics, region);
5130 expect(Ok, status);
5131 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5132 expect(Ok, status);
5133 ret = GetRgnBox(hrgn, &rc);
5134 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5135 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5136 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5137 DeleteObject(hrgn);
5138 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5139 expect(Ok, status);
5140 ret = GetRgnBox(hrgn, &rc);
5141 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5142 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5143 "expected 9600,9600-19200,19200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5144 DeleteObject(hrgn);
5146 ptf[0].X = 9600.0;
5147 ptf[0].Y = 9600.0;
5148 ptf[1].X = 19200.0;
5149 ptf[1].Y = 19200.0;
5150 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5151 expect(Ok, status);
5152 expectf(100.0, ptf[0].X);
5153 expectf(100.0, ptf[0].Y);
5154 expectf(200.0, ptf[1].X);
5155 expectf(200.0, ptf[1].X);
5157 GdipSetPageUnit(graphics, UnitPoint);
5159 status = GdipGetClip(graphics, region);
5160 expect(Ok, status);
5161 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5162 expect(Ok, status);
5163 ret = GetRgnBox(hrgn, &rc);
5164 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5165 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5166 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5167 "expected 7200,7200-14400,14400, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5168 DeleteObject(hrgn);
5169 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5170 expect(Ok, status);
5171 ret = GetRgnBox(hrgn, &rc);
5172 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5173 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5174 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5175 "expected 9600,9600-19200,19200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5176 DeleteObject(hrgn);
5178 ptf[0].X = 9600.0;
5179 ptf[0].Y = 9600.0;
5180 ptf[1].X = 19200.0;
5181 ptf[1].Y = 19200.0;
5182 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5183 expect(Ok, status);
5184 if (fabs(ptf[0].X - 7200.0) < 0.001)
5185 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5186 "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);
5187 else /* before Win7 */
5189 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5190 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5191 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5192 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5195 GdipDeleteRegion(region);
5197 GdipSetPageUnit(graphics, UnitPixel);
5199 status = GdipCreateRegion(&region);
5200 expect(Ok, status);
5201 status = GdipSetEmpty(region);
5202 expect(Ok, status);
5203 rect.X = rect.Y = 100.0;
5204 rect.Width = rect.Height = 100.0;
5205 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5206 expect(Ok, status);
5207 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5208 expect(Ok, status);
5210 status = GdipGetClip(graphics, region);
5211 expect(Ok, status);
5212 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5213 expect(Ok, status);
5214 ret = GetRgnBox(hrgn, &rc);
5215 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5216 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5217 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5218 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5219 DeleteObject(hrgn);
5220 status = GdipGetRegionHRgn(region, graphics, &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);
5229 ptf[0].X = 100.0;
5230 ptf[0].Y = 100.0;
5231 ptf[1].X = 200.0;
5232 ptf[1].Y = 200.0;
5233 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5234 expect(Ok, status);
5235 if (fabs(ptf[0].X - 100.0) < 0.001)
5236 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5237 "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);
5238 else /* before Win7 */
5240 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5241 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5242 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5243 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5246 GdipSetPageUnit(graphics, UnitPoint);
5248 status = GdipGetClip(graphics, region);
5249 expect(Ok, status);
5250 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5251 expect(Ok, status);
5252 ret = GetRgnBox(hrgn, &rc);
5253 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5254 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5255 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5256 "expected 75,75-150,150, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5257 DeleteObject(hrgn);
5258 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5259 expect(Ok, status);
5260 ret = GetRgnBox(hrgn, &rc);
5261 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5262 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5263 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5264 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5265 DeleteObject(hrgn);
5267 ptf[0].X = 100.0;
5268 ptf[0].Y = 100.0;
5269 ptf[1].X = 200.0;
5270 ptf[1].Y = 200.0;
5271 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5272 expect(Ok, status);
5273 if (fabs(ptf[0].X - 75.0) < 0.001)
5274 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5275 "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);
5276 else /* before Win7 */
5278 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5279 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5280 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5281 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5284 status = GdipCreateMatrix(&matrix);
5285 expect(Ok, status);
5286 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5287 expect(Ok, status);
5288 status = GdipSetWorldTransform(graphics, matrix);
5289 expect(Ok, status);
5290 GdipDeleteMatrix(matrix);
5292 status = GdipGetClip(graphics, region);
5293 expect(Ok, status);
5294 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5295 expect(Ok, status);
5296 ret = GetRgnBox(hrgn, &rc);
5297 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5298 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5299 "expected 65,65-140,140, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5300 DeleteObject(hrgn);
5301 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5302 expect(Ok, status);
5303 ret = GetRgnBox(hrgn, &rc);
5304 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5305 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5306 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5307 DeleteObject(hrgn);
5309 ptf[0].X = 100.0;
5310 ptf[0].Y = 100.0;
5311 ptf[1].X = 200.0;
5312 ptf[1].Y = 200.0;
5313 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5314 expect(Ok, status);
5315 expectf(65.0, ptf[0].X);
5316 expectf(65.0, ptf[0].Y);
5317 expectf(140.0, ptf[1].X);
5318 expectf(140.0, ptf[1].X);
5320 status = GdipCreateMatrix(&matrix);
5321 expect(Ok, status);
5322 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5323 expect(Ok, status);
5324 status = GdipSetWorldTransform(graphics, matrix);
5325 expect(Ok, status);
5326 GdipDeleteMatrix(matrix);
5328 status = GdipGetClip(graphics, region);
5329 expect(Ok, status);
5330 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5331 expect(Ok, status);
5332 ret = GetRgnBox(hrgn, &rc);
5333 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5334 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5335 "expected 300,150-600,300, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5336 DeleteObject(hrgn);
5337 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5338 expect(Ok, status);
5339 ret = GetRgnBox(hrgn, &rc);
5340 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5341 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5342 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5343 DeleteObject(hrgn);
5345 ptf[0].X = 100.0;
5346 ptf[0].Y = 100.0;
5347 ptf[1].X = 200.0;
5348 ptf[1].Y = 200.0;
5349 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5350 expect(Ok, status);
5351 expectf(300.0, ptf[0].X);
5352 expectf(150.0, ptf[0].Y);
5353 expectf(600.0, ptf[1].X);
5354 expectf(300.0, ptf[1].Y);
5356 status = GdipSetPageScale(graphics, 2.0);
5357 expect(Ok, status);
5359 status = GdipGetClip(graphics, region);
5360 expect(Ok, status);
5361 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5362 expect(Ok, status);
5363 ret = GetRgnBox(hrgn, &rc);
5364 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5365 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5366 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5367 "expected 150,75-300,150, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5368 DeleteObject(hrgn);
5369 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5370 expect(Ok, status);
5371 ret = GetRgnBox(hrgn, &rc);
5372 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5373 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5374 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5375 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5376 DeleteObject(hrgn);
5378 ptf[0].X = 100.0;
5379 ptf[0].Y = 100.0;
5380 ptf[1].X = 200.0;
5381 ptf[1].Y = 200.0;
5382 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5383 expect(Ok, status);
5384 if (fabs(ptf[0].X - 150.0) < 0.001)
5386 expectf(150.0, ptf[0].X);
5387 expectf(75.0, ptf[0].Y);
5388 expectf(300.0, ptf[1].X);
5389 expectf(150.0, ptf[1].Y);
5391 else /* before Win7 */
5393 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5394 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5395 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5396 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5399 status = GdipCreateMatrix(&matrix);
5400 expect(Ok, status);
5401 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5402 expect(Ok, status);
5403 status = GdipSetWorldTransform(graphics, matrix);
5404 expect(Ok, status);
5405 GdipDeleteMatrix(matrix);
5407 status = GdipGetClip(graphics, region);
5408 expect(Ok, status);
5409 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5410 expect(Ok, status);
5411 ret = GetRgnBox(hrgn, &rc);
5412 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5413 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5414 /* rounding under Wine is slightly different */
5415 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5416 "expected 54,-26-107,27, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5417 DeleteObject(hrgn);
5418 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5419 expect(Ok, status);
5420 ret = GetRgnBox(hrgn, &rc);
5421 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5422 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5423 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5424 DeleteObject(hrgn);
5426 ptf[0].X = 100.0;
5427 ptf[0].Y = 100.0;
5428 ptf[1].X = 200.0;
5429 ptf[1].Y = 200.0;
5430 ptf[2].X = 200.0;
5431 ptf[2].Y = 100.0;
5432 ptf[3].X = 100.0;
5433 ptf[3].Y = 200.0;
5434 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5435 expect(Ok, status);
5436 expectf(53.033016, ptf[0].X);
5437 expectf(0.0, ptf[0].Y);
5438 expectf(106.066032, ptf[1].X);
5439 expectf(0.0, ptf[1].Y);
5440 expectf(79.549522, ptf[2].X);
5441 expectf(-26.516510, ptf[2].Y);
5442 expectf(79.549522, ptf[3].X);
5443 expectf(26.516508, ptf[3].Y);
5445 status = GdipCreateMatrix(&matrix);
5446 expect(Ok, status);
5447 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5448 expect(Ok, status);
5449 status = GdipSetWorldTransform(graphics, matrix);
5450 expect(Ok, status);
5451 GdipDeleteMatrix(matrix);
5453 status = GdipGetClip(graphics, region);
5454 expect(Ok, status);
5455 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5456 expect(Ok, status);
5457 ret = GetRgnBox(hrgn, &rc);
5458 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5459 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
5460 /* rounding under Wine is slightly different */
5461 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
5462 "expected -26,54-27,107, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5463 DeleteObject(hrgn);
5464 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5465 expect(Ok, status);
5466 ret = GetRgnBox(hrgn, &rc);
5467 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5468 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5469 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5470 DeleteObject(hrgn);
5472 ptf[0].X = 100.0;
5473 ptf[0].Y = 100.0;
5474 ptf[1].X = 200.0;
5475 ptf[1].Y = 200.0;
5476 ptf[2].X = 200.0;
5477 ptf[2].Y = 100.0;
5478 ptf[3].X = 100.0;
5479 ptf[3].Y = 200.0;
5480 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5481 expect(Ok, status);
5482 expectf(0.0, ptf[0].X);
5483 expectf(53.033005, ptf[0].Y);
5484 expectf(0.0, ptf[1].X);
5485 expectf(106.066010, ptf[1].Y);
5486 expectf(26.516491, ptf[2].X);
5487 expectf(79.549507, ptf[2].Y);
5488 expectf(-26.516520, ptf[3].X);
5489 expectf(79.549500, ptf[3].Y);
5491 GdipDeleteRegion(region);
5492 GdipDeleteGraphics(graphics);
5493 DeleteDC(hdc);
5497 static void test_GdipFillRectangles(void)
5499 GpStatus status;
5500 GpGraphics *graphics = NULL;
5501 GpBrush *brush = NULL;
5502 HDC hdc = GetDC( hwnd );
5503 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
5505 ok(hdc != NULL, "Expected HDC to be initialized\n");
5507 status = GdipCreateFromHDC(hdc, &graphics);
5508 expect(Ok, status);
5509 ok(graphics != NULL, "Expected graphics to be initialized\n");
5511 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
5512 expect(Ok, status);
5513 ok(brush != NULL, "Expected brush to be initialized\n");
5515 status = GdipFillRectangles(NULL, brush, rects, 2);
5516 expect(InvalidParameter, status);
5518 status = GdipFillRectangles(graphics, NULL, rects, 2);
5519 expect(InvalidParameter, status);
5521 status = GdipFillRectangles(graphics, brush, NULL, 2);
5522 expect(InvalidParameter, status);
5524 status = GdipFillRectangles(graphics, brush, rects, 0);
5525 expect(InvalidParameter, status);
5527 status = GdipFillRectangles(graphics, brush, rects, -1);
5528 expect(InvalidParameter, status);
5530 status = GdipFillRectangles(graphics, brush, rects, 1);
5531 expect(Ok, status);
5533 status = GdipFillRectangles(graphics, brush, rects, 2);
5534 expect(Ok, status);
5536 GdipDeleteBrush(brush);
5537 GdipDeleteGraphics(graphics);
5539 ReleaseDC(hwnd, hdc);
5542 START_TEST(graphics)
5544 struct GdiplusStartupInput gdiplusStartupInput;
5545 ULONG_PTR gdiplusToken;
5546 WNDCLASSA class;
5548 memset( &class, 0, sizeof(class) );
5549 class.lpszClassName = "gdiplus_test";
5550 class.style = CS_HREDRAW | CS_VREDRAW;
5551 class.lpfnWndProc = DefWindowProcA;
5552 class.hInstance = GetModuleHandleA(0);
5553 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5554 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5555 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
5556 RegisterClassA( &class );
5557 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5558 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
5559 ok(hwnd != NULL, "Expected window to be created\n");
5561 gdiplusStartupInput.GdiplusVersion = 1;
5562 gdiplusStartupInput.DebugEventCallback = NULL;
5563 gdiplusStartupInput.SuppressBackgroundThread = 0;
5564 gdiplusStartupInput.SuppressExternalCodecs = 0;
5566 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
5568 test_clipping();
5569 test_clipping_2();
5570 test_measured_extra_space();
5571 test_measure_string();
5572 test_font_height_scaling();
5573 test_transform();
5574 test_GdipMeasureString();
5575 test_constructor_destructor();
5576 test_save_restore();
5577 test_GdipFillClosedCurve2();
5578 test_GdipFillClosedCurve2I();
5579 test_GdipDrawBezierI();
5580 test_GdipDrawArc();
5581 test_GdipDrawArcI();
5582 test_GdipDrawCurve();
5583 test_GdipDrawCurveI();
5584 test_GdipDrawCurve2();
5585 test_GdipDrawCurve2I();
5586 test_GdipDrawCurve3();
5587 test_GdipDrawCurve3I();
5588 test_GdipDrawLineI();
5589 test_GdipDrawLinesI();
5590 test_GdipDrawImagePointsRect();
5591 test_GdipFillClosedCurve();
5592 test_GdipFillClosedCurveI();
5593 test_GdipDrawString();
5594 test_GdipGetNearestColor();
5595 test_GdipGetVisibleClipBounds();
5596 test_GdipIsVisiblePoint();
5597 test_GdipIsVisibleRect();
5598 test_Get_Release_DC();
5599 test_BeginContainer2();
5600 test_transformpoints();
5601 test_get_set_clip();
5602 test_isempty();
5603 test_clear();
5604 test_textcontrast();
5605 test_fromMemoryBitmap();
5606 test_string_functions();
5607 test_get_set_interpolation();
5608 test_get_set_textrenderinghint();
5609 test_getdc_scaled();
5610 test_alpha_hdc();
5611 test_bitmapfromgraphics();
5612 test_GdipFillRectangles();
5614 GdiplusShutdown(gdiplusToken);
5615 DestroyWindow( hwnd );