7d308d77fff01c35963a56b9dd0865a2b85ff4da
[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 /* window bounds with transform applied */
2323 status = GdipResetClip(graphics);
2324 expect(Ok, status);
2325
2326 status = GdipScaleWorldTransform(graphics, 0.5, 0.5, MatrixOrderPrepend);
2327 expect(Ok, status);
2328
2329 exp.X = window.X * 2.0;
2330 exp.Y = window.Y * 2.0;
2331 exp.Width = window.Width * 2.0;
2332 exp.Height = window.Height * 2.0;
2333
2334 status = GdipGetVisibleClipBounds(graphics, &rectf);
2335 expect(Ok, status);
2336 ok(rectf.X == exp.X &&
2337 rectf.Y == exp.Y &&
2338 rectf.Width == exp.Width &&
2339 rectf.Height == exp.Height,
2340 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be "
2341 "twice the window size (%0.f, %0.f, %0.f, %0.f)\n",
2342 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2343 exp.X, exp.Y, exp.Width, exp.Height);
2344
2345 GdipDeleteGraphics(graphics);
2346 EndPaint(hwnd, &ps);
2347 }
2348
2349 static void test_GdipGetVisibleClipBounds(void)
2350 {
2351 GpGraphics* graphics = NULL;
2352 GpRectF rectf;
2353 GpRect rect;
2354 HDC hdc = GetDC( hwnd );
2355 GpStatus status;
2356
2357 status = GdipCreateFromHDC(hdc, &graphics);
2358 expect(Ok, status);
2359 ok(graphics != NULL, "Expected graphics to be initialized\n");
2360
2361 /* test null parameters */
2362 status = GdipGetVisibleClipBounds(graphics, NULL);
2363 expect(InvalidParameter, status);
2364
2365 status = GdipGetVisibleClipBounds(NULL, &rectf);
2366 expect(InvalidParameter, status);
2367
2368 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2369 expect(InvalidParameter, status);
2370
2371 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2372 expect(InvalidParameter, status);
2373
2374 GdipDeleteGraphics(graphics);
2375 ReleaseDC(hwnd, hdc);
2376
2377 test_GdipGetVisibleClipBounds_screen();
2378 test_GdipGetVisibleClipBounds_window();
2379 }
2380
2381 static void test_fromMemoryBitmap(void)
2382 {
2383 GpStatus status;
2384 GpGraphics *graphics = NULL;
2385 GpBitmap *bitmap = NULL;
2386 BYTE bits[48] = {0};
2387 HDC hdc=NULL;
2388 COLORREF color;
2389
2390 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2391 expect(Ok, status);
2392
2393 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2394 expect(Ok, status);
2395
2396 status = GdipGraphicsClear(graphics, 0xff686868);
2397 expect(Ok, status);
2398
2399 GdipDeleteGraphics(graphics);
2400
2401 /* drawing writes to the memory provided */
2402 expect(0x68, bits[10]);
2403
2404 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2405 expect(Ok, status);
2406
2407 status = GdipGetDC(graphics, &hdc);
2408 expect(Ok, status);
2409 ok(hdc != NULL, "got NULL hdc\n");
2410
2411 color = GetPixel(hdc, 0, 0);
2412 /* The HDC is write-only, and native fills with a solid color to figure out
2413 * which pixels have changed. */
2414 todo_wine expect(0x0c0b0d, color);
2415
2416 SetPixel(hdc, 0, 0, 0x797979);
2417 SetPixel(hdc, 1, 0, 0x0c0b0d);
2418
2419 status = GdipReleaseDC(graphics, hdc);
2420 expect(Ok, status);
2421
2422 GdipDeleteGraphics(graphics);
2423
2424 expect(0x79, bits[0]);
2425 todo_wine expect(0x68, bits[3]);
2426
2427 GdipDisposeImage((GpImage*)bitmap);
2428
2429 /* We get the same kind of write-only HDC for a "normal" bitmap */
2430 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2431 expect(Ok, status);
2432
2433 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2434 expect(Ok, status);
2435
2436 status = GdipGetDC(graphics, &hdc);
2437 expect(Ok, status);
2438 ok(hdc != NULL, "got NULL hdc\n");
2439
2440 color = GetPixel(hdc, 0, 0);
2441 todo_wine expect(0x0c0b0d, color);
2442
2443 status = GdipReleaseDC(graphics, hdc);
2444 expect(Ok, status);
2445
2446 GdipDeleteGraphics(graphics);
2447
2448 GdipDisposeImage((GpImage*)bitmap);
2449
2450 /* If we don't draw to the HDC, the bits are never accessed */
2451 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, (BYTE*)1, &bitmap);
2452 expect(Ok, status);
2453
2454 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2455 expect(Ok, status);
2456
2457 status = GdipGetDC(graphics, &hdc);
2458 expect(Ok, status);
2459 ok(hdc != NULL, "got NULL hdc\n");
2460
2461 color = GetPixel(hdc, 0, 0);
2462 todo_wine expect(0x0c0b0d, color);
2463
2464 status = GdipReleaseDC(graphics, hdc);
2465 expect(Ok, status);
2466
2467 GdipDeleteGraphics(graphics);
2468
2469 GdipDisposeImage((GpImage*)bitmap);
2470 }
2471
2472 static void test_GdipIsVisiblePoint(void)
2473 {
2474 GpStatus status;
2475 GpGraphics *graphics = NULL;
2476 HDC hdc = GetDC( hwnd );
2477 REAL x, y;
2478 BOOL val;
2479
2480 ok(hdc != NULL, "Expected HDC to be initialized\n");
2481
2482 status = GdipCreateFromHDC(hdc, &graphics);
2483 expect(Ok, status);
2484 ok(graphics != NULL, "Expected graphics to be initialized\n");
2485
2486 /* null parameters */
2487 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2488 expect(InvalidParameter, status);
2489
2490 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2491 expect(InvalidParameter, status);
2492
2493 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2494 expect(InvalidParameter, status);
2495
2496 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2497 expect(InvalidParameter, status);
2498
2499 x = 0;
2500 y = 0;
2501 status = GdipIsVisiblePoint(graphics, x, y, &val);
2502 expect(Ok, status);
2503 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2504
2505 x = -10;
2506 y = 0;
2507 status = GdipIsVisiblePoint(graphics, x, y, &val);
2508 expect(Ok, status);
2509 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2510
2511 x = 0;
2512 y = -5;
2513 status = GdipIsVisiblePoint(graphics, x, y, &val);
2514 expect(Ok, status);
2515 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2516
2517 x = 1;
2518 y = 1;
2519 status = GdipIsVisiblePoint(graphics, x, y, &val);
2520 expect(Ok, status);
2521 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2522
2523 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2524 expect(Ok, status);
2525
2526 x = 1;
2527 y = 1;
2528 status = GdipIsVisiblePoint(graphics, x, y, &val);
2529 expect(Ok, status);
2530 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2531
2532 x = 15.5;
2533 y = 40.5;
2534 status = GdipIsVisiblePoint(graphics, x, y, &val);
2535 expect(Ok, status);
2536 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2537
2538 /* translate into the center of the rect */
2539 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2540
2541 x = 0;
2542 y = 0;
2543 status = GdipIsVisiblePoint(graphics, x, y, &val);
2544 expect(Ok, status);
2545 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2546
2547 x = 25;
2548 y = 40;
2549 status = GdipIsVisiblePoint(graphics, x, y, &val);
2550 expect(Ok, status);
2551 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2552
2553 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2554
2555 /* corner cases */
2556 x = 9;
2557 y = 19;
2558 status = GdipIsVisiblePoint(graphics, x, y, &val);
2559 expect(Ok, status);
2560 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2561
2562 x = 9.25;
2563 y = 19.25;
2564 status = GdipIsVisiblePoint(graphics, x, y, &val);
2565 expect(Ok, status);
2566 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2567
2568 x = 9.5;
2569 y = 19.5;
2570 status = GdipIsVisiblePoint(graphics, x, y, &val);
2571 expect(Ok, status);
2572 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2573
2574 x = 9.75;
2575 y = 19.75;
2576 status = GdipIsVisiblePoint(graphics, x, y, &val);
2577 expect(Ok, status);
2578 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2579
2580 x = 10;
2581 y = 20;
2582 status = GdipIsVisiblePoint(graphics, x, y, &val);
2583 expect(Ok, status);
2584 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2585
2586 x = 40;
2587 y = 20;
2588 status = GdipIsVisiblePoint(graphics, x, y, &val);
2589 expect(Ok, status);
2590 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2591
2592 x = 39;
2593 y = 59;
2594 status = GdipIsVisiblePoint(graphics, x, y, &val);
2595 expect(Ok, status);
2596 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2597
2598 x = 39.25;
2599 y = 59.25;
2600 status = GdipIsVisiblePoint(graphics, x, y, &val);
2601 expect(Ok, status);
2602 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2603
2604 x = 39.5;
2605 y = 39.5;
2606 status = GdipIsVisiblePoint(graphics, x, y, &val);
2607 expect(Ok, status);
2608 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2609
2610 x = 39.75;
2611 y = 59.75;
2612 status = GdipIsVisiblePoint(graphics, x, y, &val);
2613 expect(Ok, status);
2614 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2615
2616 x = 40;
2617 y = 60;
2618 status = GdipIsVisiblePoint(graphics, x, y, &val);
2619 expect(Ok, status);
2620 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2621
2622 x = 40.15;
2623 y = 60.15;
2624 status = GdipIsVisiblePoint(graphics, x, y, &val);
2625 expect(Ok, status);
2626 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2627
2628 x = 10;
2629 y = 60;
2630 status = GdipIsVisiblePoint(graphics, x, y, &val);
2631 expect(Ok, status);
2632 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2633
2634 /* integer version */
2635 x = 25;
2636 y = 30;
2637 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2638 expect(Ok, status);
2639 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2640
2641 x = 50;
2642 y = 100;
2643 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2644 expect(Ok, status);
2645 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2646
2647 GdipDeleteGraphics(graphics);
2648 ReleaseDC(hwnd, hdc);
2649 }
2650
2651 static void test_GdipIsVisibleRect(void)
2652 {
2653 GpStatus status;
2654 GpGraphics *graphics = NULL;
2655 HDC hdc = GetDC( hwnd );
2656 REAL x, y, width, height;
2657 BOOL val;
2658
2659 ok(hdc != NULL, "Expected HDC to be initialized\n");
2660
2661 status = GdipCreateFromHDC(hdc, &graphics);
2662 expect(Ok, status);
2663 ok(graphics != NULL, "Expected graphics to be initialized\n");
2664
2665 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2666 expect(InvalidParameter, status);
2667
2668 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2669 expect(InvalidParameter, status);
2670
2671 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2672 expect(InvalidParameter, status);
2673
2674 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2675 expect(InvalidParameter, status);
2676
2677 /* entirely within the visible region */
2678 x = 0; width = 10;
2679 y = 0; height = 10;
2680 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2681 expect(Ok, status);
2682 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2683
2684 /* partially outside */
2685 x = -10; width = 20;
2686 y = -10; height = 20;
2687 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2688 expect(Ok, status);
2689 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2690
2691 /* entirely outside */
2692 x = -10; width = 5;
2693 y = -10; height = 5;
2694 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2695 expect(Ok, status);
2696 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2697
2698 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2699 expect(Ok, status);
2700
2701 /* entirely within the visible region */
2702 x = 12; width = 10;
2703 y = 22; 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 /* partially outside */
2709 x = 35; width = 10;
2710 y = 55; height = 10;
2711 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2712 expect(Ok, status);
2713 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2714
2715 /* entirely outside */
2716 x = 45; width = 5;
2717 y = 65; height = 5;
2718 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2719 expect(Ok, status);
2720 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2721
2722 /* translate into center of clipping rect */
2723 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2724
2725 x = 0; width = 10;
2726 y = 0; height = 10;
2727 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2728 expect(Ok, status);
2729 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2730
2731 x = 25; width = 5;
2732 y = 40; height = 5;
2733 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2734 expect(Ok, status);
2735 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2736
2737 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2738
2739 /* corners entirely outside, but some intersections */
2740 x = 0; width = 70;
2741 y = 0; height = 90;
2742 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2743 expect(Ok, status);
2744 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2745
2746 x = 0; width = 70;
2747 y = 0; height = 30;
2748 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2749 expect(Ok, status);
2750 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2751
2752 x = 0; width = 30;
2753 y = 0; height = 90;
2754 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2755 expect(Ok, status);
2756 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2757
2758 /* edge cases */
2759 x = 0; width = 10;
2760 y = 20; height = 40;
2761 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2762 expect(Ok, status);
2763 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2764
2765 x = 10; width = 30;
2766 y = 0; height = 20;
2767 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2768 expect(Ok, status);
2769 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2770
2771 x = 40; width = 10;
2772 y = 20; height = 40;
2773 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2774 expect(Ok, status);
2775 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2776
2777 x = 10; width = 30;
2778 y = 60; height = 10;
2779 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2780 expect(Ok, status);
2781 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2782
2783 /* rounding tests */
2784 x = 0.4; width = 10.4;
2785 y = 20; height = 40;
2786 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2787 expect(Ok, status);
2788 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2789
2790 x = 10; width = 30;
2791 y = 0.4; height = 20.4;
2792 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2793 expect(Ok, status);
2794 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2795
2796 /* integer version */
2797 x = 0; width = 30;
2798 y = 0; height = 90;
2799 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2800 expect(Ok, status);
2801 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2802
2803 x = 12; width = 10;
2804 y = 22; height = 10;
2805 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2806 expect(Ok, status);
2807 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2808
2809 GdipDeleteGraphics(graphics);
2810 ReleaseDC(hwnd, hdc);
2811 }
2812
2813 static void test_GdipGetNearestColor(void)
2814 {
2815 GpStatus status;
2816 GpGraphics *graphics;
2817 GpBitmap *bitmap;
2818 ARGB color = 0xdeadbeef;
2819 HDC hdc = GetDC( hwnd );
2820
2821 /* create a graphics object */
2822 ok(hdc != NULL, "Expected HDC to be initialized\n");
2823
2824 status = GdipCreateFromHDC(hdc, &graphics);
2825 expect(Ok, status);
2826 ok(graphics != NULL, "Expected graphics to be initialized\n");
2827
2828 status = GdipGetNearestColor(graphics, NULL);
2829 expect(InvalidParameter, status);
2830
2831 status = GdipGetNearestColor(NULL, &color);
2832 expect(InvalidParameter, status);
2833 GdipDeleteGraphics(graphics);
2834
2835 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2836 expect(Ok, status);
2837 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2838 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2839 if (status == Ok)
2840 {
2841 status = GdipGetNearestColor(graphics, &color);
2842 expect(Ok, status);
2843 expect(0xdeadbeef, color);
2844 GdipDeleteGraphics(graphics);
2845 }
2846 GdipDisposeImage((GpImage*)bitmap);
2847
2848 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2849 expect(Ok, status);
2850 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2851 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2852 if (status == Ok)
2853 {
2854 status = GdipGetNearestColor(graphics, &color);
2855 expect(Ok, status);
2856 expect(0xdeadbeef, color);
2857 GdipDeleteGraphics(graphics);
2858 }
2859 GdipDisposeImage((GpImage*)bitmap);
2860
2861 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2862 expect(Ok, status);
2863 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2864 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2865 if (status == Ok)
2866 {
2867 status = GdipGetNearestColor(graphics, &color);
2868 expect(Ok, status);
2869 expect(0xdeadbeef, color);
2870 GdipDeleteGraphics(graphics);
2871 }
2872 GdipDisposeImage((GpImage*)bitmap);
2873
2874 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2875 expect(Ok, status);
2876 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2877 todo_wine expect(OutOfMemory, status);
2878 if (status == Ok)
2879 GdipDeleteGraphics(graphics);
2880 GdipDisposeImage((GpImage*)bitmap);
2881
2882 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2883 expect(Ok, status);
2884 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2885 expect(Ok, status);
2886 status = GdipGetNearestColor(graphics, &color);
2887 expect(Ok, status);
2888 expect(0xdeadbeef, color);
2889 GdipDeleteGraphics(graphics);
2890 GdipDisposeImage((GpImage*)bitmap);
2891
2892 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2893 expect(Ok, status);
2894 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2895 expect(Ok, status);
2896 status = GdipGetNearestColor(graphics, &color);
2897 expect(Ok, status);
2898 expect(0xdeadbeef, color);
2899 GdipDeleteGraphics(graphics);
2900 GdipDisposeImage((GpImage*)bitmap);
2901
2902 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2903 expect(Ok, status);
2904 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2905 expect(Ok, status);
2906 status = GdipGetNearestColor(graphics, &color);
2907 expect(Ok, status);
2908 expect(0xdeadbeef, color);
2909 GdipDeleteGraphics(graphics);
2910 GdipDisposeImage((GpImage*)bitmap);
2911
2912 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2913 expect(Ok, status);
2914 if (status == Ok)
2915 {
2916 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2917 expect(Ok, status);
2918 status = GdipGetNearestColor(graphics, &color);
2919 expect(Ok, status);
2920 expect(0xdeadbeef, color);
2921 GdipDeleteGraphics(graphics);
2922 GdipDisposeImage((GpImage*)bitmap);
2923 }
2924
2925 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2926 expect(Ok, status);
2927 if (status == Ok)
2928 {
2929 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2930 expect(Ok, status);
2931 status = GdipGetNearestColor(graphics, &color);
2932 expect(Ok, status);
2933 expect(0xdeadbeef, color);
2934 GdipDeleteGraphics(graphics);
2935 GdipDisposeImage((GpImage*)bitmap);
2936 }
2937
2938 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2939 expect(Ok, status);
2940 if (status == Ok)
2941 {
2942 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2943 expect(Ok, status);
2944 status = GdipGetNearestColor(graphics, &color);
2945 expect(Ok, status);
2946 expect(0xdeadbeef, color);
2947 GdipDeleteGraphics(graphics);
2948 GdipDisposeImage((GpImage*)bitmap);
2949 }
2950
2951 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2952 expect(Ok, status);
2953 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2954 expect(Ok, status);
2955 status = GdipGetNearestColor(graphics, &color);
2956 expect(Ok, status);
2957 todo_wine expect(0xffa8bce8, color);
2958 GdipDeleteGraphics(graphics);
2959 GdipDisposeImage((GpImage*)bitmap);
2960
2961 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2962 expect(Ok, status);
2963 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2964 expect(Ok, status);
2965 status = GdipGetNearestColor(graphics, &color);
2966 expect(Ok, status);
2967 todo_wine
2968 ok(color == 0xffa8b8e8 ||
2969 broken(color == 0xffa0b8e0), /* Win98/WinMe */
2970 "Expected ffa8b8e8, got %.8x\n", color);
2971 GdipDeleteGraphics(graphics);
2972 GdipDisposeImage((GpImage*)bitmap);
2973
2974 ReleaseDC(hwnd, hdc);
2975 }
2976
2977 static void test_string_functions(void)
2978 {
2979 GpStatus status;
2980 GpGraphics *graphics;
2981 GpFontFamily *family;
2982 GpFont *font;
2983 RectF rc, char_bounds, bounds;
2984 GpBrush *brush;
2985 ARGB color = 0xff000000;
2986 HDC hdc = GetDC( hwnd );
2987 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2988 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2989 const WCHAR teststring2[] = {'j',0};
2990 REAL char_width, char_height;
2991 INT codepointsfitted, linesfilled;
2992 GpStringFormat *format;
2993 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2994 GpRegion *regions[4];
2995 BOOL region_isempty[4];
2996 int i;
2997 PointF positions[8];
2998 GpMatrix *identity;
2999
3000 ok(hdc != NULL, "Expected HDC to be initialized\n");
3001 status = GdipCreateFromHDC(hdc, &graphics);
3002 expect(Ok, status);
3003 ok(graphics != NULL, "Expected graphics to be initialized\n");
3004
3005 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
3006 expect(Ok, status);
3007
3008 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
3009 expect(Ok, status);
3010
3011 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
3012 expect(Ok, status);
3013
3014 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3015 expect(Ok, status);
3016
3017 rc.X = 0;
3018 rc.Y = 0;
3019 rc.Width = 100.0;
3020 rc.Height = 100.0;
3021
3022 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
3023 expect(InvalidParameter, status);
3024
3025 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
3026 expect(InvalidParameter, status);
3027
3028 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
3029 expect(InvalidParameter, status);
3030
3031 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
3032 expect(InvalidParameter, status);
3033
3034 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
3035 expect(InvalidParameter, status);
3036
3037 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
3038 expect(Ok, status);
3039
3040 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3041 expect(InvalidParameter, status);
3042
3043 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3044 expect(InvalidParameter, status);
3045
3046 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3047 expect(InvalidParameter, status);
3048
3049 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3050 expect(InvalidParameter, status);
3051
3052 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3053 expect(InvalidParameter, status);
3054
3055 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3056 expect(Ok, status);
3057
3058 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3059 expect(Ok, status);
3060
3061 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3062 expect(Ok, status);
3063 expectf(0.0, char_bounds.X);
3064 expectf(0.0, char_bounds.Y);
3065 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3066 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3067 expect(1, codepointsfitted);
3068 expect(1, linesfilled);
3069
3070 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3071 expect(Ok, status);
3072 expectf(0.0, bounds.X);
3073 expectf(0.0, bounds.Y);
3074 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3075 expectf(char_bounds.Height, bounds.Height);
3076 expect(2, codepointsfitted);
3077 expect(1, linesfilled);
3078 char_width = bounds.Width - char_bounds.Width;
3079
3080 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3081 expect(Ok, status);
3082 expectf(0.0, bounds.X);
3083 expectf(0.0, bounds.Y);
3084 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3085 bounds.Width, char_bounds.Width + char_width * 2);
3086 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3087 expect(6, codepointsfitted);
3088 expect(2, linesfilled);
3089 char_height = bounds.Height - char_bounds.Height;
3090
3091 /* Measure the first line. */
3092 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3093 expect(Ok, status);
3094 expectf(0.0, bounds.X);
3095 expectf(0.0, bounds.Y);
3096 expect(4, codepointsfitted);
3097 expect(1, linesfilled);
3098
3099 /* Give just enough space to fit the first line. */
3100 rc.Width = bounds.Width;
3101 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3102 expect(Ok, status);
3103 expectf(0.0, bounds.X);
3104 expectf(0.0, bounds.Y);
3105 todo_wine expect(5, codepointsfitted);
3106 todo_wine expect(1, linesfilled);
3107
3108 /* Cut off everything after the first space. */
3109 rc.Width = char_bounds.Width + char_width * 2.1;
3110
3111 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3112 expect(Ok, status);
3113 expectf(0.0, bounds.X);
3114 expectf(0.0, bounds.Y);
3115 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3116 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3117 expect(6, codepointsfitted);
3118 expect(3, linesfilled);
3119
3120 /* Cut off everything including the first space. */
3121 rc.Width = char_bounds.Width + char_width * 1.7;
3122
3123 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3124 expect(Ok, status);
3125 expectf(0.0, bounds.X);
3126 expectf(0.0, bounds.Y);
3127 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3128 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3129 expect(6, codepointsfitted);
3130 expect(3, linesfilled);
3131
3132 /* Cut off everything after the first character. */
3133 rc.Width = char_bounds.Width + char_width * 0.8;
3134
3135 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3136 expect(Ok, status);
3137 expectf(0.0, bounds.X);
3138 expectf(0.0, bounds.Y);
3139 expectf_(char_bounds.Width, bounds.Width, 0.01);
3140 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3141 expect(6, codepointsfitted);
3142 todo_wine expect(4, linesfilled);
3143
3144 for (i = 0; i < 4; i++)
3145 regions[i] = (GpRegion *)0xdeadbeef;
3146
3147 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3148 expect(Ok, status);
3149
3150 for (i = 0; i < 4; i++)
3151 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3152
3153 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3154 expect(Ok, status);
3155
3156 for (i = 0; i < 4; i++)
3157 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3158
3159 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3160 expect(Ok, status);
3161
3162 set_rect_empty(&rc);
3163
3164 for (i=0; i<4; i++)
3165 {
3166 status = GdipCreateRegion(&regions[i]);
3167 expect(Ok, status);
3168 status = GdipSetEmpty(regions[i]);
3169 expect(Ok, status);
3170 }
3171
3172 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3173 expect(InvalidParameter, status);
3174
3175 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3176 expect(InvalidParameter, status);
3177
3178 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3179 expect(InvalidParameter, status);
3180
3181 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3182 expect(InvalidParameter, status);
3183
3184 if (0)
3185 {
3186 /* Crashes on Windows XP */
3187 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3188 expect(InvalidParameter, status);
3189 }
3190
3191 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3192 expect(InvalidParameter, status);
3193
3194 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3195 expect(InvalidParameter, status);
3196
3197 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3198 expect(Ok, status);
3199
3200 for (i = 0; i < 4; i++)
3201 {
3202 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3203 expect(Ok, status);
3204 }
3205
3206 ok(region_isempty[0], "region should be empty\n");
3207 ok(region_isempty[1], "region should be empty\n");
3208 ok(region_isempty[2], "region should be empty\n");
3209 ok(region_isempty[3], "region should be empty\n");
3210
3211 rc.Width = 100.0;
3212 rc.Height = 100.0;
3213
3214 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3215 expect(Ok, status);
3216
3217 for (i=0; i<4; i++)
3218 {
3219 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3220 expect(Ok, status);
3221 }
3222
3223 ok(!region_isempty[0], "region shouldn't be empty\n");
3224 ok(!region_isempty[1], "region shouldn't be empty\n");
3225 ok(!region_isempty[2], "region shouldn't be empty\n");
3226 ok(region_isempty[3], "region should be empty\n");
3227
3228 /* Cut off everything after the first space, and the second line. */
3229 rc.Width = char_bounds.Width + char_width * 2.1;
3230 rc.Height = char_bounds.Height + char_height * 0.5;
3231
3232 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3233 expect(Ok, status);
3234
3235 for (i=0; i<4; i++)
3236 {
3237 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3238 expect(Ok, status);
3239 }
3240
3241 ok(!region_isempty[0], "region shouldn't be empty\n");
3242 ok(!region_isempty[1], "region shouldn't be empty\n");
3243 ok(region_isempty[2], "region should be empty\n");
3244 ok(region_isempty[3], "region should be empty\n");
3245
3246 for (i=0; i<4; i++)
3247 GdipDeleteRegion(regions[i]);
3248
3249 status = GdipCreateMatrix(&identity);
3250 expect(Ok, status);
3251
3252 rc.X = 0;
3253 rc.Y = 0;
3254 rc.Width = 0;
3255 rc.Height = 0;
3256 memset(positions, 0, sizeof(positions));
3257 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3258 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3259 identity, &rc);
3260 expect(InvalidParameter, status);
3261
3262 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3263 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3264 identity, &rc);
3265 expect(InvalidParameter, status);
3266
3267 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3268 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3269 identity, &rc);
3270 expect(InvalidParameter, status);
3271
3272 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3273 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3274 identity, &rc);
3275 expect(InvalidParameter, status);
3276
3277 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3278 0x100, identity, &rc);
3279 expect(Ok, status);
3280
3281 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3282 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3283 NULL, &rc);
3284 expect(Ok, status);
3285
3286 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3287 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3288 identity, NULL);
3289 expect(InvalidParameter, status);
3290
3291 rc.X = 0;
3292 rc.Y = 0;
3293 rc.Width = 0;
3294 rc.Height = 0;
3295 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3296 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3297 identity, &rc);
3298 expect(Ok, status);
3299
3300 expectf(0.0, rc.X);
3301 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3302 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3303 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3304
3305 char_width = rc.Width;
3306 char_height = rc.Height;
3307
3308 rc.X = 0;
3309 rc.Y = 0;
3310 rc.Width = 0;
3311 rc.Height = 0;
3312 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3313 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3314 identity, &rc);
3315 expect(Ok, status);
3316
3317 expectf(0.0, rc.X);
3318 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3319 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3320 expectf(char_height, rc.Height);
3321
3322 rc.X = 0;
3323 rc.Y = 0;
3324 rc.Width = 0;
3325 rc.Height = 0;
3326 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3327 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3328 identity, &rc);
3329 expect(Ok, status);
3330
3331 expectf(rc.X, 0.0);
3332 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3333 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3334 expectf(rc.Height, char_height);
3335
3336 GdipDeleteMatrix(identity);
3337 GdipDeleteStringFormat(format);
3338 GdipDeleteBrush(brush);
3339 GdipDeleteFont(font);
3340 GdipDeleteFontFamily(family);
3341 GdipDeleteGraphics(graphics);
3342
3343 ReleaseDC(hwnd, hdc);
3344 }
3345
3346 static void test_get_set_interpolation(void)
3347 {
3348 GpGraphics *graphics;
3349 HDC hdc = GetDC( hwnd );
3350 GpStatus status;
3351 InterpolationMode mode;
3352
3353 ok(hdc != NULL, "Expected HDC to be initialized\n");
3354 status = GdipCreateFromHDC(hdc, &graphics);
3355 expect(Ok, status);
3356 ok(graphics != NULL, "Expected graphics to be initialized\n");
3357
3358 status = GdipGetInterpolationMode(NULL, &mode);
3359 expect(InvalidParameter, status);
3360
3361 if (0)
3362 {
3363 /* Crashes on Windows XP */
3364 status = GdipGetInterpolationMode(graphics, NULL);
3365 expect(InvalidParameter, status);
3366 }
3367
3368 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3369 expect(InvalidParameter, status);
3370
3371 /* out of range */
3372 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3373 expect(InvalidParameter, status);
3374
3375 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3376 expect(InvalidParameter, status);
3377
3378 status = GdipGetInterpolationMode(graphics, &mode);
3379 expect(Ok, status);
3380 expect(InterpolationModeBilinear, mode);
3381
3382 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3383 expect(Ok, status);
3384
3385 status = GdipGetInterpolationMode(graphics, &mode);
3386 expect(Ok, status);
3387 expect(InterpolationModeNearestNeighbor, mode);
3388
3389 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3390 expect(Ok, status);
3391
3392 status = GdipGetInterpolationMode(graphics, &mode);
3393 expect(Ok, status);
3394 expect(InterpolationModeBilinear, mode);
3395
3396 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3397 expect(Ok, status);
3398
3399 status = GdipGetInterpolationMode(graphics, &mode);
3400 expect(Ok, status);
3401 expect(InterpolationModeBilinear, mode);
3402
3403 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3404 expect(Ok, status);
3405
3406 status = GdipGetInterpolationMode(graphics, &mode);
3407 expect(Ok, status);
3408 expect(InterpolationModeHighQualityBicubic, mode);
3409
3410 GdipDeleteGraphics(graphics);
3411
3412 ReleaseDC(hwnd, hdc);
3413 }
3414
3415 static void test_get_set_textrenderinghint(void)
3416 {
3417 GpGraphics *graphics;
3418 HDC hdc = GetDC( hwnd );
3419 GpStatus status;
3420 TextRenderingHint hint;
3421
3422 ok(hdc != NULL, "Expected HDC to be initialized\n");
3423 status = GdipCreateFromHDC(hdc, &graphics);
3424 expect(Ok, status);
3425 ok(graphics != NULL, "Expected graphics to be initialized\n");
3426
3427 status = GdipGetTextRenderingHint(NULL, &hint);
3428 expect(InvalidParameter, status);
3429
3430 status = GdipGetTextRenderingHint(graphics, NULL);
3431 expect(InvalidParameter, status);
3432
3433 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3434 expect(InvalidParameter, status);
3435
3436 /* out of range */
3437 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3438 expect(InvalidParameter, status);
3439
3440 status = GdipGetTextRenderingHint(graphics, &hint);
3441 expect(Ok, status);
3442 expect(TextRenderingHintSystemDefault, hint);
3443
3444 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3445 expect(Ok, status);
3446
3447 status = GdipGetTextRenderingHint(graphics, &hint);
3448 expect(Ok, status);
3449 expect(TextRenderingHintSystemDefault, hint);
3450
3451 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3452 expect(Ok, status);
3453
3454 status = GdipGetTextRenderingHint(graphics, &hint);
3455 expect(Ok, status);
3456 expect(TextRenderingHintAntiAliasGridFit, hint);
3457
3458 GdipDeleteGraphics(graphics);
3459
3460 ReleaseDC(hwnd, hdc);
3461 }
3462
3463 static void test_getdc_scaled(void)
3464 {
3465 GpStatus status;
3466 GpGraphics *graphics = NULL;
3467 GpBitmap *bitmap = NULL;
3468 HDC hdc=NULL;
3469 HBRUSH hbrush, holdbrush;
3470 ARGB color;
3471
3472 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3473 expect(Ok, status);
3474
3475 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3476 expect(Ok, status);
3477
3478 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3479 expect(Ok, status);
3480
3481 status = GdipGetDC(graphics, &hdc);
3482 expect(Ok, status);
3483 ok(hdc != NULL, "got NULL hdc\n");
3484
3485 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3486
3487 holdbrush = SelectObject(hdc, hbrush);
3488
3489 Rectangle(hdc, 2, 2, 6, 6);
3490
3491 SelectObject(hdc, holdbrush);
3492
3493 DeleteObject(hbrush);
3494
3495 status = GdipReleaseDC(graphics, hdc);
3496 expect(Ok, status);
3497
3498 GdipDeleteGraphics(graphics);
3499
3500 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3501 expect(Ok, status);
3502 expect(0xffff0000, color);
3503
3504 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3505 expect(Ok, status);
3506 expect(0xff000000, color);
3507
3508 GdipDisposeImage((GpImage*)bitmap);
3509 }
3510
3511 static void test_GdipMeasureString(void)
3512 {
3513 static const struct test_data
3514 {
3515 REAL res_x, res_y, page_scale;
3516 GpUnit unit;
3517 } td[] =
3518 {
3519 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3520 { 200.0, 200.0, 2.0, UnitPixel },
3521 { 200.0, 200.0, 1.0, UnitDisplay },
3522 { 200.0, 200.0, 2.0, UnitDisplay },
3523 { 200.0, 200.0, 1.0, UnitInch },
3524 { 200.0, 200.0, 2.0, UnitInch },
3525 { 200.0, 600.0, 1.0, UnitPoint },
3526 { 200.0, 600.0, 2.0, UnitPoint },
3527 { 200.0, 600.0, 1.0, UnitDocument },
3528 { 200.0, 600.0, 2.0, UnitDocument },
3529 { 200.0, 600.0, 1.0, UnitMillimeter },
3530 { 200.0, 600.0, 2.0, UnitMillimeter },
3531 { 200.0, 600.0, 1.0, UnitDisplay },
3532 { 200.0, 600.0, 2.0, UnitDisplay },
3533 { 200.0, 600.0, 1.0, UnitPixel },
3534 { 200.0, 600.0, 2.0, UnitPixel },
3535 };
3536 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3537 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3538 GpStatus status;
3539 GpGraphics *graphics;
3540 GpFontFamily *family;
3541 GpFont *font;
3542 GpStringFormat *format;
3543 RectF bounds, rc;
3544 REAL base_cx = 0, base_cy = 0, height;
3545 INT chars, lines;
3546 LOGFONTW lf;
3547 UINT i;
3548 REAL font_size;
3549 GpUnit font_unit, unit;
3550
3551 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3552 expect(Ok, status);
3553 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3554 expect(Ok, status);
3555
3556 /* font size in pixels */
3557 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3558 expect(Ok, status);
3559 status = GdipGetFontSize(font, &font_size);
3560 expect(Ok, status);
3561 expectf(100.0, font_size);
3562 status = GdipGetFontUnit(font, &font_unit);
3563 expect(Ok, status);
3564 expect(UnitPixel, font_unit);
3565
3566 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3567 {
3568 GpImage *image;
3569
3570 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3571
3572 lf.lfHeight = 0xdeadbeef;
3573 status = GdipGetLogFontW(font, graphics, &lf);
3574 expect(Ok, status);
3575 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3576 if (td[i].unit != UnitDisplay)
3577 height *= td[i].page_scale;
3578 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3579 i, (LONG)(height + 0.5), height, lf.lfHeight);
3580
3581 height = font_size + 2.0 * font_size / 6.0;
3582
3583 set_rect_empty(&rc);
3584 set_rect_empty(&bounds);
3585 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3586 expect(Ok, status);
3587
3588 if (i == 0)
3589 {
3590 base_cx = bounds.Width;
3591 base_cy = bounds.Height;
3592 }
3593
3594 expectf(0.0, bounds.X);
3595 expectf(0.0, bounds.Y);
3596 todo_wine
3597 expectf_(height, bounds.Height, height / 100.0);
3598 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3599 expect(7, chars);
3600 expect(1, lines);
3601
3602 /* make sure it really fits */
3603 bounds.Width += 1.0;
3604 bounds.Height += 1.0;
3605 rc = bounds;
3606 rc.X = 50.0;
3607 rc.Y = 50.0;
3608 set_rect_empty(&bounds);
3609 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3610 expect(Ok, status);
3611 expectf(50.0, bounds.X);
3612 expectf(50.0, bounds.Y);
3613 todo_wine
3614 expectf_(height, bounds.Height, height / 100.0);
3615 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3616 expect(7, chars);
3617 expect(1, lines);
3618
3619 status = GdipDeleteGraphics(graphics);
3620 expect(Ok, status);
3621
3622 status = GdipDisposeImage(image);
3623 expect(Ok, status);
3624 }
3625
3626 GdipDeleteFont(font);
3627
3628 /* font size in logical units */
3629 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3630 for (unit = 3; unit <= 6; unit++)
3631 {
3632 /* create a font which final height is 100.0 pixels with 200 dpi device */
3633 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3634 height = pixels_to_units(75.0, unit, 200.0);
3635 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3636 expect(Ok, status);
3637 status = GdipGetFontSize(font, &font_size);
3638 expect(Ok, status);
3639 expectf(height, font_size);
3640 status = GdipGetFontUnit(font, &font_unit);
3641 expect(Ok, status);
3642 expect(unit, font_unit);
3643
3644 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3645 {
3646 REAL unit_scale;
3647 GpImage *image;
3648
3649 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3650
3651 lf.lfHeight = 0xdeadbeef;
3652 status = GdipGetLogFontW(font, graphics, &lf);
3653 expect(Ok, status);
3654 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3655 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3656 else
3657 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3658 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3659 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3660 i, (LONG)(height + 0.5), height, lf.lfHeight);
3661
3662 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3663 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3664 else
3665 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3666 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3667 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3668 if (td[i].unit != UnitDisplay)
3669 height /= td[i].page_scale;
3670 /*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);*/
3671
3672 set_rect_empty(&rc);
3673 set_rect_empty(&bounds);
3674 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3675 expect(Ok, status);
3676
3677 if (i == 0)
3678 {
3679 base_cx = bounds.Width;
3680 base_cy = bounds.Height;
3681 }
3682
3683 expectf(0.0, bounds.X);
3684 expectf(0.0, bounds.Y);
3685 todo_wine
3686 expectf_(height, bounds.Height, height / 85.0);
3687 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3688 expect(7, chars);
3689 expect(1, lines);
3690
3691 /* make sure it really fits */
3692 bounds.Width += 1.0;
3693 bounds.Height += 1.0;
3694 rc = bounds;
3695 rc.X = 50.0;
3696 rc.Y = 50.0;
3697 set_rect_empty(&bounds);
3698 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3699 expect(Ok, status);
3700 expectf(50.0, bounds.X);
3701 expectf(50.0, bounds.Y);
3702 todo_wine
3703 expectf_(height, bounds.Height, height / 85.0);
3704 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3705 expect(7, chars);
3706 expect(1, lines);
3707
3708 /* verify the result */
3709 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3710 if (td[i].unit != UnitDisplay)
3711 height *= td[i].page_scale;
3712 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3713 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3714 todo_wine
3715 expectf_(100.0, height, 1.1);
3716
3717 status = GdipDeleteGraphics(graphics);
3718 expect(Ok, status);
3719
3720 status = GdipDisposeImage(image);
3721 expect(Ok, status);
3722 }
3723
3724 GdipDeleteFont(font);
3725 }
3726
3727 /* Font with units = UnitWorld */
3728 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3729 {
3730 GpPointF pt = {0.0, 100.0};
3731 GpImage* image;
3732 REAL expected_width, expected_height;
3733
3734 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3735
3736 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3737 expect(Ok, status);
3738
3739 status = GdipCreateFont(family, pt.Y, FontStyleRegular, UnitWorld, &font);
3740 expect(Ok, status);
3741
3742 status = GdipGetFontUnit(font, &font_unit);
3743 expect(Ok, status);
3744 expect(UnitWorld, font_unit);
3745
3746 lf.lfHeight = 0xdeadbeef;
3747 status = GdipGetLogFontW(font, graphics, &lf);
3748 expect(Ok, status);
3749 ok(lf.lfHeight == -100, "%u: expected -100, got %d\n", i, lf.lfHeight);
3750
3751 set_rect_empty(&rc);
3752 set_rect_empty(&bounds);
3753 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3754 expect(Ok, status);
3755
3756 if (i == 0)
3757 {
3758 base_cx = bounds.Width;
3759 base_cy = bounds.Height;
3760 }
3761
3762 pt.X = 1.0;
3763 pt.Y = 1.0;
3764
3765 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3766 expect(Ok, status);
3767
3768 /* height is constant in device space, width is proportional to height in world space */
3769 expected_width = base_cx * pt.Y;
3770 expected_height = base_cy * pt.Y;
3771
3772 todo_wine_if(td[i].unit != UnitDisplay && td[i].unit != UnitPixel)
3773 ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width);
3774 ok(fabs(expected_height - bounds.Height) <= 0.001, "%u: expected %f, got %f\n", i, expected_height, bounds.Height);
3775
3776 GdipDeleteGraphics(graphics);
3777 GdipDisposeImage(image);
3778 GdipDeleteFont(font);
3779 }
3780
3781 GdipDeleteFontFamily(family);
3782 GdipDeleteStringFormat(format);
3783 }
3784
3785 static void test_transform(void)
3786 {
3787 static const struct test_data
3788 {
3789 REAL res_x, res_y, scale;
3790 GpUnit unit;
3791 GpPointF in[2], out[2];
3792 } td[] =
3793 {
3794 { 96.0, 96.0, 1.0, UnitPixel,
3795 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3796 { 96.0, 96.0, 1.0, UnitDisplay,
3797 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3798 { 96.0, 96.0, 1.0, UnitInch,
3799 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
3800 { 123.0, 456.0, 1.0, UnitPoint,
3801 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
3802 { 123.0, 456.0, 1.0, UnitDocument,
3803 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
3804 { 123.0, 456.0, 2.0, UnitMillimeter,
3805 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
3806 { 196.0, 296.0, 1.0, UnitDisplay,
3807 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3808 { 196.0, 296.0, 1.0, UnitPixel,
3809 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3810 };
3811 GpStatus status;
3812 GpGraphics *graphics;
3813 GpImage *image;
3814 GpPointF ptf[2];
3815 UINT i;
3816
3817 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3818 {
3819 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
3820 ptf[0].X = td[i].in[0].X;
3821 ptf[0].Y = td[i].in[0].Y;
3822 ptf[1].X = td[i].in[1].X;
3823 ptf[1].Y = td[i].in[1].Y;
3824 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
3825 expect(Ok, status);
3826 expectf(td[i].out[0].X, ptf[0].X);
3827 expectf(td[i].out[0].Y, ptf[0].Y);
3828 expectf(td[i].out[1].X, ptf[1].X);
3829 expectf(td[i].out[1].Y, ptf[1].Y);
3830 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
3831 expect(Ok, status);
3832 expectf(td[i].in[0].X, ptf[0].X);
3833 expectf(td[i].in[0].Y, ptf[0].Y);
3834 expectf(td[i].in[1].X, ptf[1].X);
3835 expectf(td[i].in[1].Y, ptf[1].Y);
3836 status = GdipDeleteGraphics(graphics);
3837 expect(Ok, status);
3838 status = GdipDisposeImage(image);
3839 expect(Ok, status);
3840 }
3841 }
3842
3843 static void test_pen_thickness(void)
3844 {
3845 static const struct test_data
3846 {
3847 REAL res_x, res_y, scale;
3848 GpUnit pen_unit, page_unit;
3849 REAL pen_width;
3850 INT cx, cy;
3851 } td[] =
3852 {
3853 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 1.0, 1, 1 },
3854 { 10.0, 10.0, 3.0, UnitPixel, UnitPixel, 2.0, 2, 2 },
3855 { 10.0, 10.0, 30.0, UnitPixel, UnitInch, 1.0, 1, 1 },
3856 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 1.0, 1, 1 },
3857 { 10.0, 10.0, 3.0, UnitWorld, UnitPixel, 2.0, 6, 6 },
3858 { 10.0, 10.0, 2.0, UnitWorld, UnitInch, 1.0, 20, 20 },
3859 };
3860 GpStatus status;
3861 int i, j;
3862 GpGraphics *graphics;
3863 union
3864 {
3865 GpBitmap *bitmap;
3866 GpImage *image;
3867 } u;
3868 GpPen *pen;
3869 GpPointF corner;
3870 BitmapData bd;
3871 INT min, max, size;
3872
3873 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3874 {
3875 status = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat24bppRGB, NULL, &u.bitmap);
3876 expect(Ok, status);
3877
3878 status = GdipBitmapSetResolution(u.bitmap, td[i].res_x, td[i].res_y);
3879 expect(Ok, status);
3880
3881 status = GdipGetImageGraphicsContext(u.image, &graphics);
3882 expect(Ok, status);
3883
3884 status = GdipSetPageUnit(graphics, td[i].page_unit);
3885 expect(Ok, status);
3886
3887 status = GdipSetPageScale(graphics, td[i].scale);
3888 expect(Ok, status);
3889
3890 status = GdipCreatePen1(0xffffffff, td[i].pen_width, td[i].pen_unit, &pen);
3891 expect(Ok, status);
3892
3893 corner.X = corner.Y = 100.0;
3894 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &corner, 1);
3895 expect(Ok, status);
3896
3897 status = GdipDrawLine(graphics, pen, corner.X/2, 0, corner.X/2, corner.Y);
3898 expect(Ok, status);
3899
3900 status = GdipDrawLine(graphics, pen, 0, corner.Y/2, corner.X, corner.Y/2);
3901 expect(Ok, status);
3902
3903 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
3904 expect(Ok, status);
3905
3906 min = -1;
3907 max = -2;
3908
3909 for (j=0; j<100; j++)
3910 {
3911 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
3912 {
3913 min = j;
3914 break;
3915 }
3916 }
3917
3918 for (j=99; j>=0; j--)
3919 {
3920 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
3921 {
3922 max = j;
3923 break;
3924 }
3925 }
3926
3927 size = max-min+1;
3928
3929 ok(size == td[i].cx, "%u: expected %d, got %d\n", i, td[i].cx, size);
3930
3931 min = -1;
3932 max = -2;
3933
3934 for (j=0; j<100; j++)
3935 {
3936 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
3937 {
3938 min = j;
3939 break;
3940 }
3941 }
3942
3943 for (j=99; j>=0; j--)
3944 {
3945 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
3946 {
3947 max = j;
3948 break;
3949 }
3950 }
3951
3952 size = max-min+1;
3953
3954 ok(size == td[i].cy, "%u: expected %d, got %d\n", i, td[i].cy, size);
3955
3956 status = GdipBitmapUnlockBits(u.bitmap, &bd);
3957 expect(Ok, status);
3958
3959 GdipDeletePen(pen);
3960 GdipDeleteGraphics(graphics);
3961 GdipDisposeImage(u.image);
3962 }
3963 }
3964
3965 /* Many people on the net ask why there is so much difference in rendered
3966 * text height between gdiplus and gdi32, this test suggests an answer to
3967 * that question. Important: this test assumes that font dpi == device dpi.
3968 */
3969 static void test_font_height_scaling(void)
3970 {
3971 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3972 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3973 HDC hdc;
3974 GpStringFormat *format;
3975 CharacterRange range = { 0, 7 };
3976 GpRegion *region;
3977 GpGraphics *graphics;
3978 GpFontFamily *family;
3979 GpFont *font;
3980 GpStatus status;
3981 RectF bounds, rect;
3982 REAL height, dpi, scale;
3983 PointF ptf;
3984 GpUnit gfx_unit, font_unit;
3985
3986 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
3987 expect(Ok, status);
3988 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
3989 expect(Ok, status);
3990 status = GdipCreateRegion(&region);
3991 expect(Ok, status);
3992
3993 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3994 expect(Ok, status);
3995
3996 hdc = CreateCompatibleDC(0);
3997 status = GdipCreateFromHDC(hdc, &graphics);
3998 expect(Ok, status);
3999
4000 status = GdipGetDpiY(graphics, &dpi);
4001 expect(Ok, status);
4002
4003 /* First check if tested functionality works:
4004 * under XP if font and graphics units differ then GdipTransformPoints
4005 * followed by GdipSetPageUnit to change the graphics units breaks region
4006 * scaling in GdipMeasureCharacterRanges called later.
4007 */
4008 status = GdipSetPageUnit(graphics, UnitDocument);
4009 expect(Ok, status);
4010
4011 ptf.X = 0.0;
4012 ptf.Y = 0.0;
4013 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4014 expect(Ok, status);
4015
4016 status = GdipSetPageUnit(graphics, UnitInch);
4017 expect(Ok, status);
4018
4019 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
4020 expect(Ok, status);
4021
4022 set_rect_empty(&rect);
4023 set_rect_empty(&bounds);
4024 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4025 expect(Ok, status);
4026 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
4027
4028 set_rect_empty(&rect);
4029 rect.Width = 32000.0;
4030 rect.Height = 32000.0;
4031 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4032 expect(Ok, status);
4033
4034 set_rect_empty(&rect);
4035 status = GdipGetRegionBounds(region, graphics, &rect);
4036 expect(Ok, status);
4037 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4038
4039 GdipDeleteFont(font);
4040
4041 scale = rect.Height / bounds.Height;
4042 if (fabs(scale - 1.0) > 0.1)
4043 {
4044 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
4045 goto cleanup;
4046 }
4047
4048 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
4049 expect(Ok, status);
4050
4051 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4052 /* UnitPixel as a font base unit is not tested because it drastically
4053 differs in behaviour */
4054 for (font_unit = 3; font_unit <= 6; font_unit++)
4055 {
4056 /* create a font for the final text height of 100 pixels */
4057 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
4058 status = GdipSetPageUnit(graphics, font_unit);
4059 expect(Ok, status);
4060 ptf.X = 0;
4061 ptf.Y = 75.0;
4062 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4063 expect(Ok, status);
4064 height = ptf.Y;
4065 /*trace("height %f units\n", height);*/
4066 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
4067 expect(Ok, status);
4068
4069 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4070 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4071 {
4072 static const WCHAR doubleW[2] = { 'W','W' };
4073 RectF bounds_1, bounds_2;
4074 REAL margin, margin_y, font_height;
4075 int match;
4076
4077 status = GdipSetPageUnit(graphics, gfx_unit);
4078 expect(Ok, status);
4079
4080 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
4081 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
4082
4083 status = GdipGetFontHeight(font, graphics, &font_height);
4084 expect(Ok, status);
4085
4086 set_rect_empty(&rect);
4087 set_rect_empty(&bounds);
4088 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4089 expect(Ok, status);
4090 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
4091 todo_wine
4092 expectf_(font_height + margin_y, bounds.Height, 0.005);
4093
4094 ptf.X = 0;
4095 ptf.Y = bounds.Height;
4096 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
4097 expect(Ok, status);
4098 match = fabs(100.0 - ptf.Y) <= 1.0;
4099 todo_wine
4100 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4101
4102 /* verify the result */
4103 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
4104 ptf.Y /= 100.0;
4105 match = fabs(100.0 - ptf.Y) <= 1.0;
4106 todo_wine
4107 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4108
4109 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4110 set_rect_empty(&rect);
4111 set_rect_empty(&bounds_1);
4112 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
4113 expect(Ok, status);
4114 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4115 set_rect_empty(&rect);
4116 set_rect_empty(&bounds_2);
4117 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
4118 expect(Ok, status);
4119
4120 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4121 margin = bounds_1.Width - bounds_2.Width / 2.0;
4122 /*trace("margin %f\n", margin);*/
4123 ok(margin > 0.0, "wrong margin %f\n", margin);
4124
4125 set_rect_empty(&rect);
4126 rect.Width = 320000.0;
4127 rect.Height = 320000.0;
4128 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4129 expect(Ok, status);
4130 set_rect_empty(&rect);
4131 status = GdipGetRegionBounds(region, graphics, &rect);
4132 expect(Ok, status);
4133 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
4134 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
4135 expectf(0.0, rect.Y);
4136 match = fabs(1.0 - margin / rect.X) <= 0.05;
4137 ok(match, "Expected %f, got %f\n", margin, rect.X);
4138 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
4139 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
4140 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
4141 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
4142 }
4143
4144 GdipDeleteFont(font);
4145 }
4146
4147 cleanup:
4148 status = GdipDeleteGraphics(graphics);
4149 expect(Ok, status);
4150 DeleteDC(hdc);
4151
4152 GdipDeleteFontFamily(family);
4153 GdipDeleteRegion(region);
4154 GdipDeleteStringFormat(format);
4155 }
4156
4157 static void test_measure_string(void)
4158 {
4159 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4160 static const WCHAR string[] = { 'A','0','1',0 };
4161 HDC hdc;
4162 GpStringFormat *format;
4163 CharacterRange range;
4164 GpRegion *region;
4165 GpGraphics *graphics;
4166 GpFontFamily *family;
4167 GpFont *font;
4168 GpStatus status;
4169 RectF bounds, rect;
4170 REAL width, height, width_1, width_2;
4171 REAL margin_x, margin_y, width_rgn, height_rgn;
4172 int lines, glyphs;
4173
4174 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4175 expect(Ok, status);
4176 expect(Ok, status);
4177
4178 status = GdipCreateRegion(&region);
4179 expect(Ok, status);
4180
4181 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4182 expect(Ok, status);
4183
4184 hdc = CreateCompatibleDC(0);
4185 status = GdipCreateFromHDC(hdc, &graphics);
4186
4187 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
4188 expect(Ok, status);
4189
4190 margin_x = 20.0 / 6.0;
4191 margin_y = 20.0 / 8.0;
4192
4193 set_rect_empty(&rect);
4194 set_rect_empty(&bounds);
4195 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4196 expect(Ok, status);
4197 expect(3, glyphs);
4198 expect(1, lines);
4199 expectf(0.0, bounds.X);
4200 expectf(0.0, bounds.Y);
4201 width = bounds.Width;
4202 height = bounds.Height;
4203
4204 set_rect_empty(&rect);
4205 rect.Height = height / 2.0;
4206 set_rect_empty(&bounds);
4207 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4208 expect(Ok, status);
4209 expect(3, glyphs);
4210 expect(1, lines);
4211 expectf(0.0, bounds.X);
4212 expectf(0.0, bounds.Y);
4213 expectf(width, bounds.Width);
4214 todo_wine
4215 expectf(height / 2.0, bounds.Height);
4216
4217 range.First = 0;
4218 range.Length = lstrlenW(string);
4219 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4220 expect(Ok, status);
4221
4222 rect.X = 5.0;
4223 rect.Y = 5.0;
4224 rect.Width = 32000.0;
4225 rect.Height = 32000.0;
4226 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4227 expect(Ok, status);
4228 set_rect_empty(&bounds);
4229 status = GdipGetRegionBounds(region, graphics, &bounds);
4230 expect(Ok, status);
4231 expectf_(5.0 + margin_x, bounds.X, 1.0);
4232 expectf(5.0, bounds.Y);
4233 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4234 todo_wine
4235 expectf_(height - margin_y, bounds.Height, 1.0);
4236
4237 width_rgn = bounds.Width;
4238 height_rgn = bounds.Height;
4239
4240 range.First = 0;
4241 range.Length = 1;
4242 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4243 expect(Ok, status);
4244
4245 set_rect_empty(&rect);
4246 rect.Width = 32000.0;
4247 rect.Height = 32000.0;
4248 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4249 expect(Ok, status);
4250 set_rect_empty(&bounds);
4251 status = GdipGetRegionBounds(region, graphics, &bounds);
4252 expect(Ok, status);
4253 expectf_(margin_x, bounds.X, 1.0);
4254 expectf(0.0, bounds.Y);
4255 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4256 expectf(height_rgn, bounds.Height);
4257 width_1 = bounds.Width;
4258
4259 range.First = 0;
4260 range.Length = lstrlenW(string);
4261 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4262 expect(Ok, status);
4263
4264 rect.X = 5.0;
4265 rect.Y = 5.0;
4266 rect.Width = 0.0;
4267 rect.Height = 0.0;
4268 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4269 expect(Ok, status);
4270 set_rect_empty(&bounds);
4271 status = GdipGetRegionBounds(region, graphics, &bounds);
4272 expect(Ok, status);
4273 expectf(0.0, bounds.X);
4274 expectf(0.0, bounds.Y);
4275 expectf(0.0, bounds.Width);
4276 expectf(0.0, bounds.Height);
4277
4278 rect.X = 5.0;
4279 rect.Y = 5.0;
4280 rect.Width = width_rgn / 2.0;
4281 rect.Height = 32000.0;
4282 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4283 expect(Ok, status);
4284 set_rect_empty(&bounds);
4285 status = GdipGetRegionBounds(region, graphics, &bounds);
4286 expect(Ok, status);
4287 expectf_(5.0 + margin_x, bounds.X, 1.0);
4288 expectf(5.0, bounds.Y);
4289 expectf_(width_1, bounds.Width, 1.0);
4290 todo_wine
4291 expectf_(height - margin_y, bounds.Height, 1.0);
4292
4293 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4294
4295 rect.X = 5.0;
4296 rect.Y = 5.0;
4297 rect.Width = 0.0;
4298 rect.Height = 0.0;
4299 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4300 expect(Ok, status);
4301 set_rect_empty(&bounds);
4302 status = GdipGetRegionBounds(region, graphics, &bounds);
4303 expect(Ok, status);
4304 expectf_(5.0 + margin_x, bounds.X, 1.0);
4305 expectf(5.0, bounds.Y);
4306 expectf(width_rgn, bounds.Width);
4307 expectf(height_rgn, bounds.Height);
4308
4309 rect.X = 5.0;
4310 rect.Y = 5.0;
4311 rect.Width = width_rgn / 2.0;
4312 rect.Height = 32000.0;
4313 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4314 expect(Ok, status);
4315 set_rect_empty(&bounds);
4316 status = GdipGetRegionBounds(region, graphics, &bounds);
4317 expect(Ok, status);
4318 expectf_(5.0 + margin_x, bounds.X, 1.0);
4319 expectf(5.0, bounds.Y);
4320 expectf_(width_1, bounds.Width, 1.0);
4321 expectf(height_rgn, bounds.Height);
4322
4323 set_rect_empty(&rect);
4324 rect.Height = height / 2.0;
4325 set_rect_empty(&bounds);
4326 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4327 expect(Ok, status);
4328 expect(3, glyphs);
4329 expect(1, lines);
4330 expectf(0.0, bounds.X);
4331 expectf(0.0, bounds.Y);
4332 expectf_(width, bounds.Width, 0.01);
4333 todo_wine
4334 expectf(height, bounds.Height);
4335
4336 set_rect_empty(&rect);
4337 set_rect_empty(&bounds);
4338 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4339 expect(Ok, status);
4340 expect(1, glyphs);
4341 expect(1, lines);
4342 expectf(0.0, bounds.X);
4343 expectf(0.0, bounds.Y);
4344 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4345 expectf(height, bounds.Height);
4346 width_1 = bounds.Width;
4347
4348 set_rect_empty(&rect);
4349 set_rect_empty(&bounds);
4350 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4351 expect(Ok, status);
4352 expect(2, glyphs);
4353 expect(1, lines);
4354 expectf(0.0, bounds.X);
4355 expectf(0.0, bounds.Y);
4356 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4357 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4358 expectf(height, bounds.Height);
4359 width_2 = bounds.Width;
4360
4361 set_rect_empty(&rect);
4362 rect.Width = width / 2.0;
4363 set_rect_empty(&bounds);
4364 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4365 expect(Ok, status);
4366 expect(1, glyphs);
4367 expect(1, lines);
4368 expectf(0.0, bounds.X);
4369 expectf(0.0, bounds.Y);
4370 expectf_(width_1, bounds.Width, 0.01);
4371 expectf(height, bounds.Height);
4372
4373 set_rect_empty(&rect);
4374 rect.Height = height;
4375 rect.Width = width - 0.05;
4376 set_rect_empty(&bounds);
4377 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4378 expect(Ok, status);
4379 expect(2, glyphs);
4380 expect(1, lines);
4381 expectf(0.0, bounds.X);
4382 expectf(0.0, bounds.Y);
4383 expectf_(width_2, bounds.Width, 0.01);
4384 expectf(height, bounds.Height);
4385
4386 set_rect_empty(&rect);
4387 rect.Height = height;
4388 rect.Width = width_2 - 0.05;
4389 set_rect_empty(&bounds);
4390 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4391 expect(Ok, status);
4392 expect(1, glyphs);
4393 expect(1, lines);
4394 expectf(0.0, bounds.X);
4395 expectf(0.0, bounds.Y);
4396 expectf_(width_1, bounds.Width, 0.01);
4397 expectf(height, bounds.Height);
4398
4399 /* Default (Near) alignment */
4400 rect.X = 5.0;
4401 rect.Y = 5.0;
4402 rect.Width = width * 2.0;
4403 rect.Height = height * 2.0;
4404 set_rect_empty(&bounds);
4405 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4406 expect(Ok, status);
4407 expect(3, glyphs);
4408 expect(1, lines);
4409 expectf(5.0, bounds.X);
4410 expectf(5.0, bounds.Y);
4411 expectf_(width, bounds.Width, 0.01);
4412 expectf(height, bounds.Height);
4413
4414 rect.X = 5.0;
4415 rect.Y = 5.0;
4416 rect.Width = 32000.0;
4417 rect.Height = 32000.0;
4418 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4419 expect(Ok, status);
4420 set_rect_empty(&bounds);
4421 status = GdipGetRegionBounds(region, graphics, &bounds);
4422 expect(Ok, status);
4423 expectf_(5.0 + margin_x, bounds.X, 1.0);
4424 expectf(5.0, bounds.Y);
4425 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4426 todo_wine
4427 expectf_(height - margin_y, bounds.Height, 1.0);
4428
4429 width_rgn = bounds.Width;
4430 height_rgn = bounds.Height;
4431
4432 /* Center alignment */
4433 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4434 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4435
4436 rect.X = 5.0;
4437 rect.Y = 5.0;
4438 rect.Width = width * 2.0;
4439 rect.Height = height * 2.0;
4440 set_rect_empty(&bounds);
4441 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4442 expect(Ok, status);
4443 expect(3, glyphs);
4444 expect(1, lines);
4445 todo_wine
4446 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4447 todo_wine
4448 expectf(5.0 + height/2.0, bounds.Y);
4449 expectf_(width, bounds.Width, 0.01);
4450 expectf(height, bounds.Height);
4451
4452 rect.X = 5.0;
4453 rect.Y = 5.0;
4454 rect.Width = 0.0;
4455 rect.Height = 0.0;
4456 set_rect_empty(&bounds);
4457 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4458 expect(Ok, status);
4459 expect(3, glyphs);
4460 expect(1, lines);
4461 todo_wine
4462 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4463 todo_wine
4464 expectf(5.0 - height/2.0, bounds.Y);
4465 expectf_(width, bounds.Width, 0.01);
4466 expectf(height, bounds.Height);
4467
4468 rect.X = 5.0;
4469 rect.Y = 5.0;
4470 rect.Width = width_rgn * 2.0;
4471 rect.Height = height_rgn * 2.0;
4472 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4473 expect(Ok, status);
4474 set_rect_empty(&bounds);
4475 status = GdipGetRegionBounds(region, graphics, &bounds);
4476 expect(Ok, status);
4477 todo_wine
4478 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4479 todo_wine
4480 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4481 expectf_(width_rgn, bounds.Width, 1.0);
4482 expectf_(height_rgn, bounds.Height, 1.0);
4483
4484 rect.X = 5.0;
4485 rect.Y = 5.0;
4486 rect.Width = 0.0;
4487 rect.Height = 0.0;
4488 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4489 expect(Ok, status);
4490 set_rect_empty(&bounds);
4491 status = GdipGetRegionBounds(region, graphics, &bounds);
4492 expect(Ok, status);
4493 todo_wine
4494 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4495 todo_wine
4496 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4497 expectf_(width_rgn, bounds.Width, 1.0);
4498 expectf_(height_rgn, bounds.Height, 1.0);
4499
4500 /* Far alignment */
4501 GdipSetStringFormatAlign(format, StringAlignmentFar);
4502 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4503
4504 rect.X = 5.0;
4505 rect.Y = 5.0;
4506 rect.Width = width * 2.0;
4507 rect.Height = height * 2.0;
4508 set_rect_empty(&bounds);
4509 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4510 expect(Ok, status);
4511 expect(3, glyphs);
4512 expect(1, lines);
4513 todo_wine
4514 expectf_(5.0 + width, bounds.X, 0.01);
4515 todo_wine
4516 expectf(5.0 + height, bounds.Y);
4517 expectf_(width, bounds.Width, 0.01);
4518 expectf(height, bounds.Height);
4519
4520 rect.X = 5.0;
4521 rect.Y = 5.0;
4522 rect.Width = 0.0;
4523 rect.Height = 0.0;
4524 set_rect_empty(&bounds);
4525 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4526 expect(Ok, status);
4527 expect(3, glyphs);
4528 expect(1, lines);
4529 todo_wine
4530 expectf_(5.0 - width, bounds.X, 0.01);
4531 todo_wine
4532 expectf(5.0 - height, bounds.Y);
4533 expectf_(width, bounds.Width, 0.01);
4534 expectf(height, bounds.Height);
4535
4536 rect.X = 5.0;
4537 rect.Y = 5.0;
4538 rect.Width = width_rgn * 2.0;
4539 rect.Height = height_rgn * 2.0;
4540 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4541 expect(Ok, status);
4542 set_rect_empty(&bounds);
4543 status = GdipGetRegionBounds(region, graphics, &bounds);
4544 expect(Ok, status);
4545 todo_wine
4546 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4547 todo_wine
4548 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4549 expectf_(width_rgn, bounds.Width, 1.0);
4550 expectf_(height_rgn, bounds.Height, 1.0);
4551
4552 rect.X = 5.0;
4553 rect.Y = 5.0;
4554 rect.Width = 0.0;
4555 rect.Height = 0.0;
4556 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4557 expect(Ok, status);
4558 set_rect_empty(&bounds);
4559 status = GdipGetRegionBounds(region, graphics, &bounds);
4560 expect(Ok, status);
4561 todo_wine
4562 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4563 todo_wine
4564 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4565 expectf_(width_rgn, bounds.Width, 1.0);
4566 expectf_(height_rgn, bounds.Height, 1.0);
4567
4568 status = GdipDeleteFont(font);
4569 expect(Ok, status);
4570
4571 status = GdipDeleteGraphics(graphics);
4572 expect(Ok, status);
4573 DeleteDC(hdc);
4574
4575 GdipDeleteFontFamily(family);
4576 GdipDeleteRegion(region);
4577 GdipDeleteStringFormat(format);
4578 }
4579
4580 static void test_measured_extra_space(void)
4581 {
4582 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4583 static const WCHAR string[2] = { 'W','W' };
4584 GpStringFormat *format;
4585 HDC hdc;
4586 GpGraphics *graphics;
4587 GpFontFamily *family;
4588 GpFont *font;
4589 GpStatus status;
4590 GpUnit gfx_unit, font_unit;
4591 RectF bounds_1, bounds_2, rect;
4592 REAL margin, font_size, dpi;
4593
4594 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4595 expect(Ok, status);
4596
4597 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4598 expect(Ok, status);
4599 hdc = CreateCompatibleDC(0);
4600 status = GdipCreateFromHDC(hdc, &graphics);
4601 expect(Ok, status);
4602
4603 status = GdipGetDpiX(graphics, &dpi);
4604 expect(Ok, status);
4605
4606 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4607 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4608 for (font_unit = 3; font_unit <= 6; font_unit++)
4609 {
4610 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4611 expect(Ok, status);
4612
4613 status = GdipGetFontSize(font, &font_size);
4614 expect(Ok, status);
4615 font_size = units_to_pixels(font_size, font_unit, dpi);
4616 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4617
4618 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4619 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4620 {
4621 status = GdipSetPageUnit(graphics, gfx_unit);
4622 expect(Ok, status);
4623
4624 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4625 set_rect_empty(&rect);
4626 set_rect_empty(&bounds_1);
4627 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4628 expect(Ok, status);
4629 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4630 set_rect_empty(&rect);
4631 set_rect_empty(&bounds_2);
4632 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4633 expect(Ok, status);
4634
4635 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4636 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4637 /*trace("margin %f pixels\n", margin);*/
4638 expectf_(font_size / 6.0, margin, font_size / 100.0);
4639 }
4640
4641 GdipDeleteFont(font);
4642 }
4643
4644 GdipDeleteGraphics(graphics);
4645 DeleteDC(hdc);
4646 GdipDeleteFontFamily(family);
4647 GdipDeleteStringFormat(format);
4648 }
4649
4650 static void test_alpha_hdc(void)
4651 {
4652 GpStatus status;
4653 HDC hdc, gp_hdc;
4654 HBITMAP hbm, old_hbm;
4655 GpGraphics *graphics;
4656 ULONG *bits;
4657 BITMAPINFO bmi;
4658 GpRectF bounds;
4659 COLORREF colorref;
4660
4661 hdc = CreateCompatibleDC(0);
4662 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4663 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4664 bmi.bmiHeader.biHeight = 5;
4665 bmi.bmiHeader.biWidth = 5;
4666 bmi.bmiHeader.biBitCount = 32;
4667 bmi.bmiHeader.biPlanes = 1;
4668 bmi.bmiHeader.biCompression = BI_RGB;
4669 bmi.bmiHeader.biClrUsed = 0;
4670
4671 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4672 ok(hbm != NULL, "CreateDIBSection failed\n");
4673
4674 old_hbm = SelectObject(hdc, hbm);
4675
4676 status = GdipCreateFromHDC(hdc, &graphics);
4677 expect(Ok, status);
4678
4679 status = GdipGetVisibleClipBounds(graphics, &bounds);
4680 expect(Ok, status);
4681 expectf(0.0, bounds.X);
4682 expectf(0.0, bounds.Y);
4683 expectf(5.0, bounds.Width);
4684 expectf(5.0, bounds.Height);
4685
4686 bits[0] = 0xdeadbeef;
4687
4688 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4689 expect(Ok, status);
4690
4691 expect(0xffaaaaaa, bits[0]);
4692
4693 bits[0] = 0xdeadbeef;
4694
4695 status = GdipGetDC(graphics, &gp_hdc);
4696 expect(Ok, status);
4697
4698 colorref = GetPixel(gp_hdc, 0, 4);
4699 expect(0xefbead, colorref);
4700
4701 SetPixel(gp_hdc, 0, 4, 0xffffff);
4702
4703 expect(0xffffff, bits[0]);
4704
4705 status = GdipReleaseDC(graphics, gp_hdc);
4706 expect(Ok, status);
4707
4708 SelectObject(hdc, old_hbm);
4709
4710 bits[0] = 0xdeadbeef;
4711
4712 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4713 expect(Ok, status);
4714
4715 todo_wine expect(0xffbbbbbb, bits[0]);
4716
4717 GdipDeleteGraphics(graphics);
4718
4719 DeleteObject(hbm);
4720 DeleteDC(hdc);
4721 }
4722
4723 static void test_bitmapfromgraphics(void)
4724 {
4725 GpStatus stat;
4726 GpGraphics *graphics = NULL;
4727 HDC hdc = GetDC( hwnd );
4728 GpBitmap *bitmap = NULL;
4729 PixelFormat format;
4730 REAL imageres, graphicsres;
4731 UINT width, height;
4732
4733 stat = GdipCreateFromHDC(hdc, &graphics);
4734 expect(Ok, stat);
4735
4736 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
4737 expect(InvalidParameter, stat);
4738
4739 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
4740 expect(InvalidParameter, stat);
4741
4742 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
4743 expect(Ok, stat);
4744
4745 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
4746 expect(Ok, stat);
4747 expect(PixelFormat32bppPARGB, format);
4748
4749 stat = GdipGetDpiX(graphics, &graphicsres);
4750 expect(Ok, stat);
4751
4752 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
4753 expect(Ok, stat);
4754 expectf(graphicsres, imageres);
4755
4756 stat = GdipGetDpiY(graphics, &graphicsres);
4757 expect(Ok, stat);
4758
4759 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
4760 expect(Ok, stat);
4761 expectf(graphicsres, imageres);
4762
4763 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
4764 expect(Ok, stat);
4765 expect(12, width);
4766
4767 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
4768 expect(Ok, stat);
4769 expect(13, height);
4770
4771 GdipDeleteGraphics(graphics);
4772 GdipDisposeImage((GpImage*)bitmap);
4773 }
4774
4775 static void test_clipping(void)
4776 {
4777 HDC hdc;
4778 GpStatus status;
4779 GpGraphics *graphics;
4780 GpRegion *region, *region100x100;
4781 GpMatrix *matrix;
4782 GpRectF rect;
4783 GpPointF ptf[4];
4784 GpUnit unit;
4785 HRGN hrgn;
4786 int ret;
4787 RECT rc;
4788
4789 hdc = CreateCompatibleDC(0);
4790 status = GdipCreateFromHDC(hdc, &graphics);
4791 expect(Ok, status);
4792
4793 status = GdipGetPageUnit(graphics, &unit);
4794 expect(Ok, status);
4795 expect(UnitDisplay, unit);
4796
4797 status = GdipCreateRegion(&region);
4798 expect(Ok, status);
4799 status = GdipSetEmpty(region);
4800 expect(Ok, status);
4801
4802 status = GdipCreateRegion(&region100x100);
4803 expect(Ok, status);
4804 status = GdipSetEmpty(region100x100);
4805 expect(Ok, status);
4806
4807 rect.X = rect.Y = 100.0;
4808 rect.Width = rect.Height = 100.0;
4809 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
4810 expect(Ok, status);
4811 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
4812 expect(Ok, status);
4813
4814 status = GdipGetClipBounds(graphics, &rect);
4815 expect(Ok, status);
4816 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4817 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4818
4819 status = GdipSetEmpty(region);
4820 expect(Ok, status);
4821 status = GdipGetClip(graphics, region);
4822 expect(Ok, status);
4823 status = GdipGetRegionBounds(region, graphics, &rect);
4824 expect(Ok, status);
4825 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4826 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4827
4828 ptf[0].X = 100.0;
4829 ptf[0].Y = 100.0;
4830 ptf[1].X = 200.0;
4831 ptf[1].Y = 200.0;
4832 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4833 expect(Ok, status);
4834 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4835 "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);
4836
4837 status = GdipCreateMatrix(&matrix);
4838 expect(Ok, status);
4839 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
4840 expect(Ok, status);
4841 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
4842 expect(Ok, status);
4843 status = GdipSetWorldTransform(graphics, matrix);
4844 expect(Ok, status);
4845
4846 status = GdipGetClipBounds(graphics, &rect);
4847 expect(Ok, status);
4848 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4849 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4850
4851 status = GdipSetEmpty(region);
4852 expect(Ok, status);
4853 status = GdipGetClip(graphics, region);
4854 expect(Ok, status);
4855 status = GdipGetRegionBounds(region, graphics, &rect);
4856 expect(Ok, status);
4857 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4858 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4859
4860 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4861 expect(Ok, status);
4862 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4863 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4864
4865 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4866 expect(Ok, status);
4867 ret = GetRgnBox(hrgn, &rc);
4868 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4869 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4870 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
4871 DeleteObject(hrgn);
4872
4873 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4874 expect(Ok, status);
4875 ret = GetRgnBox(hrgn, &rc);
4876 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4877 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4878 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
4879 DeleteObject(hrgn);
4880
4881 ptf[0].X = 100.0;
4882 ptf[0].Y = 100.0;
4883 ptf[1].X = 200.0;
4884 ptf[1].Y = 200.0;
4885 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4886 expect(Ok, status);
4887 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4888 "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);
4889
4890 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4891 expect(Ok, status);
4892 ret = GetRgnBox(hrgn, &rc);
4893 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4894 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4895 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
4896 DeleteObject(hrgn);
4897
4898 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4899 expect(Ok, status);
4900 ret = GetRgnBox(hrgn, &rc);
4901 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4902 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4903 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
4904 DeleteObject(hrgn);
4905
4906 ptf[0].X = 210.0;
4907 ptf[0].Y = 420.0;
4908 ptf[1].X = 410.0;
4909 ptf[1].Y = 820.0;
4910 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4911 expect(Ok, status);
4912 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4913 "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);
4914
4915 status = GdipSetPageScale(graphics, 2.0);
4916 expect(Ok, status);
4917
4918 status = GdipGetClipBounds(graphics, &rect);
4919 expect(Ok, status);
4920 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4921 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4922
4923 status = GdipSetEmpty(region);
4924 expect(Ok, status);
4925 status = GdipGetClip(graphics, region);
4926 expect(Ok, status);
4927 status = GdipGetRegionBounds(region, graphics, &rect);
4928 expect(Ok, status);
4929 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4930 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4931
4932 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4933 expect(Ok, status);
4934 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4935 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4936
4937 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4938 expect(Ok, status);
4939 ret = GetRgnBox(hrgn, &rc);
4940 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4941 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4942 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
4943 DeleteObject(hrgn);
4944
4945 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4946 expect(Ok, status);
4947 ret = GetRgnBox(hrgn, &rc);
4948 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4949 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4950 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
4951 DeleteObject(hrgn);
4952
4953 ptf[0].X = 100.0;
4954 ptf[0].Y = 100.0;
4955 ptf[1].X = 200.0;
4956 ptf[1].Y = 200.0;
4957 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4958 expect(Ok, status);
4959 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4960 "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);
4961
4962 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4963 expect(Ok, status);
4964 ret = GetRgnBox(hrgn, &rc);
4965 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4966 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4967 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
4968 DeleteObject(hrgn);
4969
4970 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4971 expect(Ok, status);
4972 ret = GetRgnBox(hrgn, &rc);
4973 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4974 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4975 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
4976 DeleteObject(hrgn);
4977
4978 ptf[0].X = 210.0;
4979 ptf[0].Y = 420.0;
4980 ptf[1].X = 410.0;
4981 ptf[1].Y = 820.0;
4982 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4983 expect(Ok, status);
4984 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4985 "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);
4986
4987 GdipSetPageUnit(graphics, UnitPoint);
4988 expect(Ok, status);
4989
4990 status = GdipGetClipBounds(graphics, &rect);
4991 expect(Ok, status);
4992 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
4993 /* rounding under Wine is slightly different */
4994 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
4995 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
4996 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4997
4998 status = GdipSetEmpty(region);
4999 expect(Ok, status);
5000 status = GdipGetClip(graphics, region);
5001 expect(Ok, status);
5002 status = GdipGetRegionBounds(region, graphics, &rect);
5003 expect(Ok, status);
5004 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5005 /* rounding under Wine is slightly different */
5006 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5007 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5008 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5009
5010 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5011 expect(Ok, status);
5012 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5013 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5014
5015 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5016 expect(Ok, status);
5017 ret = GetRgnBox(hrgn, &rc);
5018 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5019 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
5020 /* rounding under Wine is slightly different */
5021 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
5022 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
5023 "expected 14,5-33,14, got %s\n", wine_dbgstr_rect(&rc));
5024 DeleteObject(hrgn);
5025
5026 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5027 expect(Ok, status);
5028 ret = GetRgnBox(hrgn, &rc);
5029 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5030 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5031 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
5032 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5033 DeleteObject(hrgn);
5034
5035 ptf[0].X = 100.0;
5036 ptf[0].Y = 100.0;
5037 ptf[1].X = 200.0;
5038 ptf[1].Y = 200.0;
5039 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5040 expect(Ok, status);
5041 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
5042 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
5043 "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);
5044
5045 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5046 expect(Ok, status);
5047 ret = GetRgnBox(hrgn, &rc);
5048 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5049 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5050 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5051 DeleteObject(hrgn);
5052
5053 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5054 expect(Ok, status);
5055 ret = GetRgnBox(hrgn, &rc);
5056 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5057 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
5058 /* rounding under Wine is slightly different */
5059 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
5060 "expected 560,1120-1094,2187, got %s\n", wine_dbgstr_rect(&rc));
5061 DeleteObject(hrgn);
5062
5063 ptf[0].X = 560.0;
5064 ptf[0].Y = 1120.0;
5065 ptf[1].X = 1094.0;
5066 ptf[1].Y = 2187.0;
5067 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5068 expect(Ok, status);
5069 if (fabs(ptf[0].X - 100.0) < 0.001)
5070 {
5071 expectf(100.0, ptf[0].X);
5072 expectf(100.0, ptf[0].Y);
5073 expectf(200.125, ptf[1].X);
5074 expectf(200.03125, ptf[1].Y);
5075 }
5076 else /* before Win7 */
5077 {
5078 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
5079 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
5080 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
5081 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
5082 }
5083
5084 status = GdipTransformRegion(region100x100, matrix);
5085 expect(Ok, status);
5086
5087 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5088 expect(Ok, status);
5089 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5090 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5091
5092 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5093 expect(Ok, status);
5094 ret = GetRgnBox(hrgn, &rc);
5095 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5096 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5097 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5098 DeleteObject(hrgn);
5099
5100 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5101 expect(Ok, status);
5102 ret = GetRgnBox(hrgn, &rc);
5103 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5104 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
5105 /* rounding under Wine is slightly different */
5106 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
5107 "expected 1147,4534-2214,8800, got %s\n", wine_dbgstr_rect(&rc));
5108 DeleteObject(hrgn);
5109
5110 ptf[0].X = 1147.0;
5111 ptf[0].Y = 4534.0;
5112 ptf[1].X = 2214.0;
5113 ptf[1].Y = 8800.0;
5114 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5115 expect(Ok, status);
5116 if (fabs(ptf[0].X - 210.0625) < 0.001)
5117 {
5118 expectf(210.0625, ptf[0].X);
5119 expectf(420.0625, ptf[0].Y);
5120 expectf(410.125, ptf[1].X);
5121 expectf(820.0, ptf[1].Y);
5122 }
5123 else /* before Win7 */
5124 {
5125 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
5126 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
5127 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
5128 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
5129 }
5130
5131 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
5132 expect(Ok, status);
5133 status = GdipSetWorldTransform(graphics, matrix);
5134 expect(Ok, status);
5135
5136 status = GdipGetClipBounds(graphics, &rect);
5137 expect(Ok, status);
5138 expectf_(20.612978, rect.X, 1.0);
5139 expectf_(-6.256012, rect.Y, 1.5);
5140 expectf_(25.612978, rect.Width, 1.0);
5141 expectf_(12.806489, rect.Height, 1.0);
5142
5143 status = GdipSetEmpty(region);
5144 expect(Ok, status);
5145 status = GdipGetClip(graphics, region);
5146 expect(Ok, status);
5147 status = GdipGetRegionBounds(region, graphics, &rect);
5148 expect(Ok, status);
5149 /* rounding under Wine is slightly different */
5150 expectf_(20.612978, rect.X, 1.0);
5151 expectf_(-6.256012, rect.Y, 1.5);
5152 expectf_(25.612978, rect.Width, 1.0);
5153 expectf_(12.806489, rect.Height, 1.0);
5154
5155 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5156 expect(Ok, status);
5157 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5158 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5159
5160 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5161 expect(Ok, status);
5162 ret = GetRgnBox(hrgn, &rc);
5163 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5164 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
5165 /* rounding under Wine is slightly different */
5166 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
5167 "expected (22,-6)-(46,7), got %s\n", wine_dbgstr_rect(&rc));
5168 DeleteObject(hrgn);
5169
5170 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5171 expect(Ok, status);
5172 ret = GetRgnBox(hrgn, &rc);
5173 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5174 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5175 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5176 DeleteObject(hrgn);
5177
5178 ptf[0].X = 100.0;
5179 ptf[0].Y = 100.0;
5180 ptf[1].X = 200.0;
5181 ptf[1].Y = 200.0;
5182 ptf[2].X = 200.0;
5183 ptf[2].Y = 100.0;
5184 ptf[3].X = 100.0;
5185 ptf[3].Y = 200.0;
5186 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5187 expect(Ok, status);
5188 expectf(20.612978, ptf[0].X);
5189 expectf(-1.568512, ptf[0].Y);
5190 expectf(46.225956, ptf[1].X);
5191 expectf(1.862977, ptf[1].Y);
5192 expectf(36.850956, ptf[2].X);
5193 expectf(-6.256012, ptf[2].Y);
5194 expectf(29.987980, ptf[3].X);
5195 expectf(6.550478, ptf[3].Y);
5196
5197 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5198 expect(Ok, status);
5199 ret = GetRgnBox(hrgn, &rc);
5200 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5201 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5202 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5203 DeleteObject(hrgn);
5204
5205 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5206 expect(Ok, status);
5207 ret = GetRgnBox(hrgn, &rc);
5208 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5209 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
5210 /* rounding under Wine is slightly different */
5211 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
5212 "expected (-3406,4500)-(-350,8728), got %s\n", wine_dbgstr_rect(&rc));
5213 DeleteObject(hrgn);
5214
5215 ptf[0].X = -3406.0;
5216 ptf[0].Y = 4500.0;
5217 ptf[1].X = -350.0;
5218 ptf[1].Y = 8728.0;
5219 ptf[2].X = -350.0;
5220 ptf[2].Y = 4500.0;
5221 ptf[3].X = -3406.0;
5222 ptf[3].Y = 8728.0;
5223 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5224 expect(Ok, status);
5225 expectf(-136.190491, ptf[0].X);
5226 expectf(520.010742, ptf[0].Y);
5227 expectf(756.417175, ptf[1].X);
5228 expectf(720.031616, ptf[1].Y);
5229 expectf(360.042114, ptf[2].X);
5230 expectf(376.760742, ptf[2].Y);
5231 expectf(260.184570, ptf[3].X);
5232 expectf(863.281616, ptf[3].Y);
5233
5234 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
5235 expect(Ok, status);
5236 status = GdipSetWorldTransform(graphics, matrix);
5237 expect(Ok, status);
5238
5239 status = GdipGetClipBounds(graphics, &rect);
5240 expect(Ok, status);
5241 expectf_(-28.100956, rect.X, 1.0);
5242 expectf_(7.806488, rect.Y, 1.5);
5243 expectf_(25.612978, rect.Width, 1.0);
5244 expectf_(12.806489, rect.Height, 1.0);
5245
5246 status = GdipSetEmpty(region);
5247 expect(Ok, status);
5248 status = GdipGetClip(graphics, region);
5249 expect(Ok, status);
5250 status = GdipGetRegionBounds(region, graphics, &rect);
5251 expect(Ok, status);
5252 /* rounding under Wine is slightly different */
5253 expectf_(-28.100956, rect.X, 1.0);
5254 expectf_(7.806488, rect.Y, 1.5);
5255 expectf_(25.612978, rect.Width, 1.0);
5256 expectf_(12.806489, rect.Height, 1.0);
5257
5258 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5259 expect(Ok, status);
5260 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5261 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5262
5263 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5264 expect(Ok, status);
5265 ret = GetRgnBox(hrgn, &rc);
5266 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5267 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5268 /* rounding under Wine is slightly different */
5269 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5270 "expected (-27,8)-(-2,21), got %s\n", wine_dbgstr_rect(&rc));
5271 DeleteObject(hrgn);
5272
5273 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5274 expect(Ok, status);
5275 ret = GetRgnBox(hrgn, &rc);
5276 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5277 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5278 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5279 DeleteObject(hrgn);
5280
5281 ptf[0].X = 100.0;
5282 ptf[0].Y = 100.0;
5283 ptf[1].X = 200.0;
5284 ptf[1].Y = 200.0;
5285 ptf[2].X = 200.0;
5286 ptf[2].Y = 100.0;
5287 ptf[3].X = 100.0;
5288 ptf[3].Y = 200.0;
5289 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5290 expect(Ok, status);
5291 expectf(-11.862979, ptf[0].X);
5292 expectf(7.806488, ptf[0].Y);
5293 expectf(-18.725958, ptf[1].X);
5294 expectf(20.612976, ptf[1].Y);
5295 expectf(-2.487981, ptf[2].X);
5296 expectf(15.925477, ptf[2].Y);
5297 expectf(-28.100956, ptf[3].X);
5298 expectf(12.493987, ptf[3].Y);
5299
5300 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5301 expect(Ok, status);
5302 ret = GetRgnBox(hrgn, &rc);
5303 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5304 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5305 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5306 DeleteObject(hrgn);
5307
5308 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5309 expect(Ok, status);
5310 ret = GetRgnBox(hrgn, &rc);
5311 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5312 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5313 /* rounding under Wine is slightly different */
5314 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5315 "expected (4500,351)-(8728,3407), got %s\n", wine_dbgstr_rect(&rc));
5316 DeleteObject(hrgn);
5317
5318 ptf[0].X = -3406.0;
5319 ptf[0].Y = 4500.0;
5320 ptf[1].X = -350.0;
5321 ptf[1].Y = 8728.0;
5322 ptf[2].X = -350.0;
5323 ptf[2].Y = 4500.0;
5324 ptf[3].X = -3406.0;
5325 ptf[3].Y = 8728.0;
5326 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5327 expect(Ok, status);
5328 expectf(-1055.021484, ptf[0].X);
5329 expectf(-70.595329, ptf[0].Y);
5330 expectf(-1455.063232, ptf[1].X);
5331 expectf(375.708435, ptf[1].Y);
5332 expectf(-768.521484, ptf[2].X);
5333 expectf(177.520981, ptf[2].Y);
5334 expectf(-1741.563110, ptf[3].X);
5335 expectf(127.592125, ptf[3].Y);
5336
5337 GdipDeleteMatrix(matrix);
5338 GdipDeleteRegion(region);
5339 GdipDeleteRegion(region100x100);
5340 GdipDeleteGraphics(graphics);
5341 DeleteDC(hdc);
5342 }
5343
5344 static void test_clipping_2(void)
5345 {
5346
5347 HDC hdc;
5348 GpStatus status;
5349 GpGraphics *graphics;
5350 GpRegion *region;
5351 GpMatrix *matrix;
5352 GpRectF rect;
5353 GpPointF ptf[4];
5354 GpUnit unit;
5355 HRGN hrgn;
5356 int ret;
5357 RECT rc;
5358
5359 hdc = CreateCompatibleDC(0);
5360 status = GdipCreateFromHDC(hdc, &graphics);
5361 expect(Ok, status);
5362
5363 status = GdipGetPageUnit(graphics, &unit);
5364 expect(Ok, status);
5365 expect(UnitDisplay, unit);
5366
5367 GdipSetPageUnit(graphics, UnitInch);
5368
5369 status = GdipCreateRegion(&region);
5370 expect(Ok, status);
5371 status = GdipSetEmpty(region);
5372 expect(Ok, status);
5373 rect.X = rect.Y = 100.0;
5374 rect.Width = rect.Height = 100.0;
5375 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5376 expect(Ok, status);
5377 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5378 expect(Ok, status);
5379
5380 status = GdipGetClip(graphics, region);
5381 expect(Ok, status);
5382 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5383 expect(Ok, status);
5384 ret = GetRgnBox(hrgn, &rc);
5385 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5386 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5387 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5388 DeleteObject(hrgn);
5389 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5390 expect(Ok, status);
5391 ret = GetRgnBox(hrgn, &rc);
5392 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5393 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5394 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5395 DeleteObject(hrgn);
5396
5397 ptf[0].X = 9600.0;
5398 ptf[0].Y = 9600.0;
5399 ptf[1].X = 19200.0;
5400 ptf[1].Y = 19200.0;
5401 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5402 expect(Ok, status);
5403 expectf(100.0, ptf[0].X);
5404 expectf(100.0, ptf[0].Y);
5405 expectf(200.0, ptf[1].X);
5406 expectf(200.0, ptf[1].X);
5407
5408 GdipSetPageUnit(graphics, UnitPoint);
5409
5410 status = GdipGetClip(graphics, region);
5411 expect(Ok, status);
5412 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5413 expect(Ok, status);
5414 ret = GetRgnBox(hrgn, &rc);
5415 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5416 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5417 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5418 "expected 7200,7200-14400,14400, got %s\n", wine_dbgstr_rect(&rc));
5419 DeleteObject(hrgn);
5420 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5421 expect(Ok, status);
5422 ret = GetRgnBox(hrgn, &rc);
5423 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5424 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5425 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5426 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5427 DeleteObject(hrgn);
5428
5429 ptf[0].X = 9600.0;
5430 ptf[0].Y = 9600.0;
5431 ptf[1].X = 19200.0;
5432 ptf[1].Y = 19200.0;
5433 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5434 expect(Ok, status);
5435 if (fabs(ptf[0].X - 7200.0) < 0.001)
5436 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5437 "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);
5438 else /* before Win7 */
5439 {
5440 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5441 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5442 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5443 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5444 }
5445
5446 GdipDeleteRegion(region);
5447
5448 GdipSetPageUnit(graphics, UnitPixel);
5449
5450 status = GdipCreateRegion(&region);
5451 expect(Ok, status);
5452 status = GdipSetEmpty(region);
5453 expect(Ok, status);
5454 rect.X = rect.Y = 100.0;
5455 rect.Width = rect.Height = 100.0;
5456 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5457 expect(Ok, status);
5458 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5459 expect(Ok, status);
5460
5461 status = GdipGetClip(graphics, region);
5462 expect(Ok, status);
5463 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5464 expect(Ok, status);
5465 ret = GetRgnBox(hrgn, &rc);
5466 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5467 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5468 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5469 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5470 DeleteObject(hrgn);
5471 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5472 expect(Ok, status);
5473 ret = GetRgnBox(hrgn, &rc);
5474 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5475 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5476 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5477 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5478 DeleteObject(hrgn);
5479
5480 ptf[0].X = 100.0;
5481 ptf[0].Y = 100.0;
5482 ptf[1].X = 200.0;
5483 ptf[1].Y = 200.0;
5484 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5485 expect(Ok, status);
5486 if (fabs(ptf[0].X - 100.0) < 0.001)
5487 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5488 "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);
5489 else /* before Win7 */
5490 {
5491 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5492 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5493 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5494 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5495 }
5496
5497 GdipSetPageUnit(graphics, UnitPoint);
5498
5499 status = GdipGetClip(graphics, region);
5500 expect(Ok, status);
5501 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5502 expect(Ok, status);
5503 ret = GetRgnBox(hrgn, &rc);
5504 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5505 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5506 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5507 "expected 75,75-150,150, got %s\n", wine_dbgstr_rect(&rc));
5508 DeleteObject(hrgn);
5509 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5510 expect(Ok, status);
5511 ret = GetRgnBox(hrgn, &rc);
5512 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5513 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5514 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5515 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5516 DeleteObject(hrgn);
5517
5518 ptf[0].X = 100.0;
5519 ptf[0].Y = 100.0;
5520 ptf[1].X = 200.0;
5521 ptf[1].Y = 200.0;
5522 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5523 expect(Ok, status);
5524 if (fabs(ptf[0].X - 75.0) < 0.001)
5525 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5526 "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);
5527 else /* before Win7 */
5528 {
5529 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5530 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5531 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5532 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5533 }
5534
5535 status = GdipCreateMatrix(&matrix);
5536 expect(Ok, status);
5537 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5538 expect(Ok, status);
5539 status = GdipSetWorldTransform(graphics, matrix);
5540 expect(Ok, status);
5541 GdipDeleteMatrix(matrix);
5542
5543 status = GdipGetClip(graphics, region);
5544 expect(Ok, status);
5545 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5546 expect(Ok, status);
5547 ret = GetRgnBox(hrgn, &rc);
5548 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5549 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5550 "expected 65,65-140,140, got %s\n", wine_dbgstr_rect(&rc));
5551 DeleteObject(hrgn);
5552 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5553 expect(Ok, status);
5554 ret = GetRgnBox(hrgn, &rc);
5555 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5556 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5557 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5558 DeleteObject(hrgn);
5559
5560 ptf[0].X = 100.0;
5561 ptf[0].Y = 100.0;
5562 ptf[1].X = 200.0;
5563 ptf[1].Y = 200.0;
5564 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5565 expect(Ok, status);
5566 expectf(65.0, ptf[0].X);
5567 expectf(65.0, ptf[0].Y);
5568 expectf(140.0, ptf[1].X);
5569 expectf(140.0, ptf[1].X);
5570
5571 status = GdipCreateMatrix(&matrix);
5572 expect(Ok, status);
5573 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5574 expect(Ok, status);
5575 status = GdipSetWorldTransform(graphics, matrix);
5576 expect(Ok, status);
5577 GdipDeleteMatrix(matrix);
5578
5579 status = GdipGetClip(graphics, region);
5580 expect(Ok, status);
5581 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5582 expect(Ok, status);
5583 ret = GetRgnBox(hrgn, &rc);
5584 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5585 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5586 "expected 300,150-600,300, got %s\n", wine_dbgstr_rect(&rc));
5587 DeleteObject(hrgn);
5588 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5589 expect(Ok, status);
5590 ret = GetRgnBox(hrgn, &rc);
5591 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5592 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5593 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5594 DeleteObject(hrgn);
5595
5596 ptf[0].X = 100.0;
5597 ptf[0].Y = 100.0;
5598 ptf[1].X = 200.0;
5599 ptf[1].Y = 200.0;
5600 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5601 expect(Ok, status);
5602 expectf(300.0, ptf[0].X);
5603 expectf(150.0, ptf[0].Y);
5604 expectf(600.0, ptf[1].X);
5605 expectf(300.0, ptf[1].Y);
5606
5607 status = GdipSetPageScale(graphics, 2.0);
5608 expect(Ok, status);
5609
5610 status = GdipGetClip(graphics, region);
5611 expect(Ok, status);
5612 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5613 expect(Ok, status);
5614 ret = GetRgnBox(hrgn, &rc);
5615 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5616 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5617 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5618 "expected 150,75-300,150, got %s\n", wine_dbgstr_rect(&rc));
5619 DeleteObject(hrgn);
5620 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5621 expect(Ok, status);
5622 ret = GetRgnBox(hrgn, &rc);
5623 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5624 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5625 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5626 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5627 DeleteObject(hrgn);
5628
5629 ptf[0].X = 100.0;
5630 ptf[0].Y = 100.0;
5631 ptf[1].X = 200.0;
5632 ptf[1].Y = 200.0;
5633 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5634 expect(Ok, status);
5635 if (fabs(ptf[0].X - 150.0) < 0.001)
5636 {
5637 expectf(150.0, ptf[0].X);
5638 expectf(75.0, ptf[0].Y);
5639 expectf(300.0, ptf[1].X);
5640 expectf(150.0, ptf[1].Y);
5641 }
5642 else /* before Win7 */
5643 {
5644 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5645 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5646 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5647 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5648 }
5649
5650 status = GdipCreateMatrix(&matrix);
5651 expect(Ok, status);
5652 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5653 expect(Ok, status);
5654 status = GdipSetWorldTransform(graphics, matrix);
5655 expect(Ok, status);
5656 GdipDeleteMatrix(matrix);
5657
5658 status = GdipGetClip(graphics, region);
5659 expect(Ok, status);
5660 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5661 expect(Ok, status);
5662 ret = GetRgnBox(hrgn, &rc);
5663 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5664 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5665 /* rounding under Wine is slightly different */
5666 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5667 "expected 54,-26-107,27, got %s\n", wine_dbgstr_rect(&rc));
5668 DeleteObject(hrgn);
5669 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5670 expect(Ok, status);
5671 ret = GetRgnBox(hrgn, &rc);
5672 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5673 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5674 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5675 DeleteObject(hrgn);
5676
5677 ptf[0].X = 100.0;
5678 ptf[0].Y = 100.0;
5679 ptf[1].X = 200.0;
5680 ptf[1].Y = 200.0;
5681 ptf[2].X = 200.0;
5682 ptf[2].Y = 100.0;
5683 ptf[3].X = 100.0;
5684 ptf[3].Y = 200.0;
5685 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5686 expect(Ok, status);
5687 expectf(53.033016, ptf[0].X);
5688 expectf(0.0, ptf[0].Y);
5689 expectf(106.066032, ptf[1].X);
5690 expectf(0.0, ptf[1].Y);
5691 expectf(79.549522, ptf[2].X);
5692 expectf(-26.516510, ptf[2].Y);
5693 expectf(79.549522, ptf[3].X);
5694 expectf(26.516508, ptf[3].Y);
5695
5696 status = GdipCreateMatrix(&matrix);
5697 expect(Ok, status);
5698 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5699 expect(Ok, status);
5700 status = GdipSetWorldTransform(graphics, matrix);
5701 expect(Ok, status);
5702 GdipDeleteMatrix(matrix);
5703
5704 status = GdipGetClip(graphics, region);
5705 expect(Ok, status);
5706 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5707 expect(Ok, status);
5708 ret = GetRgnBox(hrgn, &rc);
5709 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5710 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
5711 /* rounding under Wine is slightly different */
5712 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
5713 "expected -26,54-27,107, got %s\n", wine_dbgstr_rect(&rc));
5714 DeleteObject(hrgn);
5715 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5716 expect(Ok, status);
5717 ret = GetRgnBox(hrgn, &rc);
5718 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5719 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5720 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5721 DeleteObject(hrgn);
5722
5723 ptf[0].X = 100.0;
5724 ptf[0].Y = 100.0;
5725 ptf[1].X = 200.0;
5726 ptf[1].Y = 200.0;
5727 ptf[2].X = 200.0;
5728 ptf[2].Y = 100.0;
5729 ptf[3].X = 100.0;
5730 ptf[3].Y = 200.0;
5731 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5732 expect(Ok, status);
5733 expectf(0.0, ptf[0].X);
5734 expectf(53.033005, ptf[0].Y);
5735 expectf(0.0, ptf[1].X);
5736 expectf(106.066010, ptf[1].Y);
5737 expectf(26.516491, ptf[2].X);
5738 expectf(79.549507, ptf[2].Y);
5739 expectf(-26.516520, ptf[3].X);
5740 expectf(79.549500, ptf[3].Y);
5741
5742 GdipDeleteRegion(region);
5743 GdipDeleteGraphics(graphics);
5744 DeleteDC(hdc);
5745 }
5746
5747
5748 static void test_GdipFillRectangles(void)
5749 {
5750 GpStatus status;
5751 GpGraphics *graphics = NULL;
5752 GpBrush *brush = NULL;
5753 HDC hdc = GetDC( hwnd );
5754 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
5755
5756 ok(hdc != NULL, "Expected HDC to be initialized\n");
5757
5758 status = GdipCreateFromHDC(hdc, &graphics);
5759 expect(Ok, status);
5760 ok(graphics != NULL, "Expected graphics to be initialized\n");
5761
5762 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
5763 expect(Ok, status);
5764 ok(brush != NULL, "Expected brush to be initialized\n");
5765
5766 status = GdipFillRectangles(NULL, brush, rects, 2);
5767 expect(InvalidParameter, status);
5768
5769 status = GdipFillRectangles(graphics, NULL, rects, 2);
5770 expect(InvalidParameter, status);
5771
5772 status = GdipFillRectangles(graphics, brush, NULL, 2);
5773 expect(InvalidParameter, status);
5774
5775 status = GdipFillRectangles(graphics, brush, rects, 0);
5776 expect(InvalidParameter, status);
5777
5778 status = GdipFillRectangles(graphics, brush, rects, -1);
5779 expect(InvalidParameter, status);
5780
5781 status = GdipFillRectangles(graphics, brush, rects, 1);
5782 expect(Ok, status);
5783
5784 status = GdipFillRectangles(graphics, brush, rects, 2);
5785 expect(Ok, status);
5786
5787 GdipDeleteBrush(brush);
5788 GdipDeleteGraphics(graphics);
5789
5790 ReleaseDC(hwnd, hdc);
5791 }
5792
5793 static void test_GdipGetVisibleClipBounds_memoryDC(void)
5794 {
5795 HDC hdc,dc;
5796 HBITMAP bmp;
5797 HGDIOBJ old;
5798 RECT rect;
5799 POINT pt;
5800 int width = 0;
5801 int height = 0;
5802 GpGraphics* graphics = NULL;
5803 GpRect boundRect;
5804 GpStatus status;
5805
5806 ok(GetClientRect(hwnd, &rect), "GetClientRect should have succeeded\n");
5807 width = rect.right - rect.left;
5808 height = rect.bottom - rect.top;
5809
5810 dc = GetDC(hwnd);
5811 hdc = CreateCompatibleDC ( dc );
5812 bmp = CreateCompatibleBitmap ( dc, width, height );
5813 old = SelectObject (hdc, bmp);
5814
5815 /*change the window origin is the key test point*/
5816 SetWindowOrgEx (hdc, rect.left+10, rect.top+10, &pt);
5817
5818 status = GdipCreateFromHDC(hdc, &graphics);
5819 expect(Ok, status);
5820
5821 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
5822 expect(Ok, status);
5823
5824 ok(boundRect.X==rect.left+10 &&
5825 boundRect.Y==rect.top+10 &&
5826 boundRect.Width==width &&
5827 boundRect.Height==height, "Expected GdipGetVisibleClipBoundsI ok\n");
5828
5829 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
5830 expect(Ok, status);
5831
5832 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
5833 expect(Ok, status);
5834
5835 ok(boundRect.X==rect.left+10 &&
5836 boundRect.Y==rect.top+10 &&
5837 boundRect.Width==width-10 &&
5838 boundRect.Height==height-10, "Expected GdipGetVisibleClipBoundsI ok\n");
5839
5840 GdipDeleteGraphics(graphics);
5841
5842 SelectObject (hdc, old);
5843 DeleteObject (bmp);
5844 DeleteDC (hdc);
5845 ReleaseDC(hwnd, dc);
5846 }
5847
5848 START_TEST(graphics)
5849 {
5850 struct GdiplusStartupInput gdiplusStartupInput;
5851 ULONG_PTR gdiplusToken;
5852 WNDCLASSA class;
5853
5854 memset( &class, 0, sizeof(class) );
5855 class.lpszClassName = "gdiplus_test";
5856 class.style = CS_HREDRAW | CS_VREDRAW;
5857 class.lpfnWndProc = DefWindowProcA;
5858 class.hInstance = GetModuleHandleA(0);
5859 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5860 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5861 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
5862 RegisterClassA( &class );
5863 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5864 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
5865 ok(hwnd != NULL, "Expected window to be created\n");
5866
5867 gdiplusStartupInput.GdiplusVersion = 1;
5868 gdiplusStartupInput.DebugEventCallback = NULL;
5869 gdiplusStartupInput.SuppressBackgroundThread = 0;
5870 gdiplusStartupInput.SuppressExternalCodecs = 0;
5871
5872 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
5873
5874 test_clipping();
5875 test_clipping_2();
5876 test_measured_extra_space();
5877 test_measure_string();
5878 test_font_height_scaling();
5879 test_transform();
5880 test_pen_thickness();
5881 test_GdipMeasureString();
5882 test_constructor_destructor();
5883 test_save_restore();
5884 test_GdipFillClosedCurve2();
5885 test_GdipFillClosedCurve2I();
5886 test_GdipDrawBezierI();
5887 test_GdipDrawArc();
5888 test_GdipDrawArcI();
5889 test_GdipDrawCurve();
5890 test_GdipDrawCurveI();
5891 test_GdipDrawCurve2();
5892 test_GdipDrawCurve2I();
5893 test_GdipDrawCurve3();
5894 test_GdipDrawCurve3I();
5895 test_GdipDrawLineI();
5896 test_GdipDrawLinesI();
5897 test_GdipDrawImagePointsRect();
5898 test_GdipFillClosedCurve();
5899 test_GdipFillClosedCurveI();
5900 test_GdipDrawString();
5901 test_GdipGetNearestColor();
5902 test_GdipGetVisibleClipBounds();
5903 test_GdipIsVisiblePoint();
5904 test_GdipIsVisibleRect();
5905 test_Get_Release_DC();
5906 test_BeginContainer2();
5907 test_transformpoints();
5908 test_get_set_clip();
5909 test_isempty();
5910 test_clear();
5911 test_textcontrast();
5912 test_fromMemoryBitmap();
5913 test_string_functions();
5914 test_get_set_interpolation();
5915 test_get_set_textrenderinghint();
5916 test_getdc_scaled();
5917 test_alpha_hdc();
5918 test_bitmapfromgraphics();
5919 test_GdipFillRectangles();
5920 test_GdipGetVisibleClipBounds_memoryDC();
5921
5922 GdiplusShutdown(gdiplusToken);
5923 DestroyWindow( hwnd );
5924 }