[GDIPLUS_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / rostests / winetests / gdiplus / graphics.c
1 /*
2 * Unit test suite for graphics objects
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <math.h>
23
24 #define WIN32_NO_STATUS
25 #define _INC_WINDOWS
26 #define COM_NO_WINDOWS_H
27
28 //#include "windows.h"
29 #include <wine/test.h>
30 #include <wingdi.h>
31 #include <objbase.h>
32 #include <gdiplus.h>
33
34 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
35 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
36 #define expectf(expected, got) expectf_((expected), (got), 0.001)
37
38 static const REAL mm_per_inch = 25.4;
39 static const REAL point_per_inch = 72.0;
40 static HWND hwnd;
41
42 static void set_rect_empty(RectF *rc)
43 {
44 rc->X = 0.0;
45 rc->Y = 0.0;
46 rc->Width = 0.0;
47 rc->Height = 0.0;
48 }
49
50 /* converts a given unit to its value in pixels */
51 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
52 {
53 switch (unit)
54 {
55 case UnitPixel:
56 case UnitDisplay:
57 return units;
58 case UnitPoint:
59 return units * dpi / point_per_inch;
60 case UnitInch:
61 return units * dpi;
62 case UnitDocument:
63 return units * dpi / 300.0; /* Per MSDN */
64 case UnitMillimeter:
65 return units * dpi / mm_per_inch;
66 default:
67 ok(0, "Unsupported unit: %d\n", unit);
68 return 0;
69 }
70 }
71
72 /* converts value in pixels to a given unit */
73 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
74 {
75 switch (unit)
76 {
77 case UnitPixel:
78 case UnitDisplay:
79 return pixels;
80 case UnitPoint:
81 return pixels * point_per_inch / dpi;
82 case UnitInch:
83 return pixels / dpi;
84 case UnitDocument:
85 return pixels * 300.0 / dpi;
86 case UnitMillimeter:
87 return pixels * mm_per_inch / dpi;
88 default:
89 ok(0, "Unsupported unit: %d\n", unit);
90 return 0;
91 }
92 }
93
94 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
95 {
96 REAL pixels = units_to_pixels(1.0, from, dpi);
97 return pixels_to_units(pixels, to, dpi);
98 }
99
100 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale, GpImage **image)
101 {
102 GpStatus status;
103 union
104 {
105 GpBitmap *bitmap;
106 GpImage *image;
107 } u;
108 GpGraphics *graphics = NULL;
109 REAL res;
110
111 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
112 expect(Ok, status);
113
114 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
115 expect(Ok, status);
116 status = GdipGetImageHorizontalResolution(u.image, &res);
117 expect(Ok, status);
118 expectf(res_x, res);
119 status = GdipGetImageVerticalResolution(u.image, &res);
120 expect(Ok, status);
121 expectf(res_y, res);
122
123 status = GdipGetImageGraphicsContext(u.image, &graphics);
124 expect(Ok, status);
125
126 *image = u.image;
127
128 status = GdipGetDpiX(graphics, &res);
129 expect(Ok, status);
130 expectf(res_x, res);
131 status = GdipGetDpiY(graphics, &res);
132 expect(Ok, status);
133 expectf(res_y, res);
134
135 status = GdipSetPageUnit(graphics, unit);
136 expect(Ok, status);
137 status = GdipSetPageScale(graphics, scale);
138 expect(Ok, status);
139
140 return graphics;
141 }
142
143 static void test_constructor_destructor(void)
144 {
145 GpStatus stat;
146 GpGraphics *graphics = NULL;
147 HDC hdc = GetDC( hwnd );
148
149 stat = GdipCreateFromHDC(NULL, &graphics);
150 expect(OutOfMemory, stat);
151 stat = GdipDeleteGraphics(graphics);
152 expect(InvalidParameter, stat);
153
154 stat = GdipCreateFromHDC(hdc, &graphics);
155 expect(Ok, stat);
156 stat = GdipDeleteGraphics(graphics);
157 expect(Ok, stat);
158
159 stat = GdipCreateFromHWND(NULL, &graphics);
160 expect(Ok, stat);
161 stat = GdipDeleteGraphics(graphics);
162 expect(Ok, stat);
163
164 stat = GdipCreateFromHWNDICM(NULL, &graphics);
165 expect(Ok, stat);
166 stat = GdipDeleteGraphics(graphics);
167 expect(Ok, stat);
168
169 stat = GdipDeleteGraphics(NULL);
170 expect(InvalidParameter, stat);
171 ReleaseDC(hwnd, hdc);
172 }
173
174 typedef struct node{
175 GraphicsState data;
176 struct node * next;
177 } node;
178
179 /* Linked list prepend function. */
180 static void log_state(GraphicsState data, node ** log)
181 {
182 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
183
184 new_entry->data = data;
185 new_entry->next = *log;
186 *log = new_entry;
187 }
188
189 /* Checks if there are duplicates in the list, and frees it. */
190 static void check_no_duplicates(node * log)
191 {
192 INT dups = 0;
193 node * temp = NULL;
194 node * temp2 = NULL;
195 node * orig = log;
196
197 if(!log)
198 goto end;
199
200 do{
201 temp = log;
202 while((temp = temp->next)){
203 if(log->data == temp->data){
204 dups++;
205 break;
206 }
207 if(dups > 0)
208 break;
209 }
210 }while((log = log->next));
211
212 temp = orig;
213 do{
214 temp2 = temp->next;
215 HeapFree(GetProcessHeap(), 0, temp);
216 temp = temp2;
217 }while(temp);
218
219 end:
220 expect(0, dups);
221 }
222
223 static void test_save_restore(void)
224 {
225 GpStatus stat;
226 GraphicsState state_a, state_b, state_c;
227 InterpolationMode mode;
228 GpGraphics *graphics1, *graphics2;
229 node * state_log = NULL;
230 HDC hdc = GetDC( hwnd );
231 state_a = state_b = state_c = 0xdeadbeef;
232
233 /* Invalid saving. */
234 GdipCreateFromHDC(hdc, &graphics1);
235 stat = GdipSaveGraphics(graphics1, NULL);
236 expect(InvalidParameter, stat);
237 stat = GdipSaveGraphics(NULL, &state_a);
238 expect(InvalidParameter, stat);
239 GdipDeleteGraphics(graphics1);
240
241 log_state(state_a, &state_log);
242
243 /* Basic save/restore. */
244 GdipCreateFromHDC(hdc, &graphics1);
245 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
246 stat = GdipSaveGraphics(graphics1, &state_a);
247 expect(Ok, stat);
248 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
249 stat = GdipRestoreGraphics(graphics1, state_a);
250 expect(Ok, stat);
251 GdipGetInterpolationMode(graphics1, &mode);
252 expect(InterpolationModeBilinear, mode);
253 GdipDeleteGraphics(graphics1);
254
255 log_state(state_a, &state_log);
256
257 /* Restoring garbage doesn't affect saves. */
258 GdipCreateFromHDC(hdc, &graphics1);
259 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
260 GdipSaveGraphics(graphics1, &state_a);
261 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
262 GdipSaveGraphics(graphics1, &state_b);
263 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
264 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
265 expect(Ok, stat);
266 GdipRestoreGraphics(graphics1, state_b);
267 GdipGetInterpolationMode(graphics1, &mode);
268 expect(InterpolationModeBicubic, mode);
269 GdipRestoreGraphics(graphics1, state_a);
270 GdipGetInterpolationMode(graphics1, &mode);
271 expect(InterpolationModeBilinear, mode);
272 GdipDeleteGraphics(graphics1);
273
274 log_state(state_a, &state_log);
275 log_state(state_b, &state_log);
276
277 /* Restoring older state invalidates newer saves (but not older saves). */
278 GdipCreateFromHDC(hdc, &graphics1);
279 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
280 GdipSaveGraphics(graphics1, &state_a);
281 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
282 GdipSaveGraphics(graphics1, &state_b);
283 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
284 GdipSaveGraphics(graphics1, &state_c);
285 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
286 GdipRestoreGraphics(graphics1, state_b);
287 GdipGetInterpolationMode(graphics1, &mode);
288 expect(InterpolationModeBicubic, mode);
289 GdipRestoreGraphics(graphics1, state_c);
290 GdipGetInterpolationMode(graphics1, &mode);
291 expect(InterpolationModeBicubic, mode);
292 GdipRestoreGraphics(graphics1, state_a);
293 GdipGetInterpolationMode(graphics1, &mode);
294 expect(InterpolationModeBilinear, mode);
295 GdipDeleteGraphics(graphics1);
296
297 log_state(state_a, &state_log);
298 log_state(state_b, &state_log);
299 log_state(state_c, &state_log);
300
301 /* Restoring older save from one graphics object does not invalidate
302 * newer save from other graphics object. */
303 GdipCreateFromHDC(hdc, &graphics1);
304 GdipCreateFromHDC(hdc, &graphics2);
305 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
306 GdipSaveGraphics(graphics1, &state_a);
307 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
308 GdipSaveGraphics(graphics2, &state_b);
309 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
310 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
311 GdipRestoreGraphics(graphics1, state_a);
312 GdipGetInterpolationMode(graphics1, &mode);
313 expect(InterpolationModeBilinear, mode);
314 GdipRestoreGraphics(graphics2, state_b);
315 GdipGetInterpolationMode(graphics2, &mode);
316 expect(InterpolationModeBicubic, mode);
317 GdipDeleteGraphics(graphics1);
318 GdipDeleteGraphics(graphics2);
319
320 /* You can't restore a state to a graphics object that didn't save it. */
321 GdipCreateFromHDC(hdc, &graphics1);
322 GdipCreateFromHDC(hdc, &graphics2);
323 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
324 GdipSaveGraphics(graphics1, &state_a);
325 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
326 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
327 GdipRestoreGraphics(graphics2, state_a);
328 GdipGetInterpolationMode(graphics2, &mode);
329 expect(InterpolationModeNearestNeighbor, mode);
330 GdipDeleteGraphics(graphics1);
331 GdipDeleteGraphics(graphics2);
332
333 log_state(state_a, &state_log);
334
335 /* A state created by SaveGraphics cannot be restored with EndContainer. */
336 GdipCreateFromHDC(hdc, &graphics1);
337 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
338 stat = GdipSaveGraphics(graphics1, &state_a);
339 expect(Ok, stat);
340 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
341 stat = GdipEndContainer(graphics1, state_a);
342 expect(Ok, stat);
343 GdipGetInterpolationMode(graphics1, &mode);
344 expect(InterpolationModeBicubic, mode);
345 stat = GdipRestoreGraphics(graphics1, state_a);
346 expect(Ok, stat);
347 GdipGetInterpolationMode(graphics1, &mode);
348 expect(InterpolationModeBilinear, mode);
349 GdipDeleteGraphics(graphics1);
350
351 log_state(state_a, &state_log);
352
353 /* A state created by BeginContainer cannot be restored with RestoreGraphics. */
354 GdipCreateFromHDC(hdc, &graphics1);
355 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
356 stat = GdipBeginContainer2(graphics1, &state_a);
357 expect(Ok, stat);
358 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
359 stat = GdipRestoreGraphics(graphics1, state_a);
360 expect(Ok, stat);
361 GdipGetInterpolationMode(graphics1, &mode);
362 expect(InterpolationModeBicubic, mode);
363 stat = GdipEndContainer(graphics1, state_a);
364 expect(Ok, stat);
365 GdipGetInterpolationMode(graphics1, &mode);
366 expect(InterpolationModeBilinear, mode);
367 GdipDeleteGraphics(graphics1);
368
369 log_state(state_a, &state_log);
370
371 /* BeginContainer and SaveGraphics use the same stack. */
372 GdipCreateFromHDC(hdc, &graphics1);
373 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
374 stat = GdipBeginContainer2(graphics1, &state_a);
375 expect(Ok, stat);
376 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
377 stat = GdipSaveGraphics(graphics1, &state_b);
378 expect(Ok, stat);
379 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
380 stat = GdipEndContainer(graphics1, state_a);
381 expect(Ok, stat);
382 GdipGetInterpolationMode(graphics1, &mode);
383 expect(InterpolationModeBilinear, mode);
384 stat = GdipRestoreGraphics(graphics1, state_b);
385 expect(Ok, stat);
386 GdipGetInterpolationMode(graphics1, &mode);
387 expect(InterpolationModeBilinear, mode);
388 GdipDeleteGraphics(graphics1);
389
390 log_state(state_a, &state_log);
391 log_state(state_b, &state_log);
392
393 /* The same state value should never be returned twice. */
394 todo_wine
395 check_no_duplicates(state_log);
396
397 ReleaseDC(hwnd, hdc);
398 }
399
400 static void test_GdipFillClosedCurve2(void)
401 {
402 GpStatus status;
403 GpGraphics *graphics = NULL;
404 GpSolidFill *brush = NULL;
405 HDC hdc = GetDC( hwnd );
406 GpPointF points[3];
407
408 points[0].X = 0;
409 points[0].Y = 0;
410
411 points[1].X = 40;
412 points[1].Y = 20;
413
414 points[2].X = 10;
415 points[2].Y = 40;
416
417 /* make a graphics object and brush object */
418 ok(hdc != NULL, "Expected HDC to be initialized\n");
419
420 status = GdipCreateFromHDC(hdc, &graphics);
421 expect(Ok, status);
422 ok(graphics != NULL, "Expected graphics to be initialized\n");
423
424 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
425
426 /* InvalidParameter cases: null graphics, null brush, null points */
427 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
428 expect(InvalidParameter, status);
429
430 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
431 expect(InvalidParameter, status);
432
433 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
434 expect(InvalidParameter, status);
435
436 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
437 expect(InvalidParameter, status);
438
439 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
440 expect(InvalidParameter, status);
441
442 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
443 expect(InvalidParameter, status);
444
445 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
446 expect(InvalidParameter, status);
447
448 /* InvalidParameter cases: invalid count */
449 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
450 expect(InvalidParameter, status);
451
452 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
453 expect(InvalidParameter, status);
454
455 /* Valid test cases */
456 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
457 expect(Ok, status);
458
459 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
460 expect(Ok, status);
461
462 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
463 expect(Ok, status);
464
465 GdipDeleteGraphics(graphics);
466 GdipDeleteBrush((GpBrush*)brush);
467
468 ReleaseDC(hwnd, hdc);
469 }
470
471 static void test_GdipFillClosedCurve2I(void)
472 {
473 GpStatus status;
474 GpGraphics *graphics = NULL;
475 GpSolidFill *brush = NULL;
476 HDC hdc = GetDC( hwnd );
477 GpPoint points[3];
478
479 points[0].X = 0;
480 points[0].Y = 0;
481
482 points[1].X = 40;
483 points[1].Y = 20;
484
485 points[2].X = 10;
486 points[2].Y = 40;
487
488 /* make a graphics object and brush object */
489 ok(hdc != NULL, "Expected HDC to be initialized\n");
490
491 status = GdipCreateFromHDC(hdc, &graphics);
492 expect(Ok, status);
493 ok(graphics != NULL, "Expected graphics to be initialized\n");
494
495 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
496
497 /* InvalidParameter cases: null graphics, null brush */
498 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
499 when points == NULL, so don't test this condition */
500 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
501 expect(InvalidParameter, status);
502
503 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
504 expect(InvalidParameter, status);
505
506 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
507 expect(InvalidParameter, status);
508
509 /* InvalidParameter cases: invalid count */
510 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
511 expect(InvalidParameter, status);
512
513 /* OutOfMemory cases: large (unsigned) int */
514 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
515 expect(OutOfMemory, status);
516
517 /* Valid test cases */
518 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
519 expect(Ok, status);
520
521 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
522 expect(Ok, status);
523
524 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
525 expect(Ok, status);
526
527 GdipDeleteGraphics(graphics);
528 GdipDeleteBrush((GpBrush*)brush);
529
530 ReleaseDC(hwnd, hdc);
531 }
532
533 static void test_GdipDrawArc(void)
534 {
535 GpStatus status;
536 GpGraphics *graphics = NULL;
537 GpPen *pen = NULL;
538 HDC hdc = GetDC( hwnd );
539
540 /* make a graphics object and pen object */
541 ok(hdc != NULL, "Expected HDC to be initialized\n");
542
543 status = GdipCreateFromHDC(hdc, &graphics);
544 expect(Ok, status);
545 ok(graphics != NULL, "Expected graphics to be initialized\n");
546
547 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
548 expect(Ok, status);
549 ok(pen != NULL, "Expected pen to be initialized\n");
550
551 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
552 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
553 expect(InvalidParameter, status);
554
555 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
556 expect(InvalidParameter, status);
557
558 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
559 expect(InvalidParameter, status);
560
561 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
562 expect(InvalidParameter, status);
563
564 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
565 expect(InvalidParameter, status);
566
567 /* successful case */
568 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
569 expect(Ok, status);
570
571 GdipDeletePen(pen);
572 GdipDeleteGraphics(graphics);
573
574 ReleaseDC(hwnd, hdc);
575 }
576
577 static void test_GdipDrawArcI(void)
578 {
579 GpStatus status;
580 GpGraphics *graphics = NULL;
581 GpPen *pen = NULL;
582 HDC hdc = GetDC( hwnd );
583
584 /* make a graphics object and pen object */
585 ok(hdc != NULL, "Expected HDC to be initialized\n");
586
587 status = GdipCreateFromHDC(hdc, &graphics);
588 expect(Ok, status);
589 ok(graphics != NULL, "Expected graphics to be initialized\n");
590
591 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
592 expect(Ok, status);
593 ok(pen != NULL, "Expected pen to be initialized\n");
594
595 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
596 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
597 expect(InvalidParameter, status);
598
599 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
600 expect(InvalidParameter, status);
601
602 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
603 expect(InvalidParameter, status);
604
605 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
606 expect(InvalidParameter, status);
607
608 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
609 expect(InvalidParameter, status);
610
611 /* successful case */
612 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
613 expect(Ok, status);
614
615 GdipDeletePen(pen);
616 GdipDeleteGraphics(graphics);
617
618 ReleaseDC(hwnd, hdc);
619 }
620
621 static void test_BeginContainer2(void)
622 {
623 GpMatrix *transform;
624 GpRectF clip;
625 REAL defClip[] = {5, 10, 15, 20};
626 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
627 GraphicsContainer cont1, cont2, cont3, cont4;
628 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
629 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
630 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
631 REAL scale, defScale = 17;
632 GpUnit unit, defUnit = UnitPixel;
633 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
634 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
635 UINT contrast, defContrast = 5;
636 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
637
638 GpStatus status;
639 GpGraphics *graphics = NULL;
640 HDC hdc = GetDC( hwnd );
641
642 ok(hdc != NULL, "Expected HDC to be initialized\n");
643
644 status = GdipCreateFromHDC(hdc, &graphics);
645 expect(Ok, status);
646 ok(graphics != NULL, "Expected graphics to be initialized\n");
647
648 /* null graphics, null container */
649 status = GdipBeginContainer2(NULL, &cont1);
650 expect(InvalidParameter, status);
651
652 status = GdipBeginContainer2(graphics, NULL);
653 expect(InvalidParameter, status);
654
655 status = GdipEndContainer(NULL, cont1);
656 expect(InvalidParameter, status);
657
658 /* test all quality-related values */
659 GdipSetCompositingMode(graphics, defCompmode);
660 GdipSetCompositingQuality(graphics, defCompqual);
661 GdipSetInterpolationMode(graphics, defInterp);
662 GdipSetPageScale(graphics, defScale);
663 GdipSetPageUnit(graphics, defUnit);
664 GdipSetPixelOffsetMode(graphics, defOffsetmode);
665 GdipSetSmoothingMode(graphics, defSmoothmode);
666 GdipSetTextContrast(graphics, defContrast);
667 GdipSetTextRenderingHint(graphics, defTexthint);
668
669 status = GdipBeginContainer2(graphics, &cont1);
670 expect(Ok, status);
671
672 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
673 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
674 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
675 GdipSetPageScale(graphics, 10);
676 GdipSetPageUnit(graphics, UnitDocument);
677 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
678 GdipSetSmoothingMode(graphics, SmoothingModeNone);
679 GdipSetTextContrast(graphics, 7);
680 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
681
682 status = GdipEndContainer(graphics, cont1);
683 expect(Ok, status);
684
685 GdipGetCompositingMode(graphics, &compmode);
686 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
687
688 GdipGetCompositingQuality(graphics, &compqual);
689 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
690
691 GdipGetInterpolationMode(graphics, &interp);
692 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
693
694 GdipGetPageScale(graphics, &scale);
695 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
696
697 GdipGetPageUnit(graphics, &unit);
698 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
699
700 GdipGetPixelOffsetMode(graphics, &offsetmode);
701 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
702
703 GdipGetSmoothingMode(graphics, &smoothmode);
704 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
705
706 GdipGetTextContrast(graphics, &contrast);
707 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
708
709 GdipGetTextRenderingHint(graphics, &texthint);
710 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
711
712 /* test world transform */
713 status = GdipBeginContainer2(graphics, &cont1);
714 expect(Ok, status);
715
716 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
717 defTrans[4], defTrans[5], &transform);
718 expect(Ok, status);
719 GdipSetWorldTransform(graphics, transform);
720 GdipDeleteMatrix(transform);
721 transform = NULL;
722
723 status = GdipBeginContainer2(graphics, &cont2);
724 expect(Ok, status);
725
726 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
727 expect(Ok, status);
728 GdipSetWorldTransform(graphics, transform);
729 GdipDeleteMatrix(transform);
730 transform = NULL;
731
732 status = GdipEndContainer(graphics, cont2);
733 expect(Ok, status);
734
735 status = GdipCreateMatrix(&transform);
736 expect(Ok, status);
737 GdipGetWorldTransform(graphics, transform);
738 GdipGetMatrixElements(transform, elems);
739 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
740 fabs(defTrans[1] - elems[1]) < 0.0001 &&
741 fabs(defTrans[2] - elems[2]) < 0.0001 &&
742 fabs(defTrans[3] - elems[3]) < 0.0001 &&
743 fabs(defTrans[4] - elems[4]) < 0.0001 &&
744 fabs(defTrans[5] - elems[5]) < 0.0001,
745 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
746 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
747 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
748 GdipDeleteMatrix(transform);
749 transform = NULL;
750
751 status = GdipEndContainer(graphics, cont1);
752 expect(Ok, status);
753
754 /* test clipping */
755 status = GdipBeginContainer2(graphics, &cont1);
756 expect(Ok, status);
757
758 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
759
760 status = GdipBeginContainer2(graphics, &cont2);
761 expect(Ok, status);
762
763 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
764
765 status = GdipEndContainer(graphics, cont2);
766 expect(Ok, status);
767
768 status = GdipGetClipBounds(graphics, &clip);
769 expect(Ok, status);
770
771 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
772 fabs(defClip[1] - clip.Y) < 0.0001 &&
773 fabs(defClip[2] - clip.Width) < 0.0001 &&
774 fabs(defClip[3] - clip.Height) < 0.0001,
775 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
776 defClip[0], defClip[1], defClip[2], defClip[3],
777 clip.X, clip.Y, clip.Width, clip.Height);
778
779 status = GdipEndContainer(graphics, cont1);
780 expect(Ok, status);
781
782 /* nesting */
783 status = GdipBeginContainer2(graphics, &cont1);
784 expect(Ok, status);
785
786 status = GdipBeginContainer2(graphics, &cont2);
787 expect(Ok, status);
788
789 status = GdipBeginContainer2(graphics, &cont3);
790 expect(Ok, status);
791
792 status = GdipEndContainer(graphics, cont3);
793 expect(Ok, status);
794
795 status = GdipBeginContainer2(graphics, &cont4);
796 expect(Ok, status);
797
798 status = GdipEndContainer(graphics, cont4);
799 expect(Ok, status);
800
801 /* skip cont2 */
802 status = GdipEndContainer(graphics, cont1);
803 expect(Ok, status);
804
805 /* end an already-ended container */
806 status = GdipEndContainer(graphics, cont1);
807 expect(Ok, status);
808
809 GdipDeleteGraphics(graphics);
810 ReleaseDC(hwnd, hdc);
811 }
812
813 static void test_GdipDrawBezierI(void)
814 {
815 GpStatus status;
816 GpGraphics *graphics = NULL;
817 GpPen *pen = NULL;
818 HDC hdc = GetDC( hwnd );
819
820 /* make a graphics object and pen object */
821 ok(hdc != NULL, "Expected HDC to be initialized\n");
822
823 status = GdipCreateFromHDC(hdc, &graphics);
824 expect(Ok, status);
825 ok(graphics != NULL, "Expected graphics to be initialized\n");
826
827 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
828 expect(Ok, status);
829 ok(pen != NULL, "Expected pen to be initialized\n");
830
831 /* InvalidParameter cases: null graphics, null pen */
832 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
833 expect(InvalidParameter, status);
834
835 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
836 expect(InvalidParameter, status);
837
838 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
839 expect(InvalidParameter, status);
840
841 /* successful case */
842 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
843 expect(Ok, status);
844
845 GdipDeletePen(pen);
846 GdipDeleteGraphics(graphics);
847
848 ReleaseDC(hwnd, hdc);
849 }
850
851 static void test_GdipDrawCurve3(void)
852 {
853 GpStatus status;
854 GpGraphics *graphics = NULL;
855 GpPen *pen = NULL;
856 HDC hdc = GetDC( hwnd );
857 GpPointF points[3];
858
859 points[0].X = 0;
860 points[0].Y = 0;
861
862 points[1].X = 40;
863 points[1].Y = 20;
864
865 points[2].X = 10;
866 points[2].Y = 40;
867
868 /* make a graphics object and pen object */
869 ok(hdc != NULL, "Expected HDC to be initialized\n");
870
871 status = GdipCreateFromHDC(hdc, &graphics);
872 expect(Ok, status);
873 ok(graphics != NULL, "Expected graphics to be initialized\n");
874
875 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
876 expect(Ok, status);
877 ok(pen != NULL, "Expected pen to be initialized\n");
878
879 /* InvalidParameter cases: null graphics, null pen */
880 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
881 expect(InvalidParameter, status);
882
883 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
884 expect(InvalidParameter, status);
885
886 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
887 expect(InvalidParameter, status);
888
889 /* InvalidParameter cases: invalid count */
890 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
891 expect(InvalidParameter, status);
892
893 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
894 expect(InvalidParameter, status);
895
896 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
897 expect(InvalidParameter, status);
898
899 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
900 expect(InvalidParameter, status);
901
902 /* InvalidParameter cases: invalid number of segments */
903 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
904 expect(InvalidParameter, status);
905
906 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
907 expect(InvalidParameter, status);
908
909 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
910 expect(InvalidParameter, status);
911
912 /* Valid test cases */
913 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
914 expect(Ok, status);
915
916 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
917 expect(Ok, status);
918
919 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
920 expect(Ok, status);
921
922 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
923 expect(Ok, status);
924
925 GdipDeletePen(pen);
926 GdipDeleteGraphics(graphics);
927
928 ReleaseDC(hwnd, hdc);
929 }
930
931 static void test_GdipDrawCurve3I(void)
932 {
933 GpStatus status;
934 GpGraphics *graphics = NULL;
935 GpPen *pen = NULL;
936 HDC hdc = GetDC( hwnd );
937 GpPoint points[3];
938
939 points[0].X = 0;
940 points[0].Y = 0;
941
942 points[1].X = 40;
943 points[1].Y = 20;
944
945 points[2].X = 10;
946 points[2].Y = 40;
947
948 /* make a graphics object and pen object */
949 ok(hdc != NULL, "Expected HDC to be initialized\n");
950
951 status = GdipCreateFromHDC(hdc, &graphics);
952 expect(Ok, status);
953 ok(graphics != NULL, "Expected graphics to be initialized\n");
954
955 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
956 expect(Ok, status);
957 ok(pen != NULL, "Expected pen to be initialized\n");
958
959 /* InvalidParameter cases: null graphics, null pen */
960 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
961 expect(InvalidParameter, status);
962
963 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
964 expect(InvalidParameter, status);
965
966 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
967 expect(InvalidParameter, status);
968
969 /* InvalidParameter cases: invalid count */
970 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
971 expect(OutOfMemory, status);
972
973 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
974 expect(InvalidParameter, status);
975
976 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
977 expect(InvalidParameter, status);
978
979 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
980 expect(InvalidParameter, status);
981
982 /* InvalidParameter cases: invalid number of segments */
983 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
984 expect(InvalidParameter, status);
985
986 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
987 expect(InvalidParameter, status);
988
989 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
990 expect(InvalidParameter, status);
991
992 /* Valid test cases */
993 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
994 expect(Ok, status);
995
996 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
997 expect(Ok, status);
998
999 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
1000 expect(Ok, status);
1001
1002 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
1003 expect(Ok, status);
1004
1005 GdipDeletePen(pen);
1006 GdipDeleteGraphics(graphics);
1007
1008 ReleaseDC(hwnd, hdc);
1009 }
1010
1011 static void test_GdipDrawCurve2(void)
1012 {
1013 GpStatus status;
1014 GpGraphics *graphics = NULL;
1015 GpPen *pen = NULL;
1016 HDC hdc = GetDC( hwnd );
1017 GpPointF points[3];
1018
1019 points[0].X = 0;
1020 points[0].Y = 0;
1021
1022 points[1].X = 40;
1023 points[1].Y = 20;
1024
1025 points[2].X = 10;
1026 points[2].Y = 40;
1027
1028 /* make a graphics object and pen object */
1029 ok(hdc != NULL, "Expected HDC to be initialized\n");
1030
1031 status = GdipCreateFromHDC(hdc, &graphics);
1032 expect(Ok, status);
1033 ok(graphics != NULL, "Expected graphics to be initialized\n");
1034
1035 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1036 expect(Ok, status);
1037 ok(pen != NULL, "Expected pen to be initialized\n");
1038
1039 /* InvalidParameter cases: null graphics, null pen */
1040 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
1041 expect(InvalidParameter, status);
1042
1043 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
1044 expect(InvalidParameter, status);
1045
1046 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
1047 expect(InvalidParameter, status);
1048
1049 /* InvalidParameter cases: invalid count */
1050 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
1051 expect(InvalidParameter, status);
1052
1053 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
1054 expect(InvalidParameter, status);
1055
1056 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
1057 expect(InvalidParameter, status);
1058
1059 /* Valid test cases */
1060 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1061 expect(Ok, status);
1062
1063 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1064 expect(Ok, status);
1065
1066 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1067 expect(Ok, status);
1068
1069 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1070 expect(Ok, status);
1071
1072 GdipDeletePen(pen);
1073 GdipDeleteGraphics(graphics);
1074
1075 ReleaseDC(hwnd, hdc);
1076 }
1077
1078 static void test_GdipDrawCurve2I(void)
1079 {
1080 GpStatus status;
1081 GpGraphics *graphics = NULL;
1082 GpPen *pen = NULL;
1083 HDC hdc = GetDC( hwnd );
1084 GpPoint points[3];
1085
1086 points[0].X = 0;
1087 points[0].Y = 0;
1088
1089 points[1].X = 40;
1090 points[1].Y = 20;
1091
1092 points[2].X = 10;
1093 points[2].Y = 40;
1094
1095 /* make a graphics object and pen object */
1096 ok(hdc != NULL, "Expected HDC to be initialized\n");
1097
1098 status = GdipCreateFromHDC(hdc, &graphics);
1099 expect(Ok, status);
1100 ok(graphics != NULL, "Expected graphics to be initialized\n");
1101
1102 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1103 expect(Ok, status);
1104 ok(pen != NULL, "Expected pen to be initialized\n");
1105
1106 /* InvalidParameter cases: null graphics, null pen */
1107 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1108 expect(InvalidParameter, status);
1109
1110 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1111 expect(InvalidParameter, status);
1112
1113 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1114 expect(InvalidParameter, status);
1115
1116 /* InvalidParameter cases: invalid count */
1117 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1118 expect(OutOfMemory, status);
1119
1120 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1121 expect(InvalidParameter, status);
1122
1123 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1124 expect(InvalidParameter, status);
1125
1126 /* Valid test cases */
1127 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1128 expect(Ok, status);
1129
1130 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1131 expect(Ok, status);
1132
1133 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1134 expect(Ok, status);
1135
1136 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1137 expect(Ok, status);
1138
1139 GdipDeletePen(pen);
1140 GdipDeleteGraphics(graphics);
1141
1142 ReleaseDC(hwnd, hdc);
1143 }
1144
1145 static void test_GdipDrawCurve(void)
1146 {
1147 GpStatus status;
1148 GpGraphics *graphics = NULL;
1149 GpPen *pen = NULL;
1150 HDC hdc = GetDC( hwnd );
1151 GpPointF points[3];
1152
1153 points[0].X = 0;
1154 points[0].Y = 0;
1155
1156 points[1].X = 40;
1157 points[1].Y = 20;
1158
1159 points[2].X = 10;
1160 points[2].Y = 40;
1161
1162 /* make a graphics object and pen object */
1163 ok(hdc != NULL, "Expected HDC to be initialized\n");
1164
1165 status = GdipCreateFromHDC(hdc, &graphics);
1166 expect(Ok, status);
1167 ok(graphics != NULL, "Expected graphics to be initialized\n");
1168
1169 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1170 expect(Ok, status);
1171 ok(pen != NULL, "Expected pen to be initialized\n");
1172
1173 /* InvalidParameter cases: null graphics, null pen */
1174 status = GdipDrawCurve(NULL, NULL, points, 3);
1175 expect(InvalidParameter, status);
1176
1177 status = GdipDrawCurve(graphics, NULL, points, 3);
1178 expect(InvalidParameter, status);
1179
1180 status = GdipDrawCurve(NULL, pen, points, 3);
1181 expect(InvalidParameter, status);
1182
1183 /* InvalidParameter cases: invalid count */
1184 status = GdipDrawCurve(graphics, pen, points, -1);
1185 expect(InvalidParameter, status);
1186
1187 status = GdipDrawCurve(graphics, pen, points, 0);
1188 expect(InvalidParameter, status);
1189
1190 status = GdipDrawCurve(graphics, pen, points, 1);
1191 expect(InvalidParameter, status);
1192
1193 /* Valid test cases */
1194 status = GdipDrawCurve(graphics, pen, points, 2);
1195 expect(Ok, status);
1196
1197 status = GdipDrawCurve(graphics, pen, points, 3);
1198 expect(Ok, status);
1199
1200 GdipDeletePen(pen);
1201 GdipDeleteGraphics(graphics);
1202
1203 ReleaseDC(hwnd, hdc);
1204 }
1205
1206 static void test_GdipDrawCurveI(void)
1207 {
1208 GpStatus status;
1209 GpGraphics *graphics = NULL;
1210 GpPen *pen = NULL;
1211 HDC hdc = GetDC( hwnd );
1212 GpPoint points[3];
1213
1214 points[0].X = 0;
1215 points[0].Y = 0;
1216
1217 points[1].X = 40;
1218 points[1].Y = 20;
1219
1220 points[2].X = 10;
1221 points[2].Y = 40;
1222
1223 /* make a graphics object and pen object */
1224 ok(hdc != NULL, "Expected HDC to be initialized\n");
1225
1226 status = GdipCreateFromHDC(hdc, &graphics);
1227 expect(Ok, status);
1228 ok(graphics != NULL, "Expected graphics to be initialized\n");
1229
1230 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1231 expect(Ok, status);
1232 ok(pen != NULL, "Expected pen to be initialized\n");
1233
1234 /* InvalidParameter cases: null graphics, null pen */
1235 status = GdipDrawCurveI(NULL, NULL, points, 3);
1236 expect(InvalidParameter, status);
1237
1238 status = GdipDrawCurveI(graphics, NULL, points, 3);
1239 expect(InvalidParameter, status);
1240
1241 status = GdipDrawCurveI(NULL, pen, points, 3);
1242 expect(InvalidParameter, status);
1243
1244 /* InvalidParameter cases: invalid count */
1245 status = GdipDrawCurveI(graphics, pen, points, -1);
1246 expect(OutOfMemory, status);
1247
1248 status = GdipDrawCurveI(graphics, pen, points, 0);
1249 expect(InvalidParameter, status);
1250
1251 status = GdipDrawCurveI(graphics, pen, points, 1);
1252 expect(InvalidParameter, status);
1253
1254 /* Valid test cases */
1255 status = GdipDrawCurveI(graphics, pen, points, 2);
1256 expect(Ok, status);
1257
1258 status = GdipDrawCurveI(graphics, pen, points, 3);
1259 expect(Ok, status);
1260
1261 GdipDeletePen(pen);
1262 GdipDeleteGraphics(graphics);
1263
1264 ReleaseDC(hwnd, hdc);
1265 }
1266
1267 static void test_GdipDrawLineI(void)
1268 {
1269 GpStatus status;
1270 GpGraphics *graphics = NULL;
1271 GpPen *pen = NULL;
1272 HDC hdc = GetDC( hwnd );
1273
1274 /* make a graphics object and pen object */
1275 ok(hdc != NULL, "Expected HDC to be initialized\n");
1276
1277 status = GdipCreateFromHDC(hdc, &graphics);
1278 expect(Ok, status);
1279 ok(graphics != NULL, "Expected graphics to be initialized\n");
1280
1281 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1282 expect(Ok, status);
1283 ok(pen != NULL, "Expected pen to be initialized\n");
1284
1285 /* InvalidParameter cases: null graphics, null pen */
1286 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1287 expect(InvalidParameter, status);
1288
1289 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1290 expect(InvalidParameter, status);
1291
1292 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1293 expect(InvalidParameter, status);
1294
1295 /* successful case */
1296 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1297 expect(Ok, status);
1298
1299 GdipDeletePen(pen);
1300 GdipDeleteGraphics(graphics);
1301
1302 ReleaseDC(hwnd, hdc);
1303 }
1304
1305 static void test_GdipDrawImagePointsRect(void)
1306 {
1307 GpStatus status;
1308 GpGraphics *graphics = NULL;
1309 GpPointF ptf[4];
1310 GpBitmap *bm = NULL;
1311 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1312 BYTE buff[400];
1313 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1314 HDC hdc = GetDC( hwnd );
1315 if (!hdc)
1316 return;
1317
1318 memset(rbmi, 0, sizeof(rbmi));
1319 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1320 bmi->bmiHeader.biWidth = 10;
1321 bmi->bmiHeader.biHeight = 10;
1322 bmi->bmiHeader.biPlanes = 1;
1323 bmi->bmiHeader.biBitCount = 32;
1324 bmi->bmiHeader.biCompression = BI_RGB;
1325 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1326 expect(Ok, status);
1327 ok(NULL != bm, "Expected bitmap to be initialized\n");
1328 status = GdipCreateFromHDC(hdc, &graphics);
1329 expect(Ok, status);
1330 ptf[0].X = 0;
1331 ptf[0].Y = 0;
1332 ptf[1].X = 10;
1333 ptf[1].Y = 0;
1334 ptf[2].X = 0;
1335 ptf[2].Y = 10;
1336 ptf[3].X = 10;
1337 ptf[3].Y = 10;
1338 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1339 expect(NotImplemented, status);
1340 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1341 expect(InvalidParameter, status);
1342 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1343 expect(Ok, status);
1344 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1345 expect(InvalidParameter, status);
1346 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1347 expect(InvalidParameter, status);
1348 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1349 expect(Ok, status);
1350 memset(ptf, 0, sizeof(ptf));
1351 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1352 expect(Ok, status);
1353
1354 GdipDisposeImage((GpImage*)bm);
1355 GdipDeleteGraphics(graphics);
1356 ReleaseDC(hwnd, hdc);
1357 }
1358
1359 static void test_GdipDrawLinesI(void)
1360 {
1361 GpStatus status;
1362 GpGraphics *graphics = NULL;
1363 GpPen *pen = NULL;
1364 GpPoint *ptf = NULL;
1365 HDC hdc = GetDC( hwnd );
1366
1367 /* make a graphics object and pen object */
1368 ok(hdc != NULL, "Expected HDC to be initialized\n");
1369
1370 status = GdipCreateFromHDC(hdc, &graphics);
1371 expect(Ok, status);
1372 ok(graphics != NULL, "Expected graphics to be initialized\n");
1373
1374 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1375 expect(Ok, status);
1376 ok(pen != NULL, "Expected pen to be initialized\n");
1377
1378 /* make some arbitrary valid points*/
1379 ptf = GdipAlloc(2 * sizeof(GpPointF));
1380
1381 ptf[0].X = 1;
1382 ptf[0].Y = 1;
1383
1384 ptf[1].X = 2;
1385 ptf[1].Y = 2;
1386
1387 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1388 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1389 expect(InvalidParameter, status);
1390
1391 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1392 expect(InvalidParameter, status);
1393
1394 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1395 expect(InvalidParameter, status);
1396
1397 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1398 expect(InvalidParameter, status);
1399
1400 /* successful case */
1401 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1402 expect(Ok, status);
1403
1404 GdipFree(ptf);
1405 GdipDeletePen(pen);
1406 GdipDeleteGraphics(graphics);
1407
1408 ReleaseDC(hwnd, hdc);
1409 }
1410
1411 static void test_GdipFillClosedCurve(void)
1412 {
1413 GpStatus status;
1414 GpGraphics *graphics = NULL;
1415 GpSolidFill *brush = NULL;
1416 HDC hdc = GetDC( hwnd );
1417 GpPointF points[3];
1418
1419 points[0].X = 0;
1420 points[0].Y = 0;
1421
1422 points[1].X = 40;
1423 points[1].Y = 20;
1424
1425 points[2].X = 10;
1426 points[2].Y = 40;
1427
1428 /* make a graphics object and brush object */
1429 ok(hdc != NULL, "Expected HDC to be initialized\n");
1430
1431 status = GdipCreateFromHDC(hdc, &graphics);
1432 expect(Ok, status);
1433 ok(graphics != NULL, "Expected graphics to be initialized\n");
1434
1435 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1436
1437 /* InvalidParameter cases: null graphics, null brush, null points */
1438 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1439 expect(InvalidParameter, status);
1440
1441 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1442 expect(InvalidParameter, status);
1443
1444 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1445 expect(InvalidParameter, status);
1446
1447 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1448 expect(InvalidParameter, status);
1449
1450 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1451 expect(InvalidParameter, status);
1452
1453 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1454 expect(InvalidParameter, status);
1455
1456 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1457 expect(InvalidParameter, status);
1458
1459 /* InvalidParameter cases: invalid count */
1460 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1461 expect(InvalidParameter, status);
1462
1463 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1464 expect(InvalidParameter, status);
1465
1466 /* Valid test cases */
1467 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1468 expect(Ok, status);
1469
1470 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1471 expect(Ok, status);
1472
1473 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1474 expect(Ok, status);
1475
1476 GdipDeleteGraphics(graphics);
1477 GdipDeleteBrush((GpBrush*)brush);
1478
1479 ReleaseDC(hwnd, hdc);
1480 }
1481
1482 static void test_GdipFillClosedCurveI(void)
1483 {
1484 GpStatus status;
1485 GpGraphics *graphics = NULL;
1486 GpSolidFill *brush = NULL;
1487 HDC hdc = GetDC( hwnd );
1488 GpPoint points[3];
1489
1490 points[0].X = 0;
1491 points[0].Y = 0;
1492
1493 points[1].X = 40;
1494 points[1].Y = 20;
1495
1496 points[2].X = 10;
1497 points[2].Y = 40;
1498
1499 /* make a graphics object and brush object */
1500 ok(hdc != NULL, "Expected HDC to be initialized\n");
1501
1502 status = GdipCreateFromHDC(hdc, &graphics);
1503 expect(Ok, status);
1504 ok(graphics != NULL, "Expected graphics to be initialized\n");
1505
1506 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1507
1508 /* InvalidParameter cases: null graphics, null brush */
1509 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1510 when points == NULL, so don't test this condition */
1511 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1512 expect(InvalidParameter, status);
1513
1514 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1515 expect(InvalidParameter, status);
1516
1517 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1518 expect(InvalidParameter, status);
1519
1520 /* InvalidParameter cases: invalid count */
1521 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1522 expect(InvalidParameter, status);
1523
1524 /* OutOfMemory cases: large (unsigned) int */
1525 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1526 expect(OutOfMemory, status);
1527
1528 /* Valid test cases */
1529 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1530 expect(Ok, status);
1531
1532 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1533 expect(Ok, status);
1534
1535 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1536 expect(Ok, status);
1537
1538 GdipDeleteGraphics(graphics);
1539 GdipDeleteBrush((GpBrush*)brush);
1540
1541 ReleaseDC(hwnd, hdc);
1542 }
1543
1544 static void test_Get_Release_DC(void)
1545 {
1546 GpStatus status;
1547 GpGraphics *graphics = NULL;
1548 GpPen *pen;
1549 GpSolidFill *brush;
1550 GpPath *path;
1551 HDC hdc = GetDC( hwnd );
1552 HDC retdc;
1553 REAL r;
1554 CompositingQuality quality;
1555 CompositingMode compmode;
1556 InterpolationMode intmode;
1557 GpMatrix *m;
1558 GpRegion *region;
1559 GpUnit unit;
1560 PixelOffsetMode offsetmode;
1561 SmoothingMode smoothmode;
1562 TextRenderingHint texthint;
1563 GpPointF ptf[5];
1564 GpPoint pt[5];
1565 GpRectF rectf[2];
1566 GpRect rect[2];
1567 GpRegion *clip;
1568 INT i;
1569 BOOL res;
1570 ARGB color = 0x00000000;
1571 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1572
1573 pt[0].X = 10;
1574 pt[0].Y = 10;
1575 pt[1].X = 20;
1576 pt[1].Y = 15;
1577 pt[2].X = 40;
1578 pt[2].Y = 80;
1579 pt[3].X = -20;
1580 pt[3].Y = 20;
1581 pt[4].X = 50;
1582 pt[4].Y = 110;
1583
1584 for(i = 0; i < 5;i++){
1585 ptf[i].X = (REAL)pt[i].X;
1586 ptf[i].Y = (REAL)pt[i].Y;
1587 }
1588
1589 rect[0].X = 0;
1590 rect[0].Y = 0;
1591 rect[0].Width = 50;
1592 rect[0].Height = 70;
1593 rect[1].X = 0;
1594 rect[1].Y = 0;
1595 rect[1].Width = 10;
1596 rect[1].Height = 20;
1597
1598 for(i = 0; i < 2;i++){
1599 rectf[i].X = (REAL)rect[i].X;
1600 rectf[i].Y = (REAL)rect[i].Y;
1601 rectf[i].Height = (REAL)rect[i].Height;
1602 rectf[i].Width = (REAL)rect[i].Width;
1603 }
1604
1605 status = GdipCreateMatrix(&m);
1606 expect(Ok, status);
1607 GdipCreateRegion(&region);
1608 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1609 GdipCreatePath(FillModeAlternate, &path);
1610 GdipCreateRegion(&clip);
1611
1612 status = GdipCreateFromHDC(hdc, &graphics);
1613 expect(Ok, status);
1614 ok(graphics != NULL, "Expected graphics to be initialized\n");
1615 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1616 expect(Ok, status);
1617
1618 /* NULL arguments */
1619 status = GdipGetDC(NULL, NULL);
1620 expect(InvalidParameter, status);
1621 status = GdipGetDC(graphics, NULL);
1622 expect(InvalidParameter, status);
1623 status = GdipGetDC(NULL, &retdc);
1624 expect(InvalidParameter, status);
1625
1626 status = GdipReleaseDC(NULL, NULL);
1627 expect(InvalidParameter, status);
1628 status = GdipReleaseDC(graphics, NULL);
1629 expect(InvalidParameter, status);
1630 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1631 expect(InvalidParameter, status);
1632
1633 /* Release without Get */
1634 status = GdipReleaseDC(graphics, hdc);
1635 expect(InvalidParameter, status);
1636
1637 retdc = NULL;
1638 status = GdipGetDC(graphics, &retdc);
1639 expect(Ok, status);
1640 ok(retdc == hdc, "Invalid HDC returned\n");
1641 /* call it once more */
1642 status = GdipGetDC(graphics, &retdc);
1643 expect(ObjectBusy, status);
1644
1645 /* try all Graphics calls here */
1646 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1647 expect(ObjectBusy, status);
1648 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1649 expect(ObjectBusy, status);
1650 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1651 expect(ObjectBusy, status);
1652 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1653 expect(ObjectBusy, status);
1654 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1655 expect(ObjectBusy, status);
1656 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1657 expect(ObjectBusy, status);
1658 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1659 expect(ObjectBusy, status);
1660 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1661 expect(ObjectBusy, status);
1662 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1663 expect(ObjectBusy, status);
1664 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1665 expect(ObjectBusy, status);
1666 status = GdipDrawCurve(graphics, pen, ptf, 5);
1667 expect(ObjectBusy, status);
1668 status = GdipDrawCurveI(graphics, pen, pt, 5);
1669 expect(ObjectBusy, status);
1670 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1671 expect(ObjectBusy, status);
1672 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1673 expect(ObjectBusy, status);
1674 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1675 expect(ObjectBusy, status);
1676 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1677 expect(ObjectBusy, status);
1678 /* GdipDrawImage/GdipDrawImageI */
1679 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1680 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1681 /* GdipDrawImageRect/GdipDrawImageRectI */
1682 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1683 expect(ObjectBusy, status);
1684 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1685 expect(ObjectBusy, status);
1686 status = GdipDrawLines(graphics, pen, ptf, 5);
1687 expect(ObjectBusy, status);
1688 status = GdipDrawLinesI(graphics, pen, pt, 5);
1689 expect(ObjectBusy, status);
1690 status = GdipDrawPath(graphics, pen, path);
1691 expect(ObjectBusy, status);
1692 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1693 expect(ObjectBusy, status);
1694 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1695 expect(ObjectBusy, status);
1696 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1697 expect(ObjectBusy, status);
1698 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1699 expect(ObjectBusy, status);
1700 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1701 expect(ObjectBusy, status);
1702 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1703 expect(ObjectBusy, status);
1704 /* GdipDrawString */
1705 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1706 expect(ObjectBusy, status);
1707 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1708 expect(ObjectBusy, status);
1709 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1710 expect(ObjectBusy, status);
1711 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1712 expect(ObjectBusy, status);
1713 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1714 expect(ObjectBusy, status);
1715 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1716 expect(ObjectBusy, status);
1717 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1718 expect(ObjectBusy, status);
1719 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1720 expect(ObjectBusy, status);
1721 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1722 expect(ObjectBusy, status);
1723 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1724 expect(ObjectBusy, status);
1725 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1726 expect(ObjectBusy, status);
1727 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1728 expect(ObjectBusy, status);
1729 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1730 expect(ObjectBusy, status);
1731 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1732 expect(ObjectBusy, status);
1733 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1734 expect(ObjectBusy, status);
1735 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1736 expect(ObjectBusy, status);
1737 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1738 expect(ObjectBusy, status);
1739 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1740 expect(ObjectBusy, status);
1741 status = GdipFlush(graphics, FlushIntentionFlush);
1742 expect(ObjectBusy, status);
1743 status = GdipGetClipBounds(graphics, rectf);
1744 expect(ObjectBusy, status);
1745 status = GdipGetClipBoundsI(graphics, rect);
1746 expect(ObjectBusy, status);
1747 status = GdipGetCompositingMode(graphics, &compmode);
1748 expect(ObjectBusy, status);
1749 status = GdipGetCompositingQuality(graphics, &quality);
1750 expect(ObjectBusy, status);
1751 status = GdipGetInterpolationMode(graphics, &intmode);
1752 expect(ObjectBusy, status);
1753 status = GdipGetNearestColor(graphics, &color);
1754 expect(ObjectBusy, status);
1755 status = GdipGetPageScale(graphics, &r);
1756 expect(ObjectBusy, status);
1757 status = GdipGetPageUnit(graphics, &unit);
1758 expect(ObjectBusy, status);
1759 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1760 expect(ObjectBusy, status);
1761 status = GdipGetSmoothingMode(graphics, &smoothmode);
1762 expect(ObjectBusy, status);
1763 status = GdipGetTextRenderingHint(graphics, &texthint);
1764 expect(ObjectBusy, status);
1765 status = GdipGetWorldTransform(graphics, m);
1766 expect(ObjectBusy, status);
1767 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1768 expect(ObjectBusy, status);
1769 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1770 expect(ObjectBusy, status);
1771 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1772 expect(ObjectBusy, status);
1773 /* GdipMeasureCharacterRanges */
1774 /* GdipMeasureString */
1775 status = GdipResetClip(graphics);
1776 expect(ObjectBusy, status);
1777 status = GdipResetWorldTransform(graphics);
1778 expect(ObjectBusy, status);
1779 /* GdipRestoreGraphics */
1780 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1781 expect(ObjectBusy, status);
1782 /* GdipSaveGraphics */
1783 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1784 expect(ObjectBusy, status);
1785 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1786 expect(ObjectBusy, status);
1787 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1788 expect(ObjectBusy, status);
1789 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1790 expect(ObjectBusy, status);
1791 status = GdipSetPageScale(graphics, 1.0);
1792 expect(ObjectBusy, status);
1793 status = GdipSetPageUnit(graphics, UnitWorld);
1794 expect(ObjectBusy, status);
1795 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1796 expect(ObjectBusy, status);
1797 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1798 expect(ObjectBusy, status);
1799 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1800 expect(ObjectBusy, status);
1801 status = GdipSetWorldTransform(graphics, m);
1802 expect(ObjectBusy, status);
1803 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1804 expect(ObjectBusy, status);
1805 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1806 expect(ObjectBusy, status);
1807 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1808 expect(ObjectBusy, status);
1809 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1810 expect(ObjectBusy, status);
1811 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1812 expect(ObjectBusy, status);
1813 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1814 expect(ObjectBusy, status);
1815 status = GdipTranslateClip(graphics, 0.0, 0.0);
1816 expect(ObjectBusy, status);
1817 status = GdipTranslateClipI(graphics, 0, 0);
1818 expect(ObjectBusy, status);
1819 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1820 expect(ObjectBusy, status);
1821 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1822 expect(ObjectBusy, status);
1823 status = GdipGetDpiX(graphics, &r);
1824 expect(ObjectBusy, status);
1825 status = GdipGetDpiY(graphics, &r);
1826 expect(ObjectBusy, status);
1827 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1828 expect(ObjectBusy, status);
1829 status = GdipGetClip(graphics, region);
1830 expect(ObjectBusy, status);
1831 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1832 expect(ObjectBusy, status);
1833
1834 /* try to delete before release */
1835 status = GdipDeleteGraphics(graphics);
1836 expect(ObjectBusy, status);
1837
1838 status = GdipReleaseDC(graphics, retdc);
1839 expect(Ok, status);
1840
1841 GdipDeletePen(pen);
1842 GdipDeleteGraphics(graphics);
1843
1844 GdipDeleteRegion(clip);
1845 GdipDeletePath(path);
1846 GdipDeleteBrush((GpBrush*)brush);
1847 GdipDeleteRegion(region);
1848 GdipDeleteMatrix(m);
1849 DeleteObject(hrgn);
1850
1851 ReleaseDC(hwnd, hdc);
1852 }
1853
1854 static void test_transformpoints(void)
1855 {
1856 GpStatus status;
1857 GpGraphics *graphics = NULL;
1858 HDC hdc = GetDC( hwnd );
1859 GpPointF ptf[2];
1860 GpPoint pt[2];
1861
1862 status = GdipCreateFromHDC(hdc, &graphics);
1863 expect(Ok, status);
1864
1865 /* NULL arguments */
1866 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1867 expect(InvalidParameter, status);
1868 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1869 expect(InvalidParameter, status);
1870 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1871 expect(InvalidParameter, status);
1872 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1873 expect(InvalidParameter, status);
1874
1875 ptf[0].X = 1.0;
1876 ptf[0].Y = 0.0;
1877 ptf[1].X = 0.0;
1878 ptf[1].Y = 1.0;
1879 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1880 expect(Ok, status);
1881 expectf(1.0, ptf[0].X);
1882 expectf(0.0, ptf[0].Y);
1883 expectf(0.0, ptf[1].X);
1884 expectf(1.0, ptf[1].Y);
1885
1886 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1887 expect(Ok, status);
1888 status = GdipSetPageUnit(graphics, UnitPixel);
1889 expect(Ok, status);
1890 status = GdipSetPageScale(graphics, 3.0);
1891 expect(Ok, status);
1892
1893 ptf[0].X = 1.0;
1894 ptf[0].Y = 0.0;
1895 ptf[1].X = 0.0;
1896 ptf[1].Y = 1.0;
1897 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1898 expect(Ok, status);
1899 expectf(18.0, ptf[0].X);
1900 expectf(15.0, ptf[0].Y);
1901 expectf(15.0, ptf[1].X);
1902 expectf(18.0, ptf[1].Y);
1903
1904 ptf[0].X = 1.0;
1905 ptf[0].Y = 0.0;
1906 ptf[1].X = 0.0;
1907 ptf[1].Y = 1.0;
1908 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1909 expect(Ok, status);
1910 expectf(6.0, ptf[0].X);
1911 expectf(5.0, ptf[0].Y);
1912 expectf(5.0, ptf[1].X);
1913 expectf(6.0, ptf[1].Y);
1914
1915 ptf[0].X = 1.0;
1916 ptf[0].Y = 0.0;
1917 ptf[1].X = 0.0;
1918 ptf[1].Y = 1.0;
1919 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1920 expect(Ok, status);
1921 expectf(3.0, ptf[0].X);
1922 expectf(0.0, ptf[0].Y);
1923 expectf(0.0, ptf[1].X);
1924 expectf(3.0, ptf[1].Y);
1925
1926 ptf[0].X = 18.0;
1927 ptf[0].Y = 15.0;
1928 ptf[1].X = 15.0;
1929 ptf[1].Y = 18.0;
1930 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1931 expect(Ok, status);
1932 expectf(1.0, ptf[0].X);
1933 expectf(0.0, ptf[0].Y);
1934 expectf(0.0, ptf[1].X);
1935 expectf(1.0, ptf[1].Y);
1936
1937 ptf[0].X = 6.0;
1938 ptf[0].Y = 5.0;
1939 ptf[1].X = 5.0;
1940 ptf[1].Y = 6.0;
1941 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1942 expect(Ok, status);
1943 expectf(1.0, ptf[0].X);
1944 expectf(0.0, ptf[0].Y);
1945 expectf(0.0, ptf[1].X);
1946 expectf(1.0, ptf[1].Y);
1947
1948 ptf[0].X = 3.0;
1949 ptf[0].Y = 0.0;
1950 ptf[1].X = 0.0;
1951 ptf[1].Y = 3.0;
1952 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1953 expect(Ok, status);
1954 expectf(1.0, ptf[0].X);
1955 expectf(0.0, ptf[0].Y);
1956 expectf(0.0, ptf[1].X);
1957 expectf(1.0, ptf[1].Y);
1958
1959 pt[0].X = 1;
1960 pt[0].Y = 0;
1961 pt[1].X = 0;
1962 pt[1].Y = 1;
1963 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1964 expect(Ok, status);
1965 expect(18, pt[0].X);
1966 expect(15, pt[0].Y);
1967 expect(15, pt[1].X);
1968 expect(18, pt[1].Y);
1969
1970 GdipDeleteGraphics(graphics);
1971 ReleaseDC(hwnd, hdc);
1972 }
1973
1974 static void test_get_set_clip(void)
1975 {
1976 GpStatus status;
1977 GpGraphics *graphics = NULL;
1978 HDC hdc = GetDC( hwnd );
1979 GpRegion *clip;
1980 GpRectF rect;
1981 BOOL res;
1982
1983 status = GdipCreateFromHDC(hdc, &graphics);
1984 expect(Ok, status);
1985
1986 rect.X = rect.Y = 0.0;
1987 rect.Height = rect.Width = 100.0;
1988
1989 status = GdipCreateRegionRect(&rect, &clip);
1990 expect(Ok, status);
1991
1992 /* NULL arguments */
1993 status = GdipGetClip(NULL, NULL);
1994 expect(InvalidParameter, status);
1995 status = GdipGetClip(graphics, NULL);
1996 expect(InvalidParameter, status);
1997 status = GdipGetClip(NULL, clip);
1998 expect(InvalidParameter, status);
1999
2000 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
2001 expect(InvalidParameter, status);
2002 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
2003 expect(InvalidParameter, status);
2004
2005 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
2006 expect(InvalidParameter, status);
2007 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
2008 expect(InvalidParameter, status);
2009
2010 res = FALSE;
2011 status = GdipGetClip(graphics, clip);
2012 expect(Ok, status);
2013 status = GdipIsInfiniteRegion(clip, graphics, &res);
2014 expect(Ok, status);
2015 expect(TRUE, res);
2016
2017 /* remains infinite after reset */
2018 res = FALSE;
2019 status = GdipResetClip(graphics);
2020 expect(Ok, status);
2021 status = GdipGetClip(graphics, clip);
2022 expect(Ok, status);
2023 status = GdipIsInfiniteRegion(clip, graphics, &res);
2024 expect(Ok, status);
2025 expect(TRUE, res);
2026
2027 /* set to empty and then reset to infinite */
2028 status = GdipSetEmpty(clip);
2029 expect(Ok, status);
2030 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
2031 expect(Ok, status);
2032
2033 status = GdipGetClip(graphics, clip);
2034 expect(Ok, status);
2035 res = FALSE;
2036 status = GdipIsEmptyRegion(clip, graphics, &res);
2037 expect(Ok, status);
2038 expect(TRUE, res);
2039 status = GdipResetClip(graphics);
2040 expect(Ok, status);
2041 status = GdipGetClip(graphics, clip);
2042 expect(Ok, status);
2043 res = FALSE;
2044 status = GdipIsInfiniteRegion(clip, graphics, &res);
2045 expect(Ok, status);
2046 expect(TRUE, res);
2047
2048 GdipDeleteRegion(clip);
2049
2050 GdipDeleteGraphics(graphics);
2051 ReleaseDC(hwnd, hdc);
2052 }
2053
2054 static void test_isempty(void)
2055 {
2056 GpStatus status;
2057 GpGraphics *graphics = NULL;
2058 HDC hdc = GetDC( hwnd );
2059 GpRegion *clip;
2060 BOOL res;
2061
2062 status = GdipCreateFromHDC(hdc, &graphics);
2063 expect(Ok, status);
2064
2065 status = GdipCreateRegion(&clip);
2066 expect(Ok, status);
2067
2068 /* NULL */
2069 status = GdipIsClipEmpty(NULL, NULL);
2070 expect(InvalidParameter, status);
2071 status = GdipIsClipEmpty(graphics, NULL);
2072 expect(InvalidParameter, status);
2073 status = GdipIsClipEmpty(NULL, &res);
2074 expect(InvalidParameter, status);
2075
2076 /* default is infinite */
2077 res = TRUE;
2078 status = GdipIsClipEmpty(graphics, &res);
2079 expect(Ok, status);
2080 expect(FALSE, res);
2081
2082 GdipDeleteRegion(clip);
2083
2084 GdipDeleteGraphics(graphics);
2085 ReleaseDC(hwnd, hdc);
2086 }
2087
2088 static void test_clear(void)
2089 {
2090 GpStatus status;
2091
2092 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2093 expect(InvalidParameter, status);
2094 }
2095
2096 static void test_textcontrast(void)
2097 {
2098 GpStatus status;
2099 HDC hdc = GetDC( hwnd );
2100 GpGraphics *graphics;
2101 UINT contrast;
2102
2103 status = GdipGetTextContrast(NULL, NULL);
2104 expect(InvalidParameter, status);
2105
2106 status = GdipCreateFromHDC(hdc, &graphics);
2107 expect(Ok, status);
2108
2109 status = GdipGetTextContrast(graphics, NULL);
2110 expect(InvalidParameter, status);
2111 status = GdipGetTextContrast(graphics, &contrast);
2112 expect(Ok, status);
2113 expect(4, contrast);
2114
2115 GdipDeleteGraphics(graphics);
2116 ReleaseDC(hwnd, hdc);
2117 }
2118
2119 static void test_GdipDrawString(void)
2120 {
2121 GpStatus status;
2122 GpGraphics *graphics = NULL;
2123 GpFont *fnt = NULL;
2124 RectF rect;
2125 GpStringFormat *format;
2126 GpBrush *brush;
2127 LOGFONTA logfont;
2128 HDC hdc = GetDC( hwnd );
2129 static const WCHAR string[] = {'T','e','s','t',0};
2130 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2131 GpMatrix *matrix;
2132
2133 memset(&logfont,0,sizeof(logfont));
2134 strcpy(logfont.lfFaceName,"Arial");
2135 logfont.lfHeight = 12;
2136 logfont.lfCharSet = DEFAULT_CHARSET;
2137
2138 status = GdipCreateFromHDC(hdc, &graphics);
2139 expect(Ok, status);
2140
2141 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2142 if (status == NotTrueTypeFont || status == FileNotFound)
2143 {
2144 skip("Arial not installed.\n");
2145 return;
2146 }
2147 expect(Ok, status);
2148
2149 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2150 expect(Ok, status);
2151
2152 status = GdipCreateStringFormat(0,0,&format);
2153 expect(Ok, status);
2154
2155 rect.X = 0;
2156 rect.Y = 0;
2157 rect.Width = 0;
2158 rect.Height = 12;
2159
2160 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2161 expect(Ok, status);
2162
2163 status = GdipCreateMatrix(&matrix);
2164 expect(Ok, status);
2165
2166 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2167 expect(InvalidParameter, status);
2168
2169 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2170 expect(InvalidParameter, status);
2171
2172 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2173 expect(InvalidParameter, status);
2174
2175 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2176 expect(InvalidParameter, status);
2177
2178 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2179 expect(InvalidParameter, status);
2180
2181 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2182 expect(Ok, status);
2183
2184 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2185 expect(Ok, status);
2186
2187 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2188 expect(Ok, status);
2189
2190 GdipDeleteMatrix(matrix);
2191 GdipDeleteGraphics(graphics);
2192 GdipDeleteBrush(brush);
2193 GdipDeleteFont(fnt);
2194 GdipDeleteStringFormat(format);
2195
2196 ReleaseDC(hwnd, hdc);
2197 }
2198
2199 static void test_GdipGetVisibleClipBounds_screen(void)
2200 {
2201 GpStatus status;
2202 GpGraphics *graphics = NULL;
2203 HDC hdc = GetDC(0);
2204 GpRectF rectf, exp, clipr;
2205 GpRect recti;
2206
2207 ok(hdc != NULL, "Expected HDC to be initialized\n");
2208
2209 status = GdipCreateFromHDC(hdc, &graphics);
2210 expect(Ok, status);
2211 ok(graphics != NULL, "Expected graphics to be initialized\n");
2212
2213 /* no clipping rect */
2214 exp.X = 0;
2215 exp.Y = 0;
2216 exp.Width = GetDeviceCaps(hdc, HORZRES);
2217 exp.Height = GetDeviceCaps(hdc, VERTRES);
2218
2219 status = GdipGetVisibleClipBounds(graphics, &rectf);
2220 expect(Ok, status);
2221 ok(rectf.X == exp.X &&
2222 rectf.Y == exp.Y &&
2223 rectf.Width == exp.Width &&
2224 rectf.Height == exp.Height,
2225 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2226 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2227 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2228 exp.X, exp.Y, exp.Width, exp.Height);
2229
2230 /* clipping rect entirely within window */
2231 exp.X = clipr.X = 10;
2232 exp.Y = clipr.Y = 12;
2233 exp.Width = clipr.Width = 14;
2234 exp.Height = clipr.Height = 16;
2235
2236 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2237 expect(Ok, status);
2238
2239 status = GdipGetVisibleClipBounds(graphics, &rectf);
2240 expect(Ok, status);
2241 ok(rectf.X == exp.X &&
2242 rectf.Y == exp.Y &&
2243 rectf.Width == exp.Width &&
2244 rectf.Height == exp.Height,
2245 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2246 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2247 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2248 exp.X, exp.Y, exp.Width, exp.Height);
2249
2250 /* clipping rect partially outside of screen */
2251 clipr.X = -10;
2252 clipr.Y = -12;
2253 clipr.Width = 20;
2254 clipr.Height = 24;
2255
2256 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2257 expect(Ok, status);
2258
2259 exp.X = 0;
2260 exp.Y = 0;
2261 exp.Width = 10;
2262 exp.Height = 12;
2263
2264 status = GdipGetVisibleClipBounds(graphics, &rectf);
2265 expect(Ok, status);
2266 ok(rectf.X == exp.X &&
2267 rectf.Y == exp.Y &&
2268 rectf.Width == exp.Width &&
2269 rectf.Height == exp.Height,
2270 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2271 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2272 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2273 exp.X, exp.Y, exp.Width, exp.Height);
2274
2275 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2276 expect(Ok, status);
2277 ok(recti.X == exp.X &&
2278 recti.Y == exp.Y &&
2279 recti.Width == exp.Width &&
2280 recti.Height == exp.Height,
2281 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2282 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2283 recti.X, recti.Y, recti.Width, recti.Height,
2284 exp.X, exp.Y, exp.Width, exp.Height);
2285
2286 GdipDeleteGraphics(graphics);
2287 ReleaseDC(0, hdc);
2288 }
2289
2290 static void test_GdipGetVisibleClipBounds_window(void)
2291 {
2292 GpStatus status;
2293 GpGraphics *graphics = NULL;
2294 GpRectF rectf, window, exp, clipr;
2295 GpRect recti;
2296 HDC hdc;
2297 PAINTSTRUCT ps;
2298 RECT wnd_rect;
2299
2300 /* get client area size */
2301 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2302 window.X = wnd_rect.left;
2303 window.Y = wnd_rect.top;
2304 window.Width = wnd_rect.right - wnd_rect.left;
2305 window.Height = wnd_rect.bottom - wnd_rect.top;
2306
2307 hdc = BeginPaint(hwnd, &ps);
2308
2309 status = GdipCreateFromHDC(hdc, &graphics);
2310 expect(Ok, status);
2311 ok(graphics != NULL, "Expected graphics to be initialized\n");
2312
2313 status = GdipGetVisibleClipBounds(graphics, &rectf);
2314 expect(Ok, status);
2315 ok(rectf.X == window.X &&
2316 rectf.Y == window.Y &&
2317 rectf.Width == window.Width &&
2318 rectf.Height == window.Height,
2319 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2320 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2321 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2322 window.X, window.Y, window.Width, window.Height);
2323
2324 /* clipping rect entirely within window */
2325 exp.X = clipr.X = 20;
2326 exp.Y = clipr.Y = 8;
2327 exp.Width = clipr.Width = 30;
2328 exp.Height = clipr.Height = 20;
2329
2330 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2331 expect(Ok, status);
2332
2333 status = GdipGetVisibleClipBounds(graphics, &rectf);
2334 expect(Ok, status);
2335 ok(rectf.X == exp.X &&
2336 rectf.Y == exp.Y &&
2337 rectf.Width == exp.Width &&
2338 rectf.Height == exp.Height,
2339 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2340 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2341 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2342 exp.X, exp.Y, exp.Width, exp.Height);
2343
2344 /* clipping rect partially outside of window */
2345 clipr.X = window.Width - 10;
2346 clipr.Y = window.Height - 15;
2347 clipr.Width = 20;
2348 clipr.Height = 30;
2349
2350 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2351 expect(Ok, status);
2352
2353 exp.X = window.Width - 10;
2354 exp.Y = window.Height - 15;
2355 exp.Width = 10;
2356 exp.Height = 15;
2357
2358 status = GdipGetVisibleClipBounds(graphics, &rectf);
2359 expect(Ok, status);
2360 ok(rectf.X == exp.X &&
2361 rectf.Y == exp.Y &&
2362 rectf.Width == exp.Width &&
2363 rectf.Height == exp.Height,
2364 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2365 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2366 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2367 exp.X, exp.Y, exp.Width, exp.Height);
2368
2369 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2370 expect(Ok, status);
2371 ok(recti.X == exp.X &&
2372 recti.Y == exp.Y &&
2373 recti.Width == exp.Width &&
2374 recti.Height == exp.Height,
2375 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2376 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2377 recti.X, recti.Y, recti.Width, recti.Height,
2378 exp.X, exp.Y, exp.Width, exp.Height);
2379
2380 /* window bounds with transform applied */
2381 status = GdipResetClip(graphics);
2382 expect(Ok, status);
2383
2384 status = GdipScaleWorldTransform(graphics, 0.5, 0.5, MatrixOrderPrepend);
2385 expect(Ok, status);
2386
2387 exp.X = window.X * 2.0;
2388 exp.Y = window.Y * 2.0;
2389 exp.Width = window.Width * 2.0;
2390 exp.Height = window.Height * 2.0;
2391
2392 status = GdipGetVisibleClipBounds(graphics, &rectf);
2393 expect(Ok, status);
2394 ok(rectf.X == exp.X &&
2395 rectf.Y == exp.Y &&
2396 rectf.Width == exp.Width &&
2397 rectf.Height == exp.Height,
2398 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be "
2399 "twice the window size (%0.f, %0.f, %0.f, %0.f)\n",
2400 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2401 exp.X, exp.Y, exp.Width, exp.Height);
2402
2403 GdipDeleteGraphics(graphics);
2404 EndPaint(hwnd, &ps);
2405 }
2406
2407 static void test_GdipGetVisibleClipBounds(void)
2408 {
2409 GpGraphics* graphics = NULL;
2410 GpRectF rectf;
2411 GpRect rect;
2412 HDC hdc = GetDC( hwnd );
2413 GpStatus status;
2414
2415 status = GdipCreateFromHDC(hdc, &graphics);
2416 expect(Ok, status);
2417 ok(graphics != NULL, "Expected graphics to be initialized\n");
2418
2419 /* test null parameters */
2420 status = GdipGetVisibleClipBounds(graphics, NULL);
2421 expect(InvalidParameter, status);
2422
2423 status = GdipGetVisibleClipBounds(NULL, &rectf);
2424 expect(InvalidParameter, status);
2425
2426 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2427 expect(InvalidParameter, status);
2428
2429 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2430 expect(InvalidParameter, status);
2431
2432 GdipDeleteGraphics(graphics);
2433 ReleaseDC(hwnd, hdc);
2434
2435 test_GdipGetVisibleClipBounds_screen();
2436 test_GdipGetVisibleClipBounds_window();
2437 }
2438
2439 static void test_fromMemoryBitmap(void)
2440 {
2441 GpStatus status;
2442 GpGraphics *graphics = NULL;
2443 GpBitmap *bitmap = NULL;
2444 BYTE bits[48] = {0};
2445 HDC hdc=NULL;
2446 COLORREF color;
2447
2448 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2449 expect(Ok, status);
2450
2451 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2452 expect(Ok, status);
2453
2454 status = GdipGraphicsClear(graphics, 0xff686868);
2455 expect(Ok, status);
2456
2457 GdipDeleteGraphics(graphics);
2458
2459 /* drawing writes to the memory provided */
2460 expect(0x68, bits[10]);
2461
2462 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2463 expect(Ok, status);
2464
2465 status = GdipGetDC(graphics, &hdc);
2466 expect(Ok, status);
2467 ok(hdc != NULL, "got NULL hdc\n");
2468
2469 color = GetPixel(hdc, 0, 0);
2470 /* The HDC is write-only, and native fills with a solid color to figure out
2471 * which pixels have changed. */
2472 todo_wine expect(0x0c0b0d, color);
2473
2474 SetPixel(hdc, 0, 0, 0x797979);
2475 SetPixel(hdc, 1, 0, 0x0c0b0d);
2476
2477 status = GdipReleaseDC(graphics, hdc);
2478 expect(Ok, status);
2479
2480 GdipDeleteGraphics(graphics);
2481
2482 expect(0x79, bits[0]);
2483 todo_wine expect(0x68, bits[3]);
2484
2485 GdipDisposeImage((GpImage*)bitmap);
2486
2487 /* We get the same kind of write-only HDC for a "normal" bitmap */
2488 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2489 expect(Ok, status);
2490
2491 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2492 expect(Ok, status);
2493
2494 status = GdipGetDC(graphics, &hdc);
2495 expect(Ok, status);
2496 ok(hdc != NULL, "got NULL hdc\n");
2497
2498 color = GetPixel(hdc, 0, 0);
2499 todo_wine expect(0x0c0b0d, color);
2500
2501 status = GdipReleaseDC(graphics, hdc);
2502 expect(Ok, status);
2503
2504 GdipDeleteGraphics(graphics);
2505
2506 GdipDisposeImage((GpImage*)bitmap);
2507
2508 /* If we don't draw to the HDC, the bits are never accessed */
2509 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, (BYTE*)1, &bitmap);
2510 expect(Ok, status);
2511
2512 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2513 expect(Ok, status);
2514
2515 status = GdipGetDC(graphics, &hdc);
2516 expect(Ok, status);
2517 ok(hdc != NULL, "got NULL hdc\n");
2518
2519 color = GetPixel(hdc, 0, 0);
2520 todo_wine expect(0x0c0b0d, color);
2521
2522 status = GdipReleaseDC(graphics, hdc);
2523 expect(Ok, status);
2524
2525 GdipDeleteGraphics(graphics);
2526
2527 GdipDisposeImage((GpImage*)bitmap);
2528 }
2529
2530 static void test_GdipIsVisiblePoint(void)
2531 {
2532 GpStatus status;
2533 GpGraphics *graphics = NULL;
2534 HDC hdc = GetDC( hwnd );
2535 REAL x, y;
2536 BOOL val;
2537
2538 ok(hdc != NULL, "Expected HDC to be initialized\n");
2539
2540 status = GdipCreateFromHDC(hdc, &graphics);
2541 expect(Ok, status);
2542 ok(graphics != NULL, "Expected graphics to be initialized\n");
2543
2544 /* null parameters */
2545 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2546 expect(InvalidParameter, status);
2547
2548 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2549 expect(InvalidParameter, status);
2550
2551 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2552 expect(InvalidParameter, status);
2553
2554 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2555 expect(InvalidParameter, status);
2556
2557 x = 0;
2558 y = 0;
2559 status = GdipIsVisiblePoint(graphics, x, y, &val);
2560 expect(Ok, status);
2561 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2562
2563 x = -10;
2564 y = 0;
2565 status = GdipIsVisiblePoint(graphics, x, y, &val);
2566 expect(Ok, status);
2567 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2568
2569 x = 0;
2570 y = -5;
2571 status = GdipIsVisiblePoint(graphics, x, y, &val);
2572 expect(Ok, status);
2573 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2574
2575 x = 1;
2576 y = 1;
2577 status = GdipIsVisiblePoint(graphics, x, y, &val);
2578 expect(Ok, status);
2579 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2580
2581 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2582 expect(Ok, status);
2583
2584 x = 1;
2585 y = 1;
2586 status = GdipIsVisiblePoint(graphics, x, y, &val);
2587 expect(Ok, status);
2588 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2589
2590 x = 15.5;
2591 y = 40.5;
2592 status = GdipIsVisiblePoint(graphics, x, y, &val);
2593 expect(Ok, status);
2594 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2595
2596 /* translate into the center of the rect */
2597 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2598
2599 x = 0;
2600 y = 0;
2601 status = GdipIsVisiblePoint(graphics, x, y, &val);
2602 expect(Ok, status);
2603 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2604
2605 x = 25;
2606 y = 40;
2607 status = GdipIsVisiblePoint(graphics, x, y, &val);
2608 expect(Ok, status);
2609 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2610
2611 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2612
2613 /* corner cases */
2614 x = 9;
2615 y = 19;
2616 status = GdipIsVisiblePoint(graphics, x, y, &val);
2617 expect(Ok, status);
2618 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2619
2620 x = 9.25;
2621 y = 19.25;
2622 status = GdipIsVisiblePoint(graphics, x, y, &val);
2623 expect(Ok, status);
2624 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2625
2626 x = 9.5;
2627 y = 19.5;
2628 status = GdipIsVisiblePoint(graphics, x, y, &val);
2629 expect(Ok, status);
2630 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2631
2632 x = 9.75;
2633 y = 19.75;
2634 status = GdipIsVisiblePoint(graphics, x, y, &val);
2635 expect(Ok, status);
2636 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2637
2638 x = 10;
2639 y = 20;
2640 status = GdipIsVisiblePoint(graphics, x, y, &val);
2641 expect(Ok, status);
2642 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2643
2644 x = 40;
2645 y = 20;
2646 status = GdipIsVisiblePoint(graphics, x, y, &val);
2647 expect(Ok, status);
2648 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2649
2650 x = 39;
2651 y = 59;
2652 status = GdipIsVisiblePoint(graphics, x, y, &val);
2653 expect(Ok, status);
2654 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2655
2656 x = 39.25;
2657 y = 59.25;
2658 status = GdipIsVisiblePoint(graphics, x, y, &val);
2659 expect(Ok, status);
2660 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2661
2662 x = 39.5;
2663 y = 39.5;
2664 status = GdipIsVisiblePoint(graphics, x, y, &val);
2665 expect(Ok, status);
2666 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2667
2668 x = 39.75;
2669 y = 59.75;
2670 status = GdipIsVisiblePoint(graphics, x, y, &val);
2671 expect(Ok, status);
2672 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2673
2674 x = 40;
2675 y = 60;
2676 status = GdipIsVisiblePoint(graphics, x, y, &val);
2677 expect(Ok, status);
2678 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2679
2680 x = 40.15;
2681 y = 60.15;
2682 status = GdipIsVisiblePoint(graphics, x, y, &val);
2683 expect(Ok, status);
2684 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2685
2686 x = 10;
2687 y = 60;
2688 status = GdipIsVisiblePoint(graphics, x, y, &val);
2689 expect(Ok, status);
2690 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2691
2692 /* integer version */
2693 x = 25;
2694 y = 30;
2695 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2696 expect(Ok, status);
2697 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2698
2699 x = 50;
2700 y = 100;
2701 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2702 expect(Ok, status);
2703 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2704
2705 GdipDeleteGraphics(graphics);
2706 ReleaseDC(hwnd, hdc);
2707 }
2708
2709 static void test_GdipIsVisibleRect(void)
2710 {
2711 GpStatus status;
2712 GpGraphics *graphics = NULL;
2713 HDC hdc = GetDC( hwnd );
2714 REAL x, y, width, height;
2715 BOOL val;
2716
2717 ok(hdc != NULL, "Expected HDC to be initialized\n");
2718
2719 status = GdipCreateFromHDC(hdc, &graphics);
2720 expect(Ok, status);
2721 ok(graphics != NULL, "Expected graphics to be initialized\n");
2722
2723 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2724 expect(InvalidParameter, status);
2725
2726 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2727 expect(InvalidParameter, status);
2728
2729 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2730 expect(InvalidParameter, status);
2731
2732 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2733 expect(InvalidParameter, status);
2734
2735 /* entirely within the visible region */
2736 x = 0; width = 10;
2737 y = 0; height = 10;
2738 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2739 expect(Ok, status);
2740 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2741
2742 /* partially outside */
2743 x = -10; width = 20;
2744 y = -10; height = 20;
2745 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2746 expect(Ok, status);
2747 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2748
2749 /* entirely outside */
2750 x = -10; width = 5;
2751 y = -10; height = 5;
2752 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2753 expect(Ok, status);
2754 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2755
2756 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2757 expect(Ok, status);
2758
2759 /* entirely within the visible region */
2760 x = 12; width = 10;
2761 y = 22; height = 10;
2762 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2763 expect(Ok, status);
2764 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2765
2766 /* partially outside */
2767 x = 35; width = 10;
2768 y = 55; height = 10;
2769 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2770 expect(Ok, status);
2771 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2772
2773 /* entirely outside */
2774 x = 45; width = 5;
2775 y = 65; height = 5;
2776 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2777 expect(Ok, status);
2778 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2779
2780 /* translate into center of clipping rect */
2781 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2782
2783 x = 0; width = 10;
2784 y = 0; height = 10;
2785 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2786 expect(Ok, status);
2787 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2788
2789 x = 25; width = 5;
2790 y = 40; height = 5;
2791 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2792 expect(Ok, status);
2793 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2794
2795 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2796
2797 /* corners entirely outside, but some intersections */
2798 x = 0; width = 70;
2799 y = 0; height = 90;
2800 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2801 expect(Ok, status);
2802 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2803
2804 x = 0; width = 70;
2805 y = 0; height = 30;
2806 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2807 expect(Ok, status);
2808 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2809
2810 x = 0; width = 30;
2811 y = 0; height = 90;
2812 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2813 expect(Ok, status);
2814 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2815
2816 /* edge cases */
2817 x = 0; width = 10;
2818 y = 20; height = 40;
2819 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2820 expect(Ok, status);
2821 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2822
2823 x = 10; width = 30;
2824 y = 0; height = 20;
2825 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2826 expect(Ok, status);
2827 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2828
2829 x = 40; width = 10;
2830 y = 20; height = 40;
2831 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2832 expect(Ok, status);
2833 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2834
2835 x = 10; width = 30;
2836 y = 60; height = 10;
2837 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2838 expect(Ok, status);
2839 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2840
2841 /* rounding tests */
2842 x = 0.4; width = 10.4;
2843 y = 20; height = 40;
2844 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2845 expect(Ok, status);
2846 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2847
2848 x = 10; width = 30;
2849 y = 0.4; height = 20.4;
2850 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2851 expect(Ok, status);
2852 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2853
2854 /* integer version */
2855 x = 0; width = 30;
2856 y = 0; height = 90;
2857 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2858 expect(Ok, status);
2859 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2860
2861 x = 12; width = 10;
2862 y = 22; height = 10;
2863 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2864 expect(Ok, status);
2865 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2866
2867 GdipDeleteGraphics(graphics);
2868 ReleaseDC(hwnd, hdc);
2869 }
2870
2871 static void test_GdipGetNearestColor(void)
2872 {
2873 GpStatus status;
2874 GpGraphics *graphics;
2875 GpBitmap *bitmap;
2876 ARGB color = 0xdeadbeef;
2877 HDC hdc = GetDC( hwnd );
2878
2879 /* create a graphics object */
2880 ok(hdc != NULL, "Expected HDC to be initialized\n");
2881
2882 status = GdipCreateFromHDC(hdc, &graphics);
2883 expect(Ok, status);
2884 ok(graphics != NULL, "Expected graphics to be initialized\n");
2885
2886 status = GdipGetNearestColor(graphics, NULL);
2887 expect(InvalidParameter, status);
2888
2889 status = GdipGetNearestColor(NULL, &color);
2890 expect(InvalidParameter, status);
2891 GdipDeleteGraphics(graphics);
2892
2893 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2894 expect(Ok, status);
2895 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2896 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2897 if (status == Ok)
2898 {
2899 status = GdipGetNearestColor(graphics, &color);
2900 expect(Ok, status);
2901 expect(0xdeadbeef, color);
2902 GdipDeleteGraphics(graphics);
2903 }
2904 GdipDisposeImage((GpImage*)bitmap);
2905
2906 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2907 expect(Ok, status);
2908 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2909 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2910 if (status == Ok)
2911 {
2912 status = GdipGetNearestColor(graphics, &color);
2913 expect(Ok, status);
2914 expect(0xdeadbeef, color);
2915 GdipDeleteGraphics(graphics);
2916 }
2917 GdipDisposeImage((GpImage*)bitmap);
2918
2919 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2920 expect(Ok, status);
2921 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2922 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2923 if (status == Ok)
2924 {
2925 status = GdipGetNearestColor(graphics, &color);
2926 expect(Ok, status);
2927 expect(0xdeadbeef, color);
2928 GdipDeleteGraphics(graphics);
2929 }
2930 GdipDisposeImage((GpImage*)bitmap);
2931
2932 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2933 expect(Ok, status);
2934 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2935 todo_wine expect(OutOfMemory, status);
2936 if (status == Ok)
2937 GdipDeleteGraphics(graphics);
2938 GdipDisposeImage((GpImage*)bitmap);
2939
2940 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2941 expect(Ok, status);
2942 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2943 expect(Ok, status);
2944 status = GdipGetNearestColor(graphics, &color);
2945 expect(Ok, status);
2946 expect(0xdeadbeef, color);
2947 GdipDeleteGraphics(graphics);
2948 GdipDisposeImage((GpImage*)bitmap);
2949
2950 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2951 expect(Ok, status);
2952 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2953 expect(Ok, status);
2954 status = GdipGetNearestColor(graphics, &color);
2955 expect(Ok, status);
2956 expect(0xdeadbeef, color);
2957 GdipDeleteGraphics(graphics);
2958 GdipDisposeImage((GpImage*)bitmap);
2959
2960 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2961 expect(Ok, status);
2962 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2963 expect(Ok, status);
2964 status = GdipGetNearestColor(graphics, &color);
2965 expect(Ok, status);
2966 expect(0xdeadbeef, color);
2967 GdipDeleteGraphics(graphics);
2968 GdipDisposeImage((GpImage*)bitmap);
2969
2970 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2971 expect(Ok, status);
2972 if (status == Ok)
2973 {
2974 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2975 expect(Ok, status);
2976 status = GdipGetNearestColor(graphics, &color);
2977 expect(Ok, status);
2978 expect(0xdeadbeef, color);
2979 GdipDeleteGraphics(graphics);
2980 GdipDisposeImage((GpImage*)bitmap);
2981 }
2982
2983 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2984 expect(Ok, status);
2985 if (status == Ok)
2986 {
2987 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2988 expect(Ok, status);
2989 status = GdipGetNearestColor(graphics, &color);
2990 expect(Ok, status);
2991 expect(0xdeadbeef, color);
2992 GdipDeleteGraphics(graphics);
2993 GdipDisposeImage((GpImage*)bitmap);
2994 }
2995
2996 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2997 expect(Ok, status);
2998 if (status == Ok)
2999 {
3000 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3001 expect(Ok, status);
3002 status = GdipGetNearestColor(graphics, &color);
3003 expect(Ok, status);
3004 expect(0xdeadbeef, color);
3005 GdipDeleteGraphics(graphics);
3006 GdipDisposeImage((GpImage*)bitmap);
3007 }
3008
3009 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
3010 expect(Ok, status);
3011 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3012 expect(Ok, status);
3013 status = GdipGetNearestColor(graphics, &color);
3014 expect(Ok, status);
3015 todo_wine expect(0xffa8bce8, color);
3016 GdipDeleteGraphics(graphics);
3017 GdipDisposeImage((GpImage*)bitmap);
3018
3019 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
3020 expect(Ok, status);
3021 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3022 expect(Ok, status);
3023 status = GdipGetNearestColor(graphics, &color);
3024 expect(Ok, status);
3025 todo_wine
3026 ok(color == 0xffa8b8e8 ||
3027 broken(color == 0xffa0b8e0), /* Win98/WinMe */
3028 "Expected ffa8b8e8, got %.8x\n", color);
3029 GdipDeleteGraphics(graphics);
3030 GdipDisposeImage((GpImage*)bitmap);
3031
3032 ReleaseDC(hwnd, hdc);
3033 }
3034
3035 static void test_string_functions(void)
3036 {
3037 GpStatus status;
3038 GpGraphics *graphics;
3039 GpFontFamily *family;
3040 GpFont *font;
3041 RectF rc, char_bounds, bounds;
3042 GpBrush *brush;
3043 ARGB color = 0xff000000;
3044 HDC hdc = GetDC( hwnd );
3045 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
3046 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
3047 const WCHAR teststring2[] = {'j',0};
3048 REAL char_width, char_height;
3049 INT codepointsfitted, linesfilled;
3050 GpStringFormat *format;
3051 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
3052 GpRegion *regions[4];
3053 BOOL region_isempty[4];
3054 int i;
3055 PointF positions[8];
3056 GpMatrix *identity;
3057
3058 ok(hdc != NULL, "Expected HDC to be initialized\n");
3059 status = GdipCreateFromHDC(hdc, &graphics);
3060 expect(Ok, status);
3061 ok(graphics != NULL, "Expected graphics to be initialized\n");
3062
3063 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
3064 expect(Ok, status);
3065
3066 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
3067 expect(Ok, status);
3068
3069 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
3070 expect(Ok, status);
3071
3072 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3073 expect(Ok, status);
3074
3075 rc.X = 0;
3076 rc.Y = 0;
3077 rc.Width = 100.0;
3078 rc.Height = 100.0;
3079
3080 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
3081 expect(InvalidParameter, status);
3082
3083 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
3084 expect(InvalidParameter, status);
3085
3086 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
3087 expect(InvalidParameter, status);
3088
3089 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
3090 expect(InvalidParameter, status);
3091
3092 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
3093 expect(InvalidParameter, status);
3094
3095 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
3096 expect(Ok, status);
3097
3098 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3099 expect(InvalidParameter, status);
3100
3101 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3102 expect(InvalidParameter, status);
3103
3104 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3105 expect(InvalidParameter, status);
3106
3107 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3108 expect(InvalidParameter, status);
3109
3110 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3111 expect(InvalidParameter, status);
3112
3113 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3114 expect(Ok, status);
3115
3116 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3117 expect(Ok, status);
3118
3119 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3120 expect(Ok, status);
3121 expectf(0.0, char_bounds.X);
3122 expectf(0.0, char_bounds.Y);
3123 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3124 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3125 expect(1, codepointsfitted);
3126 expect(1, linesfilled);
3127
3128 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3129 expect(Ok, status);
3130 expectf(0.0, bounds.X);
3131 expectf(0.0, bounds.Y);
3132 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3133 expectf(char_bounds.Height, bounds.Height);
3134 expect(2, codepointsfitted);
3135 expect(1, linesfilled);
3136 char_width = bounds.Width - char_bounds.Width;
3137
3138 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3139 expect(Ok, status);
3140 expectf(0.0, bounds.X);
3141 expectf(0.0, bounds.Y);
3142 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3143 bounds.Width, char_bounds.Width + char_width * 2);
3144 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3145 expect(6, codepointsfitted);
3146 expect(2, linesfilled);
3147 char_height = bounds.Height - char_bounds.Height;
3148
3149 /* Measure the first line. */
3150 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3151 expect(Ok, status);
3152 expectf(0.0, bounds.X);
3153 expectf(0.0, bounds.Y);
3154 expect(4, codepointsfitted);
3155 expect(1, linesfilled);
3156
3157 /* Give just enough space to fit the first line. */
3158 rc.Width = bounds.Width;
3159 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3160 expect(Ok, status);
3161 expectf(0.0, bounds.X);
3162 expectf(0.0, bounds.Y);
3163 todo_wine expect(5, codepointsfitted);
3164 todo_wine expect(1, linesfilled);
3165
3166 /* Cut off everything after the first space. */
3167 rc.Width = char_bounds.Width + char_width * 2.1;
3168
3169 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3170 expect(Ok, status);
3171 expectf(0.0, bounds.X);
3172 expectf(0.0, bounds.Y);
3173 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3174 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3175 expect(6, codepointsfitted);
3176 expect(3, linesfilled);
3177
3178 /* Cut off everything including the first space. */
3179 rc.Width = char_bounds.Width + char_width * 1.7;
3180
3181 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3182 expect(Ok, status);
3183 expectf(0.0, bounds.X);
3184 expectf(0.0, bounds.Y);
3185 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3186 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3187 expect(6, codepointsfitted);
3188 expect(3, linesfilled);
3189
3190 /* Cut off everything after the first character. */
3191 rc.Width = char_bounds.Width + char_width * 0.8;
3192
3193 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3194 expect(Ok, status);
3195 expectf(0.0, bounds.X);
3196 expectf(0.0, bounds.Y);
3197 expectf_(char_bounds.Width, bounds.Width, 0.01);
3198 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3199 expect(6, codepointsfitted);
3200 todo_wine expect(4, linesfilled);
3201
3202 for (i = 0; i < 4; i++)
3203 regions[i] = (GpRegion *)0xdeadbeef;
3204
3205 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3206 expect(Ok, status);
3207
3208 for (i = 0; i < 4; i++)
3209 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3210
3211 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3212 expect(Ok, status);
3213
3214 for (i = 0; i < 4; i++)
3215 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3216
3217 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3218 expect(Ok, status);
3219
3220 set_rect_empty(&rc);
3221
3222 for (i=0; i<4; i++)
3223 {
3224 status = GdipCreateRegion(&regions[i]);
3225 expect(Ok, status);
3226 status = GdipSetEmpty(regions[i]);
3227 expect(Ok, status);
3228 }
3229
3230 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3231 expect(InvalidParameter, status);
3232
3233 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3234 expect(InvalidParameter, status);
3235
3236 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3237 expect(InvalidParameter, status);
3238
3239 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3240 expect(InvalidParameter, status);
3241
3242 if (0)
3243 {
3244 /* Crashes on Windows XP */
3245 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3246 expect(InvalidParameter, status);
3247 }
3248
3249 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3250 expect(InvalidParameter, status);
3251
3252 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3253 expect(InvalidParameter, status);
3254
3255 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3256 expect(Ok, status);
3257
3258 for (i = 0; i < 4; i++)
3259 {
3260 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3261 expect(Ok, status);
3262 }
3263
3264 ok(region_isempty[0], "region should be empty\n");
3265 ok(region_isempty[1], "region should be empty\n");
3266 ok(region_isempty[2], "region should be empty\n");
3267 ok(region_isempty[3], "region should be empty\n");
3268
3269 rc.Width = 100.0;
3270 rc.Height = 100.0;
3271
3272 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3273 expect(Ok, status);
3274
3275 for (i=0; i<4; i++)
3276 {
3277 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3278 expect(Ok, status);
3279 }
3280
3281 ok(!region_isempty[0], "region shouldn't be empty\n");
3282 ok(!region_isempty[1], "region shouldn't be empty\n");
3283 ok(!region_isempty[2], "region shouldn't be empty\n");
3284 ok(region_isempty[3], "region should be empty\n");
3285
3286 /* Cut off everything after the first space, and the second line. */
3287 rc.Width = char_bounds.Width + char_width * 2.1;
3288 rc.Height = char_bounds.Height + char_height * 0.5;
3289
3290 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3291 expect(Ok, status);
3292
3293 for (i=0; i<4; i++)
3294 {
3295 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3296 expect(Ok, status);
3297 }
3298
3299 ok(!region_isempty[0], "region shouldn't be empty\n");
3300 ok(!region_isempty[1], "region shouldn't be empty\n");
3301 ok(region_isempty[2], "region should be empty\n");
3302 ok(region_isempty[3], "region should be empty\n");
3303
3304 for (i=0; i<4; i++)
3305 GdipDeleteRegion(regions[i]);
3306
3307 status = GdipCreateMatrix(&identity);
3308 expect(Ok, status);
3309
3310 rc.X = 0;
3311 rc.Y = 0;
3312 rc.Width = 0;
3313 rc.Height = 0;
3314 memset(positions, 0, sizeof(positions));
3315 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3316 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3317 identity, &rc);
3318 expect(InvalidParameter, status);
3319
3320 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3321 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3322 identity, &rc);
3323 expect(InvalidParameter, status);
3324
3325 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3326 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3327 identity, &rc);
3328 expect(InvalidParameter, status);
3329
3330 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3331 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3332 identity, &rc);
3333 expect(InvalidParameter, status);
3334
3335 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3336 0x100, identity, &rc);
3337 expect(Ok, status);
3338
3339 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3340 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3341 NULL, &rc);
3342 expect(Ok, status);
3343
3344 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3345 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3346 identity, NULL);
3347 expect(InvalidParameter, status);
3348
3349 rc.X = 0;
3350 rc.Y = 0;
3351 rc.Width = 0;
3352 rc.Height = 0;
3353 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3354 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3355 identity, &rc);
3356 expect(Ok, status);
3357
3358 expectf(0.0, rc.X);
3359 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3360 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3361 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3362
3363 char_width = rc.Width;
3364 char_height = rc.Height;
3365
3366 rc.X = 0;
3367 rc.Y = 0;
3368 rc.Width = 0;
3369 rc.Height = 0;
3370 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3371 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3372 identity, &rc);
3373 expect(Ok, status);
3374
3375 expectf(0.0, rc.X);
3376 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3377 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3378 expectf(char_height, rc.Height);
3379
3380 rc.X = 0;
3381 rc.Y = 0;
3382 rc.Width = 0;
3383 rc.Height = 0;
3384 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3385 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3386 identity, &rc);
3387 expect(Ok, status);
3388
3389 expectf(rc.X, 0.0);
3390 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3391 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3392 expectf(rc.Height, char_height);
3393
3394 GdipDeleteMatrix(identity);
3395 GdipDeleteStringFormat(format);
3396 GdipDeleteBrush(brush);
3397 GdipDeleteFont(font);
3398 GdipDeleteFontFamily(family);
3399 GdipDeleteGraphics(graphics);
3400
3401 ReleaseDC(hwnd, hdc);
3402 }
3403
3404 static void test_get_set_interpolation(void)
3405 {
3406 GpGraphics *graphics;
3407 HDC hdc = GetDC( hwnd );
3408 GpStatus status;
3409 InterpolationMode mode;
3410
3411 ok(hdc != NULL, "Expected HDC to be initialized\n");
3412 status = GdipCreateFromHDC(hdc, &graphics);
3413 expect(Ok, status);
3414 ok(graphics != NULL, "Expected graphics to be initialized\n");
3415
3416 status = GdipGetInterpolationMode(NULL, &mode);
3417 expect(InvalidParameter, status);
3418
3419 if (0)
3420 {
3421 /* Crashes on Windows XP */
3422 status = GdipGetInterpolationMode(graphics, NULL);
3423 expect(InvalidParameter, status);
3424 }
3425
3426 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3427 expect(InvalidParameter, status);
3428
3429 /* out of range */
3430 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3431 expect(InvalidParameter, status);
3432
3433 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3434 expect(InvalidParameter, status);
3435
3436 status = GdipGetInterpolationMode(graphics, &mode);
3437 expect(Ok, status);
3438 expect(InterpolationModeBilinear, mode);
3439
3440 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3441 expect(Ok, status);
3442
3443 status = GdipGetInterpolationMode(graphics, &mode);
3444 expect(Ok, status);
3445 expect(InterpolationModeNearestNeighbor, mode);
3446
3447 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3448 expect(Ok, status);
3449
3450 status = GdipGetInterpolationMode(graphics, &mode);
3451 expect(Ok, status);
3452 expect(InterpolationModeBilinear, mode);
3453
3454 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3455 expect(Ok, status);
3456
3457 status = GdipGetInterpolationMode(graphics, &mode);
3458 expect(Ok, status);
3459 expect(InterpolationModeBilinear, mode);
3460
3461 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3462 expect(Ok, status);
3463
3464 status = GdipGetInterpolationMode(graphics, &mode);
3465 expect(Ok, status);
3466 expect(InterpolationModeHighQualityBicubic, mode);
3467
3468 GdipDeleteGraphics(graphics);
3469
3470 ReleaseDC(hwnd, hdc);
3471 }
3472
3473 static void test_get_set_textrenderinghint(void)
3474 {
3475 GpGraphics *graphics;
3476 HDC hdc = GetDC( hwnd );
3477 GpStatus status;
3478 TextRenderingHint hint;
3479
3480 ok(hdc != NULL, "Expected HDC to be initialized\n");
3481 status = GdipCreateFromHDC(hdc, &graphics);
3482 expect(Ok, status);
3483 ok(graphics != NULL, "Expected graphics to be initialized\n");
3484
3485 status = GdipGetTextRenderingHint(NULL, &hint);
3486 expect(InvalidParameter, status);
3487
3488 status = GdipGetTextRenderingHint(graphics, NULL);
3489 expect(InvalidParameter, status);
3490
3491 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3492 expect(InvalidParameter, status);
3493
3494 /* out of range */
3495 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3496 expect(InvalidParameter, status);
3497
3498 status = GdipGetTextRenderingHint(graphics, &hint);
3499 expect(Ok, status);
3500 expect(TextRenderingHintSystemDefault, hint);
3501
3502 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3503 expect(Ok, status);
3504
3505 status = GdipGetTextRenderingHint(graphics, &hint);
3506 expect(Ok, status);
3507 expect(TextRenderingHintSystemDefault, hint);
3508
3509 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3510 expect(Ok, status);
3511
3512 status = GdipGetTextRenderingHint(graphics, &hint);
3513 expect(Ok, status);
3514 expect(TextRenderingHintAntiAliasGridFit, hint);
3515
3516 GdipDeleteGraphics(graphics);
3517
3518 ReleaseDC(hwnd, hdc);
3519 }
3520
3521 static void test_getdc_scaled(void)
3522 {
3523 GpStatus status;
3524 GpGraphics *graphics = NULL;
3525 GpBitmap *bitmap = NULL;
3526 HDC hdc=NULL;
3527 HBRUSH hbrush, holdbrush;
3528 ARGB color;
3529
3530 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3531 expect(Ok, status);
3532
3533 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3534 expect(Ok, status);
3535
3536 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3537 expect(Ok, status);
3538
3539 status = GdipGetDC(graphics, &hdc);
3540 expect(Ok, status);
3541 ok(hdc != NULL, "got NULL hdc\n");
3542
3543 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3544
3545 holdbrush = SelectObject(hdc, hbrush);
3546
3547 Rectangle(hdc, 2, 2, 6, 6);
3548
3549 SelectObject(hdc, holdbrush);
3550
3551 DeleteObject(hbrush);
3552
3553 status = GdipReleaseDC(graphics, hdc);
3554 expect(Ok, status);
3555
3556 GdipDeleteGraphics(graphics);
3557
3558 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3559 expect(Ok, status);
3560 expect(0xffff0000, color);
3561
3562 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3563 expect(Ok, status);
3564 expect(0xff000000, color);
3565
3566 GdipDisposeImage((GpImage*)bitmap);
3567 }
3568
3569 static void test_GdipMeasureString(void)
3570 {
3571 static const struct test_data
3572 {
3573 REAL res_x, res_y, page_scale;
3574 GpUnit unit;
3575 } td[] =
3576 {
3577 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3578 { 200.0, 200.0, 2.0, UnitPixel },
3579 { 200.0, 200.0, 1.0, UnitDisplay },
3580 { 200.0, 200.0, 2.0, UnitDisplay },
3581 { 200.0, 200.0, 1.0, UnitInch },
3582 { 200.0, 200.0, 2.0, UnitInch },
3583 { 200.0, 600.0, 1.0, UnitPoint },
3584 { 200.0, 600.0, 2.0, UnitPoint },
3585 { 200.0, 600.0, 1.0, UnitDocument },
3586 { 200.0, 600.0, 2.0, UnitDocument },
3587 { 200.0, 600.0, 1.0, UnitMillimeter },
3588 { 200.0, 600.0, 2.0, UnitMillimeter },
3589 { 200.0, 600.0, 1.0, UnitDisplay },
3590 { 200.0, 600.0, 2.0, UnitDisplay },
3591 { 200.0, 600.0, 1.0, UnitPixel },
3592 { 200.0, 600.0, 2.0, UnitPixel },
3593 };
3594 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3595 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3596 GpStatus status;
3597 GpGraphics *graphics;
3598 GpFontFamily *family;
3599 GpFont *font;
3600 GpStringFormat *format;
3601 RectF bounds, rc;
3602 REAL base_cx = 0, base_cy = 0, height;
3603 INT chars, lines;
3604 LOGFONTW lf;
3605 UINT i;
3606 REAL font_size;
3607 GpUnit font_unit, unit;
3608
3609 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3610 expect(Ok, status);
3611 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3612 expect(Ok, status);
3613
3614 /* font size in pixels */
3615 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3616 expect(Ok, status);
3617 status = GdipGetFontSize(font, &font_size);
3618 expect(Ok, status);
3619 expectf(100.0, font_size);
3620 status = GdipGetFontUnit(font, &font_unit);
3621 expect(Ok, status);
3622 expect(UnitPixel, font_unit);
3623
3624 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3625 {
3626 GpImage *image;
3627
3628 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3629
3630 lf.lfHeight = 0xdeadbeef;
3631 status = GdipGetLogFontW(font, graphics, &lf);
3632 expect(Ok, status);
3633 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3634 if (td[i].unit != UnitDisplay)
3635 height *= td[i].page_scale;
3636 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3637 i, (LONG)(height + 0.5), height, lf.lfHeight);
3638
3639 height = font_size + 2.0 * font_size / 6.0;
3640
3641 set_rect_empty(&rc);
3642 set_rect_empty(&bounds);
3643 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3644 expect(Ok, status);
3645
3646 if (i == 0)
3647 {
3648 base_cx = bounds.Width;
3649 base_cy = bounds.Height;
3650 }
3651
3652 expectf(0.0, bounds.X);
3653 expectf(0.0, bounds.Y);
3654 todo_wine
3655 expectf_(height, bounds.Height, height / 100.0);
3656 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3657 expect(7, chars);
3658 expect(1, lines);
3659
3660 /* make sure it really fits */
3661 bounds.Width += 1.0;
3662 bounds.Height += 1.0;
3663 rc = bounds;
3664 rc.X = 50.0;
3665 rc.Y = 50.0;
3666 set_rect_empty(&bounds);
3667 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3668 expect(Ok, status);
3669 expectf(50.0, bounds.X);
3670 expectf(50.0, bounds.Y);
3671 todo_wine
3672 expectf_(height, bounds.Height, height / 100.0);
3673 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3674 expect(7, chars);
3675 expect(1, lines);
3676
3677 status = GdipDeleteGraphics(graphics);
3678 expect(Ok, status);
3679
3680 status = GdipDisposeImage(image);
3681 expect(Ok, status);
3682 }
3683
3684 GdipDeleteFont(font);
3685
3686 /* font size in logical units */
3687 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3688 for (unit = 3; unit <= 6; unit++)
3689 {
3690 /* create a font which final height is 100.0 pixels with 200 dpi device */
3691 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3692 height = pixels_to_units(75.0, unit, 200.0);
3693 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3694 expect(Ok, status);
3695 status = GdipGetFontSize(font, &font_size);
3696 expect(Ok, status);
3697 expectf(height, font_size);
3698 status = GdipGetFontUnit(font, &font_unit);
3699 expect(Ok, status);
3700 expect(unit, font_unit);
3701
3702 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3703 {
3704 REAL unit_scale;
3705 GpImage *image;
3706
3707 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3708
3709 lf.lfHeight = 0xdeadbeef;
3710 status = GdipGetLogFontW(font, graphics, &lf);
3711 expect(Ok, status);
3712 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3713 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3714 else
3715 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3716 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3717 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3718 i, (LONG)(height + 0.5), height, lf.lfHeight);
3719
3720 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3721 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3722 else
3723 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3724 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3725 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3726 if (td[i].unit != UnitDisplay)
3727 height /= td[i].page_scale;
3728 /*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);*/
3729
3730 set_rect_empty(&rc);
3731 set_rect_empty(&bounds);
3732 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3733 expect(Ok, status);
3734
3735 if (i == 0)
3736 {
3737 base_cx = bounds.Width;
3738 base_cy = bounds.Height;
3739 }
3740
3741 expectf(0.0, bounds.X);
3742 expectf(0.0, bounds.Y);
3743 todo_wine
3744 expectf_(height, bounds.Height, height / 85.0);
3745 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3746 expect(7, chars);
3747 expect(1, lines);
3748
3749 /* make sure it really fits */
3750 bounds.Width += 1.0;
3751 bounds.Height += 1.0;
3752 rc = bounds;
3753 rc.X = 50.0;
3754 rc.Y = 50.0;
3755 set_rect_empty(&bounds);
3756 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3757 expect(Ok, status);
3758 expectf(50.0, bounds.X);
3759 expectf(50.0, bounds.Y);
3760 todo_wine
3761 expectf_(height, bounds.Height, height / 85.0);
3762 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3763 expect(7, chars);
3764 expect(1, lines);
3765
3766 /* verify the result */
3767 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3768 if (td[i].unit != UnitDisplay)
3769 height *= td[i].page_scale;
3770 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3771 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3772 todo_wine
3773 expectf_(100.0, height, 1.1);
3774
3775 status = GdipDeleteGraphics(graphics);
3776 expect(Ok, status);
3777
3778 status = GdipDisposeImage(image);
3779 expect(Ok, status);
3780 }
3781
3782 GdipDeleteFont(font);
3783 }
3784
3785 /* Font with units = UnitWorld */
3786 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3787 {
3788 GpPointF pt = {0.0, 100.0};
3789 GpImage* image;
3790 REAL expected_width, expected_height;
3791
3792 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3793
3794 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3795 expect(Ok, status);
3796
3797 status = GdipCreateFont(family, pt.Y, FontStyleRegular, UnitWorld, &font);
3798 expect(Ok, status);
3799
3800 status = GdipGetFontUnit(font, &font_unit);
3801 expect(Ok, status);
3802 expect(UnitWorld, font_unit);
3803
3804 lf.lfHeight = 0xdeadbeef;
3805 status = GdipGetLogFontW(font, graphics, &lf);
3806 expect(Ok, status);
3807 ok(lf.lfHeight == -100, "%u: expected -100, got %d\n", i, lf.lfHeight);
3808
3809 set_rect_empty(&rc);
3810 set_rect_empty(&bounds);
3811 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3812 expect(Ok, status);
3813
3814 if (i == 0)
3815 {
3816 base_cx = bounds.Width;
3817 base_cy = bounds.Height;
3818 }
3819
3820 pt.X = 1.0;
3821 pt.Y = 1.0;
3822
3823 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3824 expect(Ok, status);
3825
3826 /* height is constant in device space, width is proportional to height in world space */
3827 expected_width = base_cx * pt.Y;
3828 expected_height = base_cy * pt.Y;
3829
3830 todo_wine_if(td[i].unit != UnitDisplay && td[i].unit != UnitPixel)
3831 ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width);
3832 ok(fabs(expected_height - bounds.Height) <= 0.001, "%u: expected %f, got %f\n", i, expected_height, bounds.Height);
3833
3834 GdipDeleteGraphics(graphics);
3835 GdipDisposeImage(image);
3836 GdipDeleteFont(font);
3837 }
3838
3839 GdipDeleteFontFamily(family);
3840 GdipDeleteStringFormat(format);
3841 }
3842
3843 static void test_transform(void)
3844 {
3845 static const struct test_data
3846 {
3847 REAL res_x, res_y, scale;
3848 GpUnit unit;
3849 GpPointF in[2], out[2];
3850 } td[] =
3851 {
3852 { 96.0, 96.0, 1.0, UnitPixel,
3853 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3854 { 96.0, 96.0, 1.0, UnitDisplay,
3855 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3856 { 96.0, 96.0, 1.0, UnitInch,
3857 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
3858 { 123.0, 456.0, 1.0, UnitPoint,
3859 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
3860 { 123.0, 456.0, 1.0, UnitDocument,
3861 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
3862 { 123.0, 456.0, 2.0, UnitMillimeter,
3863 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
3864 { 196.0, 296.0, 1.0, UnitDisplay,
3865 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3866 { 196.0, 296.0, 1.0, UnitPixel,
3867 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3868 };
3869 GpStatus status;
3870 GpGraphics *graphics;
3871 GpImage *image;
3872 GpPointF ptf[2];
3873 UINT i;
3874
3875 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3876 {
3877 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
3878 ptf[0].X = td[i].in[0].X;
3879 ptf[0].Y = td[i].in[0].Y;
3880 ptf[1].X = td[i].in[1].X;
3881 ptf[1].Y = td[i].in[1].Y;
3882 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
3883 expect(Ok, status);
3884 expectf(td[i].out[0].X, ptf[0].X);
3885 expectf(td[i].out[0].Y, ptf[0].Y);
3886 expectf(td[i].out[1].X, ptf[1].X);
3887 expectf(td[i].out[1].Y, ptf[1].Y);
3888 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
3889 expect(Ok, status);
3890 expectf(td[i].in[0].X, ptf[0].X);
3891 expectf(td[i].in[0].Y, ptf[0].Y);
3892 expectf(td[i].in[1].X, ptf[1].X);
3893 expectf(td[i].in[1].Y, ptf[1].Y);
3894 status = GdipDeleteGraphics(graphics);
3895 expect(Ok, status);
3896 status = GdipDisposeImage(image);
3897 expect(Ok, status);
3898 }
3899 }
3900
3901 static void test_pen_thickness(void)
3902 {
3903 static const struct test_data
3904 {
3905 REAL res_x, res_y, scale;
3906 GpUnit pen_unit, page_unit;
3907 REAL pen_width;
3908 INT cx, cy, path_cx, path_cy;
3909 } td[] =
3910 {
3911 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 1.0, 1, 1, 1, 1 },
3912 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 0.0, 0, 0, 1, 1 },
3913 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 0.1, 1, 1, 1, 1 },
3914 { 10.0, 10.0, 3.0, UnitPixel, UnitPixel, 2.0, 2, 2, 2, 2 },
3915 { 10.0, 10.0, 30.0, UnitPixel, UnitInch, 1.0, 1, 1, 1, 1 },
3916 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 1.0, 1, 1, 1, 1 },
3917 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 0.0, 1, 1, 1, 1 },
3918 { 10.0, 10.0, 3.0, UnitWorld, UnitPixel, 2.0, 6, 6, 6, 6 },
3919 { 10.0, 10.0, 2.0, UnitWorld, UnitInch, 1.0, 20, 20, 20, 20 },
3920 };
3921 GpStatus status;
3922 int i, j;
3923 GpGraphics *graphics;
3924 union
3925 {
3926 GpBitmap *bitmap;
3927 GpImage *image;
3928 } u;
3929 GpPen *pen;
3930 GpPointF corner;
3931 GpPath *path;
3932 BitmapData bd;
3933 INT min, max, size;
3934
3935 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3936 {
3937 status = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat24bppRGB, NULL, &u.bitmap);
3938 expect(Ok, status);
3939
3940 status = GdipBitmapSetResolution(u.bitmap, td[i].res_x, td[i].res_y);
3941 expect(Ok, status);
3942
3943 status = GdipGetImageGraphicsContext(u.image, &graphics);
3944 expect(Ok, status);
3945
3946 status = GdipSetPageUnit(graphics, td[i].page_unit);
3947 expect(Ok, status);
3948
3949 status = GdipSetPageScale(graphics, td[i].scale);
3950 expect(Ok, status);
3951
3952 status = GdipCreatePen1(0xffffffff, td[i].pen_width, td[i].pen_unit, &pen);
3953 expect(Ok, status);
3954
3955 corner.X = corner.Y = 100.0;
3956 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &corner, 1);
3957 expect(Ok, status);
3958
3959 status = GdipDrawLine(graphics, pen, corner.X/2, 0, corner.X/2, corner.Y);
3960 expect(Ok, status);
3961
3962 status = GdipDrawLine(graphics, pen, 0, corner.Y/2, corner.X, corner.Y/2);
3963 expect(Ok, status);
3964
3965 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
3966 expect(Ok, status);
3967
3968 min = -1;
3969 max = -2;
3970
3971 for (j=0; j<100; j++)
3972 {
3973 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
3974 {
3975 min = j;
3976 break;
3977 }
3978 }
3979
3980 for (j=99; j>=0; j--)
3981 {
3982 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
3983 {
3984 max = j;
3985 break;
3986 }
3987 }
3988
3989 size = max-min+1;
3990
3991 ok(size == td[i].cx, "%u: expected %d, got %d\n", i, td[i].cx, size);
3992
3993 min = -1;
3994 max = -2;
3995
3996 for (j=0; j<100; j++)
3997 {
3998 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
3999 {
4000 min = j;
4001 break;
4002 }
4003 }
4004
4005 for (j=99; j>=0; j--)
4006 {
4007 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4008 {
4009 max = j;
4010 break;
4011 }
4012 }
4013
4014 size = max-min+1;
4015
4016 ok(size == td[i].cy, "%u: expected %d, got %d\n", i, td[i].cy, size);
4017
4018 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4019 expect(Ok, status);
4020
4021 status = GdipGraphicsClear(graphics, 0xff000000);
4022 expect(Ok, status);
4023
4024 status = GdipCreatePath(FillModeAlternate, &path);
4025 expect(Ok, status);
4026
4027 status = GdipAddPathLine(path, corner.X/2, 0, corner.X/2, corner.Y);
4028 expect(Ok, status);
4029
4030 status = GdipClosePathFigure(path);
4031 expect(Ok, status);
4032
4033 status = GdipAddPathLine(path, 0, corner.Y/2, corner.X, corner.Y/2);
4034 expect(Ok, status);
4035
4036 status = GdipDrawPath(graphics, pen, path);
4037 expect(Ok, status);
4038
4039 GdipDeletePath(path);
4040
4041 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
4042 expect(Ok, status);
4043
4044 min = -1;
4045 max = -2;
4046
4047 for (j=0; j<100; j++)
4048 {
4049 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4050 {
4051 min = j;
4052 break;
4053 }
4054 }
4055
4056 for (j=99; j>=0; j--)
4057 {
4058 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4059 {
4060 max = j;
4061 break;
4062 }
4063 }
4064
4065 size = max-min+1;
4066
4067 ok(size == td[i].path_cx, "%u: expected %d, got %d\n", i, td[i].path_cx, size);
4068
4069 min = -1;
4070 max = -2;
4071
4072 for (j=0; j<100; j++)
4073 {
4074 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4075 {
4076 min = j;
4077 break;
4078 }
4079 }
4080
4081 for (j=99; j>=0; j--)
4082 {
4083 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4084 {
4085 max = j;
4086 break;
4087 }
4088 }
4089
4090 size = max-min+1;
4091
4092 ok(size == td[i].path_cy, "%u: expected %d, got %d\n", i, td[i].path_cy, size);
4093
4094 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4095 expect(Ok, status);
4096
4097 GdipDeletePen(pen);
4098 GdipDeleteGraphics(graphics);
4099 GdipDisposeImage(u.image);
4100 }
4101 }
4102
4103 /* Many people on the net ask why there is so much difference in rendered
4104 * text height between gdiplus and gdi32, this test suggests an answer to
4105 * that question. Important: this test assumes that font dpi == device dpi.
4106 */
4107 static void test_font_height_scaling(void)
4108 {
4109 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4110 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
4111 HDC hdc;
4112 GpStringFormat *format;
4113 CharacterRange range = { 0, 7 };
4114 GpRegion *region;
4115 GpGraphics *graphics;
4116 GpFontFamily *family;
4117 GpFont *font;
4118 GpStatus status;
4119 RectF bounds, rect;
4120 REAL height, dpi, scale;
4121 PointF ptf;
4122 GpUnit gfx_unit, font_unit;
4123
4124 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4125 expect(Ok, status);
4126 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4127 expect(Ok, status);
4128 status = GdipCreateRegion(&region);
4129 expect(Ok, status);
4130
4131 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4132 expect(Ok, status);
4133
4134 hdc = CreateCompatibleDC(0);
4135 status = GdipCreateFromHDC(hdc, &graphics);
4136 expect(Ok, status);
4137
4138 status = GdipGetDpiY(graphics, &dpi);
4139 expect(Ok, status);
4140
4141 /* First check if tested functionality works:
4142 * under XP if font and graphics units differ then GdipTransformPoints
4143 * followed by GdipSetPageUnit to change the graphics units breaks region
4144 * scaling in GdipMeasureCharacterRanges called later.
4145 */
4146 status = GdipSetPageUnit(graphics, UnitDocument);
4147 expect(Ok, status);
4148
4149 ptf.X = 0.0;
4150 ptf.Y = 0.0;
4151 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4152 expect(Ok, status);
4153
4154 status = GdipSetPageUnit(graphics, UnitInch);
4155 expect(Ok, status);
4156
4157 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
4158 expect(Ok, status);
4159
4160 set_rect_empty(&rect);
4161 set_rect_empty(&bounds);
4162 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4163 expect(Ok, status);
4164 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
4165
4166 set_rect_empty(&rect);
4167 rect.Width = 32000.0;
4168 rect.Height = 32000.0;
4169 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4170 expect(Ok, status);
4171
4172 set_rect_empty(&rect);
4173 status = GdipGetRegionBounds(region, graphics, &rect);
4174 expect(Ok, status);
4175 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4176
4177 GdipDeleteFont(font);
4178
4179 scale = rect.Height / bounds.Height;
4180 if (fabs(scale - 1.0) > 0.1)
4181 {
4182 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
4183 goto cleanup;
4184 }
4185
4186 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
4187 expect(Ok, status);
4188
4189 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4190 /* UnitPixel as a font base unit is not tested because it drastically
4191 differs in behaviour */
4192 for (font_unit = 3; font_unit <= 6; font_unit++)
4193 {
4194 /* create a font for the final text height of 100 pixels */
4195 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
4196 status = GdipSetPageUnit(graphics, font_unit);
4197 expect(Ok, status);
4198 ptf.X = 0;
4199 ptf.Y = 75.0;
4200 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4201 expect(Ok, status);
4202 height = ptf.Y;
4203 /*trace("height %f units\n", height);*/
4204 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
4205 expect(Ok, status);
4206
4207 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4208 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4209 {
4210 static const WCHAR doubleW[2] = { 'W','W' };
4211 RectF bounds_1, bounds_2;
4212 REAL margin, margin_y, font_height;
4213 int match;
4214
4215 status = GdipSetPageUnit(graphics, gfx_unit);
4216 expect(Ok, status);
4217
4218 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
4219 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
4220
4221 status = GdipGetFontHeight(font, graphics, &font_height);
4222 expect(Ok, status);
4223
4224 set_rect_empty(&rect);
4225 set_rect_empty(&bounds);
4226 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4227 expect(Ok, status);
4228 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
4229 todo_wine
4230 expectf_(font_height + margin_y, bounds.Height, 0.005);
4231
4232 ptf.X = 0;
4233 ptf.Y = bounds.Height;
4234 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
4235 expect(Ok, status);
4236 match = fabs(100.0 - ptf.Y) <= 1.0;
4237 todo_wine
4238 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4239
4240 /* verify the result */
4241 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
4242 ptf.Y /= 100.0;
4243 match = fabs(100.0 - ptf.Y) <= 1.0;
4244 todo_wine
4245 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4246
4247 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4248 set_rect_empty(&rect);
4249 set_rect_empty(&bounds_1);
4250 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
4251 expect(Ok, status);
4252 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4253 set_rect_empty(&rect);
4254 set_rect_empty(&bounds_2);
4255 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
4256 expect(Ok, status);
4257
4258 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4259 margin = bounds_1.Width - bounds_2.Width / 2.0;
4260 /*trace("margin %f\n", margin);*/
4261 ok(margin > 0.0, "wrong margin %f\n", margin);
4262
4263 set_rect_empty(&rect);
4264 rect.Width = 320000.0;
4265 rect.Height = 320000.0;
4266 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4267 expect(Ok, status);
4268 set_rect_empty(&rect);
4269 status = GdipGetRegionBounds(region, graphics, &rect);
4270 expect(Ok, status);
4271 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
4272 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
4273 expectf(0.0, rect.Y);
4274 match = fabs(1.0 - margin / rect.X) <= 0.05;
4275 ok(match, "Expected %f, got %f\n", margin, rect.X);
4276 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
4277 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
4278 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
4279 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
4280 }
4281
4282 GdipDeleteFont(font);
4283 }
4284
4285 cleanup:
4286 status = GdipDeleteGraphics(graphics);
4287 expect(Ok, status);
4288 DeleteDC(hdc);
4289
4290 GdipDeleteFontFamily(family);
4291 GdipDeleteRegion(region);
4292 GdipDeleteStringFormat(format);
4293 }
4294
4295 static void test_measure_string(void)
4296 {
4297 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4298 static const WCHAR string[] = { 'A','0','1',0 };
4299 HDC hdc;
4300 GpStringFormat *format;
4301 CharacterRange range;
4302 GpRegion *region;
4303 GpGraphics *graphics;
4304 GpFontFamily *family;
4305 GpFont *font;
4306 GpStatus status;
4307 RectF bounds, rect;
4308 REAL width, height, width_1, width_2;
4309 REAL margin_x, margin_y, width_rgn, height_rgn;
4310 int lines, glyphs;
4311
4312 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4313 expect(Ok, status);
4314 expect(Ok, status);
4315
4316 status = GdipCreateRegion(&region);
4317 expect(Ok, status);
4318
4319 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4320 expect(Ok, status);
4321
4322 hdc = CreateCompatibleDC(0);
4323 status = GdipCreateFromHDC(hdc, &graphics);
4324
4325 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
4326 expect(Ok, status);
4327
4328 margin_x = 20.0 / 6.0;
4329 margin_y = 20.0 / 8.0;
4330
4331 set_rect_empty(&rect);
4332 set_rect_empty(&bounds);
4333 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4334 expect(Ok, status);
4335 expect(3, glyphs);
4336 expect(1, lines);
4337 expectf(0.0, bounds.X);
4338 expectf(0.0, bounds.Y);
4339 width = bounds.Width;
4340 height = bounds.Height;
4341
4342 set_rect_empty(&rect);
4343 rect.Height = height / 2.0;
4344 set_rect_empty(&bounds);
4345 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4346 expect(Ok, status);
4347 expect(3, glyphs);
4348 expect(1, lines);
4349 expectf(0.0, bounds.X);
4350 expectf(0.0, bounds.Y);
4351 expectf(width, bounds.Width);
4352 todo_wine
4353 expectf(height / 2.0, bounds.Height);
4354
4355 range.First = 0;
4356 range.Length = lstrlenW(string);
4357 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4358 expect(Ok, status);
4359
4360 rect.X = 5.0;
4361 rect.Y = 5.0;
4362 rect.Width = 32000.0;
4363 rect.Height = 32000.0;
4364 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4365 expect(Ok, status);
4366 set_rect_empty(&bounds);
4367 status = GdipGetRegionBounds(region, graphics, &bounds);
4368 expect(Ok, status);
4369 expectf_(5.0 + margin_x, bounds.X, 1.0);
4370 expectf(5.0, bounds.Y);
4371 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4372 todo_wine
4373 expectf_(height - margin_y, bounds.Height, 1.0);
4374
4375 width_rgn = bounds.Width;
4376 height_rgn = bounds.Height;
4377
4378 range.First = 0;
4379 range.Length = 1;
4380 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4381 expect(Ok, status);
4382
4383 set_rect_empty(&rect);
4384 rect.Width = 32000.0;
4385 rect.Height = 32000.0;
4386 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4387 expect(Ok, status);
4388 set_rect_empty(&bounds);
4389 status = GdipGetRegionBounds(region, graphics, &bounds);
4390 expect(Ok, status);
4391 expectf_(margin_x, bounds.X, 1.0);
4392 expectf(0.0, bounds.Y);
4393 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4394 expectf(height_rgn, bounds.Height);
4395 width_1 = bounds.Width;
4396
4397 range.First = 0;
4398 range.Length = lstrlenW(string);
4399 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4400 expect(Ok, status);
4401
4402 rect.X = 5.0;
4403 rect.Y = 5.0;
4404 rect.Width = 0.0;
4405 rect.Height = 0.0;
4406 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4407 expect(Ok, status);
4408 set_rect_empty(&bounds);
4409 status = GdipGetRegionBounds(region, graphics, &bounds);
4410 expect(Ok, status);
4411 expectf(0.0, bounds.X);
4412 expectf(0.0, bounds.Y);
4413 expectf(0.0, bounds.Width);
4414 expectf(0.0, bounds.Height);
4415
4416 rect.X = 5.0;
4417 rect.Y = 5.0;
4418 rect.Width = width_rgn / 2.0;
4419 rect.Height = 32000.0;
4420 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4421 expect(Ok, status);
4422 set_rect_empty(&bounds);
4423 status = GdipGetRegionBounds(region, graphics, &bounds);
4424 expect(Ok, status);
4425 expectf_(5.0 + margin_x, bounds.X, 1.0);
4426 expectf(5.0, bounds.Y);
4427 expectf_(width_1, bounds.Width, 1.0);
4428 todo_wine
4429 expectf_(height - margin_y, bounds.Height, 1.0);
4430
4431 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4432
4433 rect.X = 5.0;
4434 rect.Y = 5.0;
4435 rect.Width = 0.0;
4436 rect.Height = 0.0;
4437 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4438 expect(Ok, status);
4439 set_rect_empty(&bounds);
4440 status = GdipGetRegionBounds(region, graphics, &bounds);
4441 expect(Ok, status);
4442 expectf_(5.0 + margin_x, bounds.X, 1.0);
4443 expectf(5.0, bounds.Y);
4444 expectf(width_rgn, bounds.Width);
4445 expectf(height_rgn, bounds.Height);
4446
4447 rect.X = 5.0;
4448 rect.Y = 5.0;
4449 rect.Width = width_rgn / 2.0;
4450 rect.Height = 32000.0;
4451 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4452 expect(Ok, status);
4453 set_rect_empty(&bounds);
4454 status = GdipGetRegionBounds(region, graphics, &bounds);
4455 expect(Ok, status);
4456 expectf_(5.0 + margin_x, bounds.X, 1.0);
4457 expectf(5.0, bounds.Y);
4458 expectf_(width_1, bounds.Width, 1.0);
4459 expectf(height_rgn, bounds.Height);
4460
4461 set_rect_empty(&rect);
4462 rect.Height = height / 2.0;
4463 set_rect_empty(&bounds);
4464 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4465 expect(Ok, status);
4466 expect(3, glyphs);
4467 expect(1, lines);
4468 expectf(0.0, bounds.X);
4469 expectf(0.0, bounds.Y);
4470 expectf_(width, bounds.Width, 0.01);
4471 todo_wine
4472 expectf(height, bounds.Height);
4473
4474 set_rect_empty(&rect);
4475 set_rect_empty(&bounds);
4476 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4477 expect(Ok, status);
4478 expect(1, glyphs);
4479 expect(1, lines);
4480 expectf(0.0, bounds.X);
4481 expectf(0.0, bounds.Y);
4482 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4483 expectf(height, bounds.Height);
4484 width_1 = bounds.Width;
4485
4486 set_rect_empty(&rect);
4487 set_rect_empty(&bounds);
4488 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4489 expect(Ok, status);
4490 expect(2, glyphs);
4491 expect(1, lines);
4492 expectf(0.0, bounds.X);
4493 expectf(0.0, bounds.Y);
4494 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4495 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4496 expectf(height, bounds.Height);
4497 width_2 = bounds.Width;
4498
4499 set_rect_empty(&rect);
4500 rect.Width = width / 2.0;
4501 set_rect_empty(&bounds);
4502 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4503 expect(Ok, status);
4504 expect(1, glyphs);
4505 expect(1, lines);
4506 expectf(0.0, bounds.X);
4507 expectf(0.0, bounds.Y);
4508 expectf_(width_1, bounds.Width, 0.01);
4509 expectf(height, bounds.Height);
4510
4511 set_rect_empty(&rect);
4512 rect.Height = height;
4513 rect.Width = width - 0.05;
4514 set_rect_empty(&bounds);
4515 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4516 expect(Ok, status);
4517 expect(2, glyphs);
4518 expect(1, lines);
4519 expectf(0.0, bounds.X);
4520 expectf(0.0, bounds.Y);
4521 expectf_(width_2, bounds.Width, 0.01);
4522 expectf(height, bounds.Height);
4523
4524 set_rect_empty(&rect);
4525 rect.Height = height;
4526 rect.Width = width_2 - 0.05;
4527 set_rect_empty(&bounds);
4528 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4529 expect(Ok, status);
4530 expect(1, glyphs);
4531 expect(1, lines);
4532 expectf(0.0, bounds.X);
4533 expectf(0.0, bounds.Y);
4534 expectf_(width_1, bounds.Width, 0.01);
4535 expectf(height, bounds.Height);
4536
4537 /* Default (Near) alignment */
4538 rect.X = 5.0;
4539 rect.Y = 5.0;
4540 rect.Width = width * 2.0;
4541 rect.Height = height * 2.0;
4542 set_rect_empty(&bounds);
4543 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4544 expect(Ok, status);
4545 expect(3, glyphs);
4546 expect(1, lines);
4547 expectf(5.0, bounds.X);
4548 expectf(5.0, bounds.Y);
4549 expectf_(width, bounds.Width, 0.01);
4550 expectf(height, bounds.Height);
4551
4552 rect.X = 5.0;
4553 rect.Y = 5.0;
4554 rect.Width = 32000.0;
4555 rect.Height = 32000.0;
4556 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4557 expect(Ok, status);
4558 set_rect_empty(&bounds);
4559 status = GdipGetRegionBounds(region, graphics, &bounds);
4560 expect(Ok, status);
4561 expectf_(5.0 + margin_x, bounds.X, 1.0);
4562 expectf(5.0, bounds.Y);
4563 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4564 todo_wine
4565 expectf_(height - margin_y, bounds.Height, 1.0);
4566
4567 width_rgn = bounds.Width;
4568 height_rgn = bounds.Height;
4569
4570 /* Center alignment */
4571 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4572 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4573
4574 rect.X = 5.0;
4575 rect.Y = 5.0;
4576 rect.Width = width * 2.0;
4577 rect.Height = height * 2.0;
4578 set_rect_empty(&bounds);
4579 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4580 expect(Ok, status);
4581 expect(3, glyphs);
4582 expect(1, lines);
4583 todo_wine
4584 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4585 todo_wine
4586 expectf(5.0 + height/2.0, bounds.Y);
4587 expectf_(width, bounds.Width, 0.01);
4588 expectf(height, bounds.Height);
4589
4590 rect.X = 5.0;
4591 rect.Y = 5.0;
4592 rect.Width = 0.0;
4593 rect.Height = 0.0;
4594 set_rect_empty(&bounds);
4595 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4596 expect(Ok, status);
4597 expect(3, glyphs);
4598 expect(1, lines);
4599 todo_wine
4600 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4601 todo_wine
4602 expectf(5.0 - height/2.0, bounds.Y);
4603 expectf_(width, bounds.Width, 0.01);
4604 expectf(height, bounds.Height);
4605
4606 rect.X = 5.0;
4607 rect.Y = 5.0;
4608 rect.Width = width_rgn * 2.0;
4609 rect.Height = height_rgn * 2.0;
4610 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4611 expect(Ok, status);
4612 set_rect_empty(&bounds);
4613 status = GdipGetRegionBounds(region, graphics, &bounds);
4614 expect(Ok, status);
4615 todo_wine
4616 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4617 todo_wine
4618 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4619 expectf_(width_rgn, bounds.Width, 1.0);
4620 expectf_(height_rgn, bounds.Height, 1.0);
4621
4622 rect.X = 5.0;
4623 rect.Y = 5.0;
4624 rect.Width = 0.0;
4625 rect.Height = 0.0;
4626 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4627 expect(Ok, status);
4628 set_rect_empty(&bounds);
4629 status = GdipGetRegionBounds(region, graphics, &bounds);
4630 expect(Ok, status);
4631 todo_wine
4632 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4633 todo_wine
4634 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4635 expectf_(width_rgn, bounds.Width, 1.0);
4636 expectf_(height_rgn, bounds.Height, 1.0);
4637
4638 /* Far alignment */
4639 GdipSetStringFormatAlign(format, StringAlignmentFar);
4640 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4641
4642 rect.X = 5.0;
4643 rect.Y = 5.0;
4644 rect.Width = width * 2.0;
4645 rect.Height = height * 2.0;
4646 set_rect_empty(&bounds);
4647 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4648 expect(Ok, status);
4649 expect(3, glyphs);
4650 expect(1, lines);
4651 todo_wine
4652 expectf_(5.0 + width, bounds.X, 0.01);
4653 todo_wine
4654 expectf(5.0 + height, bounds.Y);
4655 expectf_(width, bounds.Width, 0.01);
4656 expectf(height, bounds.Height);
4657
4658 rect.X = 5.0;
4659 rect.Y = 5.0;
4660 rect.Width = 0.0;
4661 rect.Height = 0.0;
4662 set_rect_empty(&bounds);
4663 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4664 expect(Ok, status);
4665 expect(3, glyphs);
4666 expect(1, lines);
4667 todo_wine
4668 expectf_(5.0 - width, bounds.X, 0.01);
4669 todo_wine
4670 expectf(5.0 - height, bounds.Y);
4671 expectf_(width, bounds.Width, 0.01);
4672 expectf(height, bounds.Height);
4673
4674 rect.X = 5.0;
4675 rect.Y = 5.0;
4676 rect.Width = width_rgn * 2.0;
4677 rect.Height = height_rgn * 2.0;
4678 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4679 expect(Ok, status);
4680 set_rect_empty(&bounds);
4681 status = GdipGetRegionBounds(region, graphics, &bounds);
4682 expect(Ok, status);
4683 todo_wine
4684 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4685 todo_wine
4686 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4687 expectf_(width_rgn, bounds.Width, 1.0);
4688 expectf_(height_rgn, bounds.Height, 1.0);
4689
4690 rect.X = 5.0;
4691 rect.Y = 5.0;
4692 rect.Width = 0.0;
4693 rect.Height = 0.0;
4694 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4695 expect(Ok, status);
4696 set_rect_empty(&bounds);
4697 status = GdipGetRegionBounds(region, graphics, &bounds);
4698 expect(Ok, status);
4699 todo_wine
4700 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4701 todo_wine
4702 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4703 expectf_(width_rgn, bounds.Width, 1.0);
4704 expectf_(height_rgn, bounds.Height, 1.0);
4705
4706 status = GdipDeleteFont(font);
4707 expect(Ok, status);
4708
4709 status = GdipDeleteGraphics(graphics);
4710 expect(Ok, status);
4711 DeleteDC(hdc);
4712
4713 GdipDeleteFontFamily(family);
4714 GdipDeleteRegion(region);
4715 GdipDeleteStringFormat(format);
4716 }
4717
4718 static void test_measured_extra_space(void)
4719 {
4720 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4721 static const WCHAR string[2] = { 'W','W' };
4722 GpStringFormat *format;
4723 HDC hdc;
4724 GpGraphics *graphics;
4725 GpFontFamily *family;
4726 GpFont *font;
4727 GpStatus status;
4728 GpUnit gfx_unit, font_unit;
4729 RectF bounds_1, bounds_2, rect;
4730 REAL margin, font_size, dpi;
4731
4732 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4733 expect(Ok, status);
4734
4735 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4736 expect(Ok, status);
4737 hdc = CreateCompatibleDC(0);
4738 status = GdipCreateFromHDC(hdc, &graphics);
4739 expect(Ok, status);
4740
4741 status = GdipGetDpiX(graphics, &dpi);
4742 expect(Ok, status);
4743
4744 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4745 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4746 for (font_unit = 3; font_unit <= 6; font_unit++)
4747 {
4748 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4749 expect(Ok, status);
4750
4751 status = GdipGetFontSize(font, &font_size);
4752 expect(Ok, status);
4753 font_size = units_to_pixels(font_size, font_unit, dpi);
4754 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4755
4756 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4757 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4758 {
4759 status = GdipSetPageUnit(graphics, gfx_unit);
4760 expect(Ok, status);
4761
4762 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4763 set_rect_empty(&rect);
4764 set_rect_empty(&bounds_1);
4765 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4766 expect(Ok, status);
4767 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4768 set_rect_empty(&rect);
4769 set_rect_empty(&bounds_2);
4770 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4771 expect(Ok, status);
4772
4773 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4774 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4775 /*trace("margin %f pixels\n", margin);*/
4776 expectf_(font_size / 6.0, margin, font_size / 100.0);
4777 }
4778
4779 GdipDeleteFont(font);
4780 }
4781
4782 GdipDeleteGraphics(graphics);
4783 DeleteDC(hdc);
4784 GdipDeleteFontFamily(family);
4785 GdipDeleteStringFormat(format);
4786 }
4787
4788 static void test_alpha_hdc(void)
4789 {
4790 GpStatus status;
4791 HDC hdc, gp_hdc;
4792 HBITMAP hbm, old_hbm;
4793 GpGraphics *graphics;
4794 ULONG *bits;
4795 BITMAPINFO bmi;
4796 GpRectF bounds;
4797 COLORREF colorref;
4798
4799 hdc = CreateCompatibleDC(0);
4800 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4801 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4802 bmi.bmiHeader.biHeight = 5;
4803 bmi.bmiHeader.biWidth = 5;
4804 bmi.bmiHeader.biBitCount = 32;
4805 bmi.bmiHeader.biPlanes = 1;
4806 bmi.bmiHeader.biCompression = BI_RGB;
4807 bmi.bmiHeader.biClrUsed = 0;
4808
4809 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4810 ok(hbm != NULL, "CreateDIBSection failed\n");
4811
4812 old_hbm = SelectObject(hdc, hbm);
4813
4814 status = GdipCreateFromHDC(hdc, &graphics);
4815 expect(Ok, status);
4816
4817 status = GdipGetVisibleClipBounds(graphics, &bounds);
4818 expect(Ok, status);
4819 expectf(0.0, bounds.X);
4820 expectf(0.0, bounds.Y);
4821 expectf(5.0, bounds.Width);
4822 expectf(5.0, bounds.Height);
4823
4824 bits[0] = 0xdeadbeef;
4825
4826 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4827 expect(Ok, status);
4828
4829 expect(0xffaaaaaa, bits[0]);
4830
4831 bits[0] = 0xdeadbeef;
4832
4833 status = GdipGetDC(graphics, &gp_hdc);
4834 expect(Ok, status);
4835
4836 colorref = GetPixel(gp_hdc, 0, 4);
4837 expect(0xefbead, colorref);
4838
4839 SetPixel(gp_hdc, 0, 4, 0xffffff);
4840
4841 expect(0xffffff, bits[0]);
4842
4843 status = GdipReleaseDC(graphics, gp_hdc);
4844 expect(Ok, status);
4845
4846 SelectObject(hdc, old_hbm);
4847
4848 bits[0] = 0xdeadbeef;
4849
4850 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4851 expect(Ok, status);
4852
4853 todo_wine expect(0xffbbbbbb, bits[0]);
4854
4855 GdipDeleteGraphics(graphics);
4856
4857 DeleteObject(hbm);
4858 DeleteDC(hdc);
4859 }
4860
4861 static void test_bitmapfromgraphics(void)
4862 {
4863 GpStatus stat;
4864 GpGraphics *graphics = NULL;
4865 HDC hdc = GetDC( hwnd );
4866 GpBitmap *bitmap = NULL;
4867 PixelFormat format;
4868 REAL imageres, graphicsres;
4869 UINT width, height;
4870
4871 stat = GdipCreateFromHDC(hdc, &graphics);
4872 expect(Ok, stat);
4873
4874 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
4875 expect(InvalidParameter, stat);
4876
4877 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
4878 expect(InvalidParameter, stat);
4879
4880 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
4881 expect(Ok, stat);
4882
4883 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
4884 expect(Ok, stat);
4885 expect(PixelFormat32bppPARGB, format);
4886
4887 stat = GdipGetDpiX(graphics, &graphicsres);
4888 expect(Ok, stat);
4889
4890 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
4891 expect(Ok, stat);
4892 expectf(graphicsres, imageres);
4893
4894 stat = GdipGetDpiY(graphics, &graphicsres);
4895 expect(Ok, stat);
4896
4897 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
4898 expect(Ok, stat);
4899 expectf(graphicsres, imageres);
4900
4901 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
4902 expect(Ok, stat);
4903 expect(12, width);
4904
4905 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
4906 expect(Ok, stat);
4907 expect(13, height);
4908
4909 GdipDeleteGraphics(graphics);
4910 GdipDisposeImage((GpImage*)bitmap);
4911 }
4912
4913 static void test_clipping(void)
4914 {
4915 HDC hdc;
4916 GpStatus status;
4917 GpGraphics *graphics;
4918 GpRegion *region, *region100x100;
4919 GpMatrix *matrix;
4920 GpRectF rect;
4921 GpPointF ptf[4];
4922 GpUnit unit;
4923 HRGN hrgn;
4924 int ret;
4925 RECT rc;
4926
4927 hdc = CreateCompatibleDC(0);
4928 status = GdipCreateFromHDC(hdc, &graphics);
4929 expect(Ok, status);
4930
4931 status = GdipGetPageUnit(graphics, &unit);
4932 expect(Ok, status);
4933 expect(UnitDisplay, unit);
4934
4935 status = GdipCreateRegion(&region);
4936 expect(Ok, status);
4937 status = GdipSetEmpty(region);
4938 expect(Ok, status);
4939
4940 status = GdipCreateRegion(&region100x100);
4941 expect(Ok, status);
4942 status = GdipSetEmpty(region100x100);
4943 expect(Ok, status);
4944
4945 rect.X = rect.Y = 100.0;
4946 rect.Width = rect.Height = 100.0;
4947 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
4948 expect(Ok, status);
4949 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
4950 expect(Ok, status);
4951
4952 status = GdipGetClipBounds(graphics, &rect);
4953 expect(Ok, status);
4954 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4955 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4956
4957 status = GdipSetEmpty(region);
4958 expect(Ok, status);
4959 status = GdipGetClip(graphics, region);
4960 expect(Ok, status);
4961 status = GdipGetRegionBounds(region, graphics, &rect);
4962 expect(Ok, status);
4963 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4964 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4965
4966 ptf[0].X = 100.0;
4967 ptf[0].Y = 100.0;
4968 ptf[1].X = 200.0;
4969 ptf[1].Y = 200.0;
4970 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4971 expect(Ok, status);
4972 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4973 "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);
4974
4975 status = GdipCreateMatrix(&matrix);
4976 expect(Ok, status);
4977 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
4978 expect(Ok, status);
4979 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
4980 expect(Ok, status);
4981 status = GdipSetWorldTransform(graphics, matrix);
4982 expect(Ok, status);
4983
4984 status = GdipGetClipBounds(graphics, &rect);
4985 expect(Ok, status);
4986 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4987 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4988
4989 status = GdipSetEmpty(region);
4990 expect(Ok, status);
4991 status = GdipGetClip(graphics, region);
4992 expect(Ok, status);
4993 status = GdipGetRegionBounds(region, graphics, &rect);
4994 expect(Ok, status);
4995 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4996 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4997
4998 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4999 expect(Ok, status);
5000 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5001 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5002
5003 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5004 expect(Ok, status);
5005 ret = GetRgnBox(hrgn, &rc);
5006 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5007 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
5008 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
5009 DeleteObject(hrgn);
5010
5011 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5012 expect(Ok, status);
5013 ret = GetRgnBox(hrgn, &rc);
5014 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5015 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5016 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5017 DeleteObject(hrgn);
5018
5019 ptf[0].X = 100.0;
5020 ptf[0].Y = 100.0;
5021 ptf[1].X = 200.0;
5022 ptf[1].Y = 200.0;
5023 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5024 expect(Ok, status);
5025 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5026 "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);
5027
5028 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5029 expect(Ok, status);
5030 ret = GetRgnBox(hrgn, &rc);
5031 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5032 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5033 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5034 DeleteObject(hrgn);
5035
5036 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5037 expect(Ok, status);
5038 ret = GetRgnBox(hrgn, &rc);
5039 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5040 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5041 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5042 DeleteObject(hrgn);
5043
5044 ptf[0].X = 210.0;
5045 ptf[0].Y = 420.0;
5046 ptf[1].X = 410.0;
5047 ptf[1].Y = 820.0;
5048 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5049 expect(Ok, status);
5050 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5051 "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);
5052
5053 status = GdipSetPageScale(graphics, 2.0);
5054 expect(Ok, status);
5055
5056 status = GdipGetClipBounds(graphics, &rect);
5057 expect(Ok, status);
5058 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5059 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5060
5061 status = GdipSetEmpty(region);
5062 expect(Ok, status);
5063 status = GdipGetClip(graphics, region);
5064 expect(Ok, status);
5065 status = GdipGetRegionBounds(region, graphics, &rect);
5066 expect(Ok, status);
5067 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5068 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5069
5070 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5071 expect(Ok, status);
5072 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5073 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5074
5075 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5076 expect(Ok, status);
5077 ret = GetRgnBox(hrgn, &rc);
5078 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5079 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
5080 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
5081 DeleteObject(hrgn);
5082
5083 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5084 expect(Ok, status);
5085 ret = GetRgnBox(hrgn, &rc);
5086 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5087 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5088 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5089 DeleteObject(hrgn);
5090
5091 ptf[0].X = 100.0;
5092 ptf[0].Y = 100.0;
5093 ptf[1].X = 200.0;
5094 ptf[1].Y = 200.0;
5095 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5096 expect(Ok, status);
5097 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5098 "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);
5099
5100 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5101 expect(Ok, status);
5102 ret = GetRgnBox(hrgn, &rc);
5103 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5104 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5105 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5106 DeleteObject(hrgn);
5107
5108 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5109 expect(Ok, status);
5110 ret = GetRgnBox(hrgn, &rc);
5111 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5112 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5113 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5114 DeleteObject(hrgn);
5115
5116 ptf[0].X = 210.0;
5117 ptf[0].Y = 420.0;
5118 ptf[1].X = 410.0;
5119 ptf[1].Y = 820.0;
5120 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5121 expect(Ok, status);
5122 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5123 "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);
5124
5125 GdipSetPageUnit(graphics, UnitPoint);
5126 expect(Ok, status);
5127
5128 status = GdipGetClipBounds(graphics, &rect);
5129 expect(Ok, status);
5130 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5131 /* rounding under Wine is slightly different */
5132 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5133 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5134 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5135
5136 status = GdipSetEmpty(region);
5137 expect(Ok, status);
5138 status = GdipGetClip(graphics, region);
5139 expect(Ok, status);
5140 status = GdipGetRegionBounds(region, graphics, &rect);
5141 expect(Ok, status);
5142 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5143 /* rounding under Wine is slightly different */
5144 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5145 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5146 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5147
5148 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5149 expect(Ok, status);
5150 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5151 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5152
5153 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5154 expect(Ok, status);
5155 ret = GetRgnBox(hrgn, &rc);
5156 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5157 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
5158 /* rounding under Wine is slightly different */
5159 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
5160 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
5161 "expected 14,5-33,14, got %s\n", wine_dbgstr_rect(&rc));
5162 DeleteObject(hrgn);
5163
5164 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5165 expect(Ok, status);
5166 ret = GetRgnBox(hrgn, &rc);
5167 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5168 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5169 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
5170 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5171 DeleteObject(hrgn);
5172
5173 ptf[0].X = 100.0;
5174 ptf[0].Y = 100.0;
5175 ptf[1].X = 200.0;
5176 ptf[1].Y = 200.0;
5177 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5178 expect(Ok, status);
5179 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
5180 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
5181 "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);
5182
5183 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5184 expect(Ok, status);
5185 ret = GetRgnBox(hrgn, &rc);
5186 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5187 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5188 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5189 DeleteObject(hrgn);
5190
5191 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5192 expect(Ok, status);
5193 ret = GetRgnBox(hrgn, &rc);
5194 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5195 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
5196 /* rounding under Wine is slightly different */
5197 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
5198 "expected 560,1120-1094,2187, got %s\n", wine_dbgstr_rect(&rc));
5199 DeleteObject(hrgn);
5200
5201 ptf[0].X = 560.0;
5202 ptf[0].Y = 1120.0;
5203 ptf[1].X = 1094.0;
5204 ptf[1].Y = 2187.0;
5205 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5206 expect(Ok, status);
5207 if (fabs(ptf[0].X - 100.0) < 0.001)
5208 {
5209 expectf(100.0, ptf[0].X);
5210 expectf(100.0, ptf[0].Y);
5211 expectf(200.125, ptf[1].X);
5212 expectf(200.03125, ptf[1].Y);
5213 }
5214 else /* before Win7 */
5215 {
5216 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
5217 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
5218 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
5219 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
5220 }
5221
5222 status = GdipTransformRegion(region100x100, matrix);
5223 expect(Ok, status);
5224
5225 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5226 expect(Ok, status);
5227 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5228 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5229
5230 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5231 expect(Ok, status);
5232 ret = GetRgnBox(hrgn, &rc);
5233 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5234 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5235 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5236 DeleteObject(hrgn);
5237
5238 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5239 expect(Ok, status);
5240 ret = GetRgnBox(hrgn, &rc);
5241 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5242 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
5243 /* rounding under Wine is slightly different */
5244 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
5245 "expected 1147,4534-2214,8800, got %s\n", wine_dbgstr_rect(&rc));
5246 DeleteObject(hrgn);
5247
5248 ptf[0].X = 1147.0;
5249 ptf[0].Y = 4534.0;
5250 ptf[1].X = 2214.0;
5251 ptf[1].Y = 8800.0;
5252 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5253 expect(Ok, status);
5254 if (fabs(ptf[0].X - 210.0625) < 0.001)
5255 {
5256 expectf(210.0625, ptf[0].X);
5257 expectf(420.0625, ptf[0].Y);
5258 expectf(410.125, ptf[1].X);
5259 expectf(820.0, ptf[1].Y);
5260 }
5261 else /* before Win7 */
5262 {
5263 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
5264 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
5265 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
5266 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
5267 }
5268
5269 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
5270 expect(Ok, status);
5271 status = GdipSetWorldTransform(graphics, matrix);
5272 expect(Ok, status);
5273
5274 status = GdipGetClipBounds(graphics, &rect);
5275 expect(Ok, status);
5276 expectf_(20.612978, rect.X, 1.0);
5277 expectf_(-6.256012, rect.Y, 1.5);
5278 expectf_(25.612978, rect.Width, 1.0);
5279 expectf_(12.806489, rect.Height, 1.0);
5280
5281 status = GdipSetEmpty(region);
5282 expect(Ok, status);
5283 status = GdipGetClip(graphics, region);
5284 expect(Ok, status);
5285 status = GdipGetRegionBounds(region, graphics, &rect);
5286 expect(Ok, status);
5287 /* rounding under Wine is slightly different */
5288 expectf_(20.612978, rect.X, 1.0);
5289 expectf_(-6.256012, rect.Y, 1.5);
5290 expectf_(25.612978, rect.Width, 1.0);
5291 expectf_(12.806489, rect.Height, 1.0);
5292
5293 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5294 expect(Ok, status);
5295 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5296 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5297
5298 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5299 expect(Ok, status);
5300 ret = GetRgnBox(hrgn, &rc);
5301 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5302 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
5303 /* rounding under Wine is slightly different */
5304 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
5305 "expected (22,-6)-(46,7), got %s\n", wine_dbgstr_rect(&rc));
5306 DeleteObject(hrgn);
5307
5308 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5309 expect(Ok, status);
5310 ret = GetRgnBox(hrgn, &rc);
5311 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5312 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5313 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5314 DeleteObject(hrgn);
5315
5316 ptf[0].X = 100.0;
5317 ptf[0].Y = 100.0;
5318 ptf[1].X = 200.0;
5319 ptf[1].Y = 200.0;
5320 ptf[2].X = 200.0;
5321 ptf[2].Y = 100.0;
5322 ptf[3].X = 100.0;
5323 ptf[3].Y = 200.0;
5324 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5325 expect(Ok, status);
5326 expectf(20.612978, ptf[0].X);
5327 expectf(-1.568512, ptf[0].Y);
5328 expectf(46.225956, ptf[1].X);
5329 expectf(1.862977, ptf[1].Y);
5330 expectf(36.850956, ptf[2].X);
5331 expectf(-6.256012, ptf[2].Y);
5332 expectf(29.987980, ptf[3].X);
5333 expectf(6.550478, ptf[3].Y);
5334
5335 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5336 expect(Ok, status);
5337 ret = GetRgnBox(hrgn, &rc);
5338 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5339 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5340 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5341 DeleteObject(hrgn);
5342
5343 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5344 expect(Ok, status);
5345 ret = GetRgnBox(hrgn, &rc);
5346 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5347 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
5348 /* rounding under Wine is slightly different */
5349 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
5350 "expected (-3406,4500)-(-350,8728), got %s\n", wine_dbgstr_rect(&rc));
5351 DeleteObject(hrgn);
5352
5353 ptf[0].X = -3406.0;
5354 ptf[0].Y = 4500.0;
5355 ptf[1].X = -350.0;
5356 ptf[1].Y = 8728.0;
5357 ptf[2].X = -350.0;
5358 ptf[2].Y = 4500.0;
5359 ptf[3].X = -3406.0;
5360 ptf[3].Y = 8728.0;
5361 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5362 expect(Ok, status);
5363 expectf(-136.190491, ptf[0].X);
5364 expectf(520.010742, ptf[0].Y);
5365 expectf(756.417175, ptf[1].X);
5366 expectf(720.031616, ptf[1].Y);
5367 expectf(360.042114, ptf[2].X);
5368 expectf(376.760742, ptf[2].Y);
5369 expectf(260.184570, ptf[3].X);
5370 expectf(863.281616, ptf[3].Y);
5371
5372 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
5373 expect(Ok, status);
5374 status = GdipSetWorldTransform(graphics, matrix);
5375 expect(Ok, status);
5376
5377 status = GdipGetClipBounds(graphics, &rect);
5378 expect(Ok, status);
5379 expectf_(-28.100956, rect.X, 1.0);
5380 expectf_(7.806488, rect.Y, 1.5);
5381 expectf_(25.612978, rect.Width, 1.0);
5382 expectf_(12.806489, rect.Height, 1.0);
5383
5384 status = GdipSetEmpty(region);
5385 expect(Ok, status);
5386 status = GdipGetClip(graphics, region);
5387 expect(Ok, status);
5388 status = GdipGetRegionBounds(region, graphics, &rect);
5389 expect(Ok, status);
5390 /* rounding under Wine is slightly different */
5391 expectf_(-28.100956, rect.X, 1.0);
5392 expectf_(7.806488, rect.Y, 1.5);
5393 expectf_(25.612978, rect.Width, 1.0);
5394 expectf_(12.806489, rect.Height, 1.0);
5395
5396 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5397 expect(Ok, status);
5398 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5399 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5400
5401 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5402 expect(Ok, status);
5403 ret = GetRgnBox(hrgn, &rc);
5404 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5405 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5406 /* rounding under Wine is slightly different */
5407 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5408 "expected (-27,8)-(-2,21), got %s\n", wine_dbgstr_rect(&rc));
5409 DeleteObject(hrgn);
5410
5411 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5412 expect(Ok, status);
5413 ret = GetRgnBox(hrgn, &rc);
5414 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5415 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5416 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5417 DeleteObject(hrgn);
5418
5419 ptf[0].X = 100.0;
5420 ptf[0].Y = 100.0;
5421 ptf[1].X = 200.0;
5422 ptf[1].Y = 200.0;
5423 ptf[2].X = 200.0;
5424 ptf[2].Y = 100.0;
5425 ptf[3].X = 100.0;
5426 ptf[3].Y = 200.0;
5427 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5428 expect(Ok, status);
5429 expectf(-11.862979, ptf[0].X);
5430 expectf(7.806488, ptf[0].Y);
5431 expectf(-18.725958, ptf[1].X);
5432 expectf(20.612976, ptf[1].Y);
5433 expectf(-2.487981, ptf[2].X);
5434 expectf(15.925477, ptf[2].Y);
5435 expectf(-28.100956, ptf[3].X);
5436 expectf(12.493987, ptf[3].Y);
5437
5438 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5439 expect(Ok, status);
5440 ret = GetRgnBox(hrgn, &rc);
5441 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5442 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5443 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5444 DeleteObject(hrgn);
5445
5446 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5447 expect(Ok, status);
5448 ret = GetRgnBox(hrgn, &rc);
5449 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5450 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5451 /* rounding under Wine is slightly different */
5452 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5453 "expected (4500,351)-(8728,3407), got %s\n", wine_dbgstr_rect(&rc));
5454 DeleteObject(hrgn);
5455
5456 ptf[0].X = -3406.0;
5457 ptf[0].Y = 4500.0;
5458 ptf[1].X = -350.0;
5459 ptf[1].Y = 8728.0;
5460 ptf[2].X = -350.0;
5461 ptf[2].Y = 4500.0;
5462 ptf[3].X = -3406.0;
5463 ptf[3].Y = 8728.0;
5464 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5465 expect(Ok, status);
5466 expectf(-1055.021484, ptf[0].X);
5467 expectf(-70.595329, ptf[0].Y);
5468 expectf(-1455.063232, ptf[1].X);
5469 expectf(375.708435, ptf[1].Y);
5470 expectf(-768.521484, ptf[2].X);
5471 expectf(177.520981, ptf[2].Y);
5472 expectf(-1741.563110, ptf[3].X);
5473 expectf(127.592125, ptf[3].Y);
5474
5475 GdipDeleteMatrix(matrix);
5476 GdipDeleteRegion(region);
5477 GdipDeleteRegion(region100x100);
5478 GdipDeleteGraphics(graphics);
5479 DeleteDC(hdc);
5480 }
5481
5482 static void test_clipping_2(void)
5483 {
5484
5485 HDC hdc;
5486 GpStatus status;
5487 GpGraphics *graphics;
5488 GpRegion *region;
5489 GpMatrix *matrix;
5490 GpRectF rect;
5491 GpPointF ptf[4];
5492 GpUnit unit;
5493 HRGN hrgn;
5494 int ret;
5495 RECT rc;
5496
5497 hdc = CreateCompatibleDC(0);
5498 status = GdipCreateFromHDC(hdc, &graphics);
5499 expect(Ok, status);
5500
5501 status = GdipGetPageUnit(graphics, &unit);
5502 expect(Ok, status);
5503 expect(UnitDisplay, unit);
5504
5505 GdipSetPageUnit(graphics, UnitInch);
5506
5507 status = GdipCreateRegion(&region);
5508 expect(Ok, status);
5509 status = GdipSetEmpty(region);
5510 expect(Ok, status);
5511 rect.X = rect.Y = 100.0;
5512 rect.Width = rect.Height = 100.0;
5513 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5514 expect(Ok, status);
5515 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5516 expect(Ok, status);
5517
5518 status = GdipGetClip(graphics, region);
5519 expect(Ok, status);
5520 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5521 expect(Ok, status);
5522 ret = GetRgnBox(hrgn, &rc);
5523 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5524 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5525 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5526 DeleteObject(hrgn);
5527 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5528 expect(Ok, status);
5529 ret = GetRgnBox(hrgn, &rc);
5530 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5531 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5532 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5533 DeleteObject(hrgn);
5534
5535 ptf[0].X = 9600.0;
5536 ptf[0].Y = 9600.0;
5537 ptf[1].X = 19200.0;
5538 ptf[1].Y = 19200.0;
5539 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5540 expect(Ok, status);
5541 expectf(100.0, ptf[0].X);
5542 expectf(100.0, ptf[0].Y);
5543 expectf(200.0, ptf[1].X);
5544 expectf(200.0, ptf[1].X);
5545
5546 GdipSetPageUnit(graphics, UnitPoint);
5547
5548 status = GdipGetClip(graphics, region);
5549 expect(Ok, status);
5550 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5551 expect(Ok, status);
5552 ret = GetRgnBox(hrgn, &rc);
5553 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5554 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5555 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5556 "expected 7200,7200-14400,14400, got %s\n", wine_dbgstr_rect(&rc));
5557 DeleteObject(hrgn);
5558 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5559 expect(Ok, status);
5560 ret = GetRgnBox(hrgn, &rc);
5561 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5562 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5563 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5564 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5565 DeleteObject(hrgn);
5566
5567 ptf[0].X = 9600.0;
5568 ptf[0].Y = 9600.0;
5569 ptf[1].X = 19200.0;
5570 ptf[1].Y = 19200.0;
5571 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5572 expect(Ok, status);
5573 if (fabs(ptf[0].X - 7200.0) < 0.001)
5574 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5575 "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);
5576 else /* before Win7 */
5577 {
5578 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5579 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5580 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5581 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5582 }
5583
5584 GdipDeleteRegion(region);
5585
5586 GdipSetPageUnit(graphics, UnitPixel);
5587
5588 status = GdipCreateRegion(&region);
5589 expect(Ok, status);
5590 status = GdipSetEmpty(region);
5591 expect(Ok, status);
5592 rect.X = rect.Y = 100.0;
5593 rect.Width = rect.Height = 100.0;
5594 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5595 expect(Ok, status);
5596 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5597 expect(Ok, status);
5598
5599 status = GdipGetClip(graphics, region);
5600 expect(Ok, status);
5601 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5602 expect(Ok, status);
5603 ret = GetRgnBox(hrgn, &rc);
5604 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5605 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5606 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5607 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5608 DeleteObject(hrgn);
5609 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5610 expect(Ok, status);
5611 ret = GetRgnBox(hrgn, &rc);
5612 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5613 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5614 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5615 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5616 DeleteObject(hrgn);
5617
5618 ptf[0].X = 100.0;
5619 ptf[0].Y = 100.0;
5620 ptf[1].X = 200.0;
5621 ptf[1].Y = 200.0;
5622 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5623 expect(Ok, status);
5624 if (fabs(ptf[0].X - 100.0) < 0.001)
5625 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5626 "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);
5627 else /* before Win7 */
5628 {
5629 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5630 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5631 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5632 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5633 }
5634
5635 GdipSetPageUnit(graphics, UnitPoint);
5636
5637 status = GdipGetClip(graphics, region);
5638 expect(Ok, status);
5639 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5640 expect(Ok, status);
5641 ret = GetRgnBox(hrgn, &rc);
5642 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5643 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5644 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5645 "expected 75,75-150,150, got %s\n", wine_dbgstr_rect(&rc));
5646 DeleteObject(hrgn);
5647 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5648 expect(Ok, status);
5649 ret = GetRgnBox(hrgn, &rc);
5650 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5651 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5652 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5653 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5654 DeleteObject(hrgn);
5655
5656 ptf[0].X = 100.0;
5657 ptf[0].Y = 100.0;
5658 ptf[1].X = 200.0;
5659 ptf[1].Y = 200.0;
5660 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5661 expect(Ok, status);
5662 if (fabs(ptf[0].X - 75.0) < 0.001)
5663 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5664 "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);
5665 else /* before Win7 */
5666 {
5667 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5668 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5669 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5670 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5671 }
5672
5673 status = GdipCreateMatrix(&matrix);
5674 expect(Ok, status);
5675 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5676 expect(Ok, status);
5677 status = GdipSetWorldTransform(graphics, matrix);
5678 expect(Ok, status);
5679 GdipDeleteMatrix(matrix);
5680
5681 status = GdipGetClip(graphics, region);
5682 expect(Ok, status);
5683 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5684 expect(Ok, status);
5685 ret = GetRgnBox(hrgn, &rc);
5686 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5687 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5688 "expected 65,65-140,140, got %s\n", wine_dbgstr_rect(&rc));
5689 DeleteObject(hrgn);
5690 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5691 expect(Ok, status);
5692 ret = GetRgnBox(hrgn, &rc);
5693 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5694 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5695 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5696 DeleteObject(hrgn);
5697
5698 ptf[0].X = 100.0;
5699 ptf[0].Y = 100.0;
5700 ptf[1].X = 200.0;
5701 ptf[1].Y = 200.0;
5702 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5703 expect(Ok, status);
5704 expectf(65.0, ptf[0].X);
5705 expectf(65.0, ptf[0].Y);
5706 expectf(140.0, ptf[1].X);
5707 expectf(140.0, ptf[1].X);
5708
5709 status = GdipCreateMatrix(&matrix);
5710 expect(Ok, status);
5711 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5712 expect(Ok, status);
5713 status = GdipSetWorldTransform(graphics, matrix);
5714 expect(Ok, status);
5715 GdipDeleteMatrix(matrix);
5716
5717 status = GdipGetClip(graphics, region);
5718 expect(Ok, status);
5719 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5720 expect(Ok, status);
5721 ret = GetRgnBox(hrgn, &rc);
5722 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5723 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5724 "expected 300,150-600,300, got %s\n", wine_dbgstr_rect(&rc));
5725 DeleteObject(hrgn);
5726 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5727 expect(Ok, status);
5728 ret = GetRgnBox(hrgn, &rc);
5729 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5730 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5731 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5732 DeleteObject(hrgn);
5733
5734 ptf[0].X = 100.0;
5735 ptf[0].Y = 100.0;
5736 ptf[1].X = 200.0;
5737 ptf[1].Y = 200.0;
5738 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5739 expect(Ok, status);
5740 expectf(300.0, ptf[0].X);
5741 expectf(150.0, ptf[0].Y);
5742 expectf(600.0, ptf[1].X);
5743 expectf(300.0, ptf[1].Y);
5744
5745 status = GdipSetPageScale(graphics, 2.0);
5746 expect(Ok, status);
5747
5748 status = GdipGetClip(graphics, region);
5749 expect(Ok, status);
5750 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5751 expect(Ok, status);
5752 ret = GetRgnBox(hrgn, &rc);
5753 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5754 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5755 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5756 "expected 150,75-300,150, got %s\n", wine_dbgstr_rect(&rc));
5757 DeleteObject(hrgn);
5758 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5759 expect(Ok, status);
5760 ret = GetRgnBox(hrgn, &rc);
5761 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5762 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5763 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5764 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5765 DeleteObject(hrgn);
5766
5767 ptf[0].X = 100.0;
5768 ptf[0].Y = 100.0;
5769 ptf[1].X = 200.0;
5770 ptf[1].Y = 200.0;
5771 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5772 expect(Ok, status);
5773 if (fabs(ptf[0].X - 150.0) < 0.001)
5774 {
5775 expectf(150.0, ptf[0].X);
5776 expectf(75.0, ptf[0].Y);
5777 expectf(300.0, ptf[1].X);
5778 expectf(150.0, ptf[1].Y);
5779 }
5780 else /* before Win7 */
5781 {
5782 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5783 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5784 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5785 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5786 }
5787
5788 status = GdipCreateMatrix(&matrix);
5789 expect(Ok, status);
5790 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5791 expect(Ok, status);
5792 status = GdipSetWorldTransform(graphics, matrix);
5793 expect(Ok, status);
5794 GdipDeleteMatrix(matrix);
5795
5796 status = GdipGetClip(graphics, region);
5797 expect(Ok, status);
5798 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5799 expect(Ok, status);
5800 ret = GetRgnBox(hrgn, &rc);
5801 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5802 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5803 /* rounding under Wine is slightly different */
5804 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5805 "expected 54,-26-107,27, got %s\n", wine_dbgstr_rect(&rc));
5806 DeleteObject(hrgn);
5807 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5808 expect(Ok, status);
5809 ret = GetRgnBox(hrgn, &rc);
5810 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5811 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5812 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5813 DeleteObject(hrgn);
5814
5815 ptf[0].X = 100.0;
5816 ptf[0].Y = 100.0;
5817 ptf[1].X = 200.0;
5818 ptf[1].Y = 200.0;
5819 ptf[2].X = 200.0;
5820 ptf[2].Y = 100.0;
5821 ptf[3].X = 100.0;
5822 ptf[3].Y = 200.0;
5823 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5824 expect(Ok, status);
5825 expectf(53.033016, ptf[0].X);
5826 expectf(0.0, ptf[0].Y);
5827 expectf(106.066032, ptf[1].X);
5828 expectf(0.0, ptf[1].Y);
5829 expectf(79.549522, ptf[2].X);
5830 expectf(-26.516510, ptf[2].Y);
5831 expectf(79.549522, ptf[3].X);
5832 expectf(26.516508, ptf[3].Y);
5833
5834 status = GdipCreateMatrix(&matrix);
5835 expect(Ok, status);
5836 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5837 expect(Ok, status);
5838 status = GdipSetWorldTransform(graphics, matrix);
5839 expect(Ok, status);
5840 GdipDeleteMatrix(matrix);
5841
5842 status = GdipGetClip(graphics, region);
5843 expect(Ok, status);
5844 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5845 expect(Ok, status);
5846 ret = GetRgnBox(hrgn, &rc);
5847 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5848 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
5849 /* rounding under Wine is slightly different */
5850 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
5851 "expected -26,54-27,107, got %s\n", wine_dbgstr_rect(&rc));
5852 DeleteObject(hrgn);
5853 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5854 expect(Ok, status);
5855 ret = GetRgnBox(hrgn, &rc);
5856 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5857 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5858 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5859 DeleteObject(hrgn);
5860
5861 ptf[0].X = 100.0;
5862 ptf[0].Y = 100.0;
5863 ptf[1].X = 200.0;
5864 ptf[1].Y = 200.0;
5865 ptf[2].X = 200.0;
5866 ptf[2].Y = 100.0;
5867 ptf[3].X = 100.0;
5868 ptf[3].Y = 200.0;
5869 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5870 expect(Ok, status);
5871 expectf(0.0, ptf[0].X);
5872 expectf(53.033005, ptf[0].Y);
5873 expectf(0.0, ptf[1].X);
5874 expectf(106.066010, ptf[1].Y);
5875 expectf(26.516491, ptf[2].X);
5876 expectf(79.549507, ptf[2].Y);
5877 expectf(-26.516520, ptf[3].X);
5878 expectf(79.549500, ptf[3].Y);
5879
5880 GdipDeleteRegion(region);
5881 GdipDeleteGraphics(graphics);
5882 DeleteDC(hdc);
5883 }
5884
5885
5886 static void test_GdipFillRectangles(void)
5887 {
5888 GpStatus status;
5889 GpGraphics *graphics = NULL;
5890 GpBrush *brush = NULL;
5891 HDC hdc = GetDC( hwnd );
5892 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
5893
5894 ok(hdc != NULL, "Expected HDC to be initialized\n");
5895
5896 status = GdipCreateFromHDC(hdc, &graphics);
5897 expect(Ok, status);
5898 ok(graphics != NULL, "Expected graphics to be initialized\n");
5899
5900 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
5901 expect(Ok, status);
5902 ok(brush != NULL, "Expected brush to be initialized\n");
5903
5904 status = GdipFillRectangles(NULL, brush, rects, 2);
5905 expect(InvalidParameter, status);
5906
5907 status = GdipFillRectangles(graphics, NULL, rects, 2);
5908 expect(InvalidParameter, status);
5909
5910 status = GdipFillRectangles(graphics, brush, NULL, 2);
5911 expect(InvalidParameter, status);
5912
5913 status = GdipFillRectangles(graphics, brush, rects, 0);
5914 expect(InvalidParameter, status);
5915
5916 status = GdipFillRectangles(graphics, brush, rects, -1);
5917 expect(InvalidParameter, status);
5918
5919 status = GdipFillRectangles(graphics, brush, rects, 1);
5920 expect(Ok, status);
5921
5922 status = GdipFillRectangles(graphics, brush, rects, 2);
5923 expect(Ok, status);
5924
5925 GdipDeleteBrush(brush);
5926 GdipDeleteGraphics(graphics);
5927
5928 ReleaseDC(hwnd, hdc);
5929 }
5930
5931 static void test_GdipGetVisibleClipBounds_memoryDC(void)
5932 {
5933 HDC hdc,dc;
5934 HBITMAP bmp;
5935 HGDIOBJ old;
5936 RECT rect;
5937 POINT pt;
5938 int width = 0;
5939 int height = 0;
5940 GpGraphics* graphics = NULL;
5941 GpRect boundRect;
5942 GpStatus status;
5943
5944 ok(GetClientRect(hwnd, &rect), "GetClientRect should have succeeded\n");
5945 width = rect.right - rect.left;
5946 height = rect.bottom - rect.top;
5947
5948 dc = GetDC(hwnd);
5949 hdc = CreateCompatibleDC ( dc );
5950 bmp = CreateCompatibleBitmap ( dc, width, height );
5951 old = SelectObject (hdc, bmp);
5952
5953 /*change the window origin is the key test point*/
5954 SetWindowOrgEx (hdc, rect.left+10, rect.top+10, &pt);
5955
5956 status = GdipCreateFromHDC(hdc, &graphics);
5957 expect(Ok, status);
5958
5959 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
5960 expect(Ok, status);
5961
5962 ok(boundRect.X==rect.left+10 &&
5963 boundRect.Y==rect.top+10 &&
5964 boundRect.Width==width &&
5965 boundRect.Height==height, "Expected GdipGetVisibleClipBoundsI ok\n");
5966
5967 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
5968 expect(Ok, status);
5969
5970 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
5971 expect(Ok, status);
5972
5973 ok(boundRect.X==rect.left+10 &&
5974 boundRect.Y==rect.top+10 &&
5975 boundRect.Width==width-10 &&
5976 boundRect.Height==height-10, "Expected GdipGetVisibleClipBoundsI ok\n");
5977
5978 GdipDeleteGraphics(graphics);
5979
5980 SelectObject (hdc, old);
5981 DeleteObject (bmp);
5982 DeleteDC (hdc);
5983 ReleaseDC(hwnd, dc);
5984 }
5985
5986 static void test_container_rects(void)
5987 {
5988 GpStatus status;
5989 GpGraphics *graphics;
5990 HDC hdc = GetDC( hwnd );
5991 GpRectF dstrect, srcrect;
5992 GraphicsContainer state;
5993 static const GpPointF test_points[3] = {{0.0,0.0}, {1.0,0.0}, {0.0,1.0}};
5994 GpPointF points[3];
5995 REAL dpix, dpiy;
5996
5997 status = GdipCreateFromHDC(hdc, &graphics);
5998 expect(Ok, status);
5999
6000 dstrect.X = 0.0;
6001 dstrect.Y = 0.0;
6002 dstrect.Width = 1.0;
6003 dstrect.Height = 1.0;
6004 srcrect = dstrect;
6005
6006 status = GdipGetDpiX(graphics, &dpix);
6007 expect(Ok, status);
6008
6009 status = GdipGetDpiY(graphics, &dpiy);
6010 expect(Ok, status);
6011
6012 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitWorld, &state);
6013 expect(InvalidParameter, status);
6014
6015 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitDisplay, &state);
6016 expect(InvalidParameter, status);
6017
6018 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitMillimeter+1, &state);
6019 expect(InvalidParameter, status);
6020
6021 status = GdipBeginContainer(NULL, &dstrect, &srcrect, UnitPixel, &state);
6022 expect(InvalidParameter, status);
6023
6024 status = GdipBeginContainer(graphics, NULL, &srcrect, UnitPixel, &state);
6025 expect(InvalidParameter, status);
6026
6027 status = GdipBeginContainer(graphics, &dstrect, NULL, UnitPixel, &state);
6028 expect(InvalidParameter, status);
6029
6030 status = GdipBeginContainer(graphics, &dstrect, &srcrect, -1, &state);
6031 expect(InvalidParameter, status);
6032
6033 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, NULL);
6034 expect(InvalidParameter, status);
6035
6036 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6037 expect(Ok, status);
6038
6039 memcpy(points, test_points, sizeof(points));
6040 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6041 expect(Ok, status);
6042 expectf(0.0, points[0].X);
6043 expectf(0.0, points[0].Y);
6044 expectf(1.0, points[1].X);
6045 expectf(0.0, points[1].Y);
6046 expectf(0.0, points[2].X);
6047 expectf(1.0, points[2].Y);
6048
6049 status = GdipEndContainer(graphics, state);
6050 expect(Ok, status);
6051
6052 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6053 expect(Ok, status);
6054
6055 memcpy(points, test_points, sizeof(points));
6056 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6057 expect(Ok, status);
6058 expectf(0.0, points[0].X);
6059 expectf(0.0, points[0].Y);
6060 expectf(1.0/dpix, points[1].X);
6061 expectf(0.0, points[1].Y);
6062 expectf(0.0, points[2].X);
6063 expectf(1.0/dpiy, points[2].Y);
6064
6065 status = GdipEndContainer(graphics, state);
6066 expect(Ok, status);
6067
6068 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
6069 expect(Ok, status);
6070
6071 dstrect.X = 1.0;
6072 dstrect.Height = 3.0;
6073 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6074 expect(Ok, status);
6075
6076 memcpy(points, test_points, sizeof(points));
6077 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6078 expect(Ok, status);
6079 expectf(2.0, points[0].X);
6080 expectf(0.0, points[0].Y);
6081 expectf(4.0, points[1].X);
6082 expectf(0.0, points[1].Y);
6083 expectf(2.0, points[2].X);
6084 expectf(6.0, points[2].Y);
6085
6086 status = GdipEndContainer(graphics, state);
6087 expect(Ok, status);
6088
6089 memcpy(points, test_points, sizeof(points));
6090 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6091 expect(Ok, status);
6092 expectf(0.0, points[0].X);
6093 expectf(0.0, points[0].Y);
6094 expectf(2.0, points[1].X);
6095 expectf(0.0, points[1].Y);
6096 expectf(0.0, points[2].X);
6097 expectf(2.0, points[2].Y);
6098
6099 status = GdipResetWorldTransform(graphics);
6100 expect(Ok, status);
6101
6102 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6103 expect(Ok, status);
6104
6105 memcpy(points, test_points, sizeof(points));
6106 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6107 expect(Ok, status);
6108 expectf(1.0, points[0].X);
6109 expectf(0.0, points[0].Y);
6110 expectf((dpix+1.0)/dpix, points[1].X);
6111 expectf(0.0, points[1].Y);
6112 expectf(1.0, points[2].X);
6113 expectf(3.0/dpiy, points[2].Y);
6114
6115 status = GdipEndContainer(graphics, state);
6116 expect(Ok, status);
6117
6118 status = GdipSetPageUnit(graphics, UnitInch);
6119 expect(Ok, status);
6120
6121 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6122 expect(Ok, status);
6123
6124 memcpy(points, test_points, sizeof(points));
6125 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6126 expect(Ok, status);
6127 expectf(dpix, points[0].X);
6128 expectf(0.0, points[0].Y);
6129 expectf(dpix*2, points[1].X);
6130 expectf(0.0, points[1].Y);
6131 expectf(dpix, points[2].X);
6132 expectf(dpiy*3, points[2].Y);
6133
6134 status = GdipEndContainer(graphics, state);
6135 expect(Ok, status);
6136
6137 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6138 expect(Ok, status);
6139
6140 memcpy(points, test_points, sizeof(points));
6141 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6142 expect(Ok, status);
6143 expectf(dpix, points[0].X);
6144 expectf(0.0, points[0].Y);
6145 expectf(dpix+1.0, points[1].X);
6146 expectf(0.0, points[1].Y);
6147 expectf(dpix, points[2].X);
6148 expectf(3.0, points[2].Y);
6149
6150 status = GdipEndContainer(graphics, state);
6151 expect(Ok, status);
6152
6153 GdipDeleteGraphics(graphics);
6154
6155 ReleaseDC(hwnd, hdc);
6156 }
6157
6158 START_TEST(graphics)
6159 {
6160 struct GdiplusStartupInput gdiplusStartupInput;
6161 ULONG_PTR gdiplusToken;
6162 WNDCLASSA class;
6163
6164 memset( &class, 0, sizeof(class) );
6165 class.lpszClassName = "gdiplus_test";
6166 class.style = CS_HREDRAW | CS_VREDRAW;
6167 class.lpfnWndProc = DefWindowProcA;
6168 class.hInstance = GetModuleHandleA(0);
6169 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
6170 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6171 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
6172 RegisterClassA( &class );
6173 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6174 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
6175 ok(hwnd != NULL, "Expected window to be created\n");
6176
6177 gdiplusStartupInput.GdiplusVersion = 1;
6178 gdiplusStartupInput.DebugEventCallback = NULL;
6179 gdiplusStartupInput.SuppressBackgroundThread = 0;
6180 gdiplusStartupInput.SuppressExternalCodecs = 0;
6181
6182 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
6183
6184 test_clipping();
6185 test_clipping_2();
6186 test_measured_extra_space();
6187 test_measure_string();
6188 test_font_height_scaling();
6189 test_transform();
6190 test_pen_thickness();
6191 test_GdipMeasureString();
6192 test_constructor_destructor();
6193 test_save_restore();
6194 test_GdipFillClosedCurve2();
6195 test_GdipFillClosedCurve2I();
6196 test_GdipDrawBezierI();
6197 test_GdipDrawArc();
6198 test_GdipDrawArcI();
6199 test_GdipDrawCurve();
6200 test_GdipDrawCurveI();
6201 test_GdipDrawCurve2();
6202 test_GdipDrawCurve2I();
6203 test_GdipDrawCurve3();
6204 test_GdipDrawCurve3I();
6205 test_GdipDrawLineI();
6206 test_GdipDrawLinesI();
6207 test_GdipDrawImagePointsRect();
6208 test_GdipFillClosedCurve();
6209 test_GdipFillClosedCurveI();
6210 test_GdipDrawString();
6211 test_GdipGetNearestColor();
6212 test_GdipGetVisibleClipBounds();
6213 test_GdipIsVisiblePoint();
6214 test_GdipIsVisibleRect();
6215 test_Get_Release_DC();
6216 test_BeginContainer2();
6217 test_transformpoints();
6218 test_get_set_clip();
6219 test_isempty();
6220 test_clear();
6221 test_textcontrast();
6222 test_fromMemoryBitmap();
6223 test_string_functions();
6224 test_get_set_interpolation();
6225 test_get_set_textrenderinghint();
6226 test_getdc_scaled();
6227 test_alpha_hdc();
6228 test_bitmapfromgraphics();
6229 test_GdipFillRectangles();
6230 test_GdipGetVisibleClipBounds_memoryDC();
6231 test_container_rects();
6232
6233 GdiplusShutdown(gdiplusToken);
6234 DestroyWindow( hwnd );
6235 }