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