vbscript: Added support for title and type arguments of MsgBox.
[wine.git] / dlls / gdiplus / tests / graphics.c
blobbd227dca89b7830978c50a22ba5bfa0eec3747a3
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, GpImage **image)
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);
121 *image = u.image;
123 status = GdipGetDpiX(graphics, &res);
124 expect(Ok, status);
125 expectf(res_x, res);
126 status = GdipGetDpiY(graphics, &res);
127 expect(Ok, status);
128 expectf(res_y, res);
130 status = GdipSetPageUnit(graphics, unit);
131 expect(Ok, status);
132 status = GdipSetPageScale(graphics, scale);
133 expect(Ok, status);
135 return graphics;
138 static void test_constructor_destructor(void)
140 GpStatus stat;
141 GpGraphics *graphics = NULL;
142 HDC hdc = GetDC( hwnd );
144 stat = GdipCreateFromHDC(NULL, &graphics);
145 expect(OutOfMemory, stat);
146 stat = GdipDeleteGraphics(graphics);
147 expect(InvalidParameter, stat);
149 stat = GdipCreateFromHDC(hdc, &graphics);
150 expect(Ok, stat);
151 stat = GdipDeleteGraphics(graphics);
152 expect(Ok, stat);
154 stat = GdipCreateFromHWND(NULL, &graphics);
155 expect(Ok, stat);
156 stat = GdipDeleteGraphics(graphics);
157 expect(Ok, stat);
159 stat = GdipCreateFromHWNDICM(NULL, &graphics);
160 expect(Ok, stat);
161 stat = GdipDeleteGraphics(graphics);
162 expect(Ok, stat);
164 stat = GdipDeleteGraphics(NULL);
165 expect(InvalidParameter, stat);
166 ReleaseDC(hwnd, hdc);
169 typedef struct node{
170 GraphicsState data;
171 struct node * next;
172 } node;
174 /* Linked list prepend function. */
175 static void log_state(GraphicsState data, node ** log)
177 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
179 new_entry->data = data;
180 new_entry->next = *log;
181 *log = new_entry;
184 /* Checks if there are duplicates in the list, and frees it. */
185 static void check_no_duplicates(node * log)
187 INT dups = 0;
188 node * temp = NULL;
189 node * temp2 = NULL;
190 node * orig = log;
192 if(!log)
193 goto end;
196 temp = log;
197 while((temp = temp->next)){
198 if(log->data == temp->data){
199 dups++;
200 break;
202 if(dups > 0)
203 break;
205 }while((log = log->next));
207 temp = orig;
209 temp2 = temp->next;
210 HeapFree(GetProcessHeap(), 0, temp);
211 temp = temp2;
212 }while(temp);
214 end:
215 expect(0, dups);
218 static void test_save_restore(void)
220 GpStatus stat;
221 GraphicsState state_a, state_b, state_c;
222 InterpolationMode mode;
223 GpGraphics *graphics1, *graphics2;
224 node * state_log = NULL;
225 HDC hdc = GetDC( hwnd );
226 state_a = state_b = state_c = 0xdeadbeef;
228 /* Invalid saving. */
229 GdipCreateFromHDC(hdc, &graphics1);
230 stat = GdipSaveGraphics(graphics1, NULL);
231 expect(InvalidParameter, stat);
232 stat = GdipSaveGraphics(NULL, &state_a);
233 expect(InvalidParameter, stat);
234 GdipDeleteGraphics(graphics1);
236 log_state(state_a, &state_log);
238 /* Basic save/restore. */
239 GdipCreateFromHDC(hdc, &graphics1);
240 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
241 stat = GdipSaveGraphics(graphics1, &state_a);
242 expect(Ok, stat);
243 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
244 stat = GdipRestoreGraphics(graphics1, state_a);
245 expect(Ok, stat);
246 GdipGetInterpolationMode(graphics1, &mode);
247 expect(InterpolationModeBilinear, mode);
248 GdipDeleteGraphics(graphics1);
250 log_state(state_a, &state_log);
252 /* Restoring garbage doesn't affect saves. */
253 GdipCreateFromHDC(hdc, &graphics1);
254 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
255 GdipSaveGraphics(graphics1, &state_a);
256 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
257 GdipSaveGraphics(graphics1, &state_b);
258 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
259 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
260 expect(Ok, stat);
261 GdipRestoreGraphics(graphics1, state_b);
262 GdipGetInterpolationMode(graphics1, &mode);
263 expect(InterpolationModeBicubic, mode);
264 GdipRestoreGraphics(graphics1, state_a);
265 GdipGetInterpolationMode(graphics1, &mode);
266 expect(InterpolationModeBilinear, mode);
267 GdipDeleteGraphics(graphics1);
269 log_state(state_a, &state_log);
270 log_state(state_b, &state_log);
272 /* Restoring older state invalidates newer saves (but not older saves). */
273 GdipCreateFromHDC(hdc, &graphics1);
274 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
275 GdipSaveGraphics(graphics1, &state_a);
276 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
277 GdipSaveGraphics(graphics1, &state_b);
278 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
279 GdipSaveGraphics(graphics1, &state_c);
280 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
281 GdipRestoreGraphics(graphics1, state_b);
282 GdipGetInterpolationMode(graphics1, &mode);
283 expect(InterpolationModeBicubic, mode);
284 GdipRestoreGraphics(graphics1, state_c);
285 GdipGetInterpolationMode(graphics1, &mode);
286 expect(InterpolationModeBicubic, mode);
287 GdipRestoreGraphics(graphics1, state_a);
288 GdipGetInterpolationMode(graphics1, &mode);
289 expect(InterpolationModeBilinear, mode);
290 GdipDeleteGraphics(graphics1);
292 log_state(state_a, &state_log);
293 log_state(state_b, &state_log);
294 log_state(state_c, &state_log);
296 /* Restoring older save from one graphics object does not invalidate
297 * newer save from other graphics object. */
298 GdipCreateFromHDC(hdc, &graphics1);
299 GdipCreateFromHDC(hdc, &graphics2);
300 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
301 GdipSaveGraphics(graphics1, &state_a);
302 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
303 GdipSaveGraphics(graphics2, &state_b);
304 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
305 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
306 GdipRestoreGraphics(graphics1, state_a);
307 GdipGetInterpolationMode(graphics1, &mode);
308 expect(InterpolationModeBilinear, mode);
309 GdipRestoreGraphics(graphics2, state_b);
310 GdipGetInterpolationMode(graphics2, &mode);
311 expect(InterpolationModeBicubic, mode);
312 GdipDeleteGraphics(graphics1);
313 GdipDeleteGraphics(graphics2);
315 /* You can't restore a state to a graphics object that didn't save it. */
316 GdipCreateFromHDC(hdc, &graphics1);
317 GdipCreateFromHDC(hdc, &graphics2);
318 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
319 GdipSaveGraphics(graphics1, &state_a);
320 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
321 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
322 GdipRestoreGraphics(graphics2, state_a);
323 GdipGetInterpolationMode(graphics2, &mode);
324 expect(InterpolationModeNearestNeighbor, mode);
325 GdipDeleteGraphics(graphics1);
326 GdipDeleteGraphics(graphics2);
328 log_state(state_a, &state_log);
330 /* The same state value should never be returned twice. */
331 todo_wine
332 check_no_duplicates(state_log);
334 ReleaseDC(hwnd, hdc);
337 static void test_GdipFillClosedCurve2(void)
339 GpStatus status;
340 GpGraphics *graphics = NULL;
341 GpSolidFill *brush = NULL;
342 HDC hdc = GetDC( hwnd );
343 GpPointF points[3];
345 points[0].X = 0;
346 points[0].Y = 0;
348 points[1].X = 40;
349 points[1].Y = 20;
351 points[2].X = 10;
352 points[2].Y = 40;
354 /* make a graphics object and brush object */
355 ok(hdc != NULL, "Expected HDC to be initialized\n");
357 status = GdipCreateFromHDC(hdc, &graphics);
358 expect(Ok, status);
359 ok(graphics != NULL, "Expected graphics to be initialized\n");
361 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
363 /* InvalidParameter cases: null graphics, null brush, null points */
364 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
365 expect(InvalidParameter, status);
367 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
368 expect(InvalidParameter, status);
370 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
371 expect(InvalidParameter, status);
373 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
374 expect(InvalidParameter, status);
376 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
377 expect(InvalidParameter, status);
379 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
380 expect(InvalidParameter, status);
382 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
383 expect(InvalidParameter, status);
385 /* InvalidParameter cases: invalid count */
386 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
387 expect(InvalidParameter, status);
389 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
390 expect(InvalidParameter, status);
392 /* Valid test cases */
393 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
394 expect(Ok, status);
396 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
397 expect(Ok, status);
399 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
400 expect(Ok, status);
402 GdipDeleteGraphics(graphics);
403 GdipDeleteBrush((GpBrush*)brush);
405 ReleaseDC(hwnd, hdc);
408 static void test_GdipFillClosedCurve2I(void)
410 GpStatus status;
411 GpGraphics *graphics = NULL;
412 GpSolidFill *brush = NULL;
413 HDC hdc = GetDC( hwnd );
414 GpPoint points[3];
416 points[0].X = 0;
417 points[0].Y = 0;
419 points[1].X = 40;
420 points[1].Y = 20;
422 points[2].X = 10;
423 points[2].Y = 40;
425 /* make a graphics object and brush object */
426 ok(hdc != NULL, "Expected HDC to be initialized\n");
428 status = GdipCreateFromHDC(hdc, &graphics);
429 expect(Ok, status);
430 ok(graphics != NULL, "Expected graphics to be initialized\n");
432 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
434 /* InvalidParameter cases: null graphics, null brush */
435 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
436 when points == NULL, so don't test this condition */
437 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
438 expect(InvalidParameter, status);
440 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
441 expect(InvalidParameter, status);
443 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
444 expect(InvalidParameter, status);
446 /* InvalidParameter cases: invalid count */
447 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
448 expect(InvalidParameter, status);
450 /* OutOfMemory cases: large (unsigned) int */
451 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
452 expect(OutOfMemory, status);
454 /* Valid test cases */
455 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
456 expect(Ok, status);
458 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
459 expect(Ok, status);
461 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
462 expect(Ok, status);
464 GdipDeleteGraphics(graphics);
465 GdipDeleteBrush((GpBrush*)brush);
467 ReleaseDC(hwnd, hdc);
470 static void test_GdipDrawArc(void)
472 GpStatus status;
473 GpGraphics *graphics = NULL;
474 GpPen *pen = NULL;
475 HDC hdc = GetDC( hwnd );
477 /* make a graphics object and pen object */
478 ok(hdc != NULL, "Expected HDC to be initialized\n");
480 status = GdipCreateFromHDC(hdc, &graphics);
481 expect(Ok, status);
482 ok(graphics != NULL, "Expected graphics to be initialized\n");
484 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
485 expect(Ok, status);
486 ok(pen != NULL, "Expected pen to be initialized\n");
488 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
489 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
490 expect(InvalidParameter, status);
492 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
493 expect(InvalidParameter, status);
495 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
496 expect(InvalidParameter, status);
498 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
499 expect(InvalidParameter, status);
501 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
502 expect(InvalidParameter, status);
504 /* successful case */
505 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
506 expect(Ok, status);
508 GdipDeletePen(pen);
509 GdipDeleteGraphics(graphics);
511 ReleaseDC(hwnd, hdc);
514 static void test_GdipDrawArcI(void)
516 GpStatus status;
517 GpGraphics *graphics = NULL;
518 GpPen *pen = NULL;
519 HDC hdc = GetDC( hwnd );
521 /* make a graphics object and pen object */
522 ok(hdc != NULL, "Expected HDC to be initialized\n");
524 status = GdipCreateFromHDC(hdc, &graphics);
525 expect(Ok, status);
526 ok(graphics != NULL, "Expected graphics to be initialized\n");
528 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
529 expect(Ok, status);
530 ok(pen != NULL, "Expected pen to be initialized\n");
532 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
533 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
534 expect(InvalidParameter, status);
536 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
537 expect(InvalidParameter, status);
539 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
540 expect(InvalidParameter, status);
542 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
543 expect(InvalidParameter, status);
545 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
546 expect(InvalidParameter, status);
548 /* successful case */
549 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
550 expect(Ok, status);
552 GdipDeletePen(pen);
553 GdipDeleteGraphics(graphics);
555 ReleaseDC(hwnd, hdc);
558 static void test_BeginContainer2(void)
560 GpMatrix *transform;
561 GpRectF clip;
562 REAL defClip[] = {5, 10, 15, 20};
563 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
564 GraphicsContainer cont1, cont2, cont3, cont4;
565 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
566 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
567 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
568 REAL scale, defScale = 17;
569 GpUnit unit, defUnit = UnitPixel;
570 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
571 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
572 UINT contrast, defContrast = 5;
573 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
575 GpStatus status;
576 GpGraphics *graphics = NULL;
577 HDC hdc = GetDC( hwnd );
579 ok(hdc != NULL, "Expected HDC to be initialized\n");
581 status = GdipCreateFromHDC(hdc, &graphics);
582 expect(Ok, status);
583 ok(graphics != NULL, "Expected graphics to be initialized\n");
585 /* null graphics, null container */
586 status = GdipBeginContainer2(NULL, &cont1);
587 expect(InvalidParameter, status);
589 status = GdipBeginContainer2(graphics, NULL);
590 expect(InvalidParameter, status);
592 status = GdipEndContainer(NULL, cont1);
593 expect(InvalidParameter, status);
595 /* test all quality-related values */
596 GdipSetCompositingMode(graphics, defCompmode);
597 GdipSetCompositingQuality(graphics, defCompqual);
598 GdipSetInterpolationMode(graphics, defInterp);
599 GdipSetPageScale(graphics, defScale);
600 GdipSetPageUnit(graphics, defUnit);
601 GdipSetPixelOffsetMode(graphics, defOffsetmode);
602 GdipSetSmoothingMode(graphics, defSmoothmode);
603 GdipSetTextContrast(graphics, defContrast);
604 GdipSetTextRenderingHint(graphics, defTexthint);
606 status = GdipBeginContainer2(graphics, &cont1);
607 expect(Ok, status);
609 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
610 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
611 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
612 GdipSetPageScale(graphics, 10);
613 GdipSetPageUnit(graphics, UnitDocument);
614 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
615 GdipSetSmoothingMode(graphics, SmoothingModeNone);
616 GdipSetTextContrast(graphics, 7);
617 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
619 status = GdipEndContainer(graphics, cont1);
620 expect(Ok, status);
622 GdipGetCompositingMode(graphics, &compmode);
623 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
625 GdipGetCompositingQuality(graphics, &compqual);
626 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
628 GdipGetInterpolationMode(graphics, &interp);
629 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
631 GdipGetPageScale(graphics, &scale);
632 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
634 GdipGetPageUnit(graphics, &unit);
635 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
637 GdipGetPixelOffsetMode(graphics, &offsetmode);
638 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
640 GdipGetSmoothingMode(graphics, &smoothmode);
641 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
643 GdipGetTextContrast(graphics, &contrast);
644 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
646 GdipGetTextRenderingHint(graphics, &texthint);
647 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
649 /* test world transform */
650 status = GdipBeginContainer2(graphics, &cont1);
651 expect(Ok, status);
653 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
654 defTrans[4], defTrans[5], &transform);
655 expect(Ok, status);
656 GdipSetWorldTransform(graphics, transform);
657 GdipDeleteMatrix(transform);
658 transform = NULL;
660 status = GdipBeginContainer2(graphics, &cont2);
661 expect(Ok, status);
663 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
664 expect(Ok, status);
665 GdipSetWorldTransform(graphics, transform);
666 GdipDeleteMatrix(transform);
667 transform = NULL;
669 status = GdipEndContainer(graphics, cont2);
670 expect(Ok, status);
672 status = GdipCreateMatrix(&transform);
673 expect(Ok, status);
674 GdipGetWorldTransform(graphics, transform);
675 GdipGetMatrixElements(transform, elems);
676 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
677 fabs(defTrans[1] - elems[1]) < 0.0001 &&
678 fabs(defTrans[2] - elems[2]) < 0.0001 &&
679 fabs(defTrans[3] - elems[3]) < 0.0001 &&
680 fabs(defTrans[4] - elems[4]) < 0.0001 &&
681 fabs(defTrans[5] - elems[5]) < 0.0001,
682 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
683 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
684 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
685 GdipDeleteMatrix(transform);
686 transform = NULL;
688 status = GdipEndContainer(graphics, cont1);
689 expect(Ok, status);
691 /* test clipping */
692 status = GdipBeginContainer2(graphics, &cont1);
693 expect(Ok, status);
695 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
697 status = GdipBeginContainer2(graphics, &cont2);
698 expect(Ok, status);
700 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
702 status = GdipEndContainer(graphics, cont2);
703 expect(Ok, status);
705 status = GdipGetClipBounds(graphics, &clip);
706 expect(Ok, status);
708 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
709 fabs(defClip[1] - clip.Y) < 0.0001 &&
710 fabs(defClip[2] - clip.Width) < 0.0001 &&
711 fabs(defClip[3] - clip.Height) < 0.0001,
712 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
713 defClip[0], defClip[1], defClip[2], defClip[3],
714 clip.X, clip.Y, clip.Width, clip.Height);
716 status = GdipEndContainer(graphics, cont1);
717 expect(Ok, status);
719 /* nesting */
720 status = GdipBeginContainer2(graphics, &cont1);
721 expect(Ok, status);
723 status = GdipBeginContainer2(graphics, &cont2);
724 expect(Ok, status);
726 status = GdipBeginContainer2(graphics, &cont3);
727 expect(Ok, status);
729 status = GdipEndContainer(graphics, cont3);
730 expect(Ok, status);
732 status = GdipBeginContainer2(graphics, &cont4);
733 expect(Ok, status);
735 status = GdipEndContainer(graphics, cont4);
736 expect(Ok, status);
738 /* skip cont2 */
739 status = GdipEndContainer(graphics, cont1);
740 expect(Ok, status);
742 /* end an already-ended container */
743 status = GdipEndContainer(graphics, cont1);
744 expect(Ok, status);
746 GdipDeleteGraphics(graphics);
747 ReleaseDC(hwnd, hdc);
750 static void test_GdipDrawBezierI(void)
752 GpStatus status;
753 GpGraphics *graphics = NULL;
754 GpPen *pen = NULL;
755 HDC hdc = GetDC( hwnd );
757 /* make a graphics object and pen object */
758 ok(hdc != NULL, "Expected HDC to be initialized\n");
760 status = GdipCreateFromHDC(hdc, &graphics);
761 expect(Ok, status);
762 ok(graphics != NULL, "Expected graphics to be initialized\n");
764 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
765 expect(Ok, status);
766 ok(pen != NULL, "Expected pen to be initialized\n");
768 /* InvalidParameter cases: null graphics, null pen */
769 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
770 expect(InvalidParameter, status);
772 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
773 expect(InvalidParameter, status);
775 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
776 expect(InvalidParameter, status);
778 /* successful case */
779 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
780 expect(Ok, status);
782 GdipDeletePen(pen);
783 GdipDeleteGraphics(graphics);
785 ReleaseDC(hwnd, hdc);
788 static void test_GdipDrawCurve3(void)
790 GpStatus status;
791 GpGraphics *graphics = NULL;
792 GpPen *pen = NULL;
793 HDC hdc = GetDC( hwnd );
794 GpPointF points[3];
796 points[0].X = 0;
797 points[0].Y = 0;
799 points[1].X = 40;
800 points[1].Y = 20;
802 points[2].X = 10;
803 points[2].Y = 40;
805 /* make a graphics object and pen object */
806 ok(hdc != NULL, "Expected HDC to be initialized\n");
808 status = GdipCreateFromHDC(hdc, &graphics);
809 expect(Ok, status);
810 ok(graphics != NULL, "Expected graphics to be initialized\n");
812 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
813 expect(Ok, status);
814 ok(pen != NULL, "Expected pen to be initialized\n");
816 /* InvalidParameter cases: null graphics, null pen */
817 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
818 expect(InvalidParameter, status);
820 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
821 expect(InvalidParameter, status);
823 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
824 expect(InvalidParameter, status);
826 /* InvalidParameter cases: invalid count */
827 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
828 expect(InvalidParameter, status);
830 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
831 expect(InvalidParameter, status);
833 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
834 expect(InvalidParameter, status);
836 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
837 expect(InvalidParameter, status);
839 /* InvalidParameter cases: invalid number of segments */
840 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
841 expect(InvalidParameter, status);
843 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
844 expect(InvalidParameter, status);
846 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
847 expect(InvalidParameter, status);
849 /* Valid test cases */
850 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
851 expect(Ok, status);
853 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
854 expect(Ok, status);
856 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
857 expect(Ok, status);
859 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
860 expect(Ok, status);
862 GdipDeletePen(pen);
863 GdipDeleteGraphics(graphics);
865 ReleaseDC(hwnd, hdc);
868 static void test_GdipDrawCurve3I(void)
870 GpStatus status;
871 GpGraphics *graphics = NULL;
872 GpPen *pen = NULL;
873 HDC hdc = GetDC( hwnd );
874 GpPoint points[3];
876 points[0].X = 0;
877 points[0].Y = 0;
879 points[1].X = 40;
880 points[1].Y = 20;
882 points[2].X = 10;
883 points[2].Y = 40;
885 /* make a graphics object and pen object */
886 ok(hdc != NULL, "Expected HDC to be initialized\n");
888 status = GdipCreateFromHDC(hdc, &graphics);
889 expect(Ok, status);
890 ok(graphics != NULL, "Expected graphics to be initialized\n");
892 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
893 expect(Ok, status);
894 ok(pen != NULL, "Expected pen to be initialized\n");
896 /* InvalidParameter cases: null graphics, null pen */
897 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
898 expect(InvalidParameter, status);
900 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
901 expect(InvalidParameter, status);
903 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
904 expect(InvalidParameter, status);
906 /* InvalidParameter cases: invalid count */
907 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
908 expect(OutOfMemory, status);
910 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
911 expect(InvalidParameter, status);
913 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
914 expect(InvalidParameter, status);
916 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
917 expect(InvalidParameter, status);
919 /* InvalidParameter cases: invalid number of segments */
920 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
921 expect(InvalidParameter, status);
923 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
924 expect(InvalidParameter, status);
926 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
927 expect(InvalidParameter, status);
929 /* Valid test cases */
930 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
931 expect(Ok, status);
933 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
934 expect(Ok, status);
936 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
937 expect(Ok, status);
939 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
940 expect(Ok, status);
942 GdipDeletePen(pen);
943 GdipDeleteGraphics(graphics);
945 ReleaseDC(hwnd, hdc);
948 static void test_GdipDrawCurve2(void)
950 GpStatus status;
951 GpGraphics *graphics = NULL;
952 GpPen *pen = NULL;
953 HDC hdc = GetDC( hwnd );
954 GpPointF points[3];
956 points[0].X = 0;
957 points[0].Y = 0;
959 points[1].X = 40;
960 points[1].Y = 20;
962 points[2].X = 10;
963 points[2].Y = 40;
965 /* make a graphics object and pen object */
966 ok(hdc != NULL, "Expected HDC to be initialized\n");
968 status = GdipCreateFromHDC(hdc, &graphics);
969 expect(Ok, status);
970 ok(graphics != NULL, "Expected graphics to be initialized\n");
972 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
973 expect(Ok, status);
974 ok(pen != NULL, "Expected pen to be initialized\n");
976 /* InvalidParameter cases: null graphics, null pen */
977 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
978 expect(InvalidParameter, status);
980 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
981 expect(InvalidParameter, status);
983 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
984 expect(InvalidParameter, status);
986 /* InvalidParameter cases: invalid count */
987 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
988 expect(InvalidParameter, status);
990 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
991 expect(InvalidParameter, status);
993 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
994 expect(InvalidParameter, status);
996 /* Valid test cases */
997 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
998 expect(Ok, status);
1000 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1001 expect(Ok, status);
1003 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1004 expect(Ok, status);
1006 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1007 expect(Ok, status);
1009 GdipDeletePen(pen);
1010 GdipDeleteGraphics(graphics);
1012 ReleaseDC(hwnd, hdc);
1015 static void test_GdipDrawCurve2I(void)
1017 GpStatus status;
1018 GpGraphics *graphics = NULL;
1019 GpPen *pen = NULL;
1020 HDC hdc = GetDC( hwnd );
1021 GpPoint points[3];
1023 points[0].X = 0;
1024 points[0].Y = 0;
1026 points[1].X = 40;
1027 points[1].Y = 20;
1029 points[2].X = 10;
1030 points[2].Y = 40;
1032 /* make a graphics object and pen object */
1033 ok(hdc != NULL, "Expected HDC to be initialized\n");
1035 status = GdipCreateFromHDC(hdc, &graphics);
1036 expect(Ok, status);
1037 ok(graphics != NULL, "Expected graphics to be initialized\n");
1039 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1040 expect(Ok, status);
1041 ok(pen != NULL, "Expected pen to be initialized\n");
1043 /* InvalidParameter cases: null graphics, null pen */
1044 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1045 expect(InvalidParameter, status);
1047 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1048 expect(InvalidParameter, status);
1050 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1051 expect(InvalidParameter, status);
1053 /* InvalidParameter cases: invalid count */
1054 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1055 expect(OutOfMemory, status);
1057 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1058 expect(InvalidParameter, status);
1060 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1061 expect(InvalidParameter, status);
1063 /* Valid test cases */
1064 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1065 expect(Ok, status);
1067 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1068 expect(Ok, status);
1070 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1071 expect(Ok, status);
1073 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1074 expect(Ok, status);
1076 GdipDeletePen(pen);
1077 GdipDeleteGraphics(graphics);
1079 ReleaseDC(hwnd, hdc);
1082 static void test_GdipDrawCurve(void)
1084 GpStatus status;
1085 GpGraphics *graphics = NULL;
1086 GpPen *pen = NULL;
1087 HDC hdc = GetDC( hwnd );
1088 GpPointF points[3];
1090 points[0].X = 0;
1091 points[0].Y = 0;
1093 points[1].X = 40;
1094 points[1].Y = 20;
1096 points[2].X = 10;
1097 points[2].Y = 40;
1099 /* make a graphics object and pen object */
1100 ok(hdc != NULL, "Expected HDC to be initialized\n");
1102 status = GdipCreateFromHDC(hdc, &graphics);
1103 expect(Ok, status);
1104 ok(graphics != NULL, "Expected graphics to be initialized\n");
1106 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1107 expect(Ok, status);
1108 ok(pen != NULL, "Expected pen to be initialized\n");
1110 /* InvalidParameter cases: null graphics, null pen */
1111 status = GdipDrawCurve(NULL, NULL, points, 3);
1112 expect(InvalidParameter, status);
1114 status = GdipDrawCurve(graphics, NULL, points, 3);
1115 expect(InvalidParameter, status);
1117 status = GdipDrawCurve(NULL, pen, points, 3);
1118 expect(InvalidParameter, status);
1120 /* InvalidParameter cases: invalid count */
1121 status = GdipDrawCurve(graphics, pen, points, -1);
1122 expect(InvalidParameter, status);
1124 status = GdipDrawCurve(graphics, pen, points, 0);
1125 expect(InvalidParameter, status);
1127 status = GdipDrawCurve(graphics, pen, points, 1);
1128 expect(InvalidParameter, status);
1130 /* Valid test cases */
1131 status = GdipDrawCurve(graphics, pen, points, 2);
1132 expect(Ok, status);
1134 status = GdipDrawCurve(graphics, pen, points, 3);
1135 expect(Ok, status);
1137 GdipDeletePen(pen);
1138 GdipDeleteGraphics(graphics);
1140 ReleaseDC(hwnd, hdc);
1143 static void test_GdipDrawCurveI(void)
1145 GpStatus status;
1146 GpGraphics *graphics = NULL;
1147 GpPen *pen = NULL;
1148 HDC hdc = GetDC( hwnd );
1149 GpPoint points[3];
1151 points[0].X = 0;
1152 points[0].Y = 0;
1154 points[1].X = 40;
1155 points[1].Y = 20;
1157 points[2].X = 10;
1158 points[2].Y = 40;
1160 /* make a graphics object and pen object */
1161 ok(hdc != NULL, "Expected HDC to be initialized\n");
1163 status = GdipCreateFromHDC(hdc, &graphics);
1164 expect(Ok, status);
1165 ok(graphics != NULL, "Expected graphics to be initialized\n");
1167 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1168 expect(Ok, status);
1169 ok(pen != NULL, "Expected pen to be initialized\n");
1171 /* InvalidParameter cases: null graphics, null pen */
1172 status = GdipDrawCurveI(NULL, NULL, points, 3);
1173 expect(InvalidParameter, status);
1175 status = GdipDrawCurveI(graphics, NULL, points, 3);
1176 expect(InvalidParameter, status);
1178 status = GdipDrawCurveI(NULL, pen, points, 3);
1179 expect(InvalidParameter, status);
1181 /* InvalidParameter cases: invalid count */
1182 status = GdipDrawCurveI(graphics, pen, points, -1);
1183 expect(OutOfMemory, status);
1185 status = GdipDrawCurveI(graphics, pen, points, 0);
1186 expect(InvalidParameter, status);
1188 status = GdipDrawCurveI(graphics, pen, points, 1);
1189 expect(InvalidParameter, status);
1191 /* Valid test cases */
1192 status = GdipDrawCurveI(graphics, pen, points, 2);
1193 expect(Ok, status);
1195 status = GdipDrawCurveI(graphics, pen, points, 3);
1196 expect(Ok, status);
1198 GdipDeletePen(pen);
1199 GdipDeleteGraphics(graphics);
1201 ReleaseDC(hwnd, hdc);
1204 static void test_GdipDrawLineI(void)
1206 GpStatus status;
1207 GpGraphics *graphics = NULL;
1208 GpPen *pen = NULL;
1209 HDC hdc = GetDC( hwnd );
1211 /* make a graphics object and pen object */
1212 ok(hdc != NULL, "Expected HDC to be initialized\n");
1214 status = GdipCreateFromHDC(hdc, &graphics);
1215 expect(Ok, status);
1216 ok(graphics != NULL, "Expected graphics to be initialized\n");
1218 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1219 expect(Ok, status);
1220 ok(pen != NULL, "Expected pen to be initialized\n");
1222 /* InvalidParameter cases: null graphics, null pen */
1223 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1224 expect(InvalidParameter, status);
1226 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1227 expect(InvalidParameter, status);
1229 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1230 expect(InvalidParameter, status);
1232 /* successful case */
1233 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1234 expect(Ok, status);
1236 GdipDeletePen(pen);
1237 GdipDeleteGraphics(graphics);
1239 ReleaseDC(hwnd, hdc);
1242 static void test_GdipDrawImagePointsRect(void)
1244 GpStatus status;
1245 GpGraphics *graphics = NULL;
1246 GpPointF ptf[4];
1247 GpBitmap *bm = NULL;
1248 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1249 BYTE buff[400];
1250 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1251 HDC hdc = GetDC( hwnd );
1252 if (!hdc)
1253 return;
1255 memset(rbmi, 0, sizeof(rbmi));
1256 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1257 bmi->bmiHeader.biWidth = 10;
1258 bmi->bmiHeader.biHeight = 10;
1259 bmi->bmiHeader.biPlanes = 1;
1260 bmi->bmiHeader.biBitCount = 32;
1261 bmi->bmiHeader.biCompression = BI_RGB;
1262 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1263 expect(Ok, status);
1264 ok(NULL != bm, "Expected bitmap to be initialized\n");
1265 status = GdipCreateFromHDC(hdc, &graphics);
1266 expect(Ok, status);
1267 ptf[0].X = 0;
1268 ptf[0].Y = 0;
1269 ptf[1].X = 10;
1270 ptf[1].Y = 0;
1271 ptf[2].X = 0;
1272 ptf[2].Y = 10;
1273 ptf[3].X = 10;
1274 ptf[3].Y = 10;
1275 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1276 expect(NotImplemented, status);
1277 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1278 expect(InvalidParameter, status);
1279 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1280 expect(Ok, status);
1281 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1282 expect(InvalidParameter, status);
1283 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1284 expect(InvalidParameter, status);
1285 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1286 expect(Ok, status);
1287 memset(ptf, 0, sizeof(ptf));
1288 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1289 expect(Ok, status);
1291 GdipDisposeImage((GpImage*)bm);
1292 GdipDeleteGraphics(graphics);
1293 ReleaseDC(hwnd, hdc);
1296 static void test_GdipDrawLinesI(void)
1298 GpStatus status;
1299 GpGraphics *graphics = NULL;
1300 GpPen *pen = NULL;
1301 GpPoint *ptf = NULL;
1302 HDC hdc = GetDC( hwnd );
1304 /* make a graphics object and pen object */
1305 ok(hdc != NULL, "Expected HDC to be initialized\n");
1307 status = GdipCreateFromHDC(hdc, &graphics);
1308 expect(Ok, status);
1309 ok(graphics != NULL, "Expected graphics to be initialized\n");
1311 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1312 expect(Ok, status);
1313 ok(pen != NULL, "Expected pen to be initialized\n");
1315 /* make some arbitrary valid points*/
1316 ptf = GdipAlloc(2 * sizeof(GpPointF));
1318 ptf[0].X = 1;
1319 ptf[0].Y = 1;
1321 ptf[1].X = 2;
1322 ptf[1].Y = 2;
1324 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1325 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1326 expect(InvalidParameter, status);
1328 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1329 expect(InvalidParameter, status);
1331 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1332 expect(InvalidParameter, status);
1334 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1335 expect(InvalidParameter, status);
1337 /* successful case */
1338 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1339 expect(Ok, status);
1341 GdipFree(ptf);
1342 GdipDeletePen(pen);
1343 GdipDeleteGraphics(graphics);
1345 ReleaseDC(hwnd, hdc);
1348 static void test_GdipFillClosedCurve(void)
1350 GpStatus status;
1351 GpGraphics *graphics = NULL;
1352 GpSolidFill *brush = NULL;
1353 HDC hdc = GetDC( hwnd );
1354 GpPointF points[3];
1356 points[0].X = 0;
1357 points[0].Y = 0;
1359 points[1].X = 40;
1360 points[1].Y = 20;
1362 points[2].X = 10;
1363 points[2].Y = 40;
1365 /* make a graphics object and brush object */
1366 ok(hdc != NULL, "Expected HDC to be initialized\n");
1368 status = GdipCreateFromHDC(hdc, &graphics);
1369 expect(Ok, status);
1370 ok(graphics != NULL, "Expected graphics to be initialized\n");
1372 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1374 /* InvalidParameter cases: null graphics, null brush, null points */
1375 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1376 expect(InvalidParameter, status);
1378 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1379 expect(InvalidParameter, status);
1381 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1382 expect(InvalidParameter, status);
1384 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1385 expect(InvalidParameter, status);
1387 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1388 expect(InvalidParameter, status);
1390 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1391 expect(InvalidParameter, status);
1393 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1394 expect(InvalidParameter, status);
1396 /* InvalidParameter cases: invalid count */
1397 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1398 expect(InvalidParameter, status);
1400 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1401 expect(InvalidParameter, status);
1403 /* Valid test cases */
1404 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1405 expect(Ok, status);
1407 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1408 expect(Ok, status);
1410 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1411 expect(Ok, status);
1413 GdipDeleteGraphics(graphics);
1414 GdipDeleteBrush((GpBrush*)brush);
1416 ReleaseDC(hwnd, hdc);
1419 static void test_GdipFillClosedCurveI(void)
1421 GpStatus status;
1422 GpGraphics *graphics = NULL;
1423 GpSolidFill *brush = NULL;
1424 HDC hdc = GetDC( hwnd );
1425 GpPoint points[3];
1427 points[0].X = 0;
1428 points[0].Y = 0;
1430 points[1].X = 40;
1431 points[1].Y = 20;
1433 points[2].X = 10;
1434 points[2].Y = 40;
1436 /* make a graphics object and brush object */
1437 ok(hdc != NULL, "Expected HDC to be initialized\n");
1439 status = GdipCreateFromHDC(hdc, &graphics);
1440 expect(Ok, status);
1441 ok(graphics != NULL, "Expected graphics to be initialized\n");
1443 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1445 /* InvalidParameter cases: null graphics, null brush */
1446 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1447 when points == NULL, so don't test this condition */
1448 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1449 expect(InvalidParameter, status);
1451 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1452 expect(InvalidParameter, status);
1454 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1455 expect(InvalidParameter, status);
1457 /* InvalidParameter cases: invalid count */
1458 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1459 expect(InvalidParameter, status);
1461 /* OutOfMemory cases: large (unsigned) int */
1462 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1463 expect(OutOfMemory, status);
1465 /* Valid test cases */
1466 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1467 expect(Ok, status);
1469 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1470 expect(Ok, status);
1472 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1473 expect(Ok, status);
1475 GdipDeleteGraphics(graphics);
1476 GdipDeleteBrush((GpBrush*)brush);
1478 ReleaseDC(hwnd, hdc);
1481 static void test_Get_Release_DC(void)
1483 GpStatus status;
1484 GpGraphics *graphics = NULL;
1485 GpPen *pen;
1486 GpSolidFill *brush;
1487 GpPath *path;
1488 HDC hdc = GetDC( hwnd );
1489 HDC retdc;
1490 REAL r;
1491 CompositingQuality quality;
1492 CompositingMode compmode;
1493 InterpolationMode intmode;
1494 GpMatrix *m;
1495 GpRegion *region;
1496 GpUnit unit;
1497 PixelOffsetMode offsetmode;
1498 SmoothingMode smoothmode;
1499 TextRenderingHint texthint;
1500 GpPointF ptf[5];
1501 GpPoint pt[5];
1502 GpRectF rectf[2];
1503 GpRect rect[2];
1504 GpRegion *clip;
1505 INT i;
1506 BOOL res;
1507 ARGB color = 0x00000000;
1508 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1510 pt[0].X = 10;
1511 pt[0].Y = 10;
1512 pt[1].X = 20;
1513 pt[1].Y = 15;
1514 pt[2].X = 40;
1515 pt[2].Y = 80;
1516 pt[3].X = -20;
1517 pt[3].Y = 20;
1518 pt[4].X = 50;
1519 pt[4].Y = 110;
1521 for(i = 0; i < 5;i++){
1522 ptf[i].X = (REAL)pt[i].X;
1523 ptf[i].Y = (REAL)pt[i].Y;
1526 rect[0].X = 0;
1527 rect[0].Y = 0;
1528 rect[0].Width = 50;
1529 rect[0].Height = 70;
1530 rect[1].X = 0;
1531 rect[1].Y = 0;
1532 rect[1].Width = 10;
1533 rect[1].Height = 20;
1535 for(i = 0; i < 2;i++){
1536 rectf[i].X = (REAL)rect[i].X;
1537 rectf[i].Y = (REAL)rect[i].Y;
1538 rectf[i].Height = (REAL)rect[i].Height;
1539 rectf[i].Width = (REAL)rect[i].Width;
1542 status = GdipCreateMatrix(&m);
1543 expect(Ok, status);
1544 GdipCreateRegion(&region);
1545 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1546 GdipCreatePath(FillModeAlternate, &path);
1547 GdipCreateRegion(&clip);
1549 status = GdipCreateFromHDC(hdc, &graphics);
1550 expect(Ok, status);
1551 ok(graphics != NULL, "Expected graphics to be initialized\n");
1552 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1553 expect(Ok, status);
1555 /* NULL arguments */
1556 status = GdipGetDC(NULL, NULL);
1557 expect(InvalidParameter, status);
1558 status = GdipGetDC(graphics, NULL);
1559 expect(InvalidParameter, status);
1560 status = GdipGetDC(NULL, &retdc);
1561 expect(InvalidParameter, status);
1563 status = GdipReleaseDC(NULL, NULL);
1564 expect(InvalidParameter, status);
1565 status = GdipReleaseDC(graphics, NULL);
1566 expect(InvalidParameter, status);
1567 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1568 expect(InvalidParameter, status);
1570 /* Release without Get */
1571 status = GdipReleaseDC(graphics, hdc);
1572 expect(InvalidParameter, status);
1574 retdc = NULL;
1575 status = GdipGetDC(graphics, &retdc);
1576 expect(Ok, status);
1577 ok(retdc == hdc, "Invalid HDC returned\n");
1578 /* call it once more */
1579 status = GdipGetDC(graphics, &retdc);
1580 expect(ObjectBusy, status);
1582 /* try all Graphics calls here */
1583 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1584 expect(ObjectBusy, status);
1585 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1586 expect(ObjectBusy, status);
1587 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1588 expect(ObjectBusy, status);
1589 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1590 expect(ObjectBusy, status);
1591 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1592 expect(ObjectBusy, status);
1593 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1594 expect(ObjectBusy, status);
1595 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1596 expect(ObjectBusy, status);
1597 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1598 expect(ObjectBusy, status);
1599 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1600 expect(ObjectBusy, status);
1601 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1602 expect(ObjectBusy, status);
1603 status = GdipDrawCurve(graphics, pen, ptf, 5);
1604 expect(ObjectBusy, status);
1605 status = GdipDrawCurveI(graphics, pen, pt, 5);
1606 expect(ObjectBusy, status);
1607 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1608 expect(ObjectBusy, status);
1609 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1610 expect(ObjectBusy, status);
1611 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1612 expect(ObjectBusy, status);
1613 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1614 expect(ObjectBusy, status);
1615 /* GdipDrawImage/GdipDrawImageI */
1616 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1617 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1618 /* GdipDrawImageRect/GdipDrawImageRectI */
1619 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1620 expect(ObjectBusy, status);
1621 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1622 expect(ObjectBusy, status);
1623 status = GdipDrawLines(graphics, pen, ptf, 5);
1624 expect(ObjectBusy, status);
1625 status = GdipDrawLinesI(graphics, pen, pt, 5);
1626 expect(ObjectBusy, status);
1627 status = GdipDrawPath(graphics, pen, path);
1628 expect(ObjectBusy, status);
1629 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1630 expect(ObjectBusy, status);
1631 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1632 expect(ObjectBusy, status);
1633 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1634 expect(ObjectBusy, status);
1635 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1636 expect(ObjectBusy, status);
1637 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1638 expect(ObjectBusy, status);
1639 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1640 expect(ObjectBusy, status);
1641 /* GdipDrawString */
1642 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1643 expect(ObjectBusy, status);
1644 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1645 expect(ObjectBusy, status);
1646 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1647 expect(ObjectBusy, status);
1648 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1649 expect(ObjectBusy, status);
1650 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1651 expect(ObjectBusy, status);
1652 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1653 expect(ObjectBusy, status);
1654 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1655 expect(ObjectBusy, status);
1656 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1657 expect(ObjectBusy, status);
1658 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1659 expect(ObjectBusy, status);
1660 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1661 expect(ObjectBusy, status);
1662 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1663 expect(ObjectBusy, status);
1664 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1665 expect(ObjectBusy, status);
1666 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1667 expect(ObjectBusy, status);
1668 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1669 expect(ObjectBusy, status);
1670 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1671 expect(ObjectBusy, status);
1672 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1673 expect(ObjectBusy, status);
1674 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1675 expect(ObjectBusy, status);
1676 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1677 expect(ObjectBusy, status);
1678 status = GdipFlush(graphics, FlushIntentionFlush);
1679 expect(ObjectBusy, status);
1680 status = GdipGetClipBounds(graphics, rectf);
1681 expect(ObjectBusy, status);
1682 status = GdipGetClipBoundsI(graphics, rect);
1683 expect(ObjectBusy, status);
1684 status = GdipGetCompositingMode(graphics, &compmode);
1685 expect(ObjectBusy, status);
1686 status = GdipGetCompositingQuality(graphics, &quality);
1687 expect(ObjectBusy, status);
1688 status = GdipGetInterpolationMode(graphics, &intmode);
1689 expect(ObjectBusy, status);
1690 status = GdipGetNearestColor(graphics, &color);
1691 expect(ObjectBusy, status);
1692 status = GdipGetPageScale(graphics, &r);
1693 expect(ObjectBusy, status);
1694 status = GdipGetPageUnit(graphics, &unit);
1695 expect(ObjectBusy, status);
1696 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1697 expect(ObjectBusy, status);
1698 status = GdipGetSmoothingMode(graphics, &smoothmode);
1699 expect(ObjectBusy, status);
1700 status = GdipGetTextRenderingHint(graphics, &texthint);
1701 expect(ObjectBusy, status);
1702 status = GdipGetWorldTransform(graphics, m);
1703 expect(ObjectBusy, status);
1704 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1705 expect(ObjectBusy, status);
1706 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1707 expect(ObjectBusy, status);
1708 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1709 expect(ObjectBusy, status);
1710 /* GdipMeasureCharacterRanges */
1711 /* GdipMeasureString */
1712 status = GdipResetClip(graphics);
1713 expect(ObjectBusy, status);
1714 status = GdipResetWorldTransform(graphics);
1715 expect(ObjectBusy, status);
1716 /* GdipRestoreGraphics */
1717 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1718 expect(ObjectBusy, status);
1719 /* GdipSaveGraphics */
1720 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1721 expect(ObjectBusy, status);
1722 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1723 expect(ObjectBusy, status);
1724 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1725 expect(ObjectBusy, status);
1726 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1727 expect(ObjectBusy, status);
1728 status = GdipSetPageScale(graphics, 1.0);
1729 expect(ObjectBusy, status);
1730 status = GdipSetPageUnit(graphics, UnitWorld);
1731 expect(ObjectBusy, status);
1732 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1733 expect(ObjectBusy, status);
1734 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1735 expect(ObjectBusy, status);
1736 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1737 expect(ObjectBusy, status);
1738 status = GdipSetWorldTransform(graphics, m);
1739 expect(ObjectBusy, status);
1740 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1741 expect(ObjectBusy, status);
1742 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1743 expect(ObjectBusy, status);
1744 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1745 expect(ObjectBusy, status);
1746 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1747 expect(ObjectBusy, status);
1748 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1749 expect(ObjectBusy, status);
1750 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1751 expect(ObjectBusy, status);
1752 status = GdipTranslateClip(graphics, 0.0, 0.0);
1753 expect(ObjectBusy, status);
1754 status = GdipTranslateClipI(graphics, 0, 0);
1755 expect(ObjectBusy, status);
1756 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1757 expect(ObjectBusy, status);
1758 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1759 expect(ObjectBusy, status);
1760 status = GdipGetDpiX(graphics, &r);
1761 expect(ObjectBusy, status);
1762 status = GdipGetDpiY(graphics, &r);
1763 expect(ObjectBusy, status);
1764 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1765 expect(ObjectBusy, status);
1766 status = GdipGetClip(graphics, region);
1767 expect(ObjectBusy, status);
1768 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1769 expect(ObjectBusy, status);
1771 /* try to delete before release */
1772 status = GdipDeleteGraphics(graphics);
1773 expect(ObjectBusy, status);
1775 status = GdipReleaseDC(graphics, retdc);
1776 expect(Ok, status);
1778 GdipDeletePen(pen);
1779 GdipDeleteGraphics(graphics);
1781 GdipDeleteRegion(clip);
1782 GdipDeletePath(path);
1783 GdipDeleteBrush((GpBrush*)brush);
1784 GdipDeleteRegion(region);
1785 GdipDeleteMatrix(m);
1786 DeleteObject(hrgn);
1788 ReleaseDC(hwnd, hdc);
1791 static void test_transformpoints(void)
1793 GpStatus status;
1794 GpGraphics *graphics = NULL;
1795 HDC hdc = GetDC( hwnd );
1796 GpPointF ptf[2];
1797 GpPoint pt[2];
1799 status = GdipCreateFromHDC(hdc, &graphics);
1800 expect(Ok, status);
1802 /* NULL arguments */
1803 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1804 expect(InvalidParameter, status);
1805 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1806 expect(InvalidParameter, status);
1807 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1808 expect(InvalidParameter, status);
1809 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1810 expect(InvalidParameter, status);
1812 ptf[0].X = 1.0;
1813 ptf[0].Y = 0.0;
1814 ptf[1].X = 0.0;
1815 ptf[1].Y = 1.0;
1816 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1817 expect(Ok, status);
1818 expectf(1.0, ptf[0].X);
1819 expectf(0.0, ptf[0].Y);
1820 expectf(0.0, ptf[1].X);
1821 expectf(1.0, ptf[1].Y);
1823 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1824 expect(Ok, status);
1825 status = GdipSetPageUnit(graphics, UnitPixel);
1826 expect(Ok, status);
1827 status = GdipSetPageScale(graphics, 3.0);
1828 expect(Ok, status);
1830 ptf[0].X = 1.0;
1831 ptf[0].Y = 0.0;
1832 ptf[1].X = 0.0;
1833 ptf[1].Y = 1.0;
1834 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1835 expect(Ok, status);
1836 expectf(18.0, ptf[0].X);
1837 expectf(15.0, ptf[0].Y);
1838 expectf(15.0, ptf[1].X);
1839 expectf(18.0, ptf[1].Y);
1841 ptf[0].X = 1.0;
1842 ptf[0].Y = 0.0;
1843 ptf[1].X = 0.0;
1844 ptf[1].Y = 1.0;
1845 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1846 expect(Ok, status);
1847 expectf(6.0, ptf[0].X);
1848 expectf(5.0, ptf[0].Y);
1849 expectf(5.0, ptf[1].X);
1850 expectf(6.0, ptf[1].Y);
1852 ptf[0].X = 1.0;
1853 ptf[0].Y = 0.0;
1854 ptf[1].X = 0.0;
1855 ptf[1].Y = 1.0;
1856 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1857 expect(Ok, status);
1858 expectf(3.0, ptf[0].X);
1859 expectf(0.0, ptf[0].Y);
1860 expectf(0.0, ptf[1].X);
1861 expectf(3.0, ptf[1].Y);
1863 ptf[0].X = 18.0;
1864 ptf[0].Y = 15.0;
1865 ptf[1].X = 15.0;
1866 ptf[1].Y = 18.0;
1867 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1868 expect(Ok, status);
1869 expectf(1.0, ptf[0].X);
1870 expectf(0.0, ptf[0].Y);
1871 expectf(0.0, ptf[1].X);
1872 expectf(1.0, ptf[1].Y);
1874 ptf[0].X = 6.0;
1875 ptf[0].Y = 5.0;
1876 ptf[1].X = 5.0;
1877 ptf[1].Y = 6.0;
1878 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1879 expect(Ok, status);
1880 expectf(1.0, ptf[0].X);
1881 expectf(0.0, ptf[0].Y);
1882 expectf(0.0, ptf[1].X);
1883 expectf(1.0, ptf[1].Y);
1885 ptf[0].X = 3.0;
1886 ptf[0].Y = 0.0;
1887 ptf[1].X = 0.0;
1888 ptf[1].Y = 3.0;
1889 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1890 expect(Ok, status);
1891 expectf(1.0, ptf[0].X);
1892 expectf(0.0, ptf[0].Y);
1893 expectf(0.0, ptf[1].X);
1894 expectf(1.0, ptf[1].Y);
1896 pt[0].X = 1;
1897 pt[0].Y = 0;
1898 pt[1].X = 0;
1899 pt[1].Y = 1;
1900 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1901 expect(Ok, status);
1902 expect(18, pt[0].X);
1903 expect(15, pt[0].Y);
1904 expect(15, pt[1].X);
1905 expect(18, pt[1].Y);
1907 GdipDeleteGraphics(graphics);
1908 ReleaseDC(hwnd, hdc);
1911 static void test_get_set_clip(void)
1913 GpStatus status;
1914 GpGraphics *graphics = NULL;
1915 HDC hdc = GetDC( hwnd );
1916 GpRegion *clip;
1917 GpRectF rect;
1918 BOOL res;
1920 status = GdipCreateFromHDC(hdc, &graphics);
1921 expect(Ok, status);
1923 rect.X = rect.Y = 0.0;
1924 rect.Height = rect.Width = 100.0;
1926 status = GdipCreateRegionRect(&rect, &clip);
1927 expect(Ok, status);
1929 /* NULL arguments */
1930 status = GdipGetClip(NULL, NULL);
1931 expect(InvalidParameter, status);
1932 status = GdipGetClip(graphics, NULL);
1933 expect(InvalidParameter, status);
1934 status = GdipGetClip(NULL, clip);
1935 expect(InvalidParameter, status);
1937 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1938 expect(InvalidParameter, status);
1939 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1940 expect(InvalidParameter, status);
1942 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1943 expect(InvalidParameter, status);
1944 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1945 expect(InvalidParameter, status);
1947 res = FALSE;
1948 status = GdipGetClip(graphics, clip);
1949 expect(Ok, status);
1950 status = GdipIsInfiniteRegion(clip, graphics, &res);
1951 expect(Ok, status);
1952 expect(TRUE, res);
1954 /* remains infinite after reset */
1955 res = FALSE;
1956 status = GdipResetClip(graphics);
1957 expect(Ok, status);
1958 status = GdipGetClip(graphics, clip);
1959 expect(Ok, status);
1960 status = GdipIsInfiniteRegion(clip, graphics, &res);
1961 expect(Ok, status);
1962 expect(TRUE, res);
1964 /* set to empty and then reset to infinite */
1965 status = GdipSetEmpty(clip);
1966 expect(Ok, status);
1967 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1968 expect(Ok, status);
1970 status = GdipGetClip(graphics, clip);
1971 expect(Ok, status);
1972 res = FALSE;
1973 status = GdipIsEmptyRegion(clip, graphics, &res);
1974 expect(Ok, status);
1975 expect(TRUE, res);
1976 status = GdipResetClip(graphics);
1977 expect(Ok, status);
1978 status = GdipGetClip(graphics, clip);
1979 expect(Ok, status);
1980 res = FALSE;
1981 status = GdipIsInfiniteRegion(clip, graphics, &res);
1982 expect(Ok, status);
1983 expect(TRUE, res);
1985 GdipDeleteRegion(clip);
1987 GdipDeleteGraphics(graphics);
1988 ReleaseDC(hwnd, hdc);
1991 static void test_isempty(void)
1993 GpStatus status;
1994 GpGraphics *graphics = NULL;
1995 HDC hdc = GetDC( hwnd );
1996 GpRegion *clip;
1997 BOOL res;
1999 status = GdipCreateFromHDC(hdc, &graphics);
2000 expect(Ok, status);
2002 status = GdipCreateRegion(&clip);
2003 expect(Ok, status);
2005 /* NULL */
2006 status = GdipIsClipEmpty(NULL, NULL);
2007 expect(InvalidParameter, status);
2008 status = GdipIsClipEmpty(graphics, NULL);
2009 expect(InvalidParameter, status);
2010 status = GdipIsClipEmpty(NULL, &res);
2011 expect(InvalidParameter, status);
2013 /* default is infinite */
2014 res = TRUE;
2015 status = GdipIsClipEmpty(graphics, &res);
2016 expect(Ok, status);
2017 expect(FALSE, res);
2019 GdipDeleteRegion(clip);
2021 GdipDeleteGraphics(graphics);
2022 ReleaseDC(hwnd, hdc);
2025 static void test_clear(void)
2027 GpStatus status;
2029 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2030 expect(InvalidParameter, status);
2033 static void test_textcontrast(void)
2035 GpStatus status;
2036 HDC hdc = GetDC( hwnd );
2037 GpGraphics *graphics;
2038 UINT contrast;
2040 status = GdipGetTextContrast(NULL, NULL);
2041 expect(InvalidParameter, status);
2043 status = GdipCreateFromHDC(hdc, &graphics);
2044 expect(Ok, status);
2046 status = GdipGetTextContrast(graphics, NULL);
2047 expect(InvalidParameter, status);
2048 status = GdipGetTextContrast(graphics, &contrast);
2049 expect(Ok, status);
2050 expect(4, contrast);
2052 GdipDeleteGraphics(graphics);
2053 ReleaseDC(hwnd, hdc);
2056 static void test_GdipDrawString(void)
2058 GpStatus status;
2059 GpGraphics *graphics = NULL;
2060 GpFont *fnt = NULL;
2061 RectF rect;
2062 GpStringFormat *format;
2063 GpBrush *brush;
2064 LOGFONTA logfont;
2065 HDC hdc = GetDC( hwnd );
2066 static const WCHAR string[] = {'T','e','s','t',0};
2067 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2068 GpMatrix *matrix;
2070 memset(&logfont,0,sizeof(logfont));
2071 strcpy(logfont.lfFaceName,"Arial");
2072 logfont.lfHeight = 12;
2073 logfont.lfCharSet = DEFAULT_CHARSET;
2075 status = GdipCreateFromHDC(hdc, &graphics);
2076 expect(Ok, status);
2078 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2079 if (status == NotTrueTypeFont || status == FileNotFound)
2081 skip("Arial not installed.\n");
2082 return;
2084 expect(Ok, status);
2086 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2087 expect(Ok, status);
2089 status = GdipCreateStringFormat(0,0,&format);
2090 expect(Ok, status);
2092 rect.X = 0;
2093 rect.Y = 0;
2094 rect.Width = 0;
2095 rect.Height = 12;
2097 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2098 expect(Ok, status);
2100 status = GdipCreateMatrix(&matrix);
2101 expect(Ok, status);
2103 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2104 expect(InvalidParameter, status);
2106 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2107 expect(InvalidParameter, status);
2109 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2110 expect(InvalidParameter, status);
2112 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2113 expect(InvalidParameter, status);
2115 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2116 expect(InvalidParameter, status);
2118 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2119 expect(Ok, status);
2121 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2122 expect(Ok, status);
2124 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2125 expect(Ok, status);
2127 GdipDeleteMatrix(matrix);
2128 GdipDeleteGraphics(graphics);
2129 GdipDeleteBrush(brush);
2130 GdipDeleteFont(fnt);
2131 GdipDeleteStringFormat(format);
2133 ReleaseDC(hwnd, hdc);
2136 static void test_GdipGetVisibleClipBounds_screen(void)
2138 GpStatus status;
2139 GpGraphics *graphics = NULL;
2140 HDC hdc = GetDC(0);
2141 GpRectF rectf, exp, clipr;
2142 GpRect recti;
2144 ok(hdc != NULL, "Expected HDC to be initialized\n");
2146 status = GdipCreateFromHDC(hdc, &graphics);
2147 expect(Ok, status);
2148 ok(graphics != NULL, "Expected graphics to be initialized\n");
2150 /* no clipping rect */
2151 exp.X = 0;
2152 exp.Y = 0;
2153 exp.Width = GetDeviceCaps(hdc, HORZRES);
2154 exp.Height = GetDeviceCaps(hdc, VERTRES);
2156 status = GdipGetVisibleClipBounds(graphics, &rectf);
2157 expect(Ok, status);
2158 ok(rectf.X == exp.X &&
2159 rectf.Y == exp.Y &&
2160 rectf.Width == exp.Width &&
2161 rectf.Height == exp.Height,
2162 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2163 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2164 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2165 exp.X, exp.Y, exp.Width, exp.Height);
2167 /* clipping rect entirely within window */
2168 exp.X = clipr.X = 10;
2169 exp.Y = clipr.Y = 12;
2170 exp.Width = clipr.Width = 14;
2171 exp.Height = clipr.Height = 16;
2173 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2174 expect(Ok, status);
2176 status = GdipGetVisibleClipBounds(graphics, &rectf);
2177 expect(Ok, status);
2178 ok(rectf.X == exp.X &&
2179 rectf.Y == exp.Y &&
2180 rectf.Width == exp.Width &&
2181 rectf.Height == exp.Height,
2182 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2183 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2184 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2185 exp.X, exp.Y, exp.Width, exp.Height);
2187 /* clipping rect partially outside of screen */
2188 clipr.X = -10;
2189 clipr.Y = -12;
2190 clipr.Width = 20;
2191 clipr.Height = 24;
2193 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2194 expect(Ok, status);
2196 exp.X = 0;
2197 exp.Y = 0;
2198 exp.Width = 10;
2199 exp.Height = 12;
2201 status = GdipGetVisibleClipBounds(graphics, &rectf);
2202 expect(Ok, status);
2203 ok(rectf.X == exp.X &&
2204 rectf.Y == exp.Y &&
2205 rectf.Width == exp.Width &&
2206 rectf.Height == exp.Height,
2207 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2208 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2209 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2210 exp.X, exp.Y, exp.Width, exp.Height);
2212 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2213 expect(Ok, status);
2214 ok(recti.X == exp.X &&
2215 recti.Y == exp.Y &&
2216 recti.Width == exp.Width &&
2217 recti.Height == exp.Height,
2218 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2219 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2220 recti.X, recti.Y, recti.Width, recti.Height,
2221 exp.X, exp.Y, exp.Width, exp.Height);
2223 GdipDeleteGraphics(graphics);
2224 ReleaseDC(0, hdc);
2227 static void test_GdipGetVisibleClipBounds_window(void)
2229 GpStatus status;
2230 GpGraphics *graphics = NULL;
2231 GpRectF rectf, window, exp, clipr;
2232 GpRect recti;
2233 HDC hdc;
2234 PAINTSTRUCT ps;
2235 RECT wnd_rect;
2237 /* get client area size */
2238 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2239 window.X = wnd_rect.left;
2240 window.Y = wnd_rect.top;
2241 window.Width = wnd_rect.right - wnd_rect.left;
2242 window.Height = wnd_rect.bottom - wnd_rect.top;
2244 hdc = BeginPaint(hwnd, &ps);
2246 status = GdipCreateFromHDC(hdc, &graphics);
2247 expect(Ok, status);
2248 ok(graphics != NULL, "Expected graphics to be initialized\n");
2250 status = GdipGetVisibleClipBounds(graphics, &rectf);
2251 expect(Ok, status);
2252 ok(rectf.X == window.X &&
2253 rectf.Y == window.Y &&
2254 rectf.Width == window.Width &&
2255 rectf.Height == window.Height,
2256 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2257 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2258 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2259 window.X, window.Y, window.Width, window.Height);
2261 /* clipping rect entirely within window */
2262 exp.X = clipr.X = 20;
2263 exp.Y = clipr.Y = 8;
2264 exp.Width = clipr.Width = 30;
2265 exp.Height = clipr.Height = 20;
2267 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2268 expect(Ok, status);
2270 status = GdipGetVisibleClipBounds(graphics, &rectf);
2271 expect(Ok, status);
2272 ok(rectf.X == exp.X &&
2273 rectf.Y == exp.Y &&
2274 rectf.Width == exp.Width &&
2275 rectf.Height == exp.Height,
2276 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2277 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2278 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2279 exp.X, exp.Y, exp.Width, exp.Height);
2281 /* clipping rect partially outside of window */
2282 clipr.X = window.Width - 10;
2283 clipr.Y = window.Height - 15;
2284 clipr.Width = 20;
2285 clipr.Height = 30;
2287 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2288 expect(Ok, status);
2290 exp.X = window.Width - 10;
2291 exp.Y = window.Height - 15;
2292 exp.Width = 10;
2293 exp.Height = 15;
2295 status = GdipGetVisibleClipBounds(graphics, &rectf);
2296 expect(Ok, status);
2297 ok(rectf.X == exp.X &&
2298 rectf.Y == exp.Y &&
2299 rectf.Width == exp.Width &&
2300 rectf.Height == exp.Height,
2301 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2302 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2303 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2304 exp.X, exp.Y, exp.Width, exp.Height);
2306 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2307 expect(Ok, status);
2308 ok(recti.X == exp.X &&
2309 recti.Y == exp.Y &&
2310 recti.Width == exp.Width &&
2311 recti.Height == exp.Height,
2312 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2313 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2314 recti.X, recti.Y, recti.Width, recti.Height,
2315 exp.X, exp.Y, exp.Width, exp.Height);
2317 GdipDeleteGraphics(graphics);
2318 EndPaint(hwnd, &ps);
2321 static void test_GdipGetVisibleClipBounds(void)
2323 GpGraphics* graphics = NULL;
2324 GpRectF rectf;
2325 GpRect rect;
2326 HDC hdc = GetDC( hwnd );
2327 GpStatus status;
2329 status = GdipCreateFromHDC(hdc, &graphics);
2330 expect(Ok, status);
2331 ok(graphics != NULL, "Expected graphics to be initialized\n");
2333 /* test null parameters */
2334 status = GdipGetVisibleClipBounds(graphics, NULL);
2335 expect(InvalidParameter, status);
2337 status = GdipGetVisibleClipBounds(NULL, &rectf);
2338 expect(InvalidParameter, status);
2340 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2341 expect(InvalidParameter, status);
2343 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2344 expect(InvalidParameter, status);
2346 GdipDeleteGraphics(graphics);
2347 ReleaseDC(hwnd, hdc);
2349 test_GdipGetVisibleClipBounds_screen();
2350 test_GdipGetVisibleClipBounds_window();
2353 static void test_fromMemoryBitmap(void)
2355 GpStatus status;
2356 GpGraphics *graphics = NULL;
2357 GpBitmap *bitmap = NULL;
2358 BYTE bits[48] = {0};
2359 HDC hdc=NULL;
2360 COLORREF color;
2362 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2363 expect(Ok, status);
2365 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2366 expect(Ok, status);
2368 status = GdipGraphicsClear(graphics, 0xff686868);
2369 expect(Ok, status);
2371 GdipDeleteGraphics(graphics);
2373 /* drawing writes to the memory provided */
2374 expect(0x68, bits[10]);
2376 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2377 expect(Ok, status);
2379 status = GdipGetDC(graphics, &hdc);
2380 expect(Ok, status);
2381 ok(hdc != NULL, "got NULL hdc\n");
2383 color = GetPixel(hdc, 0, 0);
2384 /* The HDC is write-only, and native fills with a solid color to figure out
2385 * which pixels have changed. */
2386 todo_wine expect(0x0c0b0d, color);
2388 SetPixel(hdc, 0, 0, 0x797979);
2389 SetPixel(hdc, 1, 0, 0x0c0b0d);
2391 status = GdipReleaseDC(graphics, hdc);
2392 expect(Ok, status);
2394 GdipDeleteGraphics(graphics);
2396 expect(0x79, bits[0]);
2397 todo_wine expect(0x68, bits[3]);
2399 GdipDisposeImage((GpImage*)bitmap);
2401 /* We get the same kind of write-only HDC for a "normal" bitmap */
2402 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2403 expect(Ok, status);
2405 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2406 expect(Ok, status);
2408 status = GdipGetDC(graphics, &hdc);
2409 expect(Ok, status);
2410 ok(hdc != NULL, "got NULL hdc\n");
2412 color = GetPixel(hdc, 0, 0);
2413 todo_wine expect(0x0c0b0d, color);
2415 status = GdipReleaseDC(graphics, hdc);
2416 expect(Ok, status);
2418 GdipDeleteGraphics(graphics);
2420 GdipDisposeImage((GpImage*)bitmap);
2423 static void test_GdipIsVisiblePoint(void)
2425 GpStatus status;
2426 GpGraphics *graphics = NULL;
2427 HDC hdc = GetDC( hwnd );
2428 REAL x, y;
2429 BOOL val;
2431 ok(hdc != NULL, "Expected HDC to be initialized\n");
2433 status = GdipCreateFromHDC(hdc, &graphics);
2434 expect(Ok, status);
2435 ok(graphics != NULL, "Expected graphics to be initialized\n");
2437 /* null parameters */
2438 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2439 expect(InvalidParameter, status);
2441 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2442 expect(InvalidParameter, status);
2444 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2445 expect(InvalidParameter, status);
2447 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2448 expect(InvalidParameter, status);
2450 x = 0;
2451 y = 0;
2452 status = GdipIsVisiblePoint(graphics, x, y, &val);
2453 expect(Ok, status);
2454 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2456 x = -10;
2457 y = 0;
2458 status = GdipIsVisiblePoint(graphics, x, y, &val);
2459 expect(Ok, status);
2460 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2462 x = 0;
2463 y = -5;
2464 status = GdipIsVisiblePoint(graphics, x, y, &val);
2465 expect(Ok, status);
2466 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2468 x = 1;
2469 y = 1;
2470 status = GdipIsVisiblePoint(graphics, x, y, &val);
2471 expect(Ok, status);
2472 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2474 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2475 expect(Ok, status);
2477 x = 1;
2478 y = 1;
2479 status = GdipIsVisiblePoint(graphics, x, y, &val);
2480 expect(Ok, status);
2481 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2483 x = 15.5;
2484 y = 40.5;
2485 status = GdipIsVisiblePoint(graphics, x, y, &val);
2486 expect(Ok, status);
2487 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2489 /* translate into the center of the rect */
2490 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2492 x = 0;
2493 y = 0;
2494 status = GdipIsVisiblePoint(graphics, x, y, &val);
2495 expect(Ok, status);
2496 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2498 x = 25;
2499 y = 40;
2500 status = GdipIsVisiblePoint(graphics, x, y, &val);
2501 expect(Ok, status);
2502 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2504 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2506 /* corner cases */
2507 x = 9;
2508 y = 19;
2509 status = GdipIsVisiblePoint(graphics, x, y, &val);
2510 expect(Ok, status);
2511 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2513 x = 9.25;
2514 y = 19.25;
2515 status = GdipIsVisiblePoint(graphics, x, y, &val);
2516 expect(Ok, status);
2517 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2519 x = 9.5;
2520 y = 19.5;
2521 status = GdipIsVisiblePoint(graphics, x, y, &val);
2522 expect(Ok, status);
2523 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2525 x = 9.75;
2526 y = 19.75;
2527 status = GdipIsVisiblePoint(graphics, x, y, &val);
2528 expect(Ok, status);
2529 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2531 x = 10;
2532 y = 20;
2533 status = GdipIsVisiblePoint(graphics, x, y, &val);
2534 expect(Ok, status);
2535 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2537 x = 40;
2538 y = 20;
2539 status = GdipIsVisiblePoint(graphics, x, y, &val);
2540 expect(Ok, status);
2541 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2543 x = 39;
2544 y = 59;
2545 status = GdipIsVisiblePoint(graphics, x, y, &val);
2546 expect(Ok, status);
2547 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2549 x = 39.25;
2550 y = 59.25;
2551 status = GdipIsVisiblePoint(graphics, x, y, &val);
2552 expect(Ok, status);
2553 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2555 x = 39.5;
2556 y = 39.5;
2557 status = GdipIsVisiblePoint(graphics, x, y, &val);
2558 expect(Ok, status);
2559 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2561 x = 39.75;
2562 y = 59.75;
2563 status = GdipIsVisiblePoint(graphics, x, y, &val);
2564 expect(Ok, status);
2565 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2567 x = 40;
2568 y = 60;
2569 status = GdipIsVisiblePoint(graphics, x, y, &val);
2570 expect(Ok, status);
2571 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2573 x = 40.15;
2574 y = 60.15;
2575 status = GdipIsVisiblePoint(graphics, x, y, &val);
2576 expect(Ok, status);
2577 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2579 x = 10;
2580 y = 60;
2581 status = GdipIsVisiblePoint(graphics, x, y, &val);
2582 expect(Ok, status);
2583 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2585 /* integer version */
2586 x = 25;
2587 y = 30;
2588 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2589 expect(Ok, status);
2590 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2592 x = 50;
2593 y = 100;
2594 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2595 expect(Ok, status);
2596 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2598 GdipDeleteGraphics(graphics);
2599 ReleaseDC(hwnd, hdc);
2602 static void test_GdipIsVisibleRect(void)
2604 GpStatus status;
2605 GpGraphics *graphics = NULL;
2606 HDC hdc = GetDC( hwnd );
2607 REAL x, y, width, height;
2608 BOOL val;
2610 ok(hdc != NULL, "Expected HDC to be initialized\n");
2612 status = GdipCreateFromHDC(hdc, &graphics);
2613 expect(Ok, status);
2614 ok(graphics != NULL, "Expected graphics to be initialized\n");
2616 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2617 expect(InvalidParameter, status);
2619 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2620 expect(InvalidParameter, status);
2622 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2623 expect(InvalidParameter, status);
2625 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2626 expect(InvalidParameter, status);
2628 /* entirely within the visible region */
2629 x = 0; width = 10;
2630 y = 0; height = 10;
2631 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2632 expect(Ok, status);
2633 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2635 /* partially outside */
2636 x = -10; width = 20;
2637 y = -10; height = 20;
2638 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2639 expect(Ok, status);
2640 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2642 /* entirely outside */
2643 x = -10; width = 5;
2644 y = -10; height = 5;
2645 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2646 expect(Ok, status);
2647 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2649 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2650 expect(Ok, status);
2652 /* entirely within the visible region */
2653 x = 12; width = 10;
2654 y = 22; height = 10;
2655 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2656 expect(Ok, status);
2657 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2659 /* partially outside */
2660 x = 35; width = 10;
2661 y = 55; height = 10;
2662 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2663 expect(Ok, status);
2664 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2666 /* entirely outside */
2667 x = 45; width = 5;
2668 y = 65; height = 5;
2669 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2670 expect(Ok, status);
2671 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2673 /* translate into center of clipping rect */
2674 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2676 x = 0; width = 10;
2677 y = 0; height = 10;
2678 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2679 expect(Ok, status);
2680 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2682 x = 25; width = 5;
2683 y = 40; height = 5;
2684 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2685 expect(Ok, status);
2686 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2688 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2690 /* corners entirely outside, but some intersections */
2691 x = 0; width = 70;
2692 y = 0; height = 90;
2693 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2694 expect(Ok, status);
2695 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2697 x = 0; width = 70;
2698 y = 0; height = 30;
2699 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2700 expect(Ok, status);
2701 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2703 x = 0; width = 30;
2704 y = 0; height = 90;
2705 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2706 expect(Ok, status);
2707 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2709 /* edge cases */
2710 x = 0; width = 10;
2711 y = 20; height = 40;
2712 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2713 expect(Ok, status);
2714 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2716 x = 10; width = 30;
2717 y = 0; height = 20;
2718 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2719 expect(Ok, status);
2720 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2722 x = 40; width = 10;
2723 y = 20; height = 40;
2724 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2725 expect(Ok, status);
2726 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2728 x = 10; width = 30;
2729 y = 60; height = 10;
2730 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2731 expect(Ok, status);
2732 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2734 /* rounding tests */
2735 x = 0.4; width = 10.4;
2736 y = 20; height = 40;
2737 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2738 expect(Ok, status);
2739 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2741 x = 10; width = 30;
2742 y = 0.4; height = 20.4;
2743 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2744 expect(Ok, status);
2745 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2747 /* integer version */
2748 x = 0; width = 30;
2749 y = 0; height = 90;
2750 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2751 expect(Ok, status);
2752 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2754 x = 12; width = 10;
2755 y = 22; height = 10;
2756 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2757 expect(Ok, status);
2758 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2760 GdipDeleteGraphics(graphics);
2761 ReleaseDC(hwnd, hdc);
2764 static void test_GdipGetNearestColor(void)
2766 GpStatus status;
2767 GpGraphics *graphics;
2768 GpBitmap *bitmap;
2769 ARGB color = 0xdeadbeef;
2770 HDC hdc = GetDC( hwnd );
2772 /* create a graphics object */
2773 ok(hdc != NULL, "Expected HDC to be initialized\n");
2775 status = GdipCreateFromHDC(hdc, &graphics);
2776 expect(Ok, status);
2777 ok(graphics != NULL, "Expected graphics to be initialized\n");
2779 status = GdipGetNearestColor(graphics, NULL);
2780 expect(InvalidParameter, status);
2782 status = GdipGetNearestColor(NULL, &color);
2783 expect(InvalidParameter, status);
2784 GdipDeleteGraphics(graphics);
2786 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2787 expect(Ok, status);
2788 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2789 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2790 if (status == Ok)
2792 status = GdipGetNearestColor(graphics, &color);
2793 expect(Ok, status);
2794 expect(0xdeadbeef, color);
2795 GdipDeleteGraphics(graphics);
2797 GdipDisposeImage((GpImage*)bitmap);
2799 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2800 expect(Ok, status);
2801 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2802 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2803 if (status == Ok)
2805 status = GdipGetNearestColor(graphics, &color);
2806 expect(Ok, status);
2807 expect(0xdeadbeef, color);
2808 GdipDeleteGraphics(graphics);
2810 GdipDisposeImage((GpImage*)bitmap);
2812 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2813 expect(Ok, status);
2814 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2815 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2816 if (status == Ok)
2818 status = GdipGetNearestColor(graphics, &color);
2819 expect(Ok, status);
2820 expect(0xdeadbeef, color);
2821 GdipDeleteGraphics(graphics);
2823 GdipDisposeImage((GpImage*)bitmap);
2825 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2826 expect(Ok, status);
2827 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2828 todo_wine expect(OutOfMemory, status);
2829 if (status == Ok)
2830 GdipDeleteGraphics(graphics);
2831 GdipDisposeImage((GpImage*)bitmap);
2833 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2834 expect(Ok, status);
2835 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2836 expect(Ok, status);
2837 status = GdipGetNearestColor(graphics, &color);
2838 expect(Ok, status);
2839 expect(0xdeadbeef, color);
2840 GdipDeleteGraphics(graphics);
2841 GdipDisposeImage((GpImage*)bitmap);
2843 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2844 expect(Ok, status);
2845 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2846 expect(Ok, status);
2847 status = GdipGetNearestColor(graphics, &color);
2848 expect(Ok, status);
2849 expect(0xdeadbeef, color);
2850 GdipDeleteGraphics(graphics);
2851 GdipDisposeImage((GpImage*)bitmap);
2853 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2854 expect(Ok, status);
2855 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2856 expect(Ok, status);
2857 status = GdipGetNearestColor(graphics, &color);
2858 expect(Ok, status);
2859 expect(0xdeadbeef, color);
2860 GdipDeleteGraphics(graphics);
2861 GdipDisposeImage((GpImage*)bitmap);
2863 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2864 expect(Ok, status);
2865 if (status == Ok)
2867 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2868 expect(Ok, status);
2869 status = GdipGetNearestColor(graphics, &color);
2870 expect(Ok, status);
2871 expect(0xdeadbeef, color);
2872 GdipDeleteGraphics(graphics);
2873 GdipDisposeImage((GpImage*)bitmap);
2876 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2877 expect(Ok, status);
2878 if (status == Ok)
2880 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2881 expect(Ok, status);
2882 status = GdipGetNearestColor(graphics, &color);
2883 expect(Ok, status);
2884 expect(0xdeadbeef, color);
2885 GdipDeleteGraphics(graphics);
2886 GdipDisposeImage((GpImage*)bitmap);
2889 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2890 expect(Ok, status);
2891 if (status == Ok)
2893 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2894 expect(Ok, status);
2895 status = GdipGetNearestColor(graphics, &color);
2896 expect(Ok, status);
2897 expect(0xdeadbeef, color);
2898 GdipDeleteGraphics(graphics);
2899 GdipDisposeImage((GpImage*)bitmap);
2902 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2903 expect(Ok, status);
2904 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2905 expect(Ok, status);
2906 status = GdipGetNearestColor(graphics, &color);
2907 expect(Ok, status);
2908 todo_wine expect(0xffa8bce8, color);
2909 GdipDeleteGraphics(graphics);
2910 GdipDisposeImage((GpImage*)bitmap);
2912 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2913 expect(Ok, status);
2914 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2915 expect(Ok, status);
2916 status = GdipGetNearestColor(graphics, &color);
2917 expect(Ok, status);
2918 todo_wine
2919 ok(color == 0xffa8b8e8 ||
2920 broken(color == 0xffa0b8e0), /* Win98/WinMe */
2921 "Expected ffa8b8e8, got %.8x\n", color);
2922 GdipDeleteGraphics(graphics);
2923 GdipDisposeImage((GpImage*)bitmap);
2925 ReleaseDC(hwnd, hdc);
2928 static void test_string_functions(void)
2930 GpStatus status;
2931 GpGraphics *graphics;
2932 GpFontFamily *family;
2933 GpFont *font;
2934 RectF rc, char_bounds, bounds;
2935 GpBrush *brush;
2936 ARGB color = 0xff000000;
2937 HDC hdc = GetDC( hwnd );
2938 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2939 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2940 const WCHAR teststring2[] = {'j',0};
2941 REAL char_width, char_height;
2942 INT codepointsfitted, linesfilled;
2943 GpStringFormat *format;
2944 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2945 GpRegion *regions[4];
2946 BOOL region_isempty[4];
2947 int i;
2948 PointF positions[8];
2949 GpMatrix *identity;
2951 ok(hdc != NULL, "Expected HDC to be initialized\n");
2952 status = GdipCreateFromHDC(hdc, &graphics);
2953 expect(Ok, status);
2954 ok(graphics != NULL, "Expected graphics to be initialized\n");
2956 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2957 expect(Ok, status);
2959 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2960 expect(Ok, status);
2962 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2963 expect(Ok, status);
2965 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2966 expect(Ok, status);
2968 rc.X = 0;
2969 rc.Y = 0;
2970 rc.Width = 100.0;
2971 rc.Height = 100.0;
2973 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2974 expect(InvalidParameter, status);
2976 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2977 expect(InvalidParameter, status);
2979 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2980 expect(InvalidParameter, status);
2982 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2983 expect(InvalidParameter, status);
2985 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2986 expect(InvalidParameter, status);
2988 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2989 expect(Ok, status);
2991 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2992 expect(InvalidParameter, status);
2994 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2995 expect(InvalidParameter, status);
2997 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2998 expect(InvalidParameter, status);
3000 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3001 expect(InvalidParameter, status);
3003 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3004 expect(InvalidParameter, status);
3006 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3007 expect(Ok, status);
3009 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3010 expect(Ok, status);
3012 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3013 expect(Ok, status);
3014 expectf(0.0, char_bounds.X);
3015 expectf(0.0, char_bounds.Y);
3016 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3017 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3018 expect(1, codepointsfitted);
3019 expect(1, linesfilled);
3021 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3022 expect(Ok, status);
3023 expectf(0.0, bounds.X);
3024 expectf(0.0, bounds.Y);
3025 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3026 expectf(char_bounds.Height, bounds.Height);
3027 expect(2, codepointsfitted);
3028 expect(1, linesfilled);
3029 char_width = bounds.Width - char_bounds.Width;
3031 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3032 expect(Ok, status);
3033 expectf(0.0, bounds.X);
3034 expectf(0.0, bounds.Y);
3035 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3036 bounds.Width, char_bounds.Width + char_width * 2);
3037 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3038 expect(6, codepointsfitted);
3039 expect(2, linesfilled);
3040 char_height = bounds.Height - char_bounds.Height;
3042 /* Measure the first line. */
3043 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3044 expect(Ok, status);
3045 expectf(0.0, bounds.X);
3046 expectf(0.0, bounds.Y);
3047 expect(4, codepointsfitted);
3048 expect(1, linesfilled);
3050 /* Give just enough space to fit the first line. */
3051 rc.Width = bounds.Width;
3052 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3053 expect(Ok, status);
3054 expectf(0.0, bounds.X);
3055 expectf(0.0, bounds.Y);
3056 todo_wine expect(5, codepointsfitted);
3057 todo_wine expect(1, linesfilled);
3059 /* Cut off everything after the first space. */
3060 rc.Width = char_bounds.Width + char_width * 2.1;
3062 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3063 expect(Ok, status);
3064 expectf(0.0, bounds.X);
3065 expectf(0.0, bounds.Y);
3066 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3067 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3068 expect(6, codepointsfitted);
3069 expect(3, linesfilled);
3071 /* Cut off everything including the first space. */
3072 rc.Width = char_bounds.Width + char_width * 1.7;
3074 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3075 expect(Ok, status);
3076 expectf(0.0, bounds.X);
3077 expectf(0.0, bounds.Y);
3078 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3079 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3080 expect(6, codepointsfitted);
3081 expect(3, linesfilled);
3083 /* Cut off everything after the first character. */
3084 rc.Width = char_bounds.Width + char_width * 0.8;
3086 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3087 expect(Ok, status);
3088 expectf(0.0, bounds.X);
3089 expectf(0.0, bounds.Y);
3090 expectf_(char_bounds.Width, bounds.Width, 0.01);
3091 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3092 expect(6, codepointsfitted);
3093 todo_wine expect(4, linesfilled);
3095 for (i = 0; i < 4; i++)
3096 regions[i] = (GpRegion *)0xdeadbeef;
3098 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3099 expect(Ok, status);
3101 for (i = 0; i < 4; i++)
3102 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3104 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3105 expect(Ok, status);
3107 for (i = 0; i < 4; i++)
3108 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3110 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3111 expect(Ok, status);
3113 set_rect_empty(&rc);
3115 for (i=0; i<4; i++)
3117 status = GdipCreateRegion(&regions[i]);
3118 expect(Ok, status);
3119 status = GdipSetEmpty(regions[i]);
3120 expect(Ok, status);
3123 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3124 expect(InvalidParameter, status);
3126 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3127 expect(InvalidParameter, status);
3129 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3130 expect(InvalidParameter, status);
3132 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3133 expect(InvalidParameter, status);
3135 if (0)
3137 /* Crashes on Windows XP */
3138 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3139 expect(InvalidParameter, status);
3142 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3143 expect(InvalidParameter, status);
3145 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3146 expect(InvalidParameter, status);
3148 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3149 expect(Ok, status);
3151 for (i = 0; i < 4; i++)
3153 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3154 expect(Ok, status);
3157 ok(region_isempty[0], "region should be empty\n");
3158 ok(region_isempty[1], "region should be empty\n");
3159 ok(region_isempty[2], "region should be empty\n");
3160 ok(region_isempty[3], "region should be empty\n");
3162 rc.Width = 100.0;
3163 rc.Height = 100.0;
3165 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3166 expect(Ok, status);
3168 for (i=0; i<4; i++)
3170 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3171 expect(Ok, status);
3174 ok(!region_isempty[0], "region shouldn't be empty\n");
3175 ok(!region_isempty[1], "region shouldn't be empty\n");
3176 ok(!region_isempty[2], "region shouldn't be empty\n");
3177 ok(region_isempty[3], "region should be empty\n");
3179 /* Cut off everything after the first space, and the second line. */
3180 rc.Width = char_bounds.Width + char_width * 2.1;
3181 rc.Height = char_bounds.Height + char_height * 0.5;
3183 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3184 expect(Ok, status);
3186 for (i=0; i<4; i++)
3188 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3189 expect(Ok, status);
3192 ok(!region_isempty[0], "region shouldn't be empty\n");
3193 ok(!region_isempty[1], "region shouldn't be empty\n");
3194 ok(region_isempty[2], "region should be empty\n");
3195 ok(region_isempty[3], "region should be empty\n");
3197 for (i=0; i<4; i++)
3198 GdipDeleteRegion(regions[i]);
3200 status = GdipCreateMatrix(&identity);
3201 expect(Ok, status);
3203 rc.X = 0;
3204 rc.Y = 0;
3205 rc.Width = 0;
3206 rc.Height = 0;
3207 memset(positions, 0, sizeof(positions));
3208 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3209 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3210 identity, &rc);
3211 expect(InvalidParameter, status);
3213 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3214 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3215 identity, &rc);
3216 expect(InvalidParameter, status);
3218 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3219 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3220 identity, &rc);
3221 expect(InvalidParameter, status);
3223 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3224 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3225 identity, &rc);
3226 expect(InvalidParameter, status);
3228 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3229 0x100, identity, &rc);
3230 expect(Ok, status);
3232 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3233 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3234 NULL, &rc);
3235 expect(Ok, status);
3237 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3238 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3239 identity, NULL);
3240 expect(InvalidParameter, status);
3242 rc.X = 0;
3243 rc.Y = 0;
3244 rc.Width = 0;
3245 rc.Height = 0;
3246 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3247 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3248 identity, &rc);
3249 expect(Ok, status);
3251 expectf(0.0, rc.X);
3252 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3253 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3254 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3256 char_width = rc.Width;
3257 char_height = rc.Height;
3259 rc.X = 0;
3260 rc.Y = 0;
3261 rc.Width = 0;
3262 rc.Height = 0;
3263 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3264 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3265 identity, &rc);
3266 expect(Ok, status);
3268 expectf(0.0, rc.X);
3269 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3270 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3271 expectf(char_height, rc.Height);
3273 rc.X = 0;
3274 rc.Y = 0;
3275 rc.Width = 0;
3276 rc.Height = 0;
3277 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3278 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3279 identity, &rc);
3280 expect(Ok, status);
3282 expectf(rc.X, 0.0);
3283 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3284 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3285 expectf(rc.Height, char_height);
3287 GdipDeleteMatrix(identity);
3288 GdipDeleteStringFormat(format);
3289 GdipDeleteBrush(brush);
3290 GdipDeleteFont(font);
3291 GdipDeleteFontFamily(family);
3292 GdipDeleteGraphics(graphics);
3294 ReleaseDC(hwnd, hdc);
3297 static void test_get_set_interpolation(void)
3299 GpGraphics *graphics;
3300 HDC hdc = GetDC( hwnd );
3301 GpStatus status;
3302 InterpolationMode mode;
3304 ok(hdc != NULL, "Expected HDC to be initialized\n");
3305 status = GdipCreateFromHDC(hdc, &graphics);
3306 expect(Ok, status);
3307 ok(graphics != NULL, "Expected graphics to be initialized\n");
3309 status = GdipGetInterpolationMode(NULL, &mode);
3310 expect(InvalidParameter, status);
3312 if (0)
3314 /* Crashes on Windows XP */
3315 status = GdipGetInterpolationMode(graphics, NULL);
3316 expect(InvalidParameter, status);
3319 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3320 expect(InvalidParameter, status);
3322 /* out of range */
3323 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3324 expect(InvalidParameter, status);
3326 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3327 expect(InvalidParameter, status);
3329 status = GdipGetInterpolationMode(graphics, &mode);
3330 expect(Ok, status);
3331 expect(InterpolationModeBilinear, mode);
3333 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3334 expect(Ok, status);
3336 status = GdipGetInterpolationMode(graphics, &mode);
3337 expect(Ok, status);
3338 expect(InterpolationModeNearestNeighbor, mode);
3340 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3341 expect(Ok, status);
3343 status = GdipGetInterpolationMode(graphics, &mode);
3344 expect(Ok, status);
3345 expect(InterpolationModeBilinear, mode);
3347 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3348 expect(Ok, status);
3350 status = GdipGetInterpolationMode(graphics, &mode);
3351 expect(Ok, status);
3352 expect(InterpolationModeBilinear, mode);
3354 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3355 expect(Ok, status);
3357 status = GdipGetInterpolationMode(graphics, &mode);
3358 expect(Ok, status);
3359 expect(InterpolationModeHighQualityBicubic, mode);
3361 GdipDeleteGraphics(graphics);
3363 ReleaseDC(hwnd, hdc);
3366 static void test_get_set_textrenderinghint(void)
3368 GpGraphics *graphics;
3369 HDC hdc = GetDC( hwnd );
3370 GpStatus status;
3371 TextRenderingHint hint;
3373 ok(hdc != NULL, "Expected HDC to be initialized\n");
3374 status = GdipCreateFromHDC(hdc, &graphics);
3375 expect(Ok, status);
3376 ok(graphics != NULL, "Expected graphics to be initialized\n");
3378 status = GdipGetTextRenderingHint(NULL, &hint);
3379 expect(InvalidParameter, status);
3381 status = GdipGetTextRenderingHint(graphics, NULL);
3382 expect(InvalidParameter, status);
3384 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3385 expect(InvalidParameter, status);
3387 /* out of range */
3388 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3389 expect(InvalidParameter, status);
3391 status = GdipGetTextRenderingHint(graphics, &hint);
3392 expect(Ok, status);
3393 expect(TextRenderingHintSystemDefault, hint);
3395 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3396 expect(Ok, status);
3398 status = GdipGetTextRenderingHint(graphics, &hint);
3399 expect(Ok, status);
3400 expect(TextRenderingHintSystemDefault, hint);
3402 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3403 expect(Ok, status);
3405 status = GdipGetTextRenderingHint(graphics, &hint);
3406 expect(Ok, status);
3407 expect(TextRenderingHintAntiAliasGridFit, hint);
3409 GdipDeleteGraphics(graphics);
3411 ReleaseDC(hwnd, hdc);
3414 static void test_getdc_scaled(void)
3416 GpStatus status;
3417 GpGraphics *graphics = NULL;
3418 GpBitmap *bitmap = NULL;
3419 HDC hdc=NULL;
3420 HBRUSH hbrush, holdbrush;
3421 ARGB color;
3423 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3424 expect(Ok, status);
3426 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3427 expect(Ok, status);
3429 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3430 expect(Ok, status);
3432 status = GdipGetDC(graphics, &hdc);
3433 expect(Ok, status);
3434 ok(hdc != NULL, "got NULL hdc\n");
3436 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3438 holdbrush = SelectObject(hdc, hbrush);
3440 Rectangle(hdc, 2, 2, 6, 6);
3442 SelectObject(hdc, holdbrush);
3444 DeleteObject(hbrush);
3446 status = GdipReleaseDC(graphics, hdc);
3447 expect(Ok, status);
3449 GdipDeleteGraphics(graphics);
3451 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3452 expect(Ok, status);
3453 expect(0xffff0000, color);
3455 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3456 expect(Ok, status);
3457 expect(0xff000000, color);
3459 GdipDisposeImage((GpImage*)bitmap);
3462 static void test_GdipMeasureString(void)
3464 static const struct test_data
3466 REAL res_x, res_y, page_scale;
3467 GpUnit unit;
3468 } td[] =
3470 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3471 { 200.0, 200.0, 2.0, UnitPixel },
3472 { 200.0, 200.0, 1.0, UnitDisplay },
3473 { 200.0, 200.0, 2.0, UnitDisplay },
3474 { 200.0, 200.0, 1.0, UnitInch },
3475 { 200.0, 200.0, 2.0, UnitInch },
3476 { 200.0, 600.0, 1.0, UnitPoint },
3477 { 200.0, 600.0, 2.0, UnitPoint },
3478 { 200.0, 600.0, 1.0, UnitDocument },
3479 { 200.0, 600.0, 2.0, UnitDocument },
3480 { 200.0, 600.0, 1.0, UnitMillimeter },
3481 { 200.0, 600.0, 2.0, UnitMillimeter },
3482 { 200.0, 600.0, 1.0, UnitDisplay },
3483 { 200.0, 600.0, 2.0, UnitDisplay },
3484 { 200.0, 600.0, 1.0, UnitPixel },
3485 { 200.0, 600.0, 2.0, UnitPixel },
3487 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3488 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3489 GpStatus status;
3490 GpGraphics *graphics;
3491 GpFontFamily *family;
3492 GpFont *font;
3493 GpStringFormat *format;
3494 RectF bounds, rc;
3495 REAL base_cx = 0, base_cy = 0, height;
3496 INT chars, lines;
3497 LOGFONTW lf;
3498 UINT i;
3499 REAL font_size;
3500 GpUnit font_unit, unit;
3502 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3503 expect(Ok, status);
3504 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3505 expect(Ok, status);
3507 /* font size in pixels */
3508 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3509 expect(Ok, status);
3510 status = GdipGetFontSize(font, &font_size);
3511 expect(Ok, status);
3512 expectf(100.0, font_size);
3513 status = GdipGetFontUnit(font, &font_unit);
3514 expect(Ok, status);
3515 expect(UnitPixel, font_unit);
3517 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3519 GpImage *image;
3521 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3523 lf.lfHeight = 0xdeadbeef;
3524 status = GdipGetLogFontW(font, graphics, &lf);
3525 expect(Ok, status);
3526 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3527 if (td[i].unit != UnitDisplay)
3528 height *= td[i].page_scale;
3529 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3530 i, (LONG)(height + 0.5), height, lf.lfHeight);
3532 height = font_size + 2.0 * font_size / 6.0;
3534 set_rect_empty(&rc);
3535 set_rect_empty(&bounds);
3536 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3537 expect(Ok, status);
3539 if (i == 0)
3541 base_cx = bounds.Width;
3542 base_cy = bounds.Height;
3545 expectf(0.0, bounds.X);
3546 expectf(0.0, bounds.Y);
3547 todo_wine
3548 expectf_(height, bounds.Height, height / 100.0);
3549 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3550 expect(7, chars);
3551 expect(1, lines);
3553 /* make sure it really fits */
3554 bounds.Width += 1.0;
3555 bounds.Height += 1.0;
3556 rc = bounds;
3557 rc.X = 50.0;
3558 rc.Y = 50.0;
3559 set_rect_empty(&bounds);
3560 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3561 expect(Ok, status);
3562 expectf(50.0, bounds.X);
3563 expectf(50.0, bounds.Y);
3564 todo_wine
3565 expectf_(height, bounds.Height, height / 100.0);
3566 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3567 expect(7, chars);
3568 expect(1, lines);
3570 status = GdipDeleteGraphics(graphics);
3571 expect(Ok, status);
3573 status = GdipDisposeImage(image);
3574 expect(Ok, status);
3577 GdipDeleteFont(font);
3579 /* font size in logical units */
3580 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3581 for (unit = 3; unit <= 6; unit++)
3583 /* create a font which final height is 100.0 pixels with 200 dpi device */
3584 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3585 height = pixels_to_units(75.0, unit, 200.0);
3586 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3587 expect(Ok, status);
3588 status = GdipGetFontSize(font, &font_size);
3589 expect(Ok, status);
3590 expectf(height, font_size);
3591 status = GdipGetFontUnit(font, &font_unit);
3592 expect(Ok, status);
3593 expect(unit, font_unit);
3595 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3597 REAL unit_scale;
3598 GpImage *image;
3600 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3602 lf.lfHeight = 0xdeadbeef;
3603 status = GdipGetLogFontW(font, graphics, &lf);
3604 expect(Ok, status);
3605 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3606 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3607 else
3608 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3609 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3610 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3611 i, (LONG)(height + 0.5), height, lf.lfHeight);
3613 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3614 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3615 else
3616 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3617 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3618 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3619 if (td[i].unit != UnitDisplay)
3620 height /= td[i].page_scale;
3621 /*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);*/
3623 set_rect_empty(&rc);
3624 set_rect_empty(&bounds);
3625 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3626 expect(Ok, status);
3628 if (i == 0)
3630 base_cx = bounds.Width;
3631 base_cy = bounds.Height;
3634 expectf(0.0, bounds.X);
3635 expectf(0.0, bounds.Y);
3636 todo_wine
3637 expectf_(height, bounds.Height, height / 85.0);
3638 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3639 expect(7, chars);
3640 expect(1, lines);
3642 /* make sure it really fits */
3643 bounds.Width += 1.0;
3644 bounds.Height += 1.0;
3645 rc = bounds;
3646 rc.X = 50.0;
3647 rc.Y = 50.0;
3648 set_rect_empty(&bounds);
3649 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3650 expect(Ok, status);
3651 expectf(50.0, bounds.X);
3652 expectf(50.0, bounds.Y);
3653 todo_wine
3654 expectf_(height, bounds.Height, height / 85.0);
3655 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3656 expect(7, chars);
3657 expect(1, lines);
3659 /* verify the result */
3660 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3661 if (td[i].unit != UnitDisplay)
3662 height *= td[i].page_scale;
3663 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3664 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3665 todo_wine
3666 expectf_(100.0, height, 1.1);
3668 status = GdipDeleteGraphics(graphics);
3669 expect(Ok, status);
3671 status = GdipDisposeImage(image);
3672 expect(Ok, status);
3675 GdipDeleteFont(font);
3678 GdipDeleteFontFamily(family);
3679 GdipDeleteStringFormat(format);
3682 static void test_transform(void)
3684 static const struct test_data
3686 REAL res_x, res_y, scale;
3687 GpUnit unit;
3688 GpPointF in[2], out[2];
3689 } td[] =
3691 { 96.0, 96.0, 1.0, UnitPixel,
3692 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3693 { 96.0, 96.0, 1.0, UnitDisplay,
3694 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3695 { 96.0, 96.0, 1.0, UnitInch,
3696 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
3697 { 123.0, 456.0, 1.0, UnitPoint,
3698 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
3699 { 123.0, 456.0, 1.0, UnitDocument,
3700 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
3701 { 123.0, 456.0, 2.0, UnitMillimeter,
3702 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
3703 { 196.0, 296.0, 1.0, UnitDisplay,
3704 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3705 { 196.0, 296.0, 1.0, UnitPixel,
3706 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3708 GpStatus status;
3709 GpGraphics *graphics;
3710 GpImage *image;
3711 GpPointF ptf[2];
3712 UINT i;
3714 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3716 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
3717 ptf[0].X = td[i].in[0].X;
3718 ptf[0].Y = td[i].in[0].Y;
3719 ptf[1].X = td[i].in[1].X;
3720 ptf[1].Y = td[i].in[1].Y;
3721 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
3722 expect(Ok, status);
3723 expectf(td[i].out[0].X, ptf[0].X);
3724 expectf(td[i].out[0].Y, ptf[0].Y);
3725 expectf(td[i].out[1].X, ptf[1].X);
3726 expectf(td[i].out[1].Y, ptf[1].Y);
3727 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
3728 expect(Ok, status);
3729 expectf(td[i].in[0].X, ptf[0].X);
3730 expectf(td[i].in[0].Y, ptf[0].Y);
3731 expectf(td[i].in[1].X, ptf[1].X);
3732 expectf(td[i].in[1].Y, ptf[1].Y);
3733 status = GdipDeleteGraphics(graphics);
3734 expect(Ok, status);
3735 status = GdipDisposeImage(image);
3736 expect(Ok, status);
3740 /* Many people on the net ask why there is so much difference in rendered
3741 * text height between gdiplus and gdi32, this test suggests an answer to
3742 * that question. Important: this test assumes that font dpi == device dpi.
3744 static void test_font_height_scaling(void)
3746 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3747 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3748 HDC hdc;
3749 GpStringFormat *format;
3750 CharacterRange range = { 0, 7 };
3751 GpRegion *region;
3752 GpGraphics *graphics;
3753 GpFontFamily *family;
3754 GpFont *font;
3755 GpStatus status;
3756 RectF bounds, rect;
3757 REAL height, dpi, scale;
3758 PointF ptf;
3759 GpUnit gfx_unit, font_unit;
3761 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3762 expect(Ok, status);
3763 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3764 expect(Ok, status);
3765 status = GdipCreateRegion(&region);
3766 expect(Ok, status);
3768 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3769 expect(Ok, status);
3771 hdc = CreateCompatibleDC(0);
3772 status = GdipCreateFromHDC(hdc, &graphics);
3774 status = GdipGetDpiY(graphics, &dpi);
3775 expect(Ok, status);
3777 /* First check if tested functionality works:
3778 * under XP if font and graphics units differ then GdipTransformPoints
3779 * followed by GdipSetPageUnit to change the graphics units breaks region
3780 * scaling in GdipMeasureCharacterRanges called later.
3782 status = GdipSetPageUnit(graphics, UnitDocument);
3783 expect(Ok, status);
3785 ptf.X = 0.0;
3786 ptf.Y = 0.0;
3787 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
3788 expect(Ok, status);
3790 status = GdipSetPageUnit(graphics, UnitInch);
3791 expect(Ok, status);
3793 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
3794 expect(Ok, status);
3796 set_rect_empty(&rect);
3797 set_rect_empty(&bounds);
3798 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
3799 expect(Ok, status);
3800 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
3802 set_rect_empty(&rect);
3803 rect.Width = 32000.0;
3804 rect.Height = 32000.0;
3805 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3806 expect(Ok, status);
3808 set_rect_empty(&rect);
3809 status = GdipGetRegionBounds(region, graphics, &rect);
3810 expect(Ok, status);
3811 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
3813 GdipDeleteFont(font);
3815 scale = rect.Height / bounds.Height;
3816 if (fabs(scale - 1.0) > 0.1)
3818 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
3819 goto cleanup;
3822 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
3823 expect(Ok, status);
3825 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3826 /* UnitPixel as a font base unit is not tested because it drastically
3827 differs in behaviour */
3828 for (font_unit = 3; font_unit <= 6; font_unit++)
3830 /* create a font for the final text height of 100 pixels */
3831 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3832 status = GdipSetPageUnit(graphics, font_unit);
3833 expect(Ok, status);
3834 ptf.X = 0;
3835 ptf.Y = 75.0;
3836 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
3837 expect(Ok, status);
3838 height = ptf.Y;
3839 /*trace("height %f units\n", height);*/
3840 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
3841 expect(Ok, status);
3843 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3844 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
3846 static const WCHAR doubleW[2] = { 'W','W' };
3847 RectF bounds_1, bounds_2;
3848 REAL margin, margin_y, font_height;
3849 int match;
3851 status = GdipSetPageUnit(graphics, gfx_unit);
3852 expect(Ok, status);
3854 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
3855 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
3857 status = GdipGetFontHeight(font, graphics, &font_height);
3858 expect(Ok, status);
3860 set_rect_empty(&rect);
3861 set_rect_empty(&bounds);
3862 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
3863 expect(Ok, status);
3864 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
3865 todo_wine
3866 expectf_(font_height + margin_y, bounds.Height, 0.005);
3868 ptf.X = 0;
3869 ptf.Y = bounds.Height;
3870 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
3871 expect(Ok, status);
3872 match = fabs(100.0 - ptf.Y) <= 1.0;
3873 todo_wine
3874 ok(match, "Expected 100.0, got %f\n", ptf.Y);
3876 /* verify the result */
3877 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
3878 ptf.Y /= 100.0;
3879 match = fabs(100.0 - ptf.Y) <= 1.0;
3880 todo_wine
3881 ok(match, "Expected 100.0, got %f\n", ptf.Y);
3883 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
3884 set_rect_empty(&rect);
3885 set_rect_empty(&bounds_1);
3886 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
3887 expect(Ok, status);
3888 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
3889 set_rect_empty(&rect);
3890 set_rect_empty(&bounds_2);
3891 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
3892 expect(Ok, status);
3894 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
3895 margin = bounds_1.Width - bounds_2.Width / 2.0;
3896 /*trace("margin %f\n", margin);*/
3897 ok(margin > 0.0, "wrong margin %f\n", margin);
3899 set_rect_empty(&rect);
3900 rect.Width = 320000.0;
3901 rect.Height = 320000.0;
3902 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
3903 expect(Ok, status);
3904 set_rect_empty(&rect);
3905 status = GdipGetRegionBounds(region, graphics, &rect);
3906 expect(Ok, status);
3907 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
3908 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
3909 expectf(0.0, rect.Y);
3910 match = fabs(1.0 - margin / rect.X) <= 0.05;
3911 ok(match, "Expected %f, got %f\n", margin, rect.X);
3912 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
3913 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
3914 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
3915 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
3918 GdipDeleteFont(font);
3921 cleanup:
3922 status = GdipDeleteGraphics(graphics);
3923 expect(Ok, status);
3924 DeleteDC(hdc);
3926 GdipDeleteFontFamily(family);
3927 GdipDeleteRegion(region);
3928 GdipDeleteStringFormat(format);
3931 static void test_measure_string(void)
3933 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3934 static const WCHAR string[] = { 'A','0','1',0 };
3935 HDC hdc;
3936 GpStringFormat *format;
3937 CharacterRange range;
3938 GpRegion *region;
3939 GpGraphics *graphics;
3940 GpFontFamily *family;
3941 GpFont *font;
3942 GpStatus status;
3943 RectF bounds, rect;
3944 REAL width, height, width_1, width_2;
3945 REAL margin_x, margin_y, width_rgn, height_rgn;
3946 int lines, glyphs;
3948 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3949 expect(Ok, status);
3950 expect(Ok, status);
3952 status = GdipCreateRegion(&region);
3953 expect(Ok, status);
3955 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3956 expect(Ok, status);
3958 hdc = CreateCompatibleDC(0);
3959 status = GdipCreateFromHDC(hdc, &graphics);
3961 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
3962 expect(Ok, status);
3964 margin_x = 20.0 / 6.0;
3965 margin_y = 20.0 / 8.0;
3967 set_rect_empty(&rect);
3968 set_rect_empty(&bounds);
3969 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
3970 expect(Ok, status);
3971 expect(3, glyphs);
3972 expect(1, lines);
3973 expectf(0.0, bounds.X);
3974 expectf(0.0, bounds.Y);
3975 width = bounds.Width;
3976 height = bounds.Height;
3978 set_rect_empty(&rect);
3979 rect.Height = height / 2.0;
3980 set_rect_empty(&bounds);
3981 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
3982 expect(Ok, status);
3983 expect(3, glyphs);
3984 expect(1, lines);
3985 expectf(0.0, bounds.X);
3986 expectf(0.0, bounds.Y);
3987 expectf(width, bounds.Width);
3988 todo_wine
3989 expectf(height / 2.0, bounds.Height);
3991 range.First = 0;
3992 range.Length = lstrlenW(string);
3993 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3994 expect(Ok, status);
3996 rect.X = 5.0;
3997 rect.Y = 5.0;
3998 rect.Width = 32000.0;
3999 rect.Height = 32000.0;
4000 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4001 expect(Ok, status);
4002 set_rect_empty(&bounds);
4003 status = GdipGetRegionBounds(region, graphics, &bounds);
4004 expect(Ok, status);
4005 expectf_(5.0 + margin_x, bounds.X, 1.0);
4006 expectf(5.0, bounds.Y);
4007 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4008 todo_wine
4009 expectf_(height - margin_y, bounds.Height, 1.0);
4011 width_rgn = bounds.Width;
4012 height_rgn = bounds.Height;
4014 range.First = 0;
4015 range.Length = 1;
4016 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4017 expect(Ok, status);
4019 set_rect_empty(&rect);
4020 rect.Width = 32000.0;
4021 rect.Height = 32000.0;
4022 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4023 expect(Ok, status);
4024 set_rect_empty(&bounds);
4025 status = GdipGetRegionBounds(region, graphics, &bounds);
4026 expect(Ok, status);
4027 expectf_(margin_x, bounds.X, 1.0);
4028 expectf(0.0, bounds.Y);
4029 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4030 expectf(height_rgn, bounds.Height);
4031 width_1 = bounds.Width;
4033 range.First = 0;
4034 range.Length = lstrlenW(string);
4035 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4036 expect(Ok, status);
4038 rect.X = 5.0;
4039 rect.Y = 5.0;
4040 rect.Width = 0.0;
4041 rect.Height = 0.0;
4042 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4043 expect(Ok, status);
4044 set_rect_empty(&bounds);
4045 status = GdipGetRegionBounds(region, graphics, &bounds);
4046 expect(Ok, status);
4047 expectf(0.0, bounds.X);
4048 expectf(0.0, bounds.Y);
4049 expectf(0.0, bounds.Width);
4050 expectf(0.0, bounds.Height);
4052 rect.X = 5.0;
4053 rect.Y = 5.0;
4054 rect.Width = width_rgn / 2.0;
4055 rect.Height = 32000.0;
4056 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4057 expect(Ok, status);
4058 set_rect_empty(&bounds);
4059 status = GdipGetRegionBounds(region, graphics, &bounds);
4060 expect(Ok, status);
4061 expectf_(5.0 + margin_x, bounds.X, 1.0);
4062 expectf(5.0, bounds.Y);
4063 expectf_(width_1, bounds.Width, 1.0);
4064 todo_wine
4065 expectf_(height - margin_y, bounds.Height, 1.0);
4067 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4069 rect.X = 5.0;
4070 rect.Y = 5.0;
4071 rect.Width = 0.0;
4072 rect.Height = 0.0;
4073 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4074 expect(Ok, status);
4075 set_rect_empty(&bounds);
4076 status = GdipGetRegionBounds(region, graphics, &bounds);
4077 expect(Ok, status);
4078 expectf_(5.0 + margin_x, bounds.X, 1.0);
4079 expectf(5.0, bounds.Y);
4080 expectf(width_rgn, bounds.Width);
4081 expectf(height_rgn, bounds.Height);
4083 rect.X = 5.0;
4084 rect.Y = 5.0;
4085 rect.Width = width_rgn / 2.0;
4086 rect.Height = 32000.0;
4087 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4088 expect(Ok, status);
4089 set_rect_empty(&bounds);
4090 status = GdipGetRegionBounds(region, graphics, &bounds);
4091 expect(Ok, status);
4092 expectf_(5.0 + margin_x, bounds.X, 1.0);
4093 expectf(5.0, bounds.Y);
4094 expectf_(width_1, bounds.Width, 1.0);
4095 expectf(height_rgn, bounds.Height);
4097 set_rect_empty(&rect);
4098 rect.Height = height / 2.0;
4099 set_rect_empty(&bounds);
4100 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4101 expect(Ok, status);
4102 expect(3, glyphs);
4103 expect(1, lines);
4104 expectf(0.0, bounds.X);
4105 expectf(0.0, bounds.Y);
4106 expectf_(width, bounds.Width, 0.01);
4107 todo_wine
4108 expectf(height, bounds.Height);
4110 set_rect_empty(&rect);
4111 set_rect_empty(&bounds);
4112 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4113 expect(Ok, status);
4114 expect(1, glyphs);
4115 expect(1, lines);
4116 expectf(0.0, bounds.X);
4117 expectf(0.0, bounds.Y);
4118 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4119 expectf(height, bounds.Height);
4120 width_1 = bounds.Width;
4122 set_rect_empty(&rect);
4123 set_rect_empty(&bounds);
4124 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4125 expect(Ok, status);
4126 expect(2, glyphs);
4127 expect(1, lines);
4128 expectf(0.0, bounds.X);
4129 expectf(0.0, bounds.Y);
4130 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4131 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4132 expectf(height, bounds.Height);
4133 width_2 = bounds.Width;
4135 set_rect_empty(&rect);
4136 rect.Width = width / 2.0;
4137 set_rect_empty(&bounds);
4138 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4139 expect(Ok, status);
4140 expect(1, glyphs);
4141 expect(1, lines);
4142 expectf(0.0, bounds.X);
4143 expectf(0.0, bounds.Y);
4144 expectf_(width_1, bounds.Width, 0.01);
4145 expectf(height, bounds.Height);
4147 set_rect_empty(&rect);
4148 rect.Height = height;
4149 rect.Width = width - 0.05;
4150 set_rect_empty(&bounds);
4151 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4152 expect(Ok, status);
4153 expect(2, glyphs);
4154 expect(1, lines);
4155 expectf(0.0, bounds.X);
4156 expectf(0.0, bounds.Y);
4157 expectf_(width_2, bounds.Width, 0.01);
4158 expectf(height, bounds.Height);
4160 set_rect_empty(&rect);
4161 rect.Height = height;
4162 rect.Width = width_2 - 0.05;
4163 set_rect_empty(&bounds);
4164 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4165 expect(Ok, status);
4166 expect(1, glyphs);
4167 expect(1, lines);
4168 expectf(0.0, bounds.X);
4169 expectf(0.0, bounds.Y);
4170 expectf_(width_1, bounds.Width, 0.01);
4171 expectf(height, bounds.Height);
4173 /* Default (Near) alignment */
4174 rect.X = 5.0;
4175 rect.Y = 5.0;
4176 rect.Width = width * 2.0;
4177 rect.Height = height * 2.0;
4178 set_rect_empty(&bounds);
4179 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4180 expect(Ok, status);
4181 expect(3, glyphs);
4182 expect(1, lines);
4183 expectf(5.0, bounds.X);
4184 expectf(5.0, bounds.Y);
4185 expectf_(width, bounds.Width, 0.01);
4186 expectf(height, bounds.Height);
4188 rect.X = 5.0;
4189 rect.Y = 5.0;
4190 rect.Width = 32000.0;
4191 rect.Height = 32000.0;
4192 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4193 expect(Ok, status);
4194 set_rect_empty(&bounds);
4195 status = GdipGetRegionBounds(region, graphics, &bounds);
4196 expect(Ok, status);
4197 expectf_(5.0 + margin_x, bounds.X, 1.0);
4198 expectf(5.0, bounds.Y);
4199 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4200 todo_wine
4201 expectf_(height - margin_y, bounds.Height, 1.0);
4203 width_rgn = bounds.Width;
4204 height_rgn = bounds.Height;
4206 /* Center alignment */
4207 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4208 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4210 rect.X = 5.0;
4211 rect.Y = 5.0;
4212 rect.Width = width * 2.0;
4213 rect.Height = height * 2.0;
4214 set_rect_empty(&bounds);
4215 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4216 expect(Ok, status);
4217 expect(3, glyphs);
4218 expect(1, lines);
4219 todo_wine
4220 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4221 todo_wine
4222 expectf(5.0 + height/2.0, bounds.Y);
4223 expectf_(width, bounds.Width, 0.01);
4224 expectf(height, bounds.Height);
4226 rect.X = 5.0;
4227 rect.Y = 5.0;
4228 rect.Width = 0.0;
4229 rect.Height = 0.0;
4230 set_rect_empty(&bounds);
4231 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4232 expect(Ok, status);
4233 expect(3, glyphs);
4234 expect(1, lines);
4235 todo_wine
4236 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4237 todo_wine
4238 expectf(5.0 - height/2.0, bounds.Y);
4239 expectf_(width, bounds.Width, 0.01);
4240 expectf(height, bounds.Height);
4242 rect.X = 5.0;
4243 rect.Y = 5.0;
4244 rect.Width = width_rgn * 2.0;
4245 rect.Height = height_rgn * 2.0;
4246 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4247 expect(Ok, status);
4248 set_rect_empty(&bounds);
4249 status = GdipGetRegionBounds(region, graphics, &bounds);
4250 expect(Ok, status);
4251 todo_wine
4252 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4253 todo_wine
4254 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4255 expectf_(width_rgn, bounds.Width, 1.0);
4256 expectf_(height_rgn, bounds.Height, 1.0);
4258 rect.X = 5.0;
4259 rect.Y = 5.0;
4260 rect.Width = 0.0;
4261 rect.Height = 0.0;
4262 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4263 expect(Ok, status);
4264 set_rect_empty(&bounds);
4265 status = GdipGetRegionBounds(region, graphics, &bounds);
4266 expect(Ok, status);
4267 todo_wine
4268 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4269 todo_wine
4270 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4271 expectf_(width_rgn, bounds.Width, 1.0);
4272 expectf_(height_rgn, bounds.Height, 1.0);
4274 /* Far alignment */
4275 GdipSetStringFormatAlign(format, StringAlignmentFar);
4276 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4278 rect.X = 5.0;
4279 rect.Y = 5.0;
4280 rect.Width = width * 2.0;
4281 rect.Height = height * 2.0;
4282 set_rect_empty(&bounds);
4283 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4284 expect(Ok, status);
4285 expect(3, glyphs);
4286 expect(1, lines);
4287 todo_wine
4288 expectf_(5.0 + width, bounds.X, 0.01);
4289 todo_wine
4290 expectf(5.0 + height, bounds.Y);
4291 expectf_(width, bounds.Width, 0.01);
4292 expectf(height, bounds.Height);
4294 rect.X = 5.0;
4295 rect.Y = 5.0;
4296 rect.Width = 0.0;
4297 rect.Height = 0.0;
4298 set_rect_empty(&bounds);
4299 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4300 expect(Ok, status);
4301 expect(3, glyphs);
4302 expect(1, lines);
4303 todo_wine
4304 expectf_(5.0 - width, bounds.X, 0.01);
4305 todo_wine
4306 expectf(5.0 - height, bounds.Y);
4307 expectf_(width, bounds.Width, 0.01);
4308 expectf(height, bounds.Height);
4310 rect.X = 5.0;
4311 rect.Y = 5.0;
4312 rect.Width = width_rgn * 2.0;
4313 rect.Height = height_rgn * 2.0;
4314 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4315 expect(Ok, status);
4316 set_rect_empty(&bounds);
4317 status = GdipGetRegionBounds(region, graphics, &bounds);
4318 expect(Ok, status);
4319 todo_wine
4320 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4321 todo_wine
4322 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4323 expectf_(width_rgn, bounds.Width, 1.0);
4324 expectf_(height_rgn, bounds.Height, 1.0);
4326 rect.X = 5.0;
4327 rect.Y = 5.0;
4328 rect.Width = 0.0;
4329 rect.Height = 0.0;
4330 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4331 expect(Ok, status);
4332 set_rect_empty(&bounds);
4333 status = GdipGetRegionBounds(region, graphics, &bounds);
4334 expect(Ok, status);
4335 todo_wine
4336 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4337 todo_wine
4338 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4339 expectf_(width_rgn, bounds.Width, 1.0);
4340 expectf_(height_rgn, bounds.Height, 1.0);
4342 status = GdipDeleteFont(font);
4343 expect(Ok, status);
4345 status = GdipDeleteGraphics(graphics);
4346 expect(Ok, status);
4347 DeleteDC(hdc);
4349 GdipDeleteFontFamily(family);
4350 GdipDeleteRegion(region);
4351 GdipDeleteStringFormat(format);
4354 static void test_measured_extra_space(void)
4356 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4357 static const WCHAR string[2] = { 'W','W' };
4358 GpStringFormat *format;
4359 HDC hdc;
4360 GpGraphics *graphics;
4361 GpFontFamily *family;
4362 GpFont *font;
4363 GpStatus status;
4364 GpUnit gfx_unit, font_unit;
4365 RectF bounds_1, bounds_2, rect;
4366 REAL margin, font_size, dpi;
4368 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4369 expect(Ok, status);
4371 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4372 expect(Ok, status);
4373 hdc = CreateCompatibleDC(0);
4374 status = GdipCreateFromHDC(hdc, &graphics);
4375 expect(Ok, status);
4377 status = GdipGetDpiX(graphics, &dpi);
4378 expect(Ok, status);
4380 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4381 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4382 for (font_unit = 3; font_unit <= 6; font_unit++)
4384 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4385 expect(Ok, status);
4387 status = GdipGetFontSize(font, &font_size);
4388 expect(Ok, status);
4389 font_size = units_to_pixels(font_size, font_unit, dpi);
4390 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4392 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4393 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4395 status = GdipSetPageUnit(graphics, gfx_unit);
4396 expect(Ok, status);
4398 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4399 set_rect_empty(&rect);
4400 set_rect_empty(&bounds_1);
4401 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4402 expect(Ok, status);
4403 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4404 set_rect_empty(&rect);
4405 set_rect_empty(&bounds_2);
4406 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4407 expect(Ok, status);
4409 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4410 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4411 /*trace("margin %f pixels\n", margin);*/
4412 expectf_(font_size / 6.0, margin, font_size / 100.0);
4415 GdipDeleteFont(font);
4418 GdipDeleteGraphics(graphics);
4419 DeleteDC(hdc);
4420 GdipDeleteFontFamily(family);
4421 GdipDeleteStringFormat(format);
4424 static void test_alpha_hdc(void)
4426 GpStatus status;
4427 HDC hdc;
4428 HBITMAP hbm, old_hbm;
4429 GpGraphics *graphics;
4430 ULONG *bits;
4431 BITMAPINFO bmi;
4432 GpRectF bounds;
4434 hdc = CreateCompatibleDC(0);
4435 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4436 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4437 bmi.bmiHeader.biHeight = 5;
4438 bmi.bmiHeader.biWidth = 5;
4439 bmi.bmiHeader.biBitCount = 32;
4440 bmi.bmiHeader.biPlanes = 1;
4441 bmi.bmiHeader.biCompression = BI_RGB;
4442 bmi.bmiHeader.biClrUsed = 0;
4444 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4445 ok(hbm != NULL, "CreateDIBSection failed\n");
4447 old_hbm = SelectObject(hdc, hbm);
4449 status = GdipCreateFromHDC(hdc, &graphics);
4450 expect(Ok, status);
4452 status = GdipGetVisibleClipBounds(graphics, &bounds);
4453 expect(Ok, status);
4454 expectf(0.0, bounds.X);
4455 expectf(0.0, bounds.Y);
4456 expectf(5.0, bounds.Width);
4457 expectf(5.0, bounds.Height);
4459 bits[0] = 0xdeadbeef;
4461 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4462 expect(Ok, status);
4464 expect(0xffaaaaaa, bits[0]);
4466 SelectObject(hdc, old_hbm);
4468 bits[0] = 0xdeadbeef;
4470 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4471 expect(Ok, status);
4473 todo_wine expect(0xffbbbbbb, bits[0]);
4475 GdipDeleteGraphics(graphics);
4477 DeleteObject(hbm);
4478 DeleteDC(hdc);
4481 static void test_bitmapfromgraphics(void)
4483 GpStatus stat;
4484 GpGraphics *graphics = NULL;
4485 HDC hdc = GetDC( hwnd );
4486 GpBitmap *bitmap = NULL;
4487 PixelFormat format;
4488 REAL imageres, graphicsres;
4489 UINT width, height;
4491 stat = GdipCreateFromHDC(hdc, &graphics);
4492 expect(Ok, stat);
4494 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
4495 expect(InvalidParameter, stat);
4497 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
4498 expect(InvalidParameter, stat);
4500 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
4501 expect(Ok, stat);
4503 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
4504 expect(Ok, stat);
4505 expect(PixelFormat32bppPARGB, format);
4507 stat = GdipGetDpiX(graphics, &graphicsres);
4508 expect(Ok, stat);
4510 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
4511 expect(Ok, stat);
4512 expectf(graphicsres, imageres);
4514 stat = GdipGetDpiY(graphics, &graphicsres);
4515 expect(Ok, stat);
4517 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
4518 expect(Ok, stat);
4519 expectf(graphicsres, imageres);
4521 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
4522 expect(Ok, stat);
4523 expect(12, width);
4525 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
4526 expect(Ok, stat);
4527 expect(13, height);
4529 GdipDeleteGraphics(graphics);
4530 GdipDisposeImage((GpImage*)bitmap);
4533 static void test_clipping(void)
4535 HDC hdc;
4536 GpStatus status;
4537 GpGraphics *graphics;
4538 GpRegion *region, *region100x100;
4539 GpMatrix *matrix;
4540 GpRectF rect;
4541 GpPointF ptf[4];
4542 GpUnit unit;
4543 HRGN hrgn;
4544 int ret;
4545 RECT rc;
4547 hdc = CreateCompatibleDC(0);
4548 status = GdipCreateFromHDC(hdc, &graphics);
4549 expect(Ok, status);
4551 status = GdipGetPageUnit(graphics, &unit);
4552 expect(Ok, status);
4553 expect(UnitDisplay, unit);
4555 status = GdipCreateRegion(&region);
4556 expect(Ok, status);
4557 status = GdipSetEmpty(region);
4558 expect(Ok, status);
4560 status = GdipCreateRegion(&region100x100);
4561 expect(Ok, status);
4562 status = GdipSetEmpty(region100x100);
4563 expect(Ok, status);
4565 rect.X = rect.Y = 100.0;
4566 rect.Width = rect.Height = 100.0;
4567 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
4568 expect(Ok, status);
4569 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
4570 expect(Ok, status);
4572 status = GdipGetClipBounds(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 status = GdipSetEmpty(region);
4578 expect(Ok, status);
4579 status = GdipGetClip(graphics, region);
4580 expect(Ok, status);
4581 status = GdipGetRegionBounds(region, graphics, &rect);
4582 expect(Ok, status);
4583 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4584 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4586 ptf[0].X = 100.0;
4587 ptf[0].Y = 100.0;
4588 ptf[1].X = 200.0;
4589 ptf[1].Y = 200.0;
4590 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4591 expect(Ok, status);
4592 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4593 "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);
4595 status = GdipCreateMatrix(&matrix);
4596 expect(Ok, status);
4597 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
4598 expect(Ok, status);
4599 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
4600 expect(Ok, status);
4601 status = GdipSetWorldTransform(graphics, matrix);
4602 expect(Ok, status);
4604 status = GdipGetClipBounds(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 = GdipSetEmpty(region);
4610 expect(Ok, status);
4611 status = GdipGetClip(graphics, region);
4612 expect(Ok, status);
4613 status = GdipGetRegionBounds(region, graphics, &rect);
4614 expect(Ok, status);
4615 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4616 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4618 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4619 expect(Ok, status);
4620 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4621 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4623 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4624 expect(Ok, status);
4625 ret = GetRgnBox(hrgn, &rc);
4626 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4627 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4628 "expected 45,20-95,45, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4629 DeleteObject(hrgn);
4631 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4632 expect(Ok, status);
4633 ret = GetRgnBox(hrgn, &rc);
4634 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4635 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4636 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4637 DeleteObject(hrgn);
4639 ptf[0].X = 100.0;
4640 ptf[0].Y = 100.0;
4641 ptf[1].X = 200.0;
4642 ptf[1].Y = 200.0;
4643 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4644 expect(Ok, status);
4645 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4646 "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);
4648 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4649 expect(Ok, status);
4650 ret = GetRgnBox(hrgn, &rc);
4651 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4652 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4653 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4654 DeleteObject(hrgn);
4656 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4657 expect(Ok, status);
4658 ret = GetRgnBox(hrgn, &rc);
4659 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4660 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4661 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4662 DeleteObject(hrgn);
4664 ptf[0].X = 210.0;
4665 ptf[0].Y = 420.0;
4666 ptf[1].X = 410.0;
4667 ptf[1].Y = 820.0;
4668 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4669 expect(Ok, status);
4670 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4671 "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);
4673 status = GdipSetPageScale(graphics, 2.0);
4674 expect(Ok, status);
4676 status = GdipGetClipBounds(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 = GdipSetEmpty(region);
4682 expect(Ok, status);
4683 status = GdipGetClip(graphics, region);
4684 expect(Ok, status);
4685 status = GdipGetRegionBounds(region, graphics, &rect);
4686 expect(Ok, status);
4687 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4688 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4690 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4691 expect(Ok, status);
4692 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4693 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4695 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4696 expect(Ok, status);
4697 ret = GetRgnBox(hrgn, &rc);
4698 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4699 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4700 "expected 45,20-95,45, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4701 DeleteObject(hrgn);
4703 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4704 expect(Ok, status);
4705 ret = GetRgnBox(hrgn, &rc);
4706 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4707 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4708 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4709 DeleteObject(hrgn);
4711 ptf[0].X = 100.0;
4712 ptf[0].Y = 100.0;
4713 ptf[1].X = 200.0;
4714 ptf[1].Y = 200.0;
4715 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4716 expect(Ok, status);
4717 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4718 "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);
4720 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4721 expect(Ok, status);
4722 ret = GetRgnBox(hrgn, &rc);
4723 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4724 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4725 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4726 DeleteObject(hrgn);
4728 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4729 expect(Ok, status);
4730 ret = GetRgnBox(hrgn, &rc);
4731 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4732 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4733 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4734 DeleteObject(hrgn);
4736 ptf[0].X = 210.0;
4737 ptf[0].Y = 420.0;
4738 ptf[1].X = 410.0;
4739 ptf[1].Y = 820.0;
4740 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4741 expect(Ok, status);
4742 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4743 "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);
4745 GdipSetPageUnit(graphics, UnitPoint);
4746 expect(Ok, status);
4748 status = GdipGetClipBounds(graphics, &rect);
4749 expect(Ok, status);
4750 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4751 /* rounding under Wine is slightly different */
4752 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4753 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4754 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4756 status = GdipSetEmpty(region);
4757 expect(Ok, status);
4758 status = GdipGetClip(graphics, region);
4759 expect(Ok, status);
4760 status = GdipGetRegionBounds(region, graphics, &rect);
4761 expect(Ok, status);
4762 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4763 /* rounding under Wine is slightly different */
4764 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4765 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4766 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4768 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4769 expect(Ok, status);
4770 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4771 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4773 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4774 expect(Ok, status);
4775 ret = GetRgnBox(hrgn, &rc);
4776 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4777 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
4778 /* rounding under Wine is slightly different */
4779 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
4780 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
4781 "expected 14,5-33,14, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4782 DeleteObject(hrgn);
4784 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4785 expect(Ok, status);
4786 ret = GetRgnBox(hrgn, &rc);
4787 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4788 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
4789 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
4790 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4791 DeleteObject(hrgn);
4793 ptf[0].X = 100.0;
4794 ptf[0].Y = 100.0;
4795 ptf[1].X = 200.0;
4796 ptf[1].Y = 200.0;
4797 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4798 expect(Ok, status);
4799 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
4800 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
4801 "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);
4803 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4804 expect(Ok, status);
4805 ret = GetRgnBox(hrgn, &rc);
4806 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4807 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4808 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4809 DeleteObject(hrgn);
4811 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4812 expect(Ok, status);
4813 ret = GetRgnBox(hrgn, &rc);
4814 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4815 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
4816 /* rounding under Wine is slightly different */
4817 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
4818 "expected 560,1120-1094,2187, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4819 DeleteObject(hrgn);
4821 ptf[0].X = 560.0;
4822 ptf[0].Y = 1120.0;
4823 ptf[1].X = 1094.0;
4824 ptf[1].Y = 2187.0;
4825 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4826 expect(Ok, status);
4827 if (fabs(ptf[0].X - 100.0) < 0.001)
4829 expectf(100.0, ptf[0].X);
4830 expectf(100.0, ptf[0].Y);
4831 expectf(200.125, ptf[1].X);
4832 expectf(200.03125, ptf[1].Y);
4834 else /* before Win7 */
4836 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
4837 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
4838 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
4839 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
4842 status = GdipTransformRegion(region100x100, matrix);
4843 expect(Ok, status);
4845 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4846 expect(Ok, status);
4847 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
4848 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4850 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4851 expect(Ok, status);
4852 ret = GetRgnBox(hrgn, &rc);
4853 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4854 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4855 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4856 DeleteObject(hrgn);
4858 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4859 expect(Ok, status);
4860 ret = GetRgnBox(hrgn, &rc);
4861 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4862 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
4863 /* rounding under Wine is slightly different */
4864 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
4865 "expected 1147,4534-2214,8800, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4866 DeleteObject(hrgn);
4868 ptf[0].X = 1147.0;
4869 ptf[0].Y = 4534.0;
4870 ptf[1].X = 2214.0;
4871 ptf[1].Y = 8800.0;
4872 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4873 expect(Ok, status);
4874 if (fabs(ptf[0].X - 210.0625) < 0.001)
4876 expectf(210.0625, ptf[0].X);
4877 expectf(420.0625, ptf[0].Y);
4878 expectf(410.125, ptf[1].X);
4879 expectf(820.0, ptf[1].Y);
4881 else /* before Win7 */
4883 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
4884 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
4885 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
4886 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
4889 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
4890 expect(Ok, status);
4891 status = GdipSetWorldTransform(graphics, matrix);
4892 expect(Ok, status);
4894 status = GdipGetClipBounds(graphics, &rect);
4895 expect(Ok, status);
4896 expectf_(20.612978, rect.X, 1.0);
4897 expectf_(-6.256012, rect.Y, 1.5);
4898 expectf_(25.612978, rect.Width, 1.0);
4899 expectf_(12.806489, rect.Height, 1.0);
4901 status = GdipSetEmpty(region);
4902 expect(Ok, status);
4903 status = GdipGetClip(graphics, region);
4904 expect(Ok, status);
4905 status = GdipGetRegionBounds(region, graphics, &rect);
4906 expect(Ok, status);
4907 /* rounding under Wine is slightly different */
4908 expectf_(20.612978, rect.X, 1.0);
4909 expectf_(-6.256012, rect.Y, 1.5);
4910 expectf_(25.612978, rect.Width, 1.0);
4911 expectf_(12.806489, rect.Height, 1.0);
4913 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4914 expect(Ok, status);
4915 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
4916 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4918 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4919 expect(Ok, status);
4920 ret = GetRgnBox(hrgn, &rc);
4921 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
4922 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
4923 /* rounding under Wine is slightly different */
4924 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
4925 "expected (22,-6)-(46,7), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4926 DeleteObject(hrgn);
4928 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4929 expect(Ok, status);
4930 ret = GetRgnBox(hrgn, &rc);
4931 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4932 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4933 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4934 DeleteObject(hrgn);
4936 ptf[0].X = 100.0;
4937 ptf[0].Y = 100.0;
4938 ptf[1].X = 200.0;
4939 ptf[1].Y = 200.0;
4940 ptf[2].X = 200.0;
4941 ptf[2].Y = 100.0;
4942 ptf[3].X = 100.0;
4943 ptf[3].Y = 200.0;
4944 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
4945 expect(Ok, status);
4946 expectf(20.612978, ptf[0].X);
4947 expectf(-1.568512, ptf[0].Y);
4948 expectf(46.225956, ptf[1].X);
4949 expectf(1.862977, ptf[1].Y);
4950 expectf(36.850956, ptf[2].X);
4951 expectf(-6.256012, ptf[2].Y);
4952 expectf(29.987980, ptf[3].X);
4953 expectf(6.550478, ptf[3].Y);
4955 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4956 expect(Ok, status);
4957 ret = GetRgnBox(hrgn, &rc);
4958 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4959 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4960 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
4961 DeleteObject(hrgn);
4963 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4964 expect(Ok, status);
4965 ret = GetRgnBox(hrgn, &rc);
4966 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
4967 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
4968 /* rounding under Wine is slightly different */
4969 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
4970 "expected (-3406,4500)-(-350,8728), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4971 DeleteObject(hrgn);
4973 ptf[0].X = -3406.0;
4974 ptf[0].Y = 4500.0;
4975 ptf[1].X = -350.0;
4976 ptf[1].Y = 8728.0;
4977 ptf[2].X = -350.0;
4978 ptf[2].Y = 4500.0;
4979 ptf[3].X = -3406.0;
4980 ptf[3].Y = 8728.0;
4981 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
4982 expect(Ok, status);
4983 expectf(-136.190491, ptf[0].X);
4984 expectf(520.010742, ptf[0].Y);
4985 expectf(756.417175, ptf[1].X);
4986 expectf(720.031616, ptf[1].Y);
4987 expectf(360.042114, ptf[2].X);
4988 expectf(376.760742, ptf[2].Y);
4989 expectf(260.184570, ptf[3].X);
4990 expectf(863.281616, ptf[3].Y);
4992 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
4993 expect(Ok, status);
4994 status = GdipSetWorldTransform(graphics, matrix);
4995 expect(Ok, status);
4997 status = GdipGetClipBounds(graphics, &rect);
4998 expect(Ok, status);
4999 expectf_(-28.100956, rect.X, 1.0);
5000 expectf_(7.806488, rect.Y, 1.5);
5001 expectf_(25.612978, rect.Width, 1.0);
5002 expectf_(12.806489, rect.Height, 1.0);
5004 status = GdipSetEmpty(region);
5005 expect(Ok, status);
5006 status = GdipGetClip(graphics, region);
5007 expect(Ok, status);
5008 status = GdipGetRegionBounds(region, graphics, &rect);
5009 expect(Ok, status);
5010 /* rounding under Wine is slightly different */
5011 expectf_(-28.100956, rect.X, 1.0);
5012 expectf_(7.806488, rect.Y, 1.5);
5013 expectf_(25.612978, rect.Width, 1.0);
5014 expectf_(12.806489, rect.Height, 1.0);
5016 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5017 expect(Ok, status);
5018 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5019 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5021 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5022 expect(Ok, status);
5023 ret = GetRgnBox(hrgn, &rc);
5024 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5025 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5026 /* rounding under Wine is slightly different */
5027 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5028 "expected (-27,8)-(-2,21), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5029 DeleteObject(hrgn);
5031 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5032 expect(Ok, status);
5033 ret = GetRgnBox(hrgn, &rc);
5034 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5035 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5036 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5037 DeleteObject(hrgn);
5039 ptf[0].X = 100.0;
5040 ptf[0].Y = 100.0;
5041 ptf[1].X = 200.0;
5042 ptf[1].Y = 200.0;
5043 ptf[2].X = 200.0;
5044 ptf[2].Y = 100.0;
5045 ptf[3].X = 100.0;
5046 ptf[3].Y = 200.0;
5047 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5048 expect(Ok, status);
5049 expectf(-11.862979, ptf[0].X);
5050 expectf(7.806488, ptf[0].Y);
5051 expectf(-18.725958, ptf[1].X);
5052 expectf(20.612976, ptf[1].Y);
5053 expectf(-2.487981, ptf[2].X);
5054 expectf(15.925477, ptf[2].Y);
5055 expectf(-28.100956, ptf[3].X);
5056 expectf(12.493987, ptf[3].Y);
5058 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5059 expect(Ok, status);
5060 ret = GetRgnBox(hrgn, &rc);
5061 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5062 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5063 "expected 210,420-410,820, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5064 DeleteObject(hrgn);
5066 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5067 expect(Ok, status);
5068 ret = GetRgnBox(hrgn, &rc);
5069 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5070 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5071 /* rounding under Wine is slightly different */
5072 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5073 "expected (4500,351)-(8728,3407), got (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5074 DeleteObject(hrgn);
5076 ptf[0].X = -3406.0;
5077 ptf[0].Y = 4500.0;
5078 ptf[1].X = -350.0;
5079 ptf[1].Y = 8728.0;
5080 ptf[2].X = -350.0;
5081 ptf[2].Y = 4500.0;
5082 ptf[3].X = -3406.0;
5083 ptf[3].Y = 8728.0;
5084 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5085 expect(Ok, status);
5086 expectf(-1055.021484, ptf[0].X);
5087 expectf(-70.595329, ptf[0].Y);
5088 expectf(-1455.063232, ptf[1].X);
5089 expectf(375.708435, ptf[1].Y);
5090 expectf(-768.521484, ptf[2].X);
5091 expectf(177.520981, ptf[2].Y);
5092 expectf(-1741.563110, ptf[3].X);
5093 expectf(127.592125, ptf[3].Y);
5095 GdipDeleteMatrix(matrix);
5096 GdipDeleteRegion(region);
5097 GdipDeleteRegion(region100x100);
5098 GdipDeleteGraphics(graphics);
5099 DeleteDC(hdc);
5102 static void test_clipping_2(void)
5105 HDC hdc;
5106 GpStatus status;
5107 GpGraphics *graphics;
5108 GpRegion *region;
5109 GpMatrix *matrix;
5110 GpRectF rect;
5111 GpPointF ptf[4];
5112 GpUnit unit;
5113 HRGN hrgn;
5114 int ret;
5115 RECT rc;
5117 hdc = CreateCompatibleDC(0);
5118 status = GdipCreateFromHDC(hdc, &graphics);
5119 expect(Ok, status);
5121 status = GdipGetPageUnit(graphics, &unit);
5122 expect(Ok, status);
5123 expect(UnitDisplay, unit);
5125 GdipSetPageUnit(graphics, UnitInch);
5127 status = GdipCreateRegion(&region);
5128 expect(Ok, status);
5129 status = GdipSetEmpty(region);
5130 expect(Ok, status);
5131 rect.X = rect.Y = 100.0;
5132 rect.Width = rect.Height = 100.0;
5133 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5134 expect(Ok, status);
5135 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5136 expect(Ok, status);
5138 status = GdipGetClip(graphics, region);
5139 expect(Ok, status);
5140 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5141 expect(Ok, status);
5142 ret = GetRgnBox(hrgn, &rc);
5143 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5144 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5145 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5146 DeleteObject(hrgn);
5147 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5148 expect(Ok, status);
5149 ret = GetRgnBox(hrgn, &rc);
5150 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5151 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5152 "expected 9600,9600-19200,19200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5153 DeleteObject(hrgn);
5155 ptf[0].X = 9600.0;
5156 ptf[0].Y = 9600.0;
5157 ptf[1].X = 19200.0;
5158 ptf[1].Y = 19200.0;
5159 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5160 expect(Ok, status);
5161 expectf(100.0, ptf[0].X);
5162 expectf(100.0, ptf[0].Y);
5163 expectf(200.0, ptf[1].X);
5164 expectf(200.0, ptf[1].X);
5166 GdipSetPageUnit(graphics, UnitPoint);
5168 status = GdipGetClip(graphics, region);
5169 expect(Ok, status);
5170 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5171 expect(Ok, status);
5172 ret = GetRgnBox(hrgn, &rc);
5173 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5174 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5175 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5176 "expected 7200,7200-14400,14400, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5177 DeleteObject(hrgn);
5178 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5179 expect(Ok, status);
5180 ret = GetRgnBox(hrgn, &rc);
5181 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5182 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5183 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5184 "expected 9600,9600-19200,19200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5185 DeleteObject(hrgn);
5187 ptf[0].X = 9600.0;
5188 ptf[0].Y = 9600.0;
5189 ptf[1].X = 19200.0;
5190 ptf[1].Y = 19200.0;
5191 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5192 expect(Ok, status);
5193 if (fabs(ptf[0].X - 7200.0) < 0.001)
5194 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5195 "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);
5196 else /* before Win7 */
5198 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5199 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5200 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5201 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5204 GdipDeleteRegion(region);
5206 GdipSetPageUnit(graphics, UnitPixel);
5208 status = GdipCreateRegion(&region);
5209 expect(Ok, status);
5210 status = GdipSetEmpty(region);
5211 expect(Ok, status);
5212 rect.X = rect.Y = 100.0;
5213 rect.Width = rect.Height = 100.0;
5214 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5215 expect(Ok, status);
5216 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5217 expect(Ok, status);
5219 status = GdipGetClip(graphics, region);
5220 expect(Ok, status);
5221 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5222 expect(Ok, status);
5223 ret = GetRgnBox(hrgn, &rc);
5224 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5225 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5226 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5227 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5228 DeleteObject(hrgn);
5229 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5230 expect(Ok, status);
5231 ret = GetRgnBox(hrgn, &rc);
5232 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5233 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5234 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5235 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5236 DeleteObject(hrgn);
5238 ptf[0].X = 100.0;
5239 ptf[0].Y = 100.0;
5240 ptf[1].X = 200.0;
5241 ptf[1].Y = 200.0;
5242 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5243 expect(Ok, status);
5244 if (fabs(ptf[0].X - 100.0) < 0.001)
5245 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5246 "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);
5247 else /* before Win7 */
5249 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5250 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5251 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5252 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5255 GdipSetPageUnit(graphics, UnitPoint);
5257 status = GdipGetClip(graphics, region);
5258 expect(Ok, status);
5259 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5260 expect(Ok, status);
5261 ret = GetRgnBox(hrgn, &rc);
5262 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5263 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5264 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5265 "expected 75,75-150,150, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5266 DeleteObject(hrgn);
5267 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5268 expect(Ok, status);
5269 ret = GetRgnBox(hrgn, &rc);
5270 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5271 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5272 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5273 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5274 DeleteObject(hrgn);
5276 ptf[0].X = 100.0;
5277 ptf[0].Y = 100.0;
5278 ptf[1].X = 200.0;
5279 ptf[1].Y = 200.0;
5280 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5281 expect(Ok, status);
5282 if (fabs(ptf[0].X - 75.0) < 0.001)
5283 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5284 "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);
5285 else /* before Win7 */
5287 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5288 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5289 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5290 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5293 status = GdipCreateMatrix(&matrix);
5294 expect(Ok, status);
5295 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5296 expect(Ok, status);
5297 status = GdipSetWorldTransform(graphics, matrix);
5298 expect(Ok, status);
5299 GdipDeleteMatrix(matrix);
5301 status = GdipGetClip(graphics, region);
5302 expect(Ok, status);
5303 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5304 expect(Ok, status);
5305 ret = GetRgnBox(hrgn, &rc);
5306 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5307 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5308 "expected 65,65-140,140, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5309 DeleteObject(hrgn);
5310 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5311 expect(Ok, status);
5312 ret = GetRgnBox(hrgn, &rc);
5313 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5314 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5315 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5316 DeleteObject(hrgn);
5318 ptf[0].X = 100.0;
5319 ptf[0].Y = 100.0;
5320 ptf[1].X = 200.0;
5321 ptf[1].Y = 200.0;
5322 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5323 expect(Ok, status);
5324 expectf(65.0, ptf[0].X);
5325 expectf(65.0, ptf[0].Y);
5326 expectf(140.0, ptf[1].X);
5327 expectf(140.0, ptf[1].X);
5329 status = GdipCreateMatrix(&matrix);
5330 expect(Ok, status);
5331 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5332 expect(Ok, status);
5333 status = GdipSetWorldTransform(graphics, matrix);
5334 expect(Ok, status);
5335 GdipDeleteMatrix(matrix);
5337 status = GdipGetClip(graphics, region);
5338 expect(Ok, status);
5339 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5340 expect(Ok, status);
5341 ret = GetRgnBox(hrgn, &rc);
5342 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5343 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5344 "expected 300,150-600,300, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5345 DeleteObject(hrgn);
5346 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5347 expect(Ok, status);
5348 ret = GetRgnBox(hrgn, &rc);
5349 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5350 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5351 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5352 DeleteObject(hrgn);
5354 ptf[0].X = 100.0;
5355 ptf[0].Y = 100.0;
5356 ptf[1].X = 200.0;
5357 ptf[1].Y = 200.0;
5358 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5359 expect(Ok, status);
5360 expectf(300.0, ptf[0].X);
5361 expectf(150.0, ptf[0].Y);
5362 expectf(600.0, ptf[1].X);
5363 expectf(300.0, ptf[1].Y);
5365 status = GdipSetPageScale(graphics, 2.0);
5366 expect(Ok, status);
5368 status = GdipGetClip(graphics, region);
5369 expect(Ok, status);
5370 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5371 expect(Ok, status);
5372 ret = GetRgnBox(hrgn, &rc);
5373 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5374 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5375 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5376 "expected 150,75-300,150, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5377 DeleteObject(hrgn);
5378 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5379 expect(Ok, status);
5380 ret = GetRgnBox(hrgn, &rc);
5381 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5382 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5383 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5384 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5385 DeleteObject(hrgn);
5387 ptf[0].X = 100.0;
5388 ptf[0].Y = 100.0;
5389 ptf[1].X = 200.0;
5390 ptf[1].Y = 200.0;
5391 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5392 expect(Ok, status);
5393 if (fabs(ptf[0].X - 150.0) < 0.001)
5395 expectf(150.0, ptf[0].X);
5396 expectf(75.0, ptf[0].Y);
5397 expectf(300.0, ptf[1].X);
5398 expectf(150.0, ptf[1].Y);
5400 else /* before Win7 */
5402 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5403 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5404 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5405 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5408 status = GdipCreateMatrix(&matrix);
5409 expect(Ok, status);
5410 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5411 expect(Ok, status);
5412 status = GdipSetWorldTransform(graphics, matrix);
5413 expect(Ok, status);
5414 GdipDeleteMatrix(matrix);
5416 status = GdipGetClip(graphics, region);
5417 expect(Ok, status);
5418 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5419 expect(Ok, status);
5420 ret = GetRgnBox(hrgn, &rc);
5421 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5422 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5423 /* rounding under Wine is slightly different */
5424 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5425 "expected 54,-26-107,27, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5426 DeleteObject(hrgn);
5427 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5428 expect(Ok, status);
5429 ret = GetRgnBox(hrgn, &rc);
5430 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5431 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5432 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5433 DeleteObject(hrgn);
5435 ptf[0].X = 100.0;
5436 ptf[0].Y = 100.0;
5437 ptf[1].X = 200.0;
5438 ptf[1].Y = 200.0;
5439 ptf[2].X = 200.0;
5440 ptf[2].Y = 100.0;
5441 ptf[3].X = 100.0;
5442 ptf[3].Y = 200.0;
5443 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5444 expect(Ok, status);
5445 expectf(53.033016, ptf[0].X);
5446 expectf(0.0, ptf[0].Y);
5447 expectf(106.066032, ptf[1].X);
5448 expectf(0.0, ptf[1].Y);
5449 expectf(79.549522, ptf[2].X);
5450 expectf(-26.516510, ptf[2].Y);
5451 expectf(79.549522, ptf[3].X);
5452 expectf(26.516508, ptf[3].Y);
5454 status = GdipCreateMatrix(&matrix);
5455 expect(Ok, status);
5456 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5457 expect(Ok, status);
5458 status = GdipSetWorldTransform(graphics, matrix);
5459 expect(Ok, status);
5460 GdipDeleteMatrix(matrix);
5462 status = GdipGetClip(graphics, region);
5463 expect(Ok, status);
5464 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5465 expect(Ok, status);
5466 ret = GetRgnBox(hrgn, &rc);
5467 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5468 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
5469 /* rounding under Wine is slightly different */
5470 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
5471 "expected -26,54-27,107, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5472 DeleteObject(hrgn);
5473 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5474 expect(Ok, status);
5475 ret = GetRgnBox(hrgn, &rc);
5476 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5477 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5478 "expected 100,100-200,200, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom);
5479 DeleteObject(hrgn);
5481 ptf[0].X = 100.0;
5482 ptf[0].Y = 100.0;
5483 ptf[1].X = 200.0;
5484 ptf[1].Y = 200.0;
5485 ptf[2].X = 200.0;
5486 ptf[2].Y = 100.0;
5487 ptf[3].X = 100.0;
5488 ptf[3].Y = 200.0;
5489 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5490 expect(Ok, status);
5491 expectf(0.0, ptf[0].X);
5492 expectf(53.033005, ptf[0].Y);
5493 expectf(0.0, ptf[1].X);
5494 expectf(106.066010, ptf[1].Y);
5495 expectf(26.516491, ptf[2].X);
5496 expectf(79.549507, ptf[2].Y);
5497 expectf(-26.516520, ptf[3].X);
5498 expectf(79.549500, ptf[3].Y);
5500 GdipDeleteRegion(region);
5501 GdipDeleteGraphics(graphics);
5502 DeleteDC(hdc);
5506 static void test_GdipFillRectangles(void)
5508 GpStatus status;
5509 GpGraphics *graphics = NULL;
5510 GpBrush *brush = NULL;
5511 HDC hdc = GetDC( hwnd );
5512 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
5514 ok(hdc != NULL, "Expected HDC to be initialized\n");
5516 status = GdipCreateFromHDC(hdc, &graphics);
5517 expect(Ok, status);
5518 ok(graphics != NULL, "Expected graphics to be initialized\n");
5520 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
5521 expect(Ok, status);
5522 ok(brush != NULL, "Expected brush to be initialized\n");
5524 status = GdipFillRectangles(NULL, brush, rects, 2);
5525 expect(InvalidParameter, status);
5527 status = GdipFillRectangles(graphics, NULL, rects, 2);
5528 expect(InvalidParameter, status);
5530 status = GdipFillRectangles(graphics, brush, NULL, 2);
5531 expect(InvalidParameter, status);
5533 status = GdipFillRectangles(graphics, brush, rects, 0);
5534 expect(InvalidParameter, status);
5536 status = GdipFillRectangles(graphics, brush, rects, -1);
5537 expect(InvalidParameter, status);
5539 status = GdipFillRectangles(graphics, brush, rects, 1);
5540 expect(Ok, status);
5542 status = GdipFillRectangles(graphics, brush, rects, 2);
5543 expect(Ok, status);
5545 GdipDeleteBrush(brush);
5546 GdipDeleteGraphics(graphics);
5548 ReleaseDC(hwnd, hdc);
5551 START_TEST(graphics)
5553 struct GdiplusStartupInput gdiplusStartupInput;
5554 ULONG_PTR gdiplusToken;
5555 WNDCLASSA class;
5557 memset( &class, 0, sizeof(class) );
5558 class.lpszClassName = "gdiplus_test";
5559 class.style = CS_HREDRAW | CS_VREDRAW;
5560 class.lpfnWndProc = DefWindowProcA;
5561 class.hInstance = GetModuleHandleA(0);
5562 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5563 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5564 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
5565 RegisterClassA( &class );
5566 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5567 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
5568 ok(hwnd != NULL, "Expected window to be created\n");
5570 gdiplusStartupInput.GdiplusVersion = 1;
5571 gdiplusStartupInput.DebugEventCallback = NULL;
5572 gdiplusStartupInput.SuppressBackgroundThread = 0;
5573 gdiplusStartupInput.SuppressExternalCodecs = 0;
5575 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
5577 test_clipping();
5578 test_clipping_2();
5579 test_measured_extra_space();
5580 test_measure_string();
5581 test_font_height_scaling();
5582 test_transform();
5583 test_GdipMeasureString();
5584 test_constructor_destructor();
5585 test_save_restore();
5586 test_GdipFillClosedCurve2();
5587 test_GdipFillClosedCurve2I();
5588 test_GdipDrawBezierI();
5589 test_GdipDrawArc();
5590 test_GdipDrawArcI();
5591 test_GdipDrawCurve();
5592 test_GdipDrawCurveI();
5593 test_GdipDrawCurve2();
5594 test_GdipDrawCurve2I();
5595 test_GdipDrawCurve3();
5596 test_GdipDrawCurve3I();
5597 test_GdipDrawLineI();
5598 test_GdipDrawLinesI();
5599 test_GdipDrawImagePointsRect();
5600 test_GdipFillClosedCurve();
5601 test_GdipFillClosedCurveI();
5602 test_GdipDrawString();
5603 test_GdipGetNearestColor();
5604 test_GdipGetVisibleClipBounds();
5605 test_GdipIsVisiblePoint();
5606 test_GdipIsVisibleRect();
5607 test_Get_Release_DC();
5608 test_BeginContainer2();
5609 test_transformpoints();
5610 test_get_set_clip();
5611 test_isempty();
5612 test_clear();
5613 test_textcontrast();
5614 test_fromMemoryBitmap();
5615 test_string_functions();
5616 test_get_set_interpolation();
5617 test_get_set_textrenderinghint();
5618 test_getdc_scaled();
5619 test_alpha_hdc();
5620 test_bitmapfromgraphics();
5621 test_GdipFillRectangles();
5623 GdiplusShutdown(gdiplusToken);
5624 DestroyWindow( hwnd );