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