gdiplus/tests: Test mixing Begin/EndContainer and Save/Restore.
[wine.git] / dlls / gdiplus / tests / graphics.c
blob4a762ccf28dcce0b9d1135c553c40a3a76d317dd
1 /*
2 * Unit test suite for graphics objects
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <math.h>
24 #include "objbase.h"
25 #include "gdiplus.h"
26 #include "wine/test.h"
28 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
29 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
30 #define expectf(expected, got) expectf_((expected), (got), 0.001)
32 static const REAL mm_per_inch = 25.4;
33 static const REAL point_per_inch = 72.0;
34 static HWND hwnd;
36 static void set_rect_empty(RectF *rc)
38 rc->X = 0.0;
39 rc->Y = 0.0;
40 rc->Width = 0.0;
41 rc->Height = 0.0;
44 /* converts a given unit to its value in pixels */
45 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
47 switch (unit)
49 case UnitPixel:
50 case UnitDisplay:
51 return units;
52 case UnitPoint:
53 return units * dpi / point_per_inch;
54 case UnitInch:
55 return units * dpi;
56 case UnitDocument:
57 return units * dpi / 300.0; /* Per MSDN */
58 case UnitMillimeter:
59 return units * dpi / mm_per_inch;
60 default:
61 ok(0, "Unsupported unit: %d\n", unit);
62 return 0;
66 /* converts value in pixels to a given unit */
67 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
69 switch (unit)
71 case UnitPixel:
72 case UnitDisplay:
73 return pixels;
74 case UnitPoint:
75 return pixels * point_per_inch / dpi;
76 case UnitInch:
77 return pixels / dpi;
78 case UnitDocument:
79 return pixels * 300.0 / dpi;
80 case UnitMillimeter:
81 return pixels * mm_per_inch / dpi;
82 default:
83 ok(0, "Unsupported unit: %d\n", unit);
84 return 0;
88 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
90 REAL pixels = units_to_pixels(1.0, from, dpi);
91 return pixels_to_units(pixels, to, dpi);
94 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale, GpImage **image)
96 GpStatus status;
97 union
99 GpBitmap *bitmap;
100 GpImage *image;
101 } u;
102 GpGraphics *graphics = NULL;
103 REAL res;
105 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
106 expect(Ok, status);
108 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
109 expect(Ok, status);
110 status = GdipGetImageHorizontalResolution(u.image, &res);
111 expect(Ok, status);
112 expectf(res_x, res);
113 status = GdipGetImageVerticalResolution(u.image, &res);
114 expect(Ok, status);
115 expectf(res_y, res);
117 status = GdipGetImageGraphicsContext(u.image, &graphics);
118 expect(Ok, status);
120 *image = u.image;
122 status = GdipGetDpiX(graphics, &res);
123 expect(Ok, status);
124 expectf(res_x, res);
125 status = GdipGetDpiY(graphics, &res);
126 expect(Ok, status);
127 expectf(res_y, res);
129 status = GdipSetPageUnit(graphics, unit);
130 expect(Ok, status);
131 status = GdipSetPageScale(graphics, scale);
132 expect(Ok, status);
134 return graphics;
137 static void test_constructor_destructor(void)
139 GpStatus stat;
140 GpGraphics *graphics = NULL;
141 HDC hdc = GetDC( hwnd );
143 stat = GdipCreateFromHDC(NULL, &graphics);
144 expect(OutOfMemory, stat);
145 stat = GdipDeleteGraphics(graphics);
146 expect(InvalidParameter, stat);
148 stat = GdipCreateFromHDC(hdc, &graphics);
149 expect(Ok, stat);
150 stat = GdipDeleteGraphics(graphics);
151 expect(Ok, stat);
153 stat = GdipCreateFromHWND(NULL, &graphics);
154 expect(Ok, stat);
155 stat = GdipDeleteGraphics(graphics);
156 expect(Ok, stat);
158 stat = GdipCreateFromHWNDICM(NULL, &graphics);
159 expect(Ok, stat);
160 stat = GdipDeleteGraphics(graphics);
161 expect(Ok, stat);
163 stat = GdipDeleteGraphics(NULL);
164 expect(InvalidParameter, stat);
165 ReleaseDC(hwnd, hdc);
168 typedef struct node{
169 GraphicsState data;
170 struct node * next;
171 } node;
173 /* Linked list prepend function. */
174 static void log_state(GraphicsState data, node ** log)
176 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
178 new_entry->data = data;
179 new_entry->next = *log;
180 *log = new_entry;
183 /* Checks if there are duplicates in the list, and frees it. */
184 static void check_no_duplicates(node * log)
186 INT dups = 0;
187 node * temp = NULL;
188 node * temp2 = NULL;
189 node * orig = log;
191 if(!log)
192 goto end;
195 temp = log;
196 while((temp = temp->next)){
197 if(log->data == temp->data){
198 dups++;
199 break;
201 if(dups > 0)
202 break;
204 }while((log = log->next));
206 temp = orig;
208 temp2 = temp->next;
209 HeapFree(GetProcessHeap(), 0, temp);
210 temp = temp2;
211 }while(temp);
213 end:
214 expect(0, dups);
217 static void test_save_restore(void)
219 GpStatus stat;
220 GraphicsState state_a, state_b, state_c;
221 InterpolationMode mode;
222 GpGraphics *graphics1, *graphics2;
223 node * state_log = NULL;
224 HDC hdc = GetDC( hwnd );
225 state_a = state_b = state_c = 0xdeadbeef;
227 /* Invalid saving. */
228 GdipCreateFromHDC(hdc, &graphics1);
229 stat = GdipSaveGraphics(graphics1, NULL);
230 expect(InvalidParameter, stat);
231 stat = GdipSaveGraphics(NULL, &state_a);
232 expect(InvalidParameter, stat);
233 GdipDeleteGraphics(graphics1);
235 log_state(state_a, &state_log);
237 /* Basic save/restore. */
238 GdipCreateFromHDC(hdc, &graphics1);
239 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
240 stat = GdipSaveGraphics(graphics1, &state_a);
241 expect(Ok, stat);
242 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
243 stat = GdipRestoreGraphics(graphics1, state_a);
244 expect(Ok, stat);
245 GdipGetInterpolationMode(graphics1, &mode);
246 expect(InterpolationModeBilinear, mode);
247 GdipDeleteGraphics(graphics1);
249 log_state(state_a, &state_log);
251 /* Restoring garbage doesn't affect saves. */
252 GdipCreateFromHDC(hdc, &graphics1);
253 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
254 GdipSaveGraphics(graphics1, &state_a);
255 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
256 GdipSaveGraphics(graphics1, &state_b);
257 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
258 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
259 expect(Ok, stat);
260 GdipRestoreGraphics(graphics1, state_b);
261 GdipGetInterpolationMode(graphics1, &mode);
262 expect(InterpolationModeBicubic, mode);
263 GdipRestoreGraphics(graphics1, state_a);
264 GdipGetInterpolationMode(graphics1, &mode);
265 expect(InterpolationModeBilinear, mode);
266 GdipDeleteGraphics(graphics1);
268 log_state(state_a, &state_log);
269 log_state(state_b, &state_log);
271 /* Restoring older state invalidates newer saves (but not older saves). */
272 GdipCreateFromHDC(hdc, &graphics1);
273 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
274 GdipSaveGraphics(graphics1, &state_a);
275 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
276 GdipSaveGraphics(graphics1, &state_b);
277 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
278 GdipSaveGraphics(graphics1, &state_c);
279 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
280 GdipRestoreGraphics(graphics1, state_b);
281 GdipGetInterpolationMode(graphics1, &mode);
282 expect(InterpolationModeBicubic, mode);
283 GdipRestoreGraphics(graphics1, state_c);
284 GdipGetInterpolationMode(graphics1, &mode);
285 expect(InterpolationModeBicubic, mode);
286 GdipRestoreGraphics(graphics1, state_a);
287 GdipGetInterpolationMode(graphics1, &mode);
288 expect(InterpolationModeBilinear, mode);
289 GdipDeleteGraphics(graphics1);
291 log_state(state_a, &state_log);
292 log_state(state_b, &state_log);
293 log_state(state_c, &state_log);
295 /* Restoring older save from one graphics object does not invalidate
296 * newer save from other graphics object. */
297 GdipCreateFromHDC(hdc, &graphics1);
298 GdipCreateFromHDC(hdc, &graphics2);
299 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
300 GdipSaveGraphics(graphics1, &state_a);
301 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
302 GdipSaveGraphics(graphics2, &state_b);
303 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
304 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
305 GdipRestoreGraphics(graphics1, state_a);
306 GdipGetInterpolationMode(graphics1, &mode);
307 expect(InterpolationModeBilinear, mode);
308 GdipRestoreGraphics(graphics2, state_b);
309 GdipGetInterpolationMode(graphics2, &mode);
310 expect(InterpolationModeBicubic, mode);
311 GdipDeleteGraphics(graphics1);
312 GdipDeleteGraphics(graphics2);
314 /* You can't restore a state to a graphics object that didn't save it. */
315 GdipCreateFromHDC(hdc, &graphics1);
316 GdipCreateFromHDC(hdc, &graphics2);
317 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
318 GdipSaveGraphics(graphics1, &state_a);
319 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
320 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
321 GdipRestoreGraphics(graphics2, state_a);
322 GdipGetInterpolationMode(graphics2, &mode);
323 expect(InterpolationModeNearestNeighbor, mode);
324 GdipDeleteGraphics(graphics1);
325 GdipDeleteGraphics(graphics2);
327 log_state(state_a, &state_log);
329 /* A state created by SaveGraphics cannot be restored with EndContainer. */
330 GdipCreateFromHDC(hdc, &graphics1);
331 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
332 stat = GdipSaveGraphics(graphics1, &state_a);
333 expect(Ok, stat);
334 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
335 stat = GdipEndContainer(graphics1, state_a);
336 expect(Ok, stat);
337 GdipGetInterpolationMode(graphics1, &mode);
338 todo_wine expect(InterpolationModeBicubic, mode);
339 stat = GdipRestoreGraphics(graphics1, state_a);
340 expect(Ok, stat);
341 GdipGetInterpolationMode(graphics1, &mode);
342 expect(InterpolationModeBilinear, mode);
343 GdipDeleteGraphics(graphics1);
345 log_state(state_a, &state_log);
347 /* A state created by BeginContainer cannot be restored with RestoreGraphics. */
348 GdipCreateFromHDC(hdc, &graphics1);
349 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
350 stat = GdipBeginContainer2(graphics1, &state_a);
351 expect(Ok, stat);
352 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
353 stat = GdipRestoreGraphics(graphics1, state_a);
354 expect(Ok, stat);
355 GdipGetInterpolationMode(graphics1, &mode);
356 todo_wine expect(InterpolationModeBicubic, mode);
357 stat = GdipEndContainer(graphics1, state_a);
358 expect(Ok, stat);
359 GdipGetInterpolationMode(graphics1, &mode);
360 expect(InterpolationModeBilinear, mode);
361 GdipDeleteGraphics(graphics1);
363 log_state(state_a, &state_log);
365 /* BeginContainer and SaveGraphics use the same stack. */
366 GdipCreateFromHDC(hdc, &graphics1);
367 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
368 stat = GdipBeginContainer2(graphics1, &state_a);
369 expect(Ok, stat);
370 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
371 stat = GdipSaveGraphics(graphics1, &state_b);
372 expect(Ok, stat);
373 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
374 stat = GdipEndContainer(graphics1, state_a);
375 expect(Ok, stat);
376 GdipGetInterpolationMode(graphics1, &mode);
377 expect(InterpolationModeBilinear, mode);
378 stat = GdipRestoreGraphics(graphics1, state_b);
379 expect(Ok, stat);
380 GdipGetInterpolationMode(graphics1, &mode);
381 expect(InterpolationModeBilinear, mode);
382 GdipDeleteGraphics(graphics1);
384 log_state(state_a, &state_log);
385 log_state(state_b, &state_log);
387 /* The same state value should never be returned twice. */
388 todo_wine
389 check_no_duplicates(state_log);
391 ReleaseDC(hwnd, hdc);
394 static void test_GdipFillClosedCurve2(void)
396 GpStatus status;
397 GpGraphics *graphics = NULL;
398 GpSolidFill *brush = NULL;
399 HDC hdc = GetDC( hwnd );
400 GpPointF points[3];
402 points[0].X = 0;
403 points[0].Y = 0;
405 points[1].X = 40;
406 points[1].Y = 20;
408 points[2].X = 10;
409 points[2].Y = 40;
411 /* make a graphics object and brush object */
412 ok(hdc != NULL, "Expected HDC to be initialized\n");
414 status = GdipCreateFromHDC(hdc, &graphics);
415 expect(Ok, status);
416 ok(graphics != NULL, "Expected graphics to be initialized\n");
418 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
420 /* InvalidParameter cases: null graphics, null brush, null points */
421 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
422 expect(InvalidParameter, status);
424 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
425 expect(InvalidParameter, status);
427 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
428 expect(InvalidParameter, status);
430 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
431 expect(InvalidParameter, status);
433 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
434 expect(InvalidParameter, status);
436 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
437 expect(InvalidParameter, status);
439 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
440 expect(InvalidParameter, status);
442 /* InvalidParameter cases: invalid count */
443 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
444 expect(InvalidParameter, status);
446 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
447 expect(InvalidParameter, status);
449 /* Valid test cases */
450 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
451 expect(Ok, status);
453 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
454 expect(Ok, status);
456 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
457 expect(Ok, status);
459 GdipDeleteGraphics(graphics);
460 GdipDeleteBrush((GpBrush*)brush);
462 ReleaseDC(hwnd, hdc);
465 static void test_GdipFillClosedCurve2I(void)
467 GpStatus status;
468 GpGraphics *graphics = NULL;
469 GpSolidFill *brush = NULL;
470 HDC hdc = GetDC( hwnd );
471 GpPoint points[3];
473 points[0].X = 0;
474 points[0].Y = 0;
476 points[1].X = 40;
477 points[1].Y = 20;
479 points[2].X = 10;
480 points[2].Y = 40;
482 /* make a graphics object and brush object */
483 ok(hdc != NULL, "Expected HDC to be initialized\n");
485 status = GdipCreateFromHDC(hdc, &graphics);
486 expect(Ok, status);
487 ok(graphics != NULL, "Expected graphics to be initialized\n");
489 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
491 /* InvalidParameter cases: null graphics, null brush */
492 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
493 when points == NULL, so don't test this condition */
494 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
495 expect(InvalidParameter, status);
497 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
498 expect(InvalidParameter, status);
500 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
501 expect(InvalidParameter, status);
503 /* InvalidParameter cases: invalid count */
504 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
505 expect(InvalidParameter, status);
507 /* OutOfMemory cases: large (unsigned) int */
508 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
509 expect(OutOfMemory, status);
511 /* Valid test cases */
512 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
513 expect(Ok, status);
515 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
516 expect(Ok, status);
518 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
519 expect(Ok, status);
521 GdipDeleteGraphics(graphics);
522 GdipDeleteBrush((GpBrush*)brush);
524 ReleaseDC(hwnd, hdc);
527 static void test_GdipDrawArc(void)
529 GpStatus status;
530 GpGraphics *graphics = NULL;
531 GpPen *pen = NULL;
532 HDC hdc = GetDC( hwnd );
534 /* make a graphics object and pen object */
535 ok(hdc != NULL, "Expected HDC to be initialized\n");
537 status = GdipCreateFromHDC(hdc, &graphics);
538 expect(Ok, status);
539 ok(graphics != NULL, "Expected graphics to be initialized\n");
541 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
542 expect(Ok, status);
543 ok(pen != NULL, "Expected pen to be initialized\n");
545 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
546 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
547 expect(InvalidParameter, status);
549 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
550 expect(InvalidParameter, status);
552 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
553 expect(InvalidParameter, status);
555 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
556 expect(InvalidParameter, status);
558 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
559 expect(InvalidParameter, status);
561 /* successful case */
562 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
563 expect(Ok, status);
565 GdipDeletePen(pen);
566 GdipDeleteGraphics(graphics);
568 ReleaseDC(hwnd, hdc);
571 static void test_GdipDrawArcI(void)
573 GpStatus status;
574 GpGraphics *graphics = NULL;
575 GpPen *pen = NULL;
576 HDC hdc = GetDC( hwnd );
578 /* make a graphics object and pen object */
579 ok(hdc != NULL, "Expected HDC to be initialized\n");
581 status = GdipCreateFromHDC(hdc, &graphics);
582 expect(Ok, status);
583 ok(graphics != NULL, "Expected graphics to be initialized\n");
585 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
586 expect(Ok, status);
587 ok(pen != NULL, "Expected pen to be initialized\n");
589 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
590 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
591 expect(InvalidParameter, status);
593 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
594 expect(InvalidParameter, status);
596 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
597 expect(InvalidParameter, status);
599 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
600 expect(InvalidParameter, status);
602 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
603 expect(InvalidParameter, status);
605 /* successful case */
606 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
607 expect(Ok, status);
609 GdipDeletePen(pen);
610 GdipDeleteGraphics(graphics);
612 ReleaseDC(hwnd, hdc);
615 static void test_BeginContainer2(void)
617 GpMatrix *transform;
618 GpRectF clip;
619 REAL defClip[] = {5, 10, 15, 20};
620 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
621 GraphicsContainer cont1, cont2, cont3, cont4;
622 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
623 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
624 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
625 REAL scale, defScale = 17;
626 GpUnit unit, defUnit = UnitPixel;
627 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
628 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
629 UINT contrast, defContrast = 5;
630 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
632 GpStatus status;
633 GpGraphics *graphics = NULL;
634 HDC hdc = GetDC( hwnd );
636 ok(hdc != NULL, "Expected HDC to be initialized\n");
638 status = GdipCreateFromHDC(hdc, &graphics);
639 expect(Ok, status);
640 ok(graphics != NULL, "Expected graphics to be initialized\n");
642 /* null graphics, null container */
643 status = GdipBeginContainer2(NULL, &cont1);
644 expect(InvalidParameter, status);
646 status = GdipBeginContainer2(graphics, NULL);
647 expect(InvalidParameter, status);
649 status = GdipEndContainer(NULL, cont1);
650 expect(InvalidParameter, status);
652 /* test all quality-related values */
653 GdipSetCompositingMode(graphics, defCompmode);
654 GdipSetCompositingQuality(graphics, defCompqual);
655 GdipSetInterpolationMode(graphics, defInterp);
656 GdipSetPageScale(graphics, defScale);
657 GdipSetPageUnit(graphics, defUnit);
658 GdipSetPixelOffsetMode(graphics, defOffsetmode);
659 GdipSetSmoothingMode(graphics, defSmoothmode);
660 GdipSetTextContrast(graphics, defContrast);
661 GdipSetTextRenderingHint(graphics, defTexthint);
663 status = GdipBeginContainer2(graphics, &cont1);
664 expect(Ok, status);
666 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
667 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
668 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
669 GdipSetPageScale(graphics, 10);
670 GdipSetPageUnit(graphics, UnitDocument);
671 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
672 GdipSetSmoothingMode(graphics, SmoothingModeNone);
673 GdipSetTextContrast(graphics, 7);
674 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
676 status = GdipEndContainer(graphics, cont1);
677 expect(Ok, status);
679 GdipGetCompositingMode(graphics, &compmode);
680 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
682 GdipGetCompositingQuality(graphics, &compqual);
683 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
685 GdipGetInterpolationMode(graphics, &interp);
686 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
688 GdipGetPageScale(graphics, &scale);
689 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
691 GdipGetPageUnit(graphics, &unit);
692 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
694 GdipGetPixelOffsetMode(graphics, &offsetmode);
695 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
697 GdipGetSmoothingMode(graphics, &smoothmode);
698 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
700 GdipGetTextContrast(graphics, &contrast);
701 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
703 GdipGetTextRenderingHint(graphics, &texthint);
704 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
706 /* test world transform */
707 status = GdipBeginContainer2(graphics, &cont1);
708 expect(Ok, status);
710 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
711 defTrans[4], defTrans[5], &transform);
712 expect(Ok, status);
713 GdipSetWorldTransform(graphics, transform);
714 GdipDeleteMatrix(transform);
715 transform = NULL;
717 status = GdipBeginContainer2(graphics, &cont2);
718 expect(Ok, status);
720 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
721 expect(Ok, status);
722 GdipSetWorldTransform(graphics, transform);
723 GdipDeleteMatrix(transform);
724 transform = NULL;
726 status = GdipEndContainer(graphics, cont2);
727 expect(Ok, status);
729 status = GdipCreateMatrix(&transform);
730 expect(Ok, status);
731 GdipGetWorldTransform(graphics, transform);
732 GdipGetMatrixElements(transform, elems);
733 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
734 fabs(defTrans[1] - elems[1]) < 0.0001 &&
735 fabs(defTrans[2] - elems[2]) < 0.0001 &&
736 fabs(defTrans[3] - elems[3]) < 0.0001 &&
737 fabs(defTrans[4] - elems[4]) < 0.0001 &&
738 fabs(defTrans[5] - elems[5]) < 0.0001,
739 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
740 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
741 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
742 GdipDeleteMatrix(transform);
743 transform = NULL;
745 status = GdipEndContainer(graphics, cont1);
746 expect(Ok, status);
748 /* test clipping */
749 status = GdipBeginContainer2(graphics, &cont1);
750 expect(Ok, status);
752 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
754 status = GdipBeginContainer2(graphics, &cont2);
755 expect(Ok, status);
757 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
759 status = GdipEndContainer(graphics, cont2);
760 expect(Ok, status);
762 status = GdipGetClipBounds(graphics, &clip);
763 expect(Ok, status);
765 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
766 fabs(defClip[1] - clip.Y) < 0.0001 &&
767 fabs(defClip[2] - clip.Width) < 0.0001 &&
768 fabs(defClip[3] - clip.Height) < 0.0001,
769 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
770 defClip[0], defClip[1], defClip[2], defClip[3],
771 clip.X, clip.Y, clip.Width, clip.Height);
773 status = GdipEndContainer(graphics, cont1);
774 expect(Ok, status);
776 /* nesting */
777 status = GdipBeginContainer2(graphics, &cont1);
778 expect(Ok, status);
780 status = GdipBeginContainer2(graphics, &cont2);
781 expect(Ok, status);
783 status = GdipBeginContainer2(graphics, &cont3);
784 expect(Ok, status);
786 status = GdipEndContainer(graphics, cont3);
787 expect(Ok, status);
789 status = GdipBeginContainer2(graphics, &cont4);
790 expect(Ok, status);
792 status = GdipEndContainer(graphics, cont4);
793 expect(Ok, status);
795 /* skip cont2 */
796 status = GdipEndContainer(graphics, cont1);
797 expect(Ok, status);
799 /* end an already-ended container */
800 status = GdipEndContainer(graphics, cont1);
801 expect(Ok, status);
803 GdipDeleteGraphics(graphics);
804 ReleaseDC(hwnd, hdc);
807 static void test_GdipDrawBezierI(void)
809 GpStatus status;
810 GpGraphics *graphics = NULL;
811 GpPen *pen = NULL;
812 HDC hdc = GetDC( hwnd );
814 /* make a graphics object and pen object */
815 ok(hdc != NULL, "Expected HDC to be initialized\n");
817 status = GdipCreateFromHDC(hdc, &graphics);
818 expect(Ok, status);
819 ok(graphics != NULL, "Expected graphics to be initialized\n");
821 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
822 expect(Ok, status);
823 ok(pen != NULL, "Expected pen to be initialized\n");
825 /* InvalidParameter cases: null graphics, null pen */
826 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
827 expect(InvalidParameter, status);
829 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
830 expect(InvalidParameter, status);
832 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
833 expect(InvalidParameter, status);
835 /* successful case */
836 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
837 expect(Ok, status);
839 GdipDeletePen(pen);
840 GdipDeleteGraphics(graphics);
842 ReleaseDC(hwnd, hdc);
845 static void test_GdipDrawCurve3(void)
847 GpStatus status;
848 GpGraphics *graphics = NULL;
849 GpPen *pen = NULL;
850 HDC hdc = GetDC( hwnd );
851 GpPointF points[3];
853 points[0].X = 0;
854 points[0].Y = 0;
856 points[1].X = 40;
857 points[1].Y = 20;
859 points[2].X = 10;
860 points[2].Y = 40;
862 /* make a graphics object and pen object */
863 ok(hdc != NULL, "Expected HDC to be initialized\n");
865 status = GdipCreateFromHDC(hdc, &graphics);
866 expect(Ok, status);
867 ok(graphics != NULL, "Expected graphics to be initialized\n");
869 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
870 expect(Ok, status);
871 ok(pen != NULL, "Expected pen to be initialized\n");
873 /* InvalidParameter cases: null graphics, null pen */
874 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
875 expect(InvalidParameter, status);
877 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
878 expect(InvalidParameter, status);
880 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
881 expect(InvalidParameter, status);
883 /* InvalidParameter cases: invalid count */
884 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
885 expect(InvalidParameter, status);
887 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
888 expect(InvalidParameter, status);
890 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
891 expect(InvalidParameter, status);
893 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
894 expect(InvalidParameter, status);
896 /* InvalidParameter cases: invalid number of segments */
897 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
898 expect(InvalidParameter, status);
900 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
901 expect(InvalidParameter, status);
903 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
904 expect(InvalidParameter, status);
906 /* Valid test cases */
907 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
908 expect(Ok, status);
910 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
911 expect(Ok, status);
913 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
914 expect(Ok, status);
916 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
917 expect(Ok, status);
919 GdipDeletePen(pen);
920 GdipDeleteGraphics(graphics);
922 ReleaseDC(hwnd, hdc);
925 static void test_GdipDrawCurve3I(void)
927 GpStatus status;
928 GpGraphics *graphics = NULL;
929 GpPen *pen = NULL;
930 HDC hdc = GetDC( hwnd );
931 GpPoint points[3];
933 points[0].X = 0;
934 points[0].Y = 0;
936 points[1].X = 40;
937 points[1].Y = 20;
939 points[2].X = 10;
940 points[2].Y = 40;
942 /* make a graphics object and pen object */
943 ok(hdc != NULL, "Expected HDC to be initialized\n");
945 status = GdipCreateFromHDC(hdc, &graphics);
946 expect(Ok, status);
947 ok(graphics != NULL, "Expected graphics to be initialized\n");
949 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
950 expect(Ok, status);
951 ok(pen != NULL, "Expected pen to be initialized\n");
953 /* InvalidParameter cases: null graphics, null pen */
954 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
955 expect(InvalidParameter, status);
957 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
958 expect(InvalidParameter, status);
960 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
961 expect(InvalidParameter, status);
963 /* InvalidParameter cases: invalid count */
964 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
965 expect(OutOfMemory, status);
967 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
968 expect(InvalidParameter, status);
970 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
971 expect(InvalidParameter, status);
973 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
974 expect(InvalidParameter, status);
976 /* InvalidParameter cases: invalid number of segments */
977 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
978 expect(InvalidParameter, status);
980 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
981 expect(InvalidParameter, status);
983 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
984 expect(InvalidParameter, status);
986 /* Valid test cases */
987 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
988 expect(Ok, status);
990 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
991 expect(Ok, status);
993 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
994 expect(Ok, status);
996 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
997 expect(Ok, status);
999 GdipDeletePen(pen);
1000 GdipDeleteGraphics(graphics);
1002 ReleaseDC(hwnd, hdc);
1005 static void test_GdipDrawCurve2(void)
1007 GpStatus status;
1008 GpGraphics *graphics = NULL;
1009 GpPen *pen = NULL;
1010 HDC hdc = GetDC( hwnd );
1011 GpPointF points[3];
1013 points[0].X = 0;
1014 points[0].Y = 0;
1016 points[1].X = 40;
1017 points[1].Y = 20;
1019 points[2].X = 10;
1020 points[2].Y = 40;
1022 /* make a graphics object and pen object */
1023 ok(hdc != NULL, "Expected HDC to be initialized\n");
1025 status = GdipCreateFromHDC(hdc, &graphics);
1026 expect(Ok, status);
1027 ok(graphics != NULL, "Expected graphics to be initialized\n");
1029 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1030 expect(Ok, status);
1031 ok(pen != NULL, "Expected pen to be initialized\n");
1033 /* InvalidParameter cases: null graphics, null pen */
1034 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
1035 expect(InvalidParameter, status);
1037 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
1038 expect(InvalidParameter, status);
1040 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
1041 expect(InvalidParameter, status);
1043 /* InvalidParameter cases: invalid count */
1044 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
1045 expect(InvalidParameter, status);
1047 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
1048 expect(InvalidParameter, status);
1050 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
1051 expect(InvalidParameter, status);
1053 /* Valid test cases */
1054 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1055 expect(Ok, status);
1057 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1058 expect(Ok, status);
1060 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1061 expect(Ok, status);
1063 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1064 expect(Ok, status);
1066 GdipDeletePen(pen);
1067 GdipDeleteGraphics(graphics);
1069 ReleaseDC(hwnd, hdc);
1072 static void test_GdipDrawCurve2I(void)
1074 GpStatus status;
1075 GpGraphics *graphics = NULL;
1076 GpPen *pen = NULL;
1077 HDC hdc = GetDC( hwnd );
1078 GpPoint points[3];
1080 points[0].X = 0;
1081 points[0].Y = 0;
1083 points[1].X = 40;
1084 points[1].Y = 20;
1086 points[2].X = 10;
1087 points[2].Y = 40;
1089 /* make a graphics object and pen object */
1090 ok(hdc != NULL, "Expected HDC to be initialized\n");
1092 status = GdipCreateFromHDC(hdc, &graphics);
1093 expect(Ok, status);
1094 ok(graphics != NULL, "Expected graphics to be initialized\n");
1096 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1097 expect(Ok, status);
1098 ok(pen != NULL, "Expected pen to be initialized\n");
1100 /* InvalidParameter cases: null graphics, null pen */
1101 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1102 expect(InvalidParameter, status);
1104 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1105 expect(InvalidParameter, status);
1107 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1108 expect(InvalidParameter, status);
1110 /* InvalidParameter cases: invalid count */
1111 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1112 expect(OutOfMemory, status);
1114 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1115 expect(InvalidParameter, status);
1117 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1118 expect(InvalidParameter, status);
1120 /* Valid test cases */
1121 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1122 expect(Ok, status);
1124 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1125 expect(Ok, status);
1127 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1128 expect(Ok, status);
1130 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1131 expect(Ok, status);
1133 GdipDeletePen(pen);
1134 GdipDeleteGraphics(graphics);
1136 ReleaseDC(hwnd, hdc);
1139 static void test_GdipDrawCurve(void)
1141 GpStatus status;
1142 GpGraphics *graphics = NULL;
1143 GpPen *pen = NULL;
1144 HDC hdc = GetDC( hwnd );
1145 GpPointF points[3];
1147 points[0].X = 0;
1148 points[0].Y = 0;
1150 points[1].X = 40;
1151 points[1].Y = 20;
1153 points[2].X = 10;
1154 points[2].Y = 40;
1156 /* make a graphics object and pen object */
1157 ok(hdc != NULL, "Expected HDC to be initialized\n");
1159 status = GdipCreateFromHDC(hdc, &graphics);
1160 expect(Ok, status);
1161 ok(graphics != NULL, "Expected graphics to be initialized\n");
1163 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1164 expect(Ok, status);
1165 ok(pen != NULL, "Expected pen to be initialized\n");
1167 /* InvalidParameter cases: null graphics, null pen */
1168 status = GdipDrawCurve(NULL, NULL, points, 3);
1169 expect(InvalidParameter, status);
1171 status = GdipDrawCurve(graphics, NULL, points, 3);
1172 expect(InvalidParameter, status);
1174 status = GdipDrawCurve(NULL, pen, points, 3);
1175 expect(InvalidParameter, status);
1177 /* InvalidParameter cases: invalid count */
1178 status = GdipDrawCurve(graphics, pen, points, -1);
1179 expect(InvalidParameter, status);
1181 status = GdipDrawCurve(graphics, pen, points, 0);
1182 expect(InvalidParameter, status);
1184 status = GdipDrawCurve(graphics, pen, points, 1);
1185 expect(InvalidParameter, status);
1187 /* Valid test cases */
1188 status = GdipDrawCurve(graphics, pen, points, 2);
1189 expect(Ok, status);
1191 status = GdipDrawCurve(graphics, pen, points, 3);
1192 expect(Ok, status);
1194 GdipDeletePen(pen);
1195 GdipDeleteGraphics(graphics);
1197 ReleaseDC(hwnd, hdc);
1200 static void test_GdipDrawCurveI(void)
1202 GpStatus status;
1203 GpGraphics *graphics = NULL;
1204 GpPen *pen = NULL;
1205 HDC hdc = GetDC( hwnd );
1206 GpPoint points[3];
1208 points[0].X = 0;
1209 points[0].Y = 0;
1211 points[1].X = 40;
1212 points[1].Y = 20;
1214 points[2].X = 10;
1215 points[2].Y = 40;
1217 /* make a graphics object and pen object */
1218 ok(hdc != NULL, "Expected HDC to be initialized\n");
1220 status = GdipCreateFromHDC(hdc, &graphics);
1221 expect(Ok, status);
1222 ok(graphics != NULL, "Expected graphics to be initialized\n");
1224 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1225 expect(Ok, status);
1226 ok(pen != NULL, "Expected pen to be initialized\n");
1228 /* InvalidParameter cases: null graphics, null pen */
1229 status = GdipDrawCurveI(NULL, NULL, points, 3);
1230 expect(InvalidParameter, status);
1232 status = GdipDrawCurveI(graphics, NULL, points, 3);
1233 expect(InvalidParameter, status);
1235 status = GdipDrawCurveI(NULL, pen, points, 3);
1236 expect(InvalidParameter, status);
1238 /* InvalidParameter cases: invalid count */
1239 status = GdipDrawCurveI(graphics, pen, points, -1);
1240 expect(OutOfMemory, status);
1242 status = GdipDrawCurveI(graphics, pen, points, 0);
1243 expect(InvalidParameter, status);
1245 status = GdipDrawCurveI(graphics, pen, points, 1);
1246 expect(InvalidParameter, status);
1248 /* Valid test cases */
1249 status = GdipDrawCurveI(graphics, pen, points, 2);
1250 expect(Ok, status);
1252 status = GdipDrawCurveI(graphics, pen, points, 3);
1253 expect(Ok, status);
1255 GdipDeletePen(pen);
1256 GdipDeleteGraphics(graphics);
1258 ReleaseDC(hwnd, hdc);
1261 static void test_GdipDrawLineI(void)
1263 GpStatus status;
1264 GpGraphics *graphics = NULL;
1265 GpPen *pen = NULL;
1266 HDC hdc = GetDC( hwnd );
1268 /* make a graphics object and pen object */
1269 ok(hdc != NULL, "Expected HDC to be initialized\n");
1271 status = GdipCreateFromHDC(hdc, &graphics);
1272 expect(Ok, status);
1273 ok(graphics != NULL, "Expected graphics to be initialized\n");
1275 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1276 expect(Ok, status);
1277 ok(pen != NULL, "Expected pen to be initialized\n");
1279 /* InvalidParameter cases: null graphics, null pen */
1280 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1281 expect(InvalidParameter, status);
1283 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1284 expect(InvalidParameter, status);
1286 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1287 expect(InvalidParameter, status);
1289 /* successful case */
1290 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1291 expect(Ok, status);
1293 GdipDeletePen(pen);
1294 GdipDeleteGraphics(graphics);
1296 ReleaseDC(hwnd, hdc);
1299 static void test_GdipDrawImagePointsRect(void)
1301 GpStatus status;
1302 GpGraphics *graphics = NULL;
1303 GpPointF ptf[4];
1304 GpBitmap *bm = NULL;
1305 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1306 BYTE buff[400];
1307 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1308 HDC hdc = GetDC( hwnd );
1309 if (!hdc)
1310 return;
1312 memset(rbmi, 0, sizeof(rbmi));
1313 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1314 bmi->bmiHeader.biWidth = 10;
1315 bmi->bmiHeader.biHeight = 10;
1316 bmi->bmiHeader.biPlanes = 1;
1317 bmi->bmiHeader.biBitCount = 32;
1318 bmi->bmiHeader.biCompression = BI_RGB;
1319 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1320 expect(Ok, status);
1321 ok(NULL != bm, "Expected bitmap to be initialized\n");
1322 status = GdipCreateFromHDC(hdc, &graphics);
1323 expect(Ok, status);
1324 ptf[0].X = 0;
1325 ptf[0].Y = 0;
1326 ptf[1].X = 10;
1327 ptf[1].Y = 0;
1328 ptf[2].X = 0;
1329 ptf[2].Y = 10;
1330 ptf[3].X = 10;
1331 ptf[3].Y = 10;
1332 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1333 expect(NotImplemented, status);
1334 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1335 expect(InvalidParameter, status);
1336 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1337 expect(Ok, status);
1338 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1339 expect(InvalidParameter, status);
1340 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1341 expect(InvalidParameter, status);
1342 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1343 expect(Ok, status);
1344 memset(ptf, 0, sizeof(ptf));
1345 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1346 expect(Ok, status);
1348 GdipDisposeImage((GpImage*)bm);
1349 GdipDeleteGraphics(graphics);
1350 ReleaseDC(hwnd, hdc);
1353 static void test_GdipDrawLinesI(void)
1355 GpStatus status;
1356 GpGraphics *graphics = NULL;
1357 GpPen *pen = NULL;
1358 GpPoint *ptf = NULL;
1359 HDC hdc = GetDC( hwnd );
1361 /* make a graphics object and pen object */
1362 ok(hdc != NULL, "Expected HDC to be initialized\n");
1364 status = GdipCreateFromHDC(hdc, &graphics);
1365 expect(Ok, status);
1366 ok(graphics != NULL, "Expected graphics to be initialized\n");
1368 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1369 expect(Ok, status);
1370 ok(pen != NULL, "Expected pen to be initialized\n");
1372 /* make some arbitrary valid points*/
1373 ptf = GdipAlloc(2 * sizeof(GpPointF));
1375 ptf[0].X = 1;
1376 ptf[0].Y = 1;
1378 ptf[1].X = 2;
1379 ptf[1].Y = 2;
1381 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1382 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1383 expect(InvalidParameter, status);
1385 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1386 expect(InvalidParameter, status);
1388 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1389 expect(InvalidParameter, status);
1391 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1392 expect(InvalidParameter, status);
1394 /* successful case */
1395 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1396 expect(Ok, status);
1398 GdipFree(ptf);
1399 GdipDeletePen(pen);
1400 GdipDeleteGraphics(graphics);
1402 ReleaseDC(hwnd, hdc);
1405 static void test_GdipFillClosedCurve(void)
1407 GpStatus status;
1408 GpGraphics *graphics = NULL;
1409 GpSolidFill *brush = NULL;
1410 HDC hdc = GetDC( hwnd );
1411 GpPointF points[3];
1413 points[0].X = 0;
1414 points[0].Y = 0;
1416 points[1].X = 40;
1417 points[1].Y = 20;
1419 points[2].X = 10;
1420 points[2].Y = 40;
1422 /* make a graphics object and brush object */
1423 ok(hdc != NULL, "Expected HDC to be initialized\n");
1425 status = GdipCreateFromHDC(hdc, &graphics);
1426 expect(Ok, status);
1427 ok(graphics != NULL, "Expected graphics to be initialized\n");
1429 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1431 /* InvalidParameter cases: null graphics, null brush, null points */
1432 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1433 expect(InvalidParameter, status);
1435 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1436 expect(InvalidParameter, status);
1438 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1439 expect(InvalidParameter, status);
1441 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1442 expect(InvalidParameter, status);
1444 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1445 expect(InvalidParameter, status);
1447 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1448 expect(InvalidParameter, status);
1450 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1451 expect(InvalidParameter, status);
1453 /* InvalidParameter cases: invalid count */
1454 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1455 expect(InvalidParameter, status);
1457 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1458 expect(InvalidParameter, status);
1460 /* Valid test cases */
1461 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1462 expect(Ok, status);
1464 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1465 expect(Ok, status);
1467 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1468 expect(Ok, status);
1470 GdipDeleteGraphics(graphics);
1471 GdipDeleteBrush((GpBrush*)brush);
1473 ReleaseDC(hwnd, hdc);
1476 static void test_GdipFillClosedCurveI(void)
1478 GpStatus status;
1479 GpGraphics *graphics = NULL;
1480 GpSolidFill *brush = NULL;
1481 HDC hdc = GetDC( hwnd );
1482 GpPoint points[3];
1484 points[0].X = 0;
1485 points[0].Y = 0;
1487 points[1].X = 40;
1488 points[1].Y = 20;
1490 points[2].X = 10;
1491 points[2].Y = 40;
1493 /* make a graphics object and brush object */
1494 ok(hdc != NULL, "Expected HDC to be initialized\n");
1496 status = GdipCreateFromHDC(hdc, &graphics);
1497 expect(Ok, status);
1498 ok(graphics != NULL, "Expected graphics to be initialized\n");
1500 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1502 /* InvalidParameter cases: null graphics, null brush */
1503 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1504 when points == NULL, so don't test this condition */
1505 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1506 expect(InvalidParameter, status);
1508 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1509 expect(InvalidParameter, status);
1511 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1512 expect(InvalidParameter, status);
1514 /* InvalidParameter cases: invalid count */
1515 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1516 expect(InvalidParameter, status);
1518 /* OutOfMemory cases: large (unsigned) int */
1519 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1520 expect(OutOfMemory, status);
1522 /* Valid test cases */
1523 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1524 expect(Ok, status);
1526 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1527 expect(Ok, status);
1529 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1530 expect(Ok, status);
1532 GdipDeleteGraphics(graphics);
1533 GdipDeleteBrush((GpBrush*)brush);
1535 ReleaseDC(hwnd, hdc);
1538 static void test_Get_Release_DC(void)
1540 GpStatus status;
1541 GpGraphics *graphics = NULL;
1542 GpPen *pen;
1543 GpSolidFill *brush;
1544 GpPath *path;
1545 HDC hdc = GetDC( hwnd );
1546 HDC retdc;
1547 REAL r;
1548 CompositingQuality quality;
1549 CompositingMode compmode;
1550 InterpolationMode intmode;
1551 GpMatrix *m;
1552 GpRegion *region;
1553 GpUnit unit;
1554 PixelOffsetMode offsetmode;
1555 SmoothingMode smoothmode;
1556 TextRenderingHint texthint;
1557 GpPointF ptf[5];
1558 GpPoint pt[5];
1559 GpRectF rectf[2];
1560 GpRect rect[2];
1561 GpRegion *clip;
1562 INT i;
1563 BOOL res;
1564 ARGB color = 0x00000000;
1565 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1567 pt[0].X = 10;
1568 pt[0].Y = 10;
1569 pt[1].X = 20;
1570 pt[1].Y = 15;
1571 pt[2].X = 40;
1572 pt[2].Y = 80;
1573 pt[3].X = -20;
1574 pt[3].Y = 20;
1575 pt[4].X = 50;
1576 pt[4].Y = 110;
1578 for(i = 0; i < 5;i++){
1579 ptf[i].X = (REAL)pt[i].X;
1580 ptf[i].Y = (REAL)pt[i].Y;
1583 rect[0].X = 0;
1584 rect[0].Y = 0;
1585 rect[0].Width = 50;
1586 rect[0].Height = 70;
1587 rect[1].X = 0;
1588 rect[1].Y = 0;
1589 rect[1].Width = 10;
1590 rect[1].Height = 20;
1592 for(i = 0; i < 2;i++){
1593 rectf[i].X = (REAL)rect[i].X;
1594 rectf[i].Y = (REAL)rect[i].Y;
1595 rectf[i].Height = (REAL)rect[i].Height;
1596 rectf[i].Width = (REAL)rect[i].Width;
1599 status = GdipCreateMatrix(&m);
1600 expect(Ok, status);
1601 GdipCreateRegion(&region);
1602 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1603 GdipCreatePath(FillModeAlternate, &path);
1604 GdipCreateRegion(&clip);
1606 status = GdipCreateFromHDC(hdc, &graphics);
1607 expect(Ok, status);
1608 ok(graphics != NULL, "Expected graphics to be initialized\n");
1609 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1610 expect(Ok, status);
1612 /* NULL arguments */
1613 status = GdipGetDC(NULL, NULL);
1614 expect(InvalidParameter, status);
1615 status = GdipGetDC(graphics, NULL);
1616 expect(InvalidParameter, status);
1617 status = GdipGetDC(NULL, &retdc);
1618 expect(InvalidParameter, status);
1620 status = GdipReleaseDC(NULL, NULL);
1621 expect(InvalidParameter, status);
1622 status = GdipReleaseDC(graphics, NULL);
1623 expect(InvalidParameter, status);
1624 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1625 expect(InvalidParameter, status);
1627 /* Release without Get */
1628 status = GdipReleaseDC(graphics, hdc);
1629 expect(InvalidParameter, status);
1631 retdc = NULL;
1632 status = GdipGetDC(graphics, &retdc);
1633 expect(Ok, status);
1634 ok(retdc == hdc, "Invalid HDC returned\n");
1635 /* call it once more */
1636 status = GdipGetDC(graphics, &retdc);
1637 expect(ObjectBusy, status);
1639 /* try all Graphics calls here */
1640 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1641 expect(ObjectBusy, status);
1642 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1643 expect(ObjectBusy, status);
1644 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1645 expect(ObjectBusy, status);
1646 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1647 expect(ObjectBusy, status);
1648 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1649 expect(ObjectBusy, status);
1650 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1651 expect(ObjectBusy, status);
1652 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1653 expect(ObjectBusy, status);
1654 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1655 expect(ObjectBusy, status);
1656 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1657 expect(ObjectBusy, status);
1658 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1659 expect(ObjectBusy, status);
1660 status = GdipDrawCurve(graphics, pen, ptf, 5);
1661 expect(ObjectBusy, status);
1662 status = GdipDrawCurveI(graphics, pen, pt, 5);
1663 expect(ObjectBusy, status);
1664 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1665 expect(ObjectBusy, status);
1666 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1667 expect(ObjectBusy, status);
1668 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1669 expect(ObjectBusy, status);
1670 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1671 expect(ObjectBusy, status);
1672 /* GdipDrawImage/GdipDrawImageI */
1673 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1674 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1675 /* GdipDrawImageRect/GdipDrawImageRectI */
1676 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1677 expect(ObjectBusy, status);
1678 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1679 expect(ObjectBusy, status);
1680 status = GdipDrawLines(graphics, pen, ptf, 5);
1681 expect(ObjectBusy, status);
1682 status = GdipDrawLinesI(graphics, pen, pt, 5);
1683 expect(ObjectBusy, status);
1684 status = GdipDrawPath(graphics, pen, path);
1685 expect(ObjectBusy, status);
1686 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1687 expect(ObjectBusy, status);
1688 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1689 expect(ObjectBusy, status);
1690 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1691 expect(ObjectBusy, status);
1692 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1693 expect(ObjectBusy, status);
1694 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1695 expect(ObjectBusy, status);
1696 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1697 expect(ObjectBusy, status);
1698 /* GdipDrawString */
1699 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1700 expect(ObjectBusy, status);
1701 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1702 expect(ObjectBusy, status);
1703 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1704 expect(ObjectBusy, status);
1705 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1706 expect(ObjectBusy, status);
1707 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1708 expect(ObjectBusy, status);
1709 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1710 expect(ObjectBusy, status);
1711 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1712 expect(ObjectBusy, status);
1713 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1714 expect(ObjectBusy, status);
1715 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1716 expect(ObjectBusy, status);
1717 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1718 expect(ObjectBusy, status);
1719 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1720 expect(ObjectBusy, status);
1721 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1722 expect(ObjectBusy, status);
1723 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1724 expect(ObjectBusy, status);
1725 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1726 expect(ObjectBusy, status);
1727 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1728 expect(ObjectBusy, status);
1729 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1730 expect(ObjectBusy, status);
1731 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1732 expect(ObjectBusy, status);
1733 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1734 expect(ObjectBusy, status);
1735 status = GdipFlush(graphics, FlushIntentionFlush);
1736 expect(ObjectBusy, status);
1737 status = GdipGetClipBounds(graphics, rectf);
1738 expect(ObjectBusy, status);
1739 status = GdipGetClipBoundsI(graphics, rect);
1740 expect(ObjectBusy, status);
1741 status = GdipGetCompositingMode(graphics, &compmode);
1742 expect(ObjectBusy, status);
1743 status = GdipGetCompositingQuality(graphics, &quality);
1744 expect(ObjectBusy, status);
1745 status = GdipGetInterpolationMode(graphics, &intmode);
1746 expect(ObjectBusy, status);
1747 status = GdipGetNearestColor(graphics, &color);
1748 expect(ObjectBusy, status);
1749 status = GdipGetPageScale(graphics, &r);
1750 expect(ObjectBusy, status);
1751 status = GdipGetPageUnit(graphics, &unit);
1752 expect(ObjectBusy, status);
1753 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1754 expect(ObjectBusy, status);
1755 status = GdipGetSmoothingMode(graphics, &smoothmode);
1756 expect(ObjectBusy, status);
1757 status = GdipGetTextRenderingHint(graphics, &texthint);
1758 expect(ObjectBusy, status);
1759 status = GdipGetWorldTransform(graphics, m);
1760 expect(ObjectBusy, status);
1761 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1762 expect(ObjectBusy, status);
1763 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1764 expect(ObjectBusy, status);
1765 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1766 expect(ObjectBusy, status);
1767 /* GdipMeasureCharacterRanges */
1768 /* GdipMeasureString */
1769 status = GdipResetClip(graphics);
1770 expect(ObjectBusy, status);
1771 status = GdipResetWorldTransform(graphics);
1772 expect(ObjectBusy, status);
1773 /* GdipRestoreGraphics */
1774 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1775 expect(ObjectBusy, status);
1776 /* GdipSaveGraphics */
1777 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1778 expect(ObjectBusy, status);
1779 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1780 expect(ObjectBusy, status);
1781 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1782 expect(ObjectBusy, status);
1783 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1784 expect(ObjectBusy, status);
1785 status = GdipSetPageScale(graphics, 1.0);
1786 expect(ObjectBusy, status);
1787 status = GdipSetPageUnit(graphics, UnitWorld);
1788 expect(ObjectBusy, status);
1789 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1790 expect(ObjectBusy, status);
1791 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1792 expect(ObjectBusy, status);
1793 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1794 expect(ObjectBusy, status);
1795 status = GdipSetWorldTransform(graphics, m);
1796 expect(ObjectBusy, status);
1797 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1798 expect(ObjectBusy, status);
1799 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1800 expect(ObjectBusy, status);
1801 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1802 expect(ObjectBusy, status);
1803 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1804 expect(ObjectBusy, status);
1805 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1806 expect(ObjectBusy, status);
1807 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1808 expect(ObjectBusy, status);
1809 status = GdipTranslateClip(graphics, 0.0, 0.0);
1810 expect(ObjectBusy, status);
1811 status = GdipTranslateClipI(graphics, 0, 0);
1812 expect(ObjectBusy, status);
1813 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1814 expect(ObjectBusy, status);
1815 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1816 expect(ObjectBusy, status);
1817 status = GdipGetDpiX(graphics, &r);
1818 expect(ObjectBusy, status);
1819 status = GdipGetDpiY(graphics, &r);
1820 expect(ObjectBusy, status);
1821 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1822 expect(ObjectBusy, status);
1823 status = GdipGetClip(graphics, region);
1824 expect(ObjectBusy, status);
1825 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1826 expect(ObjectBusy, status);
1828 /* try to delete before release */
1829 status = GdipDeleteGraphics(graphics);
1830 expect(ObjectBusy, status);
1832 status = GdipReleaseDC(graphics, retdc);
1833 expect(Ok, status);
1835 GdipDeletePen(pen);
1836 GdipDeleteGraphics(graphics);
1838 GdipDeleteRegion(clip);
1839 GdipDeletePath(path);
1840 GdipDeleteBrush((GpBrush*)brush);
1841 GdipDeleteRegion(region);
1842 GdipDeleteMatrix(m);
1843 DeleteObject(hrgn);
1845 ReleaseDC(hwnd, hdc);
1848 static void test_transformpoints(void)
1850 GpStatus status;
1851 GpGraphics *graphics = NULL;
1852 HDC hdc = GetDC( hwnd );
1853 GpPointF ptf[2];
1854 GpPoint pt[2];
1856 status = GdipCreateFromHDC(hdc, &graphics);
1857 expect(Ok, status);
1859 /* NULL arguments */
1860 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1861 expect(InvalidParameter, status);
1862 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1863 expect(InvalidParameter, status);
1864 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1865 expect(InvalidParameter, status);
1866 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1867 expect(InvalidParameter, status);
1869 ptf[0].X = 1.0;
1870 ptf[0].Y = 0.0;
1871 ptf[1].X = 0.0;
1872 ptf[1].Y = 1.0;
1873 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1874 expect(Ok, status);
1875 expectf(1.0, ptf[0].X);
1876 expectf(0.0, ptf[0].Y);
1877 expectf(0.0, ptf[1].X);
1878 expectf(1.0, ptf[1].Y);
1880 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1881 expect(Ok, status);
1882 status = GdipSetPageUnit(graphics, UnitPixel);
1883 expect(Ok, status);
1884 status = GdipSetPageScale(graphics, 3.0);
1885 expect(Ok, status);
1887 ptf[0].X = 1.0;
1888 ptf[0].Y = 0.0;
1889 ptf[1].X = 0.0;
1890 ptf[1].Y = 1.0;
1891 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1892 expect(Ok, status);
1893 expectf(18.0, ptf[0].X);
1894 expectf(15.0, ptf[0].Y);
1895 expectf(15.0, ptf[1].X);
1896 expectf(18.0, ptf[1].Y);
1898 ptf[0].X = 1.0;
1899 ptf[0].Y = 0.0;
1900 ptf[1].X = 0.0;
1901 ptf[1].Y = 1.0;
1902 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1903 expect(Ok, status);
1904 expectf(6.0, ptf[0].X);
1905 expectf(5.0, ptf[0].Y);
1906 expectf(5.0, ptf[1].X);
1907 expectf(6.0, ptf[1].Y);
1909 ptf[0].X = 1.0;
1910 ptf[0].Y = 0.0;
1911 ptf[1].X = 0.0;
1912 ptf[1].Y = 1.0;
1913 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1914 expect(Ok, status);
1915 expectf(3.0, ptf[0].X);
1916 expectf(0.0, ptf[0].Y);
1917 expectf(0.0, ptf[1].X);
1918 expectf(3.0, ptf[1].Y);
1920 ptf[0].X = 18.0;
1921 ptf[0].Y = 15.0;
1922 ptf[1].X = 15.0;
1923 ptf[1].Y = 18.0;
1924 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1925 expect(Ok, status);
1926 expectf(1.0, ptf[0].X);
1927 expectf(0.0, ptf[0].Y);
1928 expectf(0.0, ptf[1].X);
1929 expectf(1.0, ptf[1].Y);
1931 ptf[0].X = 6.0;
1932 ptf[0].Y = 5.0;
1933 ptf[1].X = 5.0;
1934 ptf[1].Y = 6.0;
1935 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1936 expect(Ok, status);
1937 expectf(1.0, ptf[0].X);
1938 expectf(0.0, ptf[0].Y);
1939 expectf(0.0, ptf[1].X);
1940 expectf(1.0, ptf[1].Y);
1942 ptf[0].X = 3.0;
1943 ptf[0].Y = 0.0;
1944 ptf[1].X = 0.0;
1945 ptf[1].Y = 3.0;
1946 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1947 expect(Ok, status);
1948 expectf(1.0, ptf[0].X);
1949 expectf(0.0, ptf[0].Y);
1950 expectf(0.0, ptf[1].X);
1951 expectf(1.0, ptf[1].Y);
1953 pt[0].X = 1;
1954 pt[0].Y = 0;
1955 pt[1].X = 0;
1956 pt[1].Y = 1;
1957 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1958 expect(Ok, status);
1959 expect(18, pt[0].X);
1960 expect(15, pt[0].Y);
1961 expect(15, pt[1].X);
1962 expect(18, pt[1].Y);
1964 GdipDeleteGraphics(graphics);
1965 ReleaseDC(hwnd, hdc);
1968 static void test_get_set_clip(void)
1970 GpStatus status;
1971 GpGraphics *graphics = NULL;
1972 HDC hdc = GetDC( hwnd );
1973 GpRegion *clip;
1974 GpRectF rect;
1975 BOOL res;
1977 status = GdipCreateFromHDC(hdc, &graphics);
1978 expect(Ok, status);
1980 rect.X = rect.Y = 0.0;
1981 rect.Height = rect.Width = 100.0;
1983 status = GdipCreateRegionRect(&rect, &clip);
1984 expect(Ok, status);
1986 /* NULL arguments */
1987 status = GdipGetClip(NULL, NULL);
1988 expect(InvalidParameter, status);
1989 status = GdipGetClip(graphics, NULL);
1990 expect(InvalidParameter, status);
1991 status = GdipGetClip(NULL, clip);
1992 expect(InvalidParameter, status);
1994 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1995 expect(InvalidParameter, status);
1996 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1997 expect(InvalidParameter, status);
1999 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
2000 expect(InvalidParameter, status);
2001 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
2002 expect(InvalidParameter, status);
2004 res = FALSE;
2005 status = GdipGetClip(graphics, clip);
2006 expect(Ok, status);
2007 status = GdipIsInfiniteRegion(clip, graphics, &res);
2008 expect(Ok, status);
2009 expect(TRUE, res);
2011 /* remains infinite after reset */
2012 res = FALSE;
2013 status = GdipResetClip(graphics);
2014 expect(Ok, status);
2015 status = GdipGetClip(graphics, clip);
2016 expect(Ok, status);
2017 status = GdipIsInfiniteRegion(clip, graphics, &res);
2018 expect(Ok, status);
2019 expect(TRUE, res);
2021 /* set to empty and then reset to infinite */
2022 status = GdipSetEmpty(clip);
2023 expect(Ok, status);
2024 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
2025 expect(Ok, status);
2027 status = GdipGetClip(graphics, clip);
2028 expect(Ok, status);
2029 res = FALSE;
2030 status = GdipIsEmptyRegion(clip, graphics, &res);
2031 expect(Ok, status);
2032 expect(TRUE, res);
2033 status = GdipResetClip(graphics);
2034 expect(Ok, status);
2035 status = GdipGetClip(graphics, clip);
2036 expect(Ok, status);
2037 res = FALSE;
2038 status = GdipIsInfiniteRegion(clip, graphics, &res);
2039 expect(Ok, status);
2040 expect(TRUE, res);
2042 GdipDeleteRegion(clip);
2044 GdipDeleteGraphics(graphics);
2045 ReleaseDC(hwnd, hdc);
2048 static void test_isempty(void)
2050 GpStatus status;
2051 GpGraphics *graphics = NULL;
2052 HDC hdc = GetDC( hwnd );
2053 GpRegion *clip;
2054 BOOL res;
2056 status = GdipCreateFromHDC(hdc, &graphics);
2057 expect(Ok, status);
2059 status = GdipCreateRegion(&clip);
2060 expect(Ok, status);
2062 /* NULL */
2063 status = GdipIsClipEmpty(NULL, NULL);
2064 expect(InvalidParameter, status);
2065 status = GdipIsClipEmpty(graphics, NULL);
2066 expect(InvalidParameter, status);
2067 status = GdipIsClipEmpty(NULL, &res);
2068 expect(InvalidParameter, status);
2070 /* default is infinite */
2071 res = TRUE;
2072 status = GdipIsClipEmpty(graphics, &res);
2073 expect(Ok, status);
2074 expect(FALSE, res);
2076 GdipDeleteRegion(clip);
2078 GdipDeleteGraphics(graphics);
2079 ReleaseDC(hwnd, hdc);
2082 static void test_clear(void)
2084 GpStatus status;
2086 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2087 expect(InvalidParameter, status);
2090 static void test_textcontrast(void)
2092 GpStatus status;
2093 HDC hdc = GetDC( hwnd );
2094 GpGraphics *graphics;
2095 UINT contrast;
2097 status = GdipGetTextContrast(NULL, NULL);
2098 expect(InvalidParameter, status);
2100 status = GdipCreateFromHDC(hdc, &graphics);
2101 expect(Ok, status);
2103 status = GdipGetTextContrast(graphics, NULL);
2104 expect(InvalidParameter, status);
2105 status = GdipGetTextContrast(graphics, &contrast);
2106 expect(Ok, status);
2107 expect(4, contrast);
2109 GdipDeleteGraphics(graphics);
2110 ReleaseDC(hwnd, hdc);
2113 static void test_GdipDrawString(void)
2115 GpStatus status;
2116 GpGraphics *graphics = NULL;
2117 GpFont *fnt = NULL;
2118 RectF rect;
2119 GpStringFormat *format;
2120 GpBrush *brush;
2121 LOGFONTA logfont;
2122 HDC hdc = GetDC( hwnd );
2123 static const WCHAR string[] = {'T','e','s','t',0};
2124 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2125 GpMatrix *matrix;
2127 memset(&logfont,0,sizeof(logfont));
2128 strcpy(logfont.lfFaceName,"Arial");
2129 logfont.lfHeight = 12;
2130 logfont.lfCharSet = DEFAULT_CHARSET;
2132 status = GdipCreateFromHDC(hdc, &graphics);
2133 expect(Ok, status);
2135 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2136 if (status == NotTrueTypeFont || status == FileNotFound)
2138 skip("Arial not installed.\n");
2139 return;
2141 expect(Ok, status);
2143 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2144 expect(Ok, status);
2146 status = GdipCreateStringFormat(0,0,&format);
2147 expect(Ok, status);
2149 rect.X = 0;
2150 rect.Y = 0;
2151 rect.Width = 0;
2152 rect.Height = 12;
2154 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2155 expect(Ok, status);
2157 status = GdipCreateMatrix(&matrix);
2158 expect(Ok, status);
2160 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2161 expect(InvalidParameter, status);
2163 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2164 expect(InvalidParameter, status);
2166 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2167 expect(InvalidParameter, status);
2169 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2170 expect(InvalidParameter, status);
2172 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2173 expect(InvalidParameter, status);
2175 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2176 expect(Ok, status);
2178 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2179 expect(Ok, status);
2181 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2182 expect(Ok, status);
2184 GdipDeleteMatrix(matrix);
2185 GdipDeleteGraphics(graphics);
2186 GdipDeleteBrush(brush);
2187 GdipDeleteFont(fnt);
2188 GdipDeleteStringFormat(format);
2190 ReleaseDC(hwnd, hdc);
2193 static void test_GdipGetVisibleClipBounds_screen(void)
2195 GpStatus status;
2196 GpGraphics *graphics = NULL;
2197 HDC hdc = GetDC(0);
2198 GpRectF rectf, exp, clipr;
2199 GpRect recti;
2201 ok(hdc != NULL, "Expected HDC to be initialized\n");
2203 status = GdipCreateFromHDC(hdc, &graphics);
2204 expect(Ok, status);
2205 ok(graphics != NULL, "Expected graphics to be initialized\n");
2207 /* no clipping rect */
2208 exp.X = 0;
2209 exp.Y = 0;
2210 exp.Width = GetDeviceCaps(hdc, HORZRES);
2211 exp.Height = GetDeviceCaps(hdc, VERTRES);
2213 status = GdipGetVisibleClipBounds(graphics, &rectf);
2214 expect(Ok, status);
2215 ok(rectf.X == exp.X &&
2216 rectf.Y == exp.Y &&
2217 rectf.Width == exp.Width &&
2218 rectf.Height == exp.Height,
2219 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2220 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2221 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2222 exp.X, exp.Y, exp.Width, exp.Height);
2224 /* clipping rect entirely within window */
2225 exp.X = clipr.X = 10;
2226 exp.Y = clipr.Y = 12;
2227 exp.Width = clipr.Width = 14;
2228 exp.Height = clipr.Height = 16;
2230 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2231 expect(Ok, status);
2233 status = GdipGetVisibleClipBounds(graphics, &rectf);
2234 expect(Ok, status);
2235 ok(rectf.X == exp.X &&
2236 rectf.Y == exp.Y &&
2237 rectf.Width == exp.Width &&
2238 rectf.Height == exp.Height,
2239 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2240 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2241 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2242 exp.X, exp.Y, exp.Width, exp.Height);
2244 /* clipping rect partially outside of screen */
2245 clipr.X = -10;
2246 clipr.Y = -12;
2247 clipr.Width = 20;
2248 clipr.Height = 24;
2250 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2251 expect(Ok, status);
2253 exp.X = 0;
2254 exp.Y = 0;
2255 exp.Width = 10;
2256 exp.Height = 12;
2258 status = GdipGetVisibleClipBounds(graphics, &rectf);
2259 expect(Ok, status);
2260 ok(rectf.X == exp.X &&
2261 rectf.Y == exp.Y &&
2262 rectf.Width == exp.Width &&
2263 rectf.Height == exp.Height,
2264 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2265 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2266 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2267 exp.X, exp.Y, exp.Width, exp.Height);
2269 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2270 expect(Ok, status);
2271 ok(recti.X == exp.X &&
2272 recti.Y == exp.Y &&
2273 recti.Width == exp.Width &&
2274 recti.Height == exp.Height,
2275 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2276 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2277 recti.X, recti.Y, recti.Width, recti.Height,
2278 exp.X, exp.Y, exp.Width, exp.Height);
2280 GdipDeleteGraphics(graphics);
2281 ReleaseDC(0, hdc);
2284 static void test_GdipGetVisibleClipBounds_window(void)
2286 GpStatus status;
2287 GpGraphics *graphics = NULL;
2288 GpRectF rectf, window, exp, clipr;
2289 GpRect recti;
2290 HDC hdc;
2291 PAINTSTRUCT ps;
2292 RECT wnd_rect;
2294 /* get client area size */
2295 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2296 window.X = wnd_rect.left;
2297 window.Y = wnd_rect.top;
2298 window.Width = wnd_rect.right - wnd_rect.left;
2299 window.Height = wnd_rect.bottom - wnd_rect.top;
2301 hdc = BeginPaint(hwnd, &ps);
2303 status = GdipCreateFromHDC(hdc, &graphics);
2304 expect(Ok, status);
2305 ok(graphics != NULL, "Expected graphics to be initialized\n");
2307 status = GdipGetVisibleClipBounds(graphics, &rectf);
2308 expect(Ok, status);
2309 ok(rectf.X == window.X &&
2310 rectf.Y == window.Y &&
2311 rectf.Width == window.Width &&
2312 rectf.Height == window.Height,
2313 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2314 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2315 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2316 window.X, window.Y, window.Width, window.Height);
2318 /* clipping rect entirely within window */
2319 exp.X = clipr.X = 20;
2320 exp.Y = clipr.Y = 8;
2321 exp.Width = clipr.Width = 30;
2322 exp.Height = clipr.Height = 20;
2324 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2325 expect(Ok, status);
2327 status = GdipGetVisibleClipBounds(graphics, &rectf);
2328 expect(Ok, status);
2329 ok(rectf.X == exp.X &&
2330 rectf.Y == exp.Y &&
2331 rectf.Width == exp.Width &&
2332 rectf.Height == exp.Height,
2333 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2334 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2335 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2336 exp.X, exp.Y, exp.Width, exp.Height);
2338 /* clipping rect partially outside of window */
2339 clipr.X = window.Width - 10;
2340 clipr.Y = window.Height - 15;
2341 clipr.Width = 20;
2342 clipr.Height = 30;
2344 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2345 expect(Ok, status);
2347 exp.X = window.Width - 10;
2348 exp.Y = window.Height - 15;
2349 exp.Width = 10;
2350 exp.Height = 15;
2352 status = GdipGetVisibleClipBounds(graphics, &rectf);
2353 expect(Ok, status);
2354 ok(rectf.X == exp.X &&
2355 rectf.Y == exp.Y &&
2356 rectf.Width == exp.Width &&
2357 rectf.Height == exp.Height,
2358 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2359 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2360 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2361 exp.X, exp.Y, exp.Width, exp.Height);
2363 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2364 expect(Ok, status);
2365 ok(recti.X == exp.X &&
2366 recti.Y == exp.Y &&
2367 recti.Width == exp.Width &&
2368 recti.Height == exp.Height,
2369 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2370 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2371 recti.X, recti.Y, recti.Width, recti.Height,
2372 exp.X, exp.Y, exp.Width, exp.Height);
2374 /* window bounds with transform applied */
2375 status = GdipResetClip(graphics);
2376 expect(Ok, status);
2378 status = GdipScaleWorldTransform(graphics, 0.5, 0.5, MatrixOrderPrepend);
2379 expect(Ok, status);
2381 exp.X = window.X * 2.0;
2382 exp.Y = window.Y * 2.0;
2383 exp.Width = window.Width * 2.0;
2384 exp.Height = window.Height * 2.0;
2386 status = GdipGetVisibleClipBounds(graphics, &rectf);
2387 expect(Ok, status);
2388 ok(rectf.X == exp.X &&
2389 rectf.Y == exp.Y &&
2390 rectf.Width == exp.Width &&
2391 rectf.Height == exp.Height,
2392 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be "
2393 "twice the window size (%0.f, %0.f, %0.f, %0.f)\n",
2394 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2395 exp.X, exp.Y, exp.Width, exp.Height);
2397 GdipDeleteGraphics(graphics);
2398 EndPaint(hwnd, &ps);
2401 static void test_GdipGetVisibleClipBounds(void)
2403 GpGraphics* graphics = NULL;
2404 GpRectF rectf;
2405 GpRect rect;
2406 HDC hdc = GetDC( hwnd );
2407 GpStatus status;
2409 status = GdipCreateFromHDC(hdc, &graphics);
2410 expect(Ok, status);
2411 ok(graphics != NULL, "Expected graphics to be initialized\n");
2413 /* test null parameters */
2414 status = GdipGetVisibleClipBounds(graphics, NULL);
2415 expect(InvalidParameter, status);
2417 status = GdipGetVisibleClipBounds(NULL, &rectf);
2418 expect(InvalidParameter, status);
2420 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2421 expect(InvalidParameter, status);
2423 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2424 expect(InvalidParameter, status);
2426 GdipDeleteGraphics(graphics);
2427 ReleaseDC(hwnd, hdc);
2429 test_GdipGetVisibleClipBounds_screen();
2430 test_GdipGetVisibleClipBounds_window();
2433 static void test_fromMemoryBitmap(void)
2435 GpStatus status;
2436 GpGraphics *graphics = NULL;
2437 GpBitmap *bitmap = NULL;
2438 BYTE bits[48] = {0};
2439 HDC hdc=NULL;
2440 COLORREF color;
2442 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2443 expect(Ok, status);
2445 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2446 expect(Ok, status);
2448 status = GdipGraphicsClear(graphics, 0xff686868);
2449 expect(Ok, status);
2451 GdipDeleteGraphics(graphics);
2453 /* drawing writes to the memory provided */
2454 expect(0x68, bits[10]);
2456 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2457 expect(Ok, status);
2459 status = GdipGetDC(graphics, &hdc);
2460 expect(Ok, status);
2461 ok(hdc != NULL, "got NULL hdc\n");
2463 color = GetPixel(hdc, 0, 0);
2464 /* The HDC is write-only, and native fills with a solid color to figure out
2465 * which pixels have changed. */
2466 todo_wine expect(0x0c0b0d, color);
2468 SetPixel(hdc, 0, 0, 0x797979);
2469 SetPixel(hdc, 1, 0, 0x0c0b0d);
2471 status = GdipReleaseDC(graphics, hdc);
2472 expect(Ok, status);
2474 GdipDeleteGraphics(graphics);
2476 expect(0x79, bits[0]);
2477 todo_wine expect(0x68, bits[3]);
2479 GdipDisposeImage((GpImage*)bitmap);
2481 /* We get the same kind of write-only HDC for a "normal" bitmap */
2482 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2483 expect(Ok, status);
2485 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2486 expect(Ok, status);
2488 status = GdipGetDC(graphics, &hdc);
2489 expect(Ok, status);
2490 ok(hdc != NULL, "got NULL hdc\n");
2492 color = GetPixel(hdc, 0, 0);
2493 todo_wine expect(0x0c0b0d, color);
2495 status = GdipReleaseDC(graphics, hdc);
2496 expect(Ok, status);
2498 GdipDeleteGraphics(graphics);
2500 GdipDisposeImage((GpImage*)bitmap);
2502 /* If we don't draw to the HDC, the bits are never accessed */
2503 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, (BYTE*)1, &bitmap);
2504 expect(Ok, status);
2506 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2507 expect(Ok, status);
2509 status = GdipGetDC(graphics, &hdc);
2510 expect(Ok, status);
2511 ok(hdc != NULL, "got NULL hdc\n");
2513 color = GetPixel(hdc, 0, 0);
2514 todo_wine expect(0x0c0b0d, color);
2516 status = GdipReleaseDC(graphics, hdc);
2517 expect(Ok, status);
2519 GdipDeleteGraphics(graphics);
2521 GdipDisposeImage((GpImage*)bitmap);
2524 static void test_GdipIsVisiblePoint(void)
2526 GpStatus status;
2527 GpGraphics *graphics = NULL;
2528 HDC hdc = GetDC( hwnd );
2529 REAL x, y;
2530 BOOL val;
2532 ok(hdc != NULL, "Expected HDC to be initialized\n");
2534 status = GdipCreateFromHDC(hdc, &graphics);
2535 expect(Ok, status);
2536 ok(graphics != NULL, "Expected graphics to be initialized\n");
2538 /* null parameters */
2539 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2540 expect(InvalidParameter, status);
2542 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2543 expect(InvalidParameter, status);
2545 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2546 expect(InvalidParameter, status);
2548 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2549 expect(InvalidParameter, status);
2551 x = 0;
2552 y = 0;
2553 status = GdipIsVisiblePoint(graphics, x, y, &val);
2554 expect(Ok, status);
2555 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2557 x = -10;
2558 y = 0;
2559 status = GdipIsVisiblePoint(graphics, x, y, &val);
2560 expect(Ok, status);
2561 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2563 x = 0;
2564 y = -5;
2565 status = GdipIsVisiblePoint(graphics, x, y, &val);
2566 expect(Ok, status);
2567 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2569 x = 1;
2570 y = 1;
2571 status = GdipIsVisiblePoint(graphics, x, y, &val);
2572 expect(Ok, status);
2573 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2575 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2576 expect(Ok, status);
2578 x = 1;
2579 y = 1;
2580 status = GdipIsVisiblePoint(graphics, x, y, &val);
2581 expect(Ok, status);
2582 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2584 x = 15.5;
2585 y = 40.5;
2586 status = GdipIsVisiblePoint(graphics, x, y, &val);
2587 expect(Ok, status);
2588 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2590 /* translate into the center of the rect */
2591 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2593 x = 0;
2594 y = 0;
2595 status = GdipIsVisiblePoint(graphics, x, y, &val);
2596 expect(Ok, status);
2597 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2599 x = 25;
2600 y = 40;
2601 status = GdipIsVisiblePoint(graphics, x, y, &val);
2602 expect(Ok, status);
2603 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2605 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2607 /* corner cases */
2608 x = 9;
2609 y = 19;
2610 status = GdipIsVisiblePoint(graphics, x, y, &val);
2611 expect(Ok, status);
2612 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2614 x = 9.25;
2615 y = 19.25;
2616 status = GdipIsVisiblePoint(graphics, x, y, &val);
2617 expect(Ok, status);
2618 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2620 x = 9.5;
2621 y = 19.5;
2622 status = GdipIsVisiblePoint(graphics, x, y, &val);
2623 expect(Ok, status);
2624 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2626 x = 9.75;
2627 y = 19.75;
2628 status = GdipIsVisiblePoint(graphics, x, y, &val);
2629 expect(Ok, status);
2630 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2632 x = 10;
2633 y = 20;
2634 status = GdipIsVisiblePoint(graphics, x, y, &val);
2635 expect(Ok, status);
2636 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2638 x = 40;
2639 y = 20;
2640 status = GdipIsVisiblePoint(graphics, x, y, &val);
2641 expect(Ok, status);
2642 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2644 x = 39;
2645 y = 59;
2646 status = GdipIsVisiblePoint(graphics, x, y, &val);
2647 expect(Ok, status);
2648 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2650 x = 39.25;
2651 y = 59.25;
2652 status = GdipIsVisiblePoint(graphics, x, y, &val);
2653 expect(Ok, status);
2654 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2656 x = 39.5;
2657 y = 39.5;
2658 status = GdipIsVisiblePoint(graphics, x, y, &val);
2659 expect(Ok, status);
2660 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2662 x = 39.75;
2663 y = 59.75;
2664 status = GdipIsVisiblePoint(graphics, x, y, &val);
2665 expect(Ok, status);
2666 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2668 x = 40;
2669 y = 60;
2670 status = GdipIsVisiblePoint(graphics, x, y, &val);
2671 expect(Ok, status);
2672 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2674 x = 40.15;
2675 y = 60.15;
2676 status = GdipIsVisiblePoint(graphics, x, y, &val);
2677 expect(Ok, status);
2678 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2680 x = 10;
2681 y = 60;
2682 status = GdipIsVisiblePoint(graphics, x, y, &val);
2683 expect(Ok, status);
2684 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2686 /* integer version */
2687 x = 25;
2688 y = 30;
2689 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2690 expect(Ok, status);
2691 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2693 x = 50;
2694 y = 100;
2695 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2696 expect(Ok, status);
2697 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2699 GdipDeleteGraphics(graphics);
2700 ReleaseDC(hwnd, hdc);
2703 static void test_GdipIsVisibleRect(void)
2705 GpStatus status;
2706 GpGraphics *graphics = NULL;
2707 HDC hdc = GetDC( hwnd );
2708 REAL x, y, width, height;
2709 BOOL val;
2711 ok(hdc != NULL, "Expected HDC to be initialized\n");
2713 status = GdipCreateFromHDC(hdc, &graphics);
2714 expect(Ok, status);
2715 ok(graphics != NULL, "Expected graphics to be initialized\n");
2717 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2718 expect(InvalidParameter, status);
2720 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2721 expect(InvalidParameter, status);
2723 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2724 expect(InvalidParameter, status);
2726 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2727 expect(InvalidParameter, status);
2729 /* entirely within the visible region */
2730 x = 0; width = 10;
2731 y = 0; height = 10;
2732 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2733 expect(Ok, status);
2734 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2736 /* partially outside */
2737 x = -10; width = 20;
2738 y = -10; height = 20;
2739 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2740 expect(Ok, status);
2741 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2743 /* entirely outside */
2744 x = -10; width = 5;
2745 y = -10; height = 5;
2746 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2747 expect(Ok, status);
2748 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2750 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2751 expect(Ok, status);
2753 /* entirely within the visible region */
2754 x = 12; width = 10;
2755 y = 22; height = 10;
2756 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2757 expect(Ok, status);
2758 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2760 /* partially outside */
2761 x = 35; width = 10;
2762 y = 55; height = 10;
2763 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2764 expect(Ok, status);
2765 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2767 /* entirely outside */
2768 x = 45; width = 5;
2769 y = 65; height = 5;
2770 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2771 expect(Ok, status);
2772 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2774 /* translate into center of clipping rect */
2775 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2777 x = 0; width = 10;
2778 y = 0; height = 10;
2779 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2780 expect(Ok, status);
2781 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2783 x = 25; width = 5;
2784 y = 40; height = 5;
2785 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2786 expect(Ok, status);
2787 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2789 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2791 /* corners entirely outside, but some intersections */
2792 x = 0; width = 70;
2793 y = 0; height = 90;
2794 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2795 expect(Ok, status);
2796 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2798 x = 0; width = 70;
2799 y = 0; height = 30;
2800 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2801 expect(Ok, status);
2802 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2804 x = 0; width = 30;
2805 y = 0; height = 90;
2806 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2807 expect(Ok, status);
2808 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2810 /* edge cases */
2811 x = 0; width = 10;
2812 y = 20; height = 40;
2813 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2814 expect(Ok, status);
2815 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2817 x = 10; width = 30;
2818 y = 0; height = 20;
2819 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2820 expect(Ok, status);
2821 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2823 x = 40; width = 10;
2824 y = 20; height = 40;
2825 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2826 expect(Ok, status);
2827 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2829 x = 10; width = 30;
2830 y = 60; height = 10;
2831 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2832 expect(Ok, status);
2833 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2835 /* rounding tests */
2836 x = 0.4; width = 10.4;
2837 y = 20; height = 40;
2838 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2839 expect(Ok, status);
2840 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2842 x = 10; width = 30;
2843 y = 0.4; height = 20.4;
2844 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2845 expect(Ok, status);
2846 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2848 /* integer version */
2849 x = 0; width = 30;
2850 y = 0; height = 90;
2851 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2852 expect(Ok, status);
2853 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2855 x = 12; width = 10;
2856 y = 22; height = 10;
2857 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2858 expect(Ok, status);
2859 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2861 GdipDeleteGraphics(graphics);
2862 ReleaseDC(hwnd, hdc);
2865 static void test_GdipGetNearestColor(void)
2867 GpStatus status;
2868 GpGraphics *graphics;
2869 GpBitmap *bitmap;
2870 ARGB color = 0xdeadbeef;
2871 HDC hdc = GetDC( hwnd );
2873 /* create a graphics object */
2874 ok(hdc != NULL, "Expected HDC to be initialized\n");
2876 status = GdipCreateFromHDC(hdc, &graphics);
2877 expect(Ok, status);
2878 ok(graphics != NULL, "Expected graphics to be initialized\n");
2880 status = GdipGetNearestColor(graphics, NULL);
2881 expect(InvalidParameter, status);
2883 status = GdipGetNearestColor(NULL, &color);
2884 expect(InvalidParameter, status);
2885 GdipDeleteGraphics(graphics);
2887 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2888 expect(Ok, status);
2889 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2890 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2891 if (status == Ok)
2893 status = GdipGetNearestColor(graphics, &color);
2894 expect(Ok, status);
2895 expect(0xdeadbeef, color);
2896 GdipDeleteGraphics(graphics);
2898 GdipDisposeImage((GpImage*)bitmap);
2900 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2901 expect(Ok, status);
2902 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2903 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2904 if (status == Ok)
2906 status = GdipGetNearestColor(graphics, &color);
2907 expect(Ok, status);
2908 expect(0xdeadbeef, color);
2909 GdipDeleteGraphics(graphics);
2911 GdipDisposeImage((GpImage*)bitmap);
2913 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2914 expect(Ok, status);
2915 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2916 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2917 if (status == Ok)
2919 status = GdipGetNearestColor(graphics, &color);
2920 expect(Ok, status);
2921 expect(0xdeadbeef, color);
2922 GdipDeleteGraphics(graphics);
2924 GdipDisposeImage((GpImage*)bitmap);
2926 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2927 expect(Ok, status);
2928 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2929 todo_wine expect(OutOfMemory, status);
2930 if (status == Ok)
2931 GdipDeleteGraphics(graphics);
2932 GdipDisposeImage((GpImage*)bitmap);
2934 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2935 expect(Ok, status);
2936 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2937 expect(Ok, status);
2938 status = GdipGetNearestColor(graphics, &color);
2939 expect(Ok, status);
2940 expect(0xdeadbeef, color);
2941 GdipDeleteGraphics(graphics);
2942 GdipDisposeImage((GpImage*)bitmap);
2944 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2945 expect(Ok, status);
2946 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2947 expect(Ok, status);
2948 status = GdipGetNearestColor(graphics, &color);
2949 expect(Ok, status);
2950 expect(0xdeadbeef, color);
2951 GdipDeleteGraphics(graphics);
2952 GdipDisposeImage((GpImage*)bitmap);
2954 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2955 expect(Ok, status);
2956 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2957 expect(Ok, status);
2958 status = GdipGetNearestColor(graphics, &color);
2959 expect(Ok, status);
2960 expect(0xdeadbeef, color);
2961 GdipDeleteGraphics(graphics);
2962 GdipDisposeImage((GpImage*)bitmap);
2964 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2965 expect(Ok, status);
2966 if (status == Ok)
2968 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2969 expect(Ok, status);
2970 status = GdipGetNearestColor(graphics, &color);
2971 expect(Ok, status);
2972 expect(0xdeadbeef, color);
2973 GdipDeleteGraphics(graphics);
2974 GdipDisposeImage((GpImage*)bitmap);
2977 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2978 expect(Ok, status);
2979 if (status == Ok)
2981 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2982 expect(Ok, status);
2983 status = GdipGetNearestColor(graphics, &color);
2984 expect(Ok, status);
2985 expect(0xdeadbeef, color);
2986 GdipDeleteGraphics(graphics);
2987 GdipDisposeImage((GpImage*)bitmap);
2990 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2991 expect(Ok, status);
2992 if (status == Ok)
2994 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2995 expect(Ok, status);
2996 status = GdipGetNearestColor(graphics, &color);
2997 expect(Ok, status);
2998 expect(0xdeadbeef, color);
2999 GdipDeleteGraphics(graphics);
3000 GdipDisposeImage((GpImage*)bitmap);
3003 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
3004 expect(Ok, status);
3005 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3006 expect(Ok, status);
3007 status = GdipGetNearestColor(graphics, &color);
3008 expect(Ok, status);
3009 todo_wine expect(0xffa8bce8, color);
3010 GdipDeleteGraphics(graphics);
3011 GdipDisposeImage((GpImage*)bitmap);
3013 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
3014 expect(Ok, status);
3015 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3016 expect(Ok, status);
3017 status = GdipGetNearestColor(graphics, &color);
3018 expect(Ok, status);
3019 todo_wine
3020 ok(color == 0xffa8b8e8 ||
3021 broken(color == 0xffa0b8e0), /* Win98/WinMe */
3022 "Expected ffa8b8e8, got %.8x\n", color);
3023 GdipDeleteGraphics(graphics);
3024 GdipDisposeImage((GpImage*)bitmap);
3026 ReleaseDC(hwnd, hdc);
3029 static void test_string_functions(void)
3031 GpStatus status;
3032 GpGraphics *graphics;
3033 GpFontFamily *family;
3034 GpFont *font;
3035 RectF rc, char_bounds, bounds;
3036 GpBrush *brush;
3037 ARGB color = 0xff000000;
3038 HDC hdc = GetDC( hwnd );
3039 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
3040 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
3041 const WCHAR teststring2[] = {'j',0};
3042 REAL char_width, char_height;
3043 INT codepointsfitted, linesfilled;
3044 GpStringFormat *format;
3045 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
3046 GpRegion *regions[4];
3047 BOOL region_isempty[4];
3048 int i;
3049 PointF positions[8];
3050 GpMatrix *identity;
3052 ok(hdc != NULL, "Expected HDC to be initialized\n");
3053 status = GdipCreateFromHDC(hdc, &graphics);
3054 expect(Ok, status);
3055 ok(graphics != NULL, "Expected graphics to be initialized\n");
3057 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
3058 expect(Ok, status);
3060 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
3061 expect(Ok, status);
3063 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
3064 expect(Ok, status);
3066 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3067 expect(Ok, status);
3069 rc.X = 0;
3070 rc.Y = 0;
3071 rc.Width = 100.0;
3072 rc.Height = 100.0;
3074 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
3075 expect(InvalidParameter, status);
3077 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
3078 expect(InvalidParameter, status);
3080 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
3081 expect(InvalidParameter, status);
3083 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
3084 expect(InvalidParameter, status);
3086 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
3087 expect(InvalidParameter, status);
3089 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
3090 expect(Ok, status);
3092 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3093 expect(InvalidParameter, status);
3095 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3096 expect(InvalidParameter, status);
3098 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3099 expect(InvalidParameter, status);
3101 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3102 expect(InvalidParameter, status);
3104 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3105 expect(InvalidParameter, status);
3107 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3108 expect(Ok, status);
3110 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3111 expect(Ok, status);
3113 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3114 expect(Ok, status);
3115 expectf(0.0, char_bounds.X);
3116 expectf(0.0, char_bounds.Y);
3117 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3118 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3119 expect(1, codepointsfitted);
3120 expect(1, linesfilled);
3122 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3123 expect(Ok, status);
3124 expectf(0.0, bounds.X);
3125 expectf(0.0, bounds.Y);
3126 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3127 expectf(char_bounds.Height, bounds.Height);
3128 expect(2, codepointsfitted);
3129 expect(1, linesfilled);
3130 char_width = bounds.Width - char_bounds.Width;
3132 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3133 expect(Ok, status);
3134 expectf(0.0, bounds.X);
3135 expectf(0.0, bounds.Y);
3136 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3137 bounds.Width, char_bounds.Width + char_width * 2);
3138 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3139 expect(6, codepointsfitted);
3140 expect(2, linesfilled);
3141 char_height = bounds.Height - char_bounds.Height;
3143 /* Measure the first line. */
3144 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3145 expect(Ok, status);
3146 expectf(0.0, bounds.X);
3147 expectf(0.0, bounds.Y);
3148 expect(4, codepointsfitted);
3149 expect(1, linesfilled);
3151 /* Give just enough space to fit the first line. */
3152 rc.Width = bounds.Width;
3153 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3154 expect(Ok, status);
3155 expectf(0.0, bounds.X);
3156 expectf(0.0, bounds.Y);
3157 todo_wine expect(5, codepointsfitted);
3158 todo_wine expect(1, linesfilled);
3160 /* Cut off everything after the first space. */
3161 rc.Width = char_bounds.Width + char_width * 2.1;
3163 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3164 expect(Ok, status);
3165 expectf(0.0, bounds.X);
3166 expectf(0.0, bounds.Y);
3167 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3168 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3169 expect(6, codepointsfitted);
3170 expect(3, linesfilled);
3172 /* Cut off everything including the first space. */
3173 rc.Width = char_bounds.Width + char_width * 1.7;
3175 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3176 expect(Ok, status);
3177 expectf(0.0, bounds.X);
3178 expectf(0.0, bounds.Y);
3179 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3180 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3181 expect(6, codepointsfitted);
3182 expect(3, linesfilled);
3184 /* Cut off everything after the first character. */
3185 rc.Width = char_bounds.Width + char_width * 0.8;
3187 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3188 expect(Ok, status);
3189 expectf(0.0, bounds.X);
3190 expectf(0.0, bounds.Y);
3191 expectf_(char_bounds.Width, bounds.Width, 0.01);
3192 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3193 expect(6, codepointsfitted);
3194 todo_wine expect(4, linesfilled);
3196 for (i = 0; i < 4; i++)
3197 regions[i] = (GpRegion *)0xdeadbeef;
3199 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3200 expect(Ok, status);
3202 for (i = 0; i < 4; i++)
3203 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3205 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3206 expect(Ok, status);
3208 for (i = 0; i < 4; i++)
3209 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3211 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3212 expect(Ok, status);
3214 set_rect_empty(&rc);
3216 for (i=0; i<4; i++)
3218 status = GdipCreateRegion(&regions[i]);
3219 expect(Ok, status);
3220 status = GdipSetEmpty(regions[i]);
3221 expect(Ok, status);
3224 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3225 expect(InvalidParameter, status);
3227 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3228 expect(InvalidParameter, status);
3230 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3231 expect(InvalidParameter, status);
3233 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3234 expect(InvalidParameter, status);
3236 if (0)
3238 /* Crashes on Windows XP */
3239 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3240 expect(InvalidParameter, status);
3243 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3244 expect(InvalidParameter, status);
3246 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3247 expect(InvalidParameter, status);
3249 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3250 expect(Ok, status);
3252 for (i = 0; i < 4; i++)
3254 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3255 expect(Ok, status);
3258 ok(region_isempty[0], "region should be empty\n");
3259 ok(region_isempty[1], "region should be empty\n");
3260 ok(region_isempty[2], "region should be empty\n");
3261 ok(region_isempty[3], "region should be empty\n");
3263 rc.Width = 100.0;
3264 rc.Height = 100.0;
3266 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3267 expect(Ok, status);
3269 for (i=0; i<4; i++)
3271 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3272 expect(Ok, status);
3275 ok(!region_isempty[0], "region shouldn't be empty\n");
3276 ok(!region_isempty[1], "region shouldn't be empty\n");
3277 ok(!region_isempty[2], "region shouldn't be empty\n");
3278 ok(region_isempty[3], "region should be empty\n");
3280 /* Cut off everything after the first space, and the second line. */
3281 rc.Width = char_bounds.Width + char_width * 2.1;
3282 rc.Height = char_bounds.Height + char_height * 0.5;
3284 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3285 expect(Ok, status);
3287 for (i=0; i<4; i++)
3289 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3290 expect(Ok, status);
3293 ok(!region_isempty[0], "region shouldn't be empty\n");
3294 ok(!region_isempty[1], "region shouldn't be empty\n");
3295 ok(region_isempty[2], "region should be empty\n");
3296 ok(region_isempty[3], "region should be empty\n");
3298 for (i=0; i<4; i++)
3299 GdipDeleteRegion(regions[i]);
3301 status = GdipCreateMatrix(&identity);
3302 expect(Ok, status);
3304 rc.X = 0;
3305 rc.Y = 0;
3306 rc.Width = 0;
3307 rc.Height = 0;
3308 memset(positions, 0, sizeof(positions));
3309 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3310 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3311 identity, &rc);
3312 expect(InvalidParameter, status);
3314 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3315 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3316 identity, &rc);
3317 expect(InvalidParameter, status);
3319 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3320 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3321 identity, &rc);
3322 expect(InvalidParameter, status);
3324 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3325 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3326 identity, &rc);
3327 expect(InvalidParameter, status);
3329 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3330 0x100, identity, &rc);
3331 expect(Ok, status);
3333 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3334 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3335 NULL, &rc);
3336 expect(Ok, status);
3338 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3339 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3340 identity, NULL);
3341 expect(InvalidParameter, status);
3343 rc.X = 0;
3344 rc.Y = 0;
3345 rc.Width = 0;
3346 rc.Height = 0;
3347 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3348 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3349 identity, &rc);
3350 expect(Ok, status);
3352 expectf(0.0, rc.X);
3353 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3354 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3355 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3357 char_width = rc.Width;
3358 char_height = rc.Height;
3360 rc.X = 0;
3361 rc.Y = 0;
3362 rc.Width = 0;
3363 rc.Height = 0;
3364 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3365 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3366 identity, &rc);
3367 expect(Ok, status);
3369 expectf(0.0, rc.X);
3370 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3371 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3372 expectf(char_height, rc.Height);
3374 rc.X = 0;
3375 rc.Y = 0;
3376 rc.Width = 0;
3377 rc.Height = 0;
3378 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3379 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3380 identity, &rc);
3381 expect(Ok, status);
3383 expectf(rc.X, 0.0);
3384 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3385 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3386 expectf(rc.Height, char_height);
3388 GdipDeleteMatrix(identity);
3389 GdipDeleteStringFormat(format);
3390 GdipDeleteBrush(brush);
3391 GdipDeleteFont(font);
3392 GdipDeleteFontFamily(family);
3393 GdipDeleteGraphics(graphics);
3395 ReleaseDC(hwnd, hdc);
3398 static void test_get_set_interpolation(void)
3400 GpGraphics *graphics;
3401 HDC hdc = GetDC( hwnd );
3402 GpStatus status;
3403 InterpolationMode mode;
3405 ok(hdc != NULL, "Expected HDC to be initialized\n");
3406 status = GdipCreateFromHDC(hdc, &graphics);
3407 expect(Ok, status);
3408 ok(graphics != NULL, "Expected graphics to be initialized\n");
3410 status = GdipGetInterpolationMode(NULL, &mode);
3411 expect(InvalidParameter, status);
3413 if (0)
3415 /* Crashes on Windows XP */
3416 status = GdipGetInterpolationMode(graphics, NULL);
3417 expect(InvalidParameter, status);
3420 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3421 expect(InvalidParameter, status);
3423 /* out of range */
3424 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3425 expect(InvalidParameter, status);
3427 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3428 expect(InvalidParameter, status);
3430 status = GdipGetInterpolationMode(graphics, &mode);
3431 expect(Ok, status);
3432 expect(InterpolationModeBilinear, mode);
3434 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3435 expect(Ok, status);
3437 status = GdipGetInterpolationMode(graphics, &mode);
3438 expect(Ok, status);
3439 expect(InterpolationModeNearestNeighbor, mode);
3441 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3442 expect(Ok, status);
3444 status = GdipGetInterpolationMode(graphics, &mode);
3445 expect(Ok, status);
3446 expect(InterpolationModeBilinear, mode);
3448 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3449 expect(Ok, status);
3451 status = GdipGetInterpolationMode(graphics, &mode);
3452 expect(Ok, status);
3453 expect(InterpolationModeBilinear, mode);
3455 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3456 expect(Ok, status);
3458 status = GdipGetInterpolationMode(graphics, &mode);
3459 expect(Ok, status);
3460 expect(InterpolationModeHighQualityBicubic, mode);
3462 GdipDeleteGraphics(graphics);
3464 ReleaseDC(hwnd, hdc);
3467 static void test_get_set_textrenderinghint(void)
3469 GpGraphics *graphics;
3470 HDC hdc = GetDC( hwnd );
3471 GpStatus status;
3472 TextRenderingHint hint;
3474 ok(hdc != NULL, "Expected HDC to be initialized\n");
3475 status = GdipCreateFromHDC(hdc, &graphics);
3476 expect(Ok, status);
3477 ok(graphics != NULL, "Expected graphics to be initialized\n");
3479 status = GdipGetTextRenderingHint(NULL, &hint);
3480 expect(InvalidParameter, status);
3482 status = GdipGetTextRenderingHint(graphics, NULL);
3483 expect(InvalidParameter, status);
3485 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3486 expect(InvalidParameter, status);
3488 /* out of range */
3489 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3490 expect(InvalidParameter, status);
3492 status = GdipGetTextRenderingHint(graphics, &hint);
3493 expect(Ok, status);
3494 expect(TextRenderingHintSystemDefault, hint);
3496 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3497 expect(Ok, status);
3499 status = GdipGetTextRenderingHint(graphics, &hint);
3500 expect(Ok, status);
3501 expect(TextRenderingHintSystemDefault, hint);
3503 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3504 expect(Ok, status);
3506 status = GdipGetTextRenderingHint(graphics, &hint);
3507 expect(Ok, status);
3508 expect(TextRenderingHintAntiAliasGridFit, hint);
3510 GdipDeleteGraphics(graphics);
3512 ReleaseDC(hwnd, hdc);
3515 static void test_getdc_scaled(void)
3517 GpStatus status;
3518 GpGraphics *graphics = NULL;
3519 GpBitmap *bitmap = NULL;
3520 HDC hdc=NULL;
3521 HBRUSH hbrush, holdbrush;
3522 ARGB color;
3524 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3525 expect(Ok, status);
3527 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3528 expect(Ok, status);
3530 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3531 expect(Ok, status);
3533 status = GdipGetDC(graphics, &hdc);
3534 expect(Ok, status);
3535 ok(hdc != NULL, "got NULL hdc\n");
3537 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3539 holdbrush = SelectObject(hdc, hbrush);
3541 Rectangle(hdc, 2, 2, 6, 6);
3543 SelectObject(hdc, holdbrush);
3545 DeleteObject(hbrush);
3547 status = GdipReleaseDC(graphics, hdc);
3548 expect(Ok, status);
3550 GdipDeleteGraphics(graphics);
3552 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3553 expect(Ok, status);
3554 expect(0xffff0000, color);
3556 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3557 expect(Ok, status);
3558 expect(0xff000000, color);
3560 GdipDisposeImage((GpImage*)bitmap);
3563 static void test_GdipMeasureString(void)
3565 static const struct test_data
3567 REAL res_x, res_y, page_scale;
3568 GpUnit unit;
3569 } td[] =
3571 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3572 { 200.0, 200.0, 2.0, UnitPixel },
3573 { 200.0, 200.0, 1.0, UnitDisplay },
3574 { 200.0, 200.0, 2.0, UnitDisplay },
3575 { 200.0, 200.0, 1.0, UnitInch },
3576 { 200.0, 200.0, 2.0, UnitInch },
3577 { 200.0, 600.0, 1.0, UnitPoint },
3578 { 200.0, 600.0, 2.0, UnitPoint },
3579 { 200.0, 600.0, 1.0, UnitDocument },
3580 { 200.0, 600.0, 2.0, UnitDocument },
3581 { 200.0, 600.0, 1.0, UnitMillimeter },
3582 { 200.0, 600.0, 2.0, UnitMillimeter },
3583 { 200.0, 600.0, 1.0, UnitDisplay },
3584 { 200.0, 600.0, 2.0, UnitDisplay },
3585 { 200.0, 600.0, 1.0, UnitPixel },
3586 { 200.0, 600.0, 2.0, UnitPixel },
3588 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3589 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3590 GpStatus status;
3591 GpGraphics *graphics;
3592 GpFontFamily *family;
3593 GpFont *font;
3594 GpStringFormat *format;
3595 RectF bounds, rc;
3596 REAL base_cx = 0, base_cy = 0, height;
3597 INT chars, lines;
3598 LOGFONTW lf;
3599 UINT i;
3600 REAL font_size;
3601 GpUnit font_unit, unit;
3603 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3604 expect(Ok, status);
3605 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3606 expect(Ok, status);
3608 /* font size in pixels */
3609 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3610 expect(Ok, status);
3611 status = GdipGetFontSize(font, &font_size);
3612 expect(Ok, status);
3613 expectf(100.0, font_size);
3614 status = GdipGetFontUnit(font, &font_unit);
3615 expect(Ok, status);
3616 expect(UnitPixel, font_unit);
3618 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3620 GpImage *image;
3622 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3624 lf.lfHeight = 0xdeadbeef;
3625 status = GdipGetLogFontW(font, graphics, &lf);
3626 expect(Ok, status);
3627 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3628 if (td[i].unit != UnitDisplay)
3629 height *= td[i].page_scale;
3630 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3631 i, (LONG)(height + 0.5), height, lf.lfHeight);
3633 height = font_size + 2.0 * font_size / 6.0;
3635 set_rect_empty(&rc);
3636 set_rect_empty(&bounds);
3637 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3638 expect(Ok, status);
3640 if (i == 0)
3642 base_cx = bounds.Width;
3643 base_cy = bounds.Height;
3646 expectf(0.0, bounds.X);
3647 expectf(0.0, bounds.Y);
3648 todo_wine
3649 expectf_(height, bounds.Height, height / 100.0);
3650 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3651 expect(7, chars);
3652 expect(1, lines);
3654 /* make sure it really fits */
3655 bounds.Width += 1.0;
3656 bounds.Height += 1.0;
3657 rc = bounds;
3658 rc.X = 50.0;
3659 rc.Y = 50.0;
3660 set_rect_empty(&bounds);
3661 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3662 expect(Ok, status);
3663 expectf(50.0, bounds.X);
3664 expectf(50.0, bounds.Y);
3665 todo_wine
3666 expectf_(height, bounds.Height, height / 100.0);
3667 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3668 expect(7, chars);
3669 expect(1, lines);
3671 status = GdipDeleteGraphics(graphics);
3672 expect(Ok, status);
3674 status = GdipDisposeImage(image);
3675 expect(Ok, status);
3678 GdipDeleteFont(font);
3680 /* font size in logical units */
3681 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3682 for (unit = 3; unit <= 6; unit++)
3684 /* create a font which final height is 100.0 pixels with 200 dpi device */
3685 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3686 height = pixels_to_units(75.0, unit, 200.0);
3687 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3688 expect(Ok, status);
3689 status = GdipGetFontSize(font, &font_size);
3690 expect(Ok, status);
3691 expectf(height, font_size);
3692 status = GdipGetFontUnit(font, &font_unit);
3693 expect(Ok, status);
3694 expect(unit, font_unit);
3696 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3698 REAL unit_scale;
3699 GpImage *image;
3701 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3703 lf.lfHeight = 0xdeadbeef;
3704 status = GdipGetLogFontW(font, graphics, &lf);
3705 expect(Ok, status);
3706 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3707 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3708 else
3709 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3710 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3711 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3712 i, (LONG)(height + 0.5), height, lf.lfHeight);
3714 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3715 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3716 else
3717 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3718 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3719 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3720 if (td[i].unit != UnitDisplay)
3721 height /= td[i].page_scale;
3722 /*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);*/
3724 set_rect_empty(&rc);
3725 set_rect_empty(&bounds);
3726 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3727 expect(Ok, status);
3729 if (i == 0)
3731 base_cx = bounds.Width;
3732 base_cy = bounds.Height;
3735 expectf(0.0, bounds.X);
3736 expectf(0.0, bounds.Y);
3737 todo_wine
3738 expectf_(height, bounds.Height, height / 85.0);
3739 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3740 expect(7, chars);
3741 expect(1, lines);
3743 /* make sure it really fits */
3744 bounds.Width += 1.0;
3745 bounds.Height += 1.0;
3746 rc = bounds;
3747 rc.X = 50.0;
3748 rc.Y = 50.0;
3749 set_rect_empty(&bounds);
3750 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3751 expect(Ok, status);
3752 expectf(50.0, bounds.X);
3753 expectf(50.0, bounds.Y);
3754 todo_wine
3755 expectf_(height, bounds.Height, height / 85.0);
3756 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3757 expect(7, chars);
3758 expect(1, lines);
3760 /* verify the result */
3761 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3762 if (td[i].unit != UnitDisplay)
3763 height *= td[i].page_scale;
3764 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3765 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3766 todo_wine
3767 expectf_(100.0, height, 1.1);
3769 status = GdipDeleteGraphics(graphics);
3770 expect(Ok, status);
3772 status = GdipDisposeImage(image);
3773 expect(Ok, status);
3776 GdipDeleteFont(font);
3779 /* Font with units = UnitWorld */
3780 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3782 GpPointF pt = {0.0, 100.0};
3783 GpImage* image;
3784 REAL expected_width, expected_height;
3786 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3788 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3789 expect(Ok, status);
3791 status = GdipCreateFont(family, pt.Y, FontStyleRegular, UnitWorld, &font);
3792 expect(Ok, status);
3794 status = GdipGetFontUnit(font, &font_unit);
3795 expect(Ok, status);
3796 expect(UnitWorld, font_unit);
3798 lf.lfHeight = 0xdeadbeef;
3799 status = GdipGetLogFontW(font, graphics, &lf);
3800 expect(Ok, status);
3801 ok(lf.lfHeight == -100, "%u: expected -100, got %d\n", i, lf.lfHeight);
3803 set_rect_empty(&rc);
3804 set_rect_empty(&bounds);
3805 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3806 expect(Ok, status);
3808 if (i == 0)
3810 base_cx = bounds.Width;
3811 base_cy = bounds.Height;
3814 pt.X = 1.0;
3815 pt.Y = 1.0;
3817 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3818 expect(Ok, status);
3820 /* height is constant in device space, width is proportional to height in world space */
3821 expected_width = base_cx * pt.Y;
3822 expected_height = base_cy * pt.Y;
3824 todo_wine_if(td[i].unit != UnitDisplay && td[i].unit != UnitPixel)
3825 ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width);
3826 ok(fabs(expected_height - bounds.Height) <= 0.001, "%u: expected %f, got %f\n", i, expected_height, bounds.Height);
3828 GdipDeleteGraphics(graphics);
3829 GdipDisposeImage(image);
3830 GdipDeleteFont(font);
3833 GdipDeleteFontFamily(family);
3834 GdipDeleteStringFormat(format);
3837 static void test_transform(void)
3839 static const struct test_data
3841 REAL res_x, res_y, scale;
3842 GpUnit unit;
3843 GpPointF in[2], out[2];
3844 } td[] =
3846 { 96.0, 96.0, 1.0, UnitPixel,
3847 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3848 { 96.0, 96.0, 1.0, UnitDisplay,
3849 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3850 { 96.0, 96.0, 1.0, UnitInch,
3851 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
3852 { 123.0, 456.0, 1.0, UnitPoint,
3853 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
3854 { 123.0, 456.0, 1.0, UnitDocument,
3855 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
3856 { 123.0, 456.0, 2.0, UnitMillimeter,
3857 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
3858 { 196.0, 296.0, 1.0, UnitDisplay,
3859 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3860 { 196.0, 296.0, 1.0, UnitPixel,
3861 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
3863 GpStatus status;
3864 GpGraphics *graphics;
3865 GpImage *image;
3866 GpPointF ptf[2];
3867 UINT i;
3869 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3871 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
3872 ptf[0].X = td[i].in[0].X;
3873 ptf[0].Y = td[i].in[0].Y;
3874 ptf[1].X = td[i].in[1].X;
3875 ptf[1].Y = td[i].in[1].Y;
3876 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
3877 expect(Ok, status);
3878 expectf(td[i].out[0].X, ptf[0].X);
3879 expectf(td[i].out[0].Y, ptf[0].Y);
3880 expectf(td[i].out[1].X, ptf[1].X);
3881 expectf(td[i].out[1].Y, ptf[1].Y);
3882 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
3883 expect(Ok, status);
3884 expectf(td[i].in[0].X, ptf[0].X);
3885 expectf(td[i].in[0].Y, ptf[0].Y);
3886 expectf(td[i].in[1].X, ptf[1].X);
3887 expectf(td[i].in[1].Y, ptf[1].Y);
3888 status = GdipDeleteGraphics(graphics);
3889 expect(Ok, status);
3890 status = GdipDisposeImage(image);
3891 expect(Ok, status);
3895 static void test_pen_thickness(void)
3897 static const struct test_data
3899 REAL res_x, res_y, scale;
3900 GpUnit pen_unit, page_unit;
3901 REAL pen_width;
3902 INT cx, cy;
3903 } td[] =
3905 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 1.0, 1, 1 },
3906 { 10.0, 10.0, 3.0, UnitPixel, UnitPixel, 2.0, 2, 2 },
3907 { 10.0, 10.0, 30.0, UnitPixel, UnitInch, 1.0, 1, 1 },
3908 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 1.0, 1, 1 },
3909 { 10.0, 10.0, 3.0, UnitWorld, UnitPixel, 2.0, 6, 6 },
3910 { 10.0, 10.0, 2.0, UnitWorld, UnitInch, 1.0, 20, 20 },
3912 GpStatus status;
3913 int i, j;
3914 GpGraphics *graphics;
3915 union
3917 GpBitmap *bitmap;
3918 GpImage *image;
3919 } u;
3920 GpPen *pen;
3921 GpPointF corner;
3922 BitmapData bd;
3923 INT min, max, size;
3925 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3927 status = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat24bppRGB, NULL, &u.bitmap);
3928 expect(Ok, status);
3930 status = GdipBitmapSetResolution(u.bitmap, td[i].res_x, td[i].res_y);
3931 expect(Ok, status);
3933 status = GdipGetImageGraphicsContext(u.image, &graphics);
3934 expect(Ok, status);
3936 status = GdipSetPageUnit(graphics, td[i].page_unit);
3937 expect(Ok, status);
3939 status = GdipSetPageScale(graphics, td[i].scale);
3940 expect(Ok, status);
3942 status = GdipCreatePen1(0xffffffff, td[i].pen_width, td[i].pen_unit, &pen);
3943 expect(Ok, status);
3945 corner.X = corner.Y = 100.0;
3946 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &corner, 1);
3947 expect(Ok, status);
3949 status = GdipDrawLine(graphics, pen, corner.X/2, 0, corner.X/2, corner.Y);
3950 expect(Ok, status);
3952 status = GdipDrawLine(graphics, pen, 0, corner.Y/2, corner.X, corner.Y/2);
3953 expect(Ok, status);
3955 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
3956 expect(Ok, status);
3958 min = -1;
3959 max = -2;
3961 for (j=0; j<100; j++)
3963 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
3965 min = j;
3966 break;
3970 for (j=99; j>=0; j--)
3972 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
3974 max = j;
3975 break;
3979 size = max-min+1;
3981 ok(size == td[i].cx, "%u: expected %d, got %d\n", i, td[i].cx, size);
3983 min = -1;
3984 max = -2;
3986 for (j=0; j<100; j++)
3988 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
3990 min = j;
3991 break;
3995 for (j=99; j>=0; j--)
3997 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
3999 max = j;
4000 break;
4004 size = max-min+1;
4006 ok(size == td[i].cy, "%u: expected %d, got %d\n", i, td[i].cy, size);
4008 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4009 expect(Ok, status);
4011 GdipDeletePen(pen);
4012 GdipDeleteGraphics(graphics);
4013 GdipDisposeImage(u.image);
4017 /* Many people on the net ask why there is so much difference in rendered
4018 * text height between gdiplus and gdi32, this test suggests an answer to
4019 * that question. Important: this test assumes that font dpi == device dpi.
4021 static void test_font_height_scaling(void)
4023 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4024 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
4025 HDC hdc;
4026 GpStringFormat *format;
4027 CharacterRange range = { 0, 7 };
4028 GpRegion *region;
4029 GpGraphics *graphics;
4030 GpFontFamily *family;
4031 GpFont *font;
4032 GpStatus status;
4033 RectF bounds, rect;
4034 REAL height, dpi, scale;
4035 PointF ptf;
4036 GpUnit gfx_unit, font_unit;
4038 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4039 expect(Ok, status);
4040 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4041 expect(Ok, status);
4042 status = GdipCreateRegion(&region);
4043 expect(Ok, status);
4045 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4046 expect(Ok, status);
4048 hdc = CreateCompatibleDC(0);
4049 status = GdipCreateFromHDC(hdc, &graphics);
4050 expect(Ok, status);
4052 status = GdipGetDpiY(graphics, &dpi);
4053 expect(Ok, status);
4055 /* First check if tested functionality works:
4056 * under XP if font and graphics units differ then GdipTransformPoints
4057 * followed by GdipSetPageUnit to change the graphics units breaks region
4058 * scaling in GdipMeasureCharacterRanges called later.
4060 status = GdipSetPageUnit(graphics, UnitDocument);
4061 expect(Ok, status);
4063 ptf.X = 0.0;
4064 ptf.Y = 0.0;
4065 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4066 expect(Ok, status);
4068 status = GdipSetPageUnit(graphics, UnitInch);
4069 expect(Ok, status);
4071 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
4072 expect(Ok, status);
4074 set_rect_empty(&rect);
4075 set_rect_empty(&bounds);
4076 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4077 expect(Ok, status);
4078 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
4080 set_rect_empty(&rect);
4081 rect.Width = 32000.0;
4082 rect.Height = 32000.0;
4083 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4084 expect(Ok, status);
4086 set_rect_empty(&rect);
4087 status = GdipGetRegionBounds(region, graphics, &rect);
4088 expect(Ok, status);
4089 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4091 GdipDeleteFont(font);
4093 scale = rect.Height / bounds.Height;
4094 if (fabs(scale - 1.0) > 0.1)
4096 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
4097 goto cleanup;
4100 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
4101 expect(Ok, status);
4103 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4104 /* UnitPixel as a font base unit is not tested because it drastically
4105 differs in behaviour */
4106 for (font_unit = 3; font_unit <= 6; font_unit++)
4108 /* create a font for the final text height of 100 pixels */
4109 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
4110 status = GdipSetPageUnit(graphics, font_unit);
4111 expect(Ok, status);
4112 ptf.X = 0;
4113 ptf.Y = 75.0;
4114 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4115 expect(Ok, status);
4116 height = ptf.Y;
4117 /*trace("height %f units\n", height);*/
4118 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
4119 expect(Ok, status);
4121 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4122 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4124 static const WCHAR doubleW[2] = { 'W','W' };
4125 RectF bounds_1, bounds_2;
4126 REAL margin, margin_y, font_height;
4127 int match;
4129 status = GdipSetPageUnit(graphics, gfx_unit);
4130 expect(Ok, status);
4132 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
4133 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
4135 status = GdipGetFontHeight(font, graphics, &font_height);
4136 expect(Ok, status);
4138 set_rect_empty(&rect);
4139 set_rect_empty(&bounds);
4140 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4141 expect(Ok, status);
4142 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
4143 todo_wine
4144 expectf_(font_height + margin_y, bounds.Height, 0.005);
4146 ptf.X = 0;
4147 ptf.Y = bounds.Height;
4148 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
4149 expect(Ok, status);
4150 match = fabs(100.0 - ptf.Y) <= 1.0;
4151 todo_wine
4152 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4154 /* verify the result */
4155 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
4156 ptf.Y /= 100.0;
4157 match = fabs(100.0 - ptf.Y) <= 1.0;
4158 todo_wine
4159 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4161 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4162 set_rect_empty(&rect);
4163 set_rect_empty(&bounds_1);
4164 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
4165 expect(Ok, status);
4166 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4167 set_rect_empty(&rect);
4168 set_rect_empty(&bounds_2);
4169 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
4170 expect(Ok, status);
4172 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4173 margin = bounds_1.Width - bounds_2.Width / 2.0;
4174 /*trace("margin %f\n", margin);*/
4175 ok(margin > 0.0, "wrong margin %f\n", margin);
4177 set_rect_empty(&rect);
4178 rect.Width = 320000.0;
4179 rect.Height = 320000.0;
4180 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4181 expect(Ok, status);
4182 set_rect_empty(&rect);
4183 status = GdipGetRegionBounds(region, graphics, &rect);
4184 expect(Ok, status);
4185 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
4186 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
4187 expectf(0.0, rect.Y);
4188 match = fabs(1.0 - margin / rect.X) <= 0.05;
4189 ok(match, "Expected %f, got %f\n", margin, rect.X);
4190 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
4191 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
4192 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
4193 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
4196 GdipDeleteFont(font);
4199 cleanup:
4200 status = GdipDeleteGraphics(graphics);
4201 expect(Ok, status);
4202 DeleteDC(hdc);
4204 GdipDeleteFontFamily(family);
4205 GdipDeleteRegion(region);
4206 GdipDeleteStringFormat(format);
4209 static void test_measure_string(void)
4211 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4212 static const WCHAR string[] = { 'A','0','1',0 };
4213 HDC hdc;
4214 GpStringFormat *format;
4215 CharacterRange range;
4216 GpRegion *region;
4217 GpGraphics *graphics;
4218 GpFontFamily *family;
4219 GpFont *font;
4220 GpStatus status;
4221 RectF bounds, rect;
4222 REAL width, height, width_1, width_2;
4223 REAL margin_x, margin_y, width_rgn, height_rgn;
4224 int lines, glyphs;
4226 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4227 expect(Ok, status);
4228 expect(Ok, status);
4230 status = GdipCreateRegion(&region);
4231 expect(Ok, status);
4233 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4234 expect(Ok, status);
4236 hdc = CreateCompatibleDC(0);
4237 status = GdipCreateFromHDC(hdc, &graphics);
4239 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
4240 expect(Ok, status);
4242 margin_x = 20.0 / 6.0;
4243 margin_y = 20.0 / 8.0;
4245 set_rect_empty(&rect);
4246 set_rect_empty(&bounds);
4247 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4248 expect(Ok, status);
4249 expect(3, glyphs);
4250 expect(1, lines);
4251 expectf(0.0, bounds.X);
4252 expectf(0.0, bounds.Y);
4253 width = bounds.Width;
4254 height = bounds.Height;
4256 set_rect_empty(&rect);
4257 rect.Height = height / 2.0;
4258 set_rect_empty(&bounds);
4259 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4260 expect(Ok, status);
4261 expect(3, glyphs);
4262 expect(1, lines);
4263 expectf(0.0, bounds.X);
4264 expectf(0.0, bounds.Y);
4265 expectf(width, bounds.Width);
4266 todo_wine
4267 expectf(height / 2.0, bounds.Height);
4269 range.First = 0;
4270 range.Length = lstrlenW(string);
4271 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4272 expect(Ok, status);
4274 rect.X = 5.0;
4275 rect.Y = 5.0;
4276 rect.Width = 32000.0;
4277 rect.Height = 32000.0;
4278 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4279 expect(Ok, status);
4280 set_rect_empty(&bounds);
4281 status = GdipGetRegionBounds(region, graphics, &bounds);
4282 expect(Ok, status);
4283 expectf_(5.0 + margin_x, bounds.X, 1.0);
4284 expectf(5.0, bounds.Y);
4285 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4286 todo_wine
4287 expectf_(height - margin_y, bounds.Height, 1.0);
4289 width_rgn = bounds.Width;
4290 height_rgn = bounds.Height;
4292 range.First = 0;
4293 range.Length = 1;
4294 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4295 expect(Ok, status);
4297 set_rect_empty(&rect);
4298 rect.Width = 32000.0;
4299 rect.Height = 32000.0;
4300 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4301 expect(Ok, status);
4302 set_rect_empty(&bounds);
4303 status = GdipGetRegionBounds(region, graphics, &bounds);
4304 expect(Ok, status);
4305 expectf_(margin_x, bounds.X, 1.0);
4306 expectf(0.0, bounds.Y);
4307 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4308 expectf(height_rgn, bounds.Height);
4309 width_1 = bounds.Width;
4311 range.First = 0;
4312 range.Length = lstrlenW(string);
4313 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4314 expect(Ok, status);
4316 rect.X = 5.0;
4317 rect.Y = 5.0;
4318 rect.Width = 0.0;
4319 rect.Height = 0.0;
4320 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4321 expect(Ok, status);
4322 set_rect_empty(&bounds);
4323 status = GdipGetRegionBounds(region, graphics, &bounds);
4324 expect(Ok, status);
4325 expectf(0.0, bounds.X);
4326 expectf(0.0, bounds.Y);
4327 expectf(0.0, bounds.Width);
4328 expectf(0.0, bounds.Height);
4330 rect.X = 5.0;
4331 rect.Y = 5.0;
4332 rect.Width = width_rgn / 2.0;
4333 rect.Height = 32000.0;
4334 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4335 expect(Ok, status);
4336 set_rect_empty(&bounds);
4337 status = GdipGetRegionBounds(region, graphics, &bounds);
4338 expect(Ok, status);
4339 expectf_(5.0 + margin_x, bounds.X, 1.0);
4340 expectf(5.0, bounds.Y);
4341 expectf_(width_1, bounds.Width, 1.0);
4342 todo_wine
4343 expectf_(height - margin_y, bounds.Height, 1.0);
4345 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4347 rect.X = 5.0;
4348 rect.Y = 5.0;
4349 rect.Width = 0.0;
4350 rect.Height = 0.0;
4351 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4352 expect(Ok, status);
4353 set_rect_empty(&bounds);
4354 status = GdipGetRegionBounds(region, graphics, &bounds);
4355 expect(Ok, status);
4356 expectf_(5.0 + margin_x, bounds.X, 1.0);
4357 expectf(5.0, bounds.Y);
4358 expectf(width_rgn, bounds.Width);
4359 expectf(height_rgn, bounds.Height);
4361 rect.X = 5.0;
4362 rect.Y = 5.0;
4363 rect.Width = width_rgn / 2.0;
4364 rect.Height = 32000.0;
4365 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4366 expect(Ok, status);
4367 set_rect_empty(&bounds);
4368 status = GdipGetRegionBounds(region, graphics, &bounds);
4369 expect(Ok, status);
4370 expectf_(5.0 + margin_x, bounds.X, 1.0);
4371 expectf(5.0, bounds.Y);
4372 expectf_(width_1, bounds.Width, 1.0);
4373 expectf(height_rgn, bounds.Height);
4375 set_rect_empty(&rect);
4376 rect.Height = height / 2.0;
4377 set_rect_empty(&bounds);
4378 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4379 expect(Ok, status);
4380 expect(3, glyphs);
4381 expect(1, lines);
4382 expectf(0.0, bounds.X);
4383 expectf(0.0, bounds.Y);
4384 expectf_(width, bounds.Width, 0.01);
4385 todo_wine
4386 expectf(height, bounds.Height);
4388 set_rect_empty(&rect);
4389 set_rect_empty(&bounds);
4390 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4391 expect(Ok, status);
4392 expect(1, glyphs);
4393 expect(1, lines);
4394 expectf(0.0, bounds.X);
4395 expectf(0.0, bounds.Y);
4396 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4397 expectf(height, bounds.Height);
4398 width_1 = bounds.Width;
4400 set_rect_empty(&rect);
4401 set_rect_empty(&bounds);
4402 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4403 expect(Ok, status);
4404 expect(2, glyphs);
4405 expect(1, lines);
4406 expectf(0.0, bounds.X);
4407 expectf(0.0, bounds.Y);
4408 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4409 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4410 expectf(height, bounds.Height);
4411 width_2 = bounds.Width;
4413 set_rect_empty(&rect);
4414 rect.Width = width / 2.0;
4415 set_rect_empty(&bounds);
4416 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4417 expect(Ok, status);
4418 expect(1, glyphs);
4419 expect(1, lines);
4420 expectf(0.0, bounds.X);
4421 expectf(0.0, bounds.Y);
4422 expectf_(width_1, bounds.Width, 0.01);
4423 expectf(height, bounds.Height);
4425 set_rect_empty(&rect);
4426 rect.Height = height;
4427 rect.Width = width - 0.05;
4428 set_rect_empty(&bounds);
4429 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4430 expect(Ok, status);
4431 expect(2, glyphs);
4432 expect(1, lines);
4433 expectf(0.0, bounds.X);
4434 expectf(0.0, bounds.Y);
4435 expectf_(width_2, bounds.Width, 0.01);
4436 expectf(height, bounds.Height);
4438 set_rect_empty(&rect);
4439 rect.Height = height;
4440 rect.Width = width_2 - 0.05;
4441 set_rect_empty(&bounds);
4442 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4443 expect(Ok, status);
4444 expect(1, glyphs);
4445 expect(1, lines);
4446 expectf(0.0, bounds.X);
4447 expectf(0.0, bounds.Y);
4448 expectf_(width_1, bounds.Width, 0.01);
4449 expectf(height, bounds.Height);
4451 /* Default (Near) alignment */
4452 rect.X = 5.0;
4453 rect.Y = 5.0;
4454 rect.Width = width * 2.0;
4455 rect.Height = height * 2.0;
4456 set_rect_empty(&bounds);
4457 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4458 expect(Ok, status);
4459 expect(3, glyphs);
4460 expect(1, lines);
4461 expectf(5.0, bounds.X);
4462 expectf(5.0, bounds.Y);
4463 expectf_(width, bounds.Width, 0.01);
4464 expectf(height, bounds.Height);
4466 rect.X = 5.0;
4467 rect.Y = 5.0;
4468 rect.Width = 32000.0;
4469 rect.Height = 32000.0;
4470 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4471 expect(Ok, status);
4472 set_rect_empty(&bounds);
4473 status = GdipGetRegionBounds(region, graphics, &bounds);
4474 expect(Ok, status);
4475 expectf_(5.0 + margin_x, bounds.X, 1.0);
4476 expectf(5.0, bounds.Y);
4477 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4478 todo_wine
4479 expectf_(height - margin_y, bounds.Height, 1.0);
4481 width_rgn = bounds.Width;
4482 height_rgn = bounds.Height;
4484 /* Center alignment */
4485 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4486 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4488 rect.X = 5.0;
4489 rect.Y = 5.0;
4490 rect.Width = width * 2.0;
4491 rect.Height = height * 2.0;
4492 set_rect_empty(&bounds);
4493 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4494 expect(Ok, status);
4495 expect(3, glyphs);
4496 expect(1, lines);
4497 todo_wine
4498 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4499 todo_wine
4500 expectf(5.0 + height/2.0, bounds.Y);
4501 expectf_(width, bounds.Width, 0.01);
4502 expectf(height, bounds.Height);
4504 rect.X = 5.0;
4505 rect.Y = 5.0;
4506 rect.Width = 0.0;
4507 rect.Height = 0.0;
4508 set_rect_empty(&bounds);
4509 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4510 expect(Ok, status);
4511 expect(3, glyphs);
4512 expect(1, lines);
4513 todo_wine
4514 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4515 todo_wine
4516 expectf(5.0 - height/2.0, bounds.Y);
4517 expectf_(width, bounds.Width, 0.01);
4518 expectf(height, bounds.Height);
4520 rect.X = 5.0;
4521 rect.Y = 5.0;
4522 rect.Width = width_rgn * 2.0;
4523 rect.Height = height_rgn * 2.0;
4524 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4525 expect(Ok, status);
4526 set_rect_empty(&bounds);
4527 status = GdipGetRegionBounds(region, graphics, &bounds);
4528 expect(Ok, status);
4529 todo_wine
4530 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4531 todo_wine
4532 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4533 expectf_(width_rgn, bounds.Width, 1.0);
4534 expectf_(height_rgn, bounds.Height, 1.0);
4536 rect.X = 5.0;
4537 rect.Y = 5.0;
4538 rect.Width = 0.0;
4539 rect.Height = 0.0;
4540 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4541 expect(Ok, status);
4542 set_rect_empty(&bounds);
4543 status = GdipGetRegionBounds(region, graphics, &bounds);
4544 expect(Ok, status);
4545 todo_wine
4546 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4547 todo_wine
4548 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4549 expectf_(width_rgn, bounds.Width, 1.0);
4550 expectf_(height_rgn, bounds.Height, 1.0);
4552 /* Far alignment */
4553 GdipSetStringFormatAlign(format, StringAlignmentFar);
4554 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4556 rect.X = 5.0;
4557 rect.Y = 5.0;
4558 rect.Width = width * 2.0;
4559 rect.Height = height * 2.0;
4560 set_rect_empty(&bounds);
4561 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4562 expect(Ok, status);
4563 expect(3, glyphs);
4564 expect(1, lines);
4565 todo_wine
4566 expectf_(5.0 + width, bounds.X, 0.01);
4567 todo_wine
4568 expectf(5.0 + height, bounds.Y);
4569 expectf_(width, bounds.Width, 0.01);
4570 expectf(height, bounds.Height);
4572 rect.X = 5.0;
4573 rect.Y = 5.0;
4574 rect.Width = 0.0;
4575 rect.Height = 0.0;
4576 set_rect_empty(&bounds);
4577 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4578 expect(Ok, status);
4579 expect(3, glyphs);
4580 expect(1, lines);
4581 todo_wine
4582 expectf_(5.0 - width, bounds.X, 0.01);
4583 todo_wine
4584 expectf(5.0 - height, bounds.Y);
4585 expectf_(width, bounds.Width, 0.01);
4586 expectf(height, bounds.Height);
4588 rect.X = 5.0;
4589 rect.Y = 5.0;
4590 rect.Width = width_rgn * 2.0;
4591 rect.Height = height_rgn * 2.0;
4592 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4593 expect(Ok, status);
4594 set_rect_empty(&bounds);
4595 status = GdipGetRegionBounds(region, graphics, &bounds);
4596 expect(Ok, status);
4597 todo_wine
4598 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4599 todo_wine
4600 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4601 expectf_(width_rgn, bounds.Width, 1.0);
4602 expectf_(height_rgn, bounds.Height, 1.0);
4604 rect.X = 5.0;
4605 rect.Y = 5.0;
4606 rect.Width = 0.0;
4607 rect.Height = 0.0;
4608 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4609 expect(Ok, status);
4610 set_rect_empty(&bounds);
4611 status = GdipGetRegionBounds(region, graphics, &bounds);
4612 expect(Ok, status);
4613 todo_wine
4614 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4615 todo_wine
4616 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4617 expectf_(width_rgn, bounds.Width, 1.0);
4618 expectf_(height_rgn, bounds.Height, 1.0);
4620 status = GdipDeleteFont(font);
4621 expect(Ok, status);
4623 status = GdipDeleteGraphics(graphics);
4624 expect(Ok, status);
4625 DeleteDC(hdc);
4627 GdipDeleteFontFamily(family);
4628 GdipDeleteRegion(region);
4629 GdipDeleteStringFormat(format);
4632 static void test_measured_extra_space(void)
4634 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4635 static const WCHAR string[2] = { 'W','W' };
4636 GpStringFormat *format;
4637 HDC hdc;
4638 GpGraphics *graphics;
4639 GpFontFamily *family;
4640 GpFont *font;
4641 GpStatus status;
4642 GpUnit gfx_unit, font_unit;
4643 RectF bounds_1, bounds_2, rect;
4644 REAL margin, font_size, dpi;
4646 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4647 expect(Ok, status);
4649 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4650 expect(Ok, status);
4651 hdc = CreateCompatibleDC(0);
4652 status = GdipCreateFromHDC(hdc, &graphics);
4653 expect(Ok, status);
4655 status = GdipGetDpiX(graphics, &dpi);
4656 expect(Ok, status);
4658 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4659 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4660 for (font_unit = 3; font_unit <= 6; font_unit++)
4662 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4663 expect(Ok, status);
4665 status = GdipGetFontSize(font, &font_size);
4666 expect(Ok, status);
4667 font_size = units_to_pixels(font_size, font_unit, dpi);
4668 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4670 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4671 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4673 status = GdipSetPageUnit(graphics, gfx_unit);
4674 expect(Ok, status);
4676 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4677 set_rect_empty(&rect);
4678 set_rect_empty(&bounds_1);
4679 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4680 expect(Ok, status);
4681 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4682 set_rect_empty(&rect);
4683 set_rect_empty(&bounds_2);
4684 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4685 expect(Ok, status);
4687 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4688 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4689 /*trace("margin %f pixels\n", margin);*/
4690 expectf_(font_size / 6.0, margin, font_size / 100.0);
4693 GdipDeleteFont(font);
4696 GdipDeleteGraphics(graphics);
4697 DeleteDC(hdc);
4698 GdipDeleteFontFamily(family);
4699 GdipDeleteStringFormat(format);
4702 static void test_alpha_hdc(void)
4704 GpStatus status;
4705 HDC hdc, gp_hdc;
4706 HBITMAP hbm, old_hbm;
4707 GpGraphics *graphics;
4708 ULONG *bits;
4709 BITMAPINFO bmi;
4710 GpRectF bounds;
4711 COLORREF colorref;
4713 hdc = CreateCompatibleDC(0);
4714 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4715 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4716 bmi.bmiHeader.biHeight = 5;
4717 bmi.bmiHeader.biWidth = 5;
4718 bmi.bmiHeader.biBitCount = 32;
4719 bmi.bmiHeader.biPlanes = 1;
4720 bmi.bmiHeader.biCompression = BI_RGB;
4721 bmi.bmiHeader.biClrUsed = 0;
4723 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4724 ok(hbm != NULL, "CreateDIBSection failed\n");
4726 old_hbm = SelectObject(hdc, hbm);
4728 status = GdipCreateFromHDC(hdc, &graphics);
4729 expect(Ok, status);
4731 status = GdipGetVisibleClipBounds(graphics, &bounds);
4732 expect(Ok, status);
4733 expectf(0.0, bounds.X);
4734 expectf(0.0, bounds.Y);
4735 expectf(5.0, bounds.Width);
4736 expectf(5.0, bounds.Height);
4738 bits[0] = 0xdeadbeef;
4740 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4741 expect(Ok, status);
4743 expect(0xffaaaaaa, bits[0]);
4745 bits[0] = 0xdeadbeef;
4747 status = GdipGetDC(graphics, &gp_hdc);
4748 expect(Ok, status);
4750 colorref = GetPixel(gp_hdc, 0, 4);
4751 expect(0xefbead, colorref);
4753 SetPixel(gp_hdc, 0, 4, 0xffffff);
4755 expect(0xffffff, bits[0]);
4757 status = GdipReleaseDC(graphics, gp_hdc);
4758 expect(Ok, status);
4760 SelectObject(hdc, old_hbm);
4762 bits[0] = 0xdeadbeef;
4764 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4765 expect(Ok, status);
4767 todo_wine expect(0xffbbbbbb, bits[0]);
4769 GdipDeleteGraphics(graphics);
4771 DeleteObject(hbm);
4772 DeleteDC(hdc);
4775 static void test_bitmapfromgraphics(void)
4777 GpStatus stat;
4778 GpGraphics *graphics = NULL;
4779 HDC hdc = GetDC( hwnd );
4780 GpBitmap *bitmap = NULL;
4781 PixelFormat format;
4782 REAL imageres, graphicsres;
4783 UINT width, height;
4785 stat = GdipCreateFromHDC(hdc, &graphics);
4786 expect(Ok, stat);
4788 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
4789 expect(InvalidParameter, stat);
4791 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
4792 expect(InvalidParameter, stat);
4794 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
4795 expect(Ok, stat);
4797 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
4798 expect(Ok, stat);
4799 expect(PixelFormat32bppPARGB, format);
4801 stat = GdipGetDpiX(graphics, &graphicsres);
4802 expect(Ok, stat);
4804 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
4805 expect(Ok, stat);
4806 expectf(graphicsres, imageres);
4808 stat = GdipGetDpiY(graphics, &graphicsres);
4809 expect(Ok, stat);
4811 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
4812 expect(Ok, stat);
4813 expectf(graphicsres, imageres);
4815 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
4816 expect(Ok, stat);
4817 expect(12, width);
4819 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
4820 expect(Ok, stat);
4821 expect(13, height);
4823 GdipDeleteGraphics(graphics);
4824 GdipDisposeImage((GpImage*)bitmap);
4827 static void test_clipping(void)
4829 HDC hdc;
4830 GpStatus status;
4831 GpGraphics *graphics;
4832 GpRegion *region, *region100x100;
4833 GpMatrix *matrix;
4834 GpRectF rect;
4835 GpPointF ptf[4];
4836 GpUnit unit;
4837 HRGN hrgn;
4838 int ret;
4839 RECT rc;
4841 hdc = CreateCompatibleDC(0);
4842 status = GdipCreateFromHDC(hdc, &graphics);
4843 expect(Ok, status);
4845 status = GdipGetPageUnit(graphics, &unit);
4846 expect(Ok, status);
4847 expect(UnitDisplay, unit);
4849 status = GdipCreateRegion(&region);
4850 expect(Ok, status);
4851 status = GdipSetEmpty(region);
4852 expect(Ok, status);
4854 status = GdipCreateRegion(&region100x100);
4855 expect(Ok, status);
4856 status = GdipSetEmpty(region100x100);
4857 expect(Ok, status);
4859 rect.X = rect.Y = 100.0;
4860 rect.Width = rect.Height = 100.0;
4861 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
4862 expect(Ok, status);
4863 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
4864 expect(Ok, status);
4866 status = GdipGetClipBounds(graphics, &rect);
4867 expect(Ok, status);
4868 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4869 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4871 status = GdipSetEmpty(region);
4872 expect(Ok, status);
4873 status = GdipGetClip(graphics, region);
4874 expect(Ok, status);
4875 status = GdipGetRegionBounds(region, graphics, &rect);
4876 expect(Ok, status);
4877 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4878 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4880 ptf[0].X = 100.0;
4881 ptf[0].Y = 100.0;
4882 ptf[1].X = 200.0;
4883 ptf[1].Y = 200.0;
4884 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4885 expect(Ok, status);
4886 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4887 "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);
4889 status = GdipCreateMatrix(&matrix);
4890 expect(Ok, status);
4891 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
4892 expect(Ok, status);
4893 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
4894 expect(Ok, status);
4895 status = GdipSetWorldTransform(graphics, matrix);
4896 expect(Ok, status);
4898 status = GdipGetClipBounds(graphics, &rect);
4899 expect(Ok, status);
4900 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4901 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4903 status = GdipSetEmpty(region);
4904 expect(Ok, status);
4905 status = GdipGetClip(graphics, region);
4906 expect(Ok, status);
4907 status = GdipGetRegionBounds(region, graphics, &rect);
4908 expect(Ok, status);
4909 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4910 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4912 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4913 expect(Ok, status);
4914 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4915 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4917 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4918 expect(Ok, status);
4919 ret = GetRgnBox(hrgn, &rc);
4920 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4921 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4922 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
4923 DeleteObject(hrgn);
4925 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4926 expect(Ok, status);
4927 ret = GetRgnBox(hrgn, &rc);
4928 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4929 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4930 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
4931 DeleteObject(hrgn);
4933 ptf[0].X = 100.0;
4934 ptf[0].Y = 100.0;
4935 ptf[1].X = 200.0;
4936 ptf[1].Y = 200.0;
4937 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4938 expect(Ok, status);
4939 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
4940 "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);
4942 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
4943 expect(Ok, status);
4944 ret = GetRgnBox(hrgn, &rc);
4945 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4946 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
4947 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
4948 DeleteObject(hrgn);
4950 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
4951 expect(Ok, status);
4952 ret = GetRgnBox(hrgn, &rc);
4953 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4954 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
4955 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
4956 DeleteObject(hrgn);
4958 ptf[0].X = 210.0;
4959 ptf[0].Y = 420.0;
4960 ptf[1].X = 410.0;
4961 ptf[1].Y = 820.0;
4962 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4963 expect(Ok, status);
4964 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
4965 "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);
4967 status = GdipSetPageScale(graphics, 2.0);
4968 expect(Ok, status);
4970 status = GdipGetClipBounds(graphics, &rect);
4971 expect(Ok, status);
4972 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4973 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4975 status = GdipSetEmpty(region);
4976 expect(Ok, status);
4977 status = GdipGetClip(graphics, region);
4978 expect(Ok, status);
4979 status = GdipGetRegionBounds(region, graphics, &rect);
4980 expect(Ok, status);
4981 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
4982 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4984 status = GdipGetRegionBounds(region100x100, graphics, &rect);
4985 expect(Ok, status);
4986 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
4987 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
4989 status = GdipGetRegionHRgn(region, NULL, &hrgn);
4990 expect(Ok, status);
4991 ret = GetRgnBox(hrgn, &rc);
4992 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
4993 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
4994 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
4995 DeleteObject(hrgn);
4997 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4998 expect(Ok, status);
4999 ret = GetRgnBox(hrgn, &rc);
5000 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5001 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5002 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5003 DeleteObject(hrgn);
5005 ptf[0].X = 100.0;
5006 ptf[0].Y = 100.0;
5007 ptf[1].X = 200.0;
5008 ptf[1].Y = 200.0;
5009 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5010 expect(Ok, status);
5011 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5012 "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);
5014 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5015 expect(Ok, status);
5016 ret = GetRgnBox(hrgn, &rc);
5017 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5018 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5019 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5020 DeleteObject(hrgn);
5022 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5023 expect(Ok, status);
5024 ret = GetRgnBox(hrgn, &rc);
5025 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5026 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5027 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5028 DeleteObject(hrgn);
5030 ptf[0].X = 210.0;
5031 ptf[0].Y = 420.0;
5032 ptf[1].X = 410.0;
5033 ptf[1].Y = 820.0;
5034 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5035 expect(Ok, status);
5036 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5037 "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);
5039 GdipSetPageUnit(graphics, UnitPoint);
5040 expect(Ok, status);
5042 status = GdipGetClipBounds(graphics, &rect);
5043 expect(Ok, status);
5044 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5045 /* rounding under Wine is slightly different */
5046 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5047 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5048 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5050 status = GdipSetEmpty(region);
5051 expect(Ok, status);
5052 status = GdipGetClip(graphics, region);
5053 expect(Ok, status);
5054 status = GdipGetRegionBounds(region, graphics, &rect);
5055 expect(Ok, status);
5056 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5057 /* rounding under Wine is slightly different */
5058 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5059 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5060 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5062 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5063 expect(Ok, status);
5064 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5065 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5067 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5068 expect(Ok, status);
5069 ret = GetRgnBox(hrgn, &rc);
5070 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5071 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
5072 /* rounding under Wine is slightly different */
5073 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
5074 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
5075 "expected 14,5-33,14, got %s\n", wine_dbgstr_rect(&rc));
5076 DeleteObject(hrgn);
5078 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5079 expect(Ok, status);
5080 ret = GetRgnBox(hrgn, &rc);
5081 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5082 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5083 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
5084 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5085 DeleteObject(hrgn);
5087 ptf[0].X = 100.0;
5088 ptf[0].Y = 100.0;
5089 ptf[1].X = 200.0;
5090 ptf[1].Y = 200.0;
5091 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5092 expect(Ok, status);
5093 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
5094 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
5095 "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);
5097 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5098 expect(Ok, status);
5099 ret = GetRgnBox(hrgn, &rc);
5100 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5101 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5102 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5103 DeleteObject(hrgn);
5105 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5106 expect(Ok, status);
5107 ret = GetRgnBox(hrgn, &rc);
5108 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5109 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
5110 /* rounding under Wine is slightly different */
5111 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
5112 "expected 560,1120-1094,2187, got %s\n", wine_dbgstr_rect(&rc));
5113 DeleteObject(hrgn);
5115 ptf[0].X = 560.0;
5116 ptf[0].Y = 1120.0;
5117 ptf[1].X = 1094.0;
5118 ptf[1].Y = 2187.0;
5119 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5120 expect(Ok, status);
5121 if (fabs(ptf[0].X - 100.0) < 0.001)
5123 expectf(100.0, ptf[0].X);
5124 expectf(100.0, ptf[0].Y);
5125 expectf(200.125, ptf[1].X);
5126 expectf(200.03125, ptf[1].Y);
5128 else /* before Win7 */
5130 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
5131 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
5132 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
5133 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
5136 status = GdipTransformRegion(region100x100, matrix);
5137 expect(Ok, status);
5139 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5140 expect(Ok, status);
5141 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5142 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5144 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5145 expect(Ok, status);
5146 ret = GetRgnBox(hrgn, &rc);
5147 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5148 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5149 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5150 DeleteObject(hrgn);
5152 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5153 expect(Ok, status);
5154 ret = GetRgnBox(hrgn, &rc);
5155 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5156 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
5157 /* rounding under Wine is slightly different */
5158 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
5159 "expected 1147,4534-2214,8800, got %s\n", wine_dbgstr_rect(&rc));
5160 DeleteObject(hrgn);
5162 ptf[0].X = 1147.0;
5163 ptf[0].Y = 4534.0;
5164 ptf[1].X = 2214.0;
5165 ptf[1].Y = 8800.0;
5166 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5167 expect(Ok, status);
5168 if (fabs(ptf[0].X - 210.0625) < 0.001)
5170 expectf(210.0625, ptf[0].X);
5171 expectf(420.0625, ptf[0].Y);
5172 expectf(410.125, ptf[1].X);
5173 expectf(820.0, ptf[1].Y);
5175 else /* before Win7 */
5177 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
5178 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
5179 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
5180 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
5183 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
5184 expect(Ok, status);
5185 status = GdipSetWorldTransform(graphics, matrix);
5186 expect(Ok, status);
5188 status = GdipGetClipBounds(graphics, &rect);
5189 expect(Ok, status);
5190 expectf_(20.612978, rect.X, 1.0);
5191 expectf_(-6.256012, rect.Y, 1.5);
5192 expectf_(25.612978, rect.Width, 1.0);
5193 expectf_(12.806489, rect.Height, 1.0);
5195 status = GdipSetEmpty(region);
5196 expect(Ok, status);
5197 status = GdipGetClip(graphics, region);
5198 expect(Ok, status);
5199 status = GdipGetRegionBounds(region, graphics, &rect);
5200 expect(Ok, status);
5201 /* rounding under Wine is slightly different */
5202 expectf_(20.612978, rect.X, 1.0);
5203 expectf_(-6.256012, rect.Y, 1.5);
5204 expectf_(25.612978, rect.Width, 1.0);
5205 expectf_(12.806489, rect.Height, 1.0);
5207 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5208 expect(Ok, status);
5209 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5210 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5212 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5213 expect(Ok, status);
5214 ret = GetRgnBox(hrgn, &rc);
5215 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5216 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
5217 /* rounding under Wine is slightly different */
5218 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
5219 "expected (22,-6)-(46,7), got %s\n", wine_dbgstr_rect(&rc));
5220 DeleteObject(hrgn);
5222 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5223 expect(Ok, status);
5224 ret = GetRgnBox(hrgn, &rc);
5225 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5226 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5227 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5228 DeleteObject(hrgn);
5230 ptf[0].X = 100.0;
5231 ptf[0].Y = 100.0;
5232 ptf[1].X = 200.0;
5233 ptf[1].Y = 200.0;
5234 ptf[2].X = 200.0;
5235 ptf[2].Y = 100.0;
5236 ptf[3].X = 100.0;
5237 ptf[3].Y = 200.0;
5238 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5239 expect(Ok, status);
5240 expectf(20.612978, ptf[0].X);
5241 expectf(-1.568512, ptf[0].Y);
5242 expectf(46.225956, ptf[1].X);
5243 expectf(1.862977, ptf[1].Y);
5244 expectf(36.850956, ptf[2].X);
5245 expectf(-6.256012, ptf[2].Y);
5246 expectf(29.987980, ptf[3].X);
5247 expectf(6.550478, ptf[3].Y);
5249 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5250 expect(Ok, status);
5251 ret = GetRgnBox(hrgn, &rc);
5252 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5253 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5254 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5255 DeleteObject(hrgn);
5257 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5258 expect(Ok, status);
5259 ret = GetRgnBox(hrgn, &rc);
5260 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5261 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
5262 /* rounding under Wine is slightly different */
5263 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
5264 "expected (-3406,4500)-(-350,8728), got %s\n", wine_dbgstr_rect(&rc));
5265 DeleteObject(hrgn);
5267 ptf[0].X = -3406.0;
5268 ptf[0].Y = 4500.0;
5269 ptf[1].X = -350.0;
5270 ptf[1].Y = 8728.0;
5271 ptf[2].X = -350.0;
5272 ptf[2].Y = 4500.0;
5273 ptf[3].X = -3406.0;
5274 ptf[3].Y = 8728.0;
5275 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5276 expect(Ok, status);
5277 expectf(-136.190491, ptf[0].X);
5278 expectf(520.010742, ptf[0].Y);
5279 expectf(756.417175, ptf[1].X);
5280 expectf(720.031616, ptf[1].Y);
5281 expectf(360.042114, ptf[2].X);
5282 expectf(376.760742, ptf[2].Y);
5283 expectf(260.184570, ptf[3].X);
5284 expectf(863.281616, ptf[3].Y);
5286 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
5287 expect(Ok, status);
5288 status = GdipSetWorldTransform(graphics, matrix);
5289 expect(Ok, status);
5291 status = GdipGetClipBounds(graphics, &rect);
5292 expect(Ok, status);
5293 expectf_(-28.100956, rect.X, 1.0);
5294 expectf_(7.806488, rect.Y, 1.5);
5295 expectf_(25.612978, rect.Width, 1.0);
5296 expectf_(12.806489, rect.Height, 1.0);
5298 status = GdipSetEmpty(region);
5299 expect(Ok, status);
5300 status = GdipGetClip(graphics, region);
5301 expect(Ok, status);
5302 status = GdipGetRegionBounds(region, graphics, &rect);
5303 expect(Ok, status);
5304 /* rounding under Wine is slightly different */
5305 expectf_(-28.100956, rect.X, 1.0);
5306 expectf_(7.806488, rect.Y, 1.5);
5307 expectf_(25.612978, rect.Width, 1.0);
5308 expectf_(12.806489, rect.Height, 1.0);
5310 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5311 expect(Ok, status);
5312 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5313 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5315 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5316 expect(Ok, status);
5317 ret = GetRgnBox(hrgn, &rc);
5318 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5319 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5320 /* rounding under Wine is slightly different */
5321 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5322 "expected (-27,8)-(-2,21), got %s\n", wine_dbgstr_rect(&rc));
5323 DeleteObject(hrgn);
5325 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5326 expect(Ok, status);
5327 ret = GetRgnBox(hrgn, &rc);
5328 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5329 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5330 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5331 DeleteObject(hrgn);
5333 ptf[0].X = 100.0;
5334 ptf[0].Y = 100.0;
5335 ptf[1].X = 200.0;
5336 ptf[1].Y = 200.0;
5337 ptf[2].X = 200.0;
5338 ptf[2].Y = 100.0;
5339 ptf[3].X = 100.0;
5340 ptf[3].Y = 200.0;
5341 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5342 expect(Ok, status);
5343 expectf(-11.862979, ptf[0].X);
5344 expectf(7.806488, ptf[0].Y);
5345 expectf(-18.725958, ptf[1].X);
5346 expectf(20.612976, ptf[1].Y);
5347 expectf(-2.487981, ptf[2].X);
5348 expectf(15.925477, ptf[2].Y);
5349 expectf(-28.100956, ptf[3].X);
5350 expectf(12.493987, ptf[3].Y);
5352 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5353 expect(Ok, status);
5354 ret = GetRgnBox(hrgn, &rc);
5355 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5356 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5357 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5358 DeleteObject(hrgn);
5360 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5361 expect(Ok, status);
5362 ret = GetRgnBox(hrgn, &rc);
5363 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5364 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5365 /* rounding under Wine is slightly different */
5366 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5367 "expected (4500,351)-(8728,3407), got %s\n", wine_dbgstr_rect(&rc));
5368 DeleteObject(hrgn);
5370 ptf[0].X = -3406.0;
5371 ptf[0].Y = 4500.0;
5372 ptf[1].X = -350.0;
5373 ptf[1].Y = 8728.0;
5374 ptf[2].X = -350.0;
5375 ptf[2].Y = 4500.0;
5376 ptf[3].X = -3406.0;
5377 ptf[3].Y = 8728.0;
5378 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5379 expect(Ok, status);
5380 expectf(-1055.021484, ptf[0].X);
5381 expectf(-70.595329, ptf[0].Y);
5382 expectf(-1455.063232, ptf[1].X);
5383 expectf(375.708435, ptf[1].Y);
5384 expectf(-768.521484, ptf[2].X);
5385 expectf(177.520981, ptf[2].Y);
5386 expectf(-1741.563110, ptf[3].X);
5387 expectf(127.592125, ptf[3].Y);
5389 GdipDeleteMatrix(matrix);
5390 GdipDeleteRegion(region);
5391 GdipDeleteRegion(region100x100);
5392 GdipDeleteGraphics(graphics);
5393 DeleteDC(hdc);
5396 static void test_clipping_2(void)
5399 HDC hdc;
5400 GpStatus status;
5401 GpGraphics *graphics;
5402 GpRegion *region;
5403 GpMatrix *matrix;
5404 GpRectF rect;
5405 GpPointF ptf[4];
5406 GpUnit unit;
5407 HRGN hrgn;
5408 int ret;
5409 RECT rc;
5411 hdc = CreateCompatibleDC(0);
5412 status = GdipCreateFromHDC(hdc, &graphics);
5413 expect(Ok, status);
5415 status = GdipGetPageUnit(graphics, &unit);
5416 expect(Ok, status);
5417 expect(UnitDisplay, unit);
5419 GdipSetPageUnit(graphics, UnitInch);
5421 status = GdipCreateRegion(&region);
5422 expect(Ok, status);
5423 status = GdipSetEmpty(region);
5424 expect(Ok, status);
5425 rect.X = rect.Y = 100.0;
5426 rect.Width = rect.Height = 100.0;
5427 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5428 expect(Ok, status);
5429 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5430 expect(Ok, status);
5432 status = GdipGetClip(graphics, region);
5433 expect(Ok, status);
5434 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5435 expect(Ok, status);
5436 ret = GetRgnBox(hrgn, &rc);
5437 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5438 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5439 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5440 DeleteObject(hrgn);
5441 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5442 expect(Ok, status);
5443 ret = GetRgnBox(hrgn, &rc);
5444 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5445 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5446 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5447 DeleteObject(hrgn);
5449 ptf[0].X = 9600.0;
5450 ptf[0].Y = 9600.0;
5451 ptf[1].X = 19200.0;
5452 ptf[1].Y = 19200.0;
5453 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5454 expect(Ok, status);
5455 expectf(100.0, ptf[0].X);
5456 expectf(100.0, ptf[0].Y);
5457 expectf(200.0, ptf[1].X);
5458 expectf(200.0, ptf[1].X);
5460 GdipSetPageUnit(graphics, UnitPoint);
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 == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5468 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5469 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5470 "expected 7200,7200-14400,14400, got %s\n", wine_dbgstr_rect(&rc));
5471 DeleteObject(hrgn);
5472 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5473 expect(Ok, status);
5474 ret = GetRgnBox(hrgn, &rc);
5475 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5476 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5477 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5478 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5479 DeleteObject(hrgn);
5481 ptf[0].X = 9600.0;
5482 ptf[0].Y = 9600.0;
5483 ptf[1].X = 19200.0;
5484 ptf[1].Y = 19200.0;
5485 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5486 expect(Ok, status);
5487 if (fabs(ptf[0].X - 7200.0) < 0.001)
5488 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5489 "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);
5490 else /* before Win7 */
5492 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5493 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5494 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5495 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5498 GdipDeleteRegion(region);
5500 GdipSetPageUnit(graphics, UnitPixel);
5502 status = GdipCreateRegion(&region);
5503 expect(Ok, status);
5504 status = GdipSetEmpty(region);
5505 expect(Ok, status);
5506 rect.X = rect.Y = 100.0;
5507 rect.Width = rect.Height = 100.0;
5508 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5509 expect(Ok, status);
5510 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5511 expect(Ok, status);
5513 status = GdipGetClip(graphics, region);
5514 expect(Ok, status);
5515 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5516 expect(Ok, status);
5517 ret = GetRgnBox(hrgn, &rc);
5518 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5519 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5520 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5521 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5522 DeleteObject(hrgn);
5523 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5524 expect(Ok, status);
5525 ret = GetRgnBox(hrgn, &rc);
5526 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5527 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5528 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5529 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5530 DeleteObject(hrgn);
5532 ptf[0].X = 100.0;
5533 ptf[0].Y = 100.0;
5534 ptf[1].X = 200.0;
5535 ptf[1].Y = 200.0;
5536 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5537 expect(Ok, status);
5538 if (fabs(ptf[0].X - 100.0) < 0.001)
5539 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5540 "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);
5541 else /* before Win7 */
5543 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5544 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5545 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5546 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5549 GdipSetPageUnit(graphics, UnitPoint);
5551 status = GdipGetClip(graphics, region);
5552 expect(Ok, status);
5553 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5554 expect(Ok, status);
5555 ret = GetRgnBox(hrgn, &rc);
5556 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5557 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5558 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5559 "expected 75,75-150,150, got %s\n", wine_dbgstr_rect(&rc));
5560 DeleteObject(hrgn);
5561 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5562 expect(Ok, status);
5563 ret = GetRgnBox(hrgn, &rc);
5564 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5565 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5566 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5567 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5568 DeleteObject(hrgn);
5570 ptf[0].X = 100.0;
5571 ptf[0].Y = 100.0;
5572 ptf[1].X = 200.0;
5573 ptf[1].Y = 200.0;
5574 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5575 expect(Ok, status);
5576 if (fabs(ptf[0].X - 75.0) < 0.001)
5577 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5578 "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);
5579 else /* before Win7 */
5581 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5582 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5583 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5584 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5587 status = GdipCreateMatrix(&matrix);
5588 expect(Ok, status);
5589 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5590 expect(Ok, status);
5591 status = GdipSetWorldTransform(graphics, matrix);
5592 expect(Ok, status);
5593 GdipDeleteMatrix(matrix);
5595 status = GdipGetClip(graphics, region);
5596 expect(Ok, status);
5597 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5598 expect(Ok, status);
5599 ret = GetRgnBox(hrgn, &rc);
5600 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5601 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5602 "expected 65,65-140,140, got %s\n", wine_dbgstr_rect(&rc));
5603 DeleteObject(hrgn);
5604 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5605 expect(Ok, status);
5606 ret = GetRgnBox(hrgn, &rc);
5607 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5608 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5609 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5610 DeleteObject(hrgn);
5612 ptf[0].X = 100.0;
5613 ptf[0].Y = 100.0;
5614 ptf[1].X = 200.0;
5615 ptf[1].Y = 200.0;
5616 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5617 expect(Ok, status);
5618 expectf(65.0, ptf[0].X);
5619 expectf(65.0, ptf[0].Y);
5620 expectf(140.0, ptf[1].X);
5621 expectf(140.0, ptf[1].X);
5623 status = GdipCreateMatrix(&matrix);
5624 expect(Ok, status);
5625 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5626 expect(Ok, status);
5627 status = GdipSetWorldTransform(graphics, matrix);
5628 expect(Ok, status);
5629 GdipDeleteMatrix(matrix);
5631 status = GdipGetClip(graphics, region);
5632 expect(Ok, status);
5633 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5634 expect(Ok, status);
5635 ret = GetRgnBox(hrgn, &rc);
5636 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5637 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5638 "expected 300,150-600,300, got %s\n", wine_dbgstr_rect(&rc));
5639 DeleteObject(hrgn);
5640 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5641 expect(Ok, status);
5642 ret = GetRgnBox(hrgn, &rc);
5643 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5644 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5645 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5646 DeleteObject(hrgn);
5648 ptf[0].X = 100.0;
5649 ptf[0].Y = 100.0;
5650 ptf[1].X = 200.0;
5651 ptf[1].Y = 200.0;
5652 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5653 expect(Ok, status);
5654 expectf(300.0, ptf[0].X);
5655 expectf(150.0, ptf[0].Y);
5656 expectf(600.0, ptf[1].X);
5657 expectf(300.0, ptf[1].Y);
5659 status = GdipSetPageScale(graphics, 2.0);
5660 expect(Ok, status);
5662 status = GdipGetClip(graphics, region);
5663 expect(Ok, status);
5664 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5665 expect(Ok, status);
5666 ret = GetRgnBox(hrgn, &rc);
5667 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5668 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5669 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5670 "expected 150,75-300,150, got %s\n", wine_dbgstr_rect(&rc));
5671 DeleteObject(hrgn);
5672 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5673 expect(Ok, status);
5674 ret = GetRgnBox(hrgn, &rc);
5675 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5676 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5677 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5678 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5679 DeleteObject(hrgn);
5681 ptf[0].X = 100.0;
5682 ptf[0].Y = 100.0;
5683 ptf[1].X = 200.0;
5684 ptf[1].Y = 200.0;
5685 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5686 expect(Ok, status);
5687 if (fabs(ptf[0].X - 150.0) < 0.001)
5689 expectf(150.0, ptf[0].X);
5690 expectf(75.0, ptf[0].Y);
5691 expectf(300.0, ptf[1].X);
5692 expectf(150.0, ptf[1].Y);
5694 else /* before Win7 */
5696 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5697 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5698 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5699 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5702 status = GdipCreateMatrix(&matrix);
5703 expect(Ok, status);
5704 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5705 expect(Ok, status);
5706 status = GdipSetWorldTransform(graphics, matrix);
5707 expect(Ok, status);
5708 GdipDeleteMatrix(matrix);
5710 status = GdipGetClip(graphics, region);
5711 expect(Ok, status);
5712 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5713 expect(Ok, status);
5714 ret = GetRgnBox(hrgn, &rc);
5715 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5716 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5717 /* rounding under Wine is slightly different */
5718 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5719 "expected 54,-26-107,27, got %s\n", wine_dbgstr_rect(&rc));
5720 DeleteObject(hrgn);
5721 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5722 expect(Ok, status);
5723 ret = GetRgnBox(hrgn, &rc);
5724 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5725 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5726 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5727 DeleteObject(hrgn);
5729 ptf[0].X = 100.0;
5730 ptf[0].Y = 100.0;
5731 ptf[1].X = 200.0;
5732 ptf[1].Y = 200.0;
5733 ptf[2].X = 200.0;
5734 ptf[2].Y = 100.0;
5735 ptf[3].X = 100.0;
5736 ptf[3].Y = 200.0;
5737 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5738 expect(Ok, status);
5739 expectf(53.033016, ptf[0].X);
5740 expectf(0.0, ptf[0].Y);
5741 expectf(106.066032, ptf[1].X);
5742 expectf(0.0, ptf[1].Y);
5743 expectf(79.549522, ptf[2].X);
5744 expectf(-26.516510, ptf[2].Y);
5745 expectf(79.549522, ptf[3].X);
5746 expectf(26.516508, ptf[3].Y);
5748 status = GdipCreateMatrix(&matrix);
5749 expect(Ok, status);
5750 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5751 expect(Ok, status);
5752 status = GdipSetWorldTransform(graphics, matrix);
5753 expect(Ok, status);
5754 GdipDeleteMatrix(matrix);
5756 status = GdipGetClip(graphics, region);
5757 expect(Ok, status);
5758 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5759 expect(Ok, status);
5760 ret = GetRgnBox(hrgn, &rc);
5761 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5762 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
5763 /* rounding under Wine is slightly different */
5764 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
5765 "expected -26,54-27,107, got %s\n", wine_dbgstr_rect(&rc));
5766 DeleteObject(hrgn);
5767 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5768 expect(Ok, status);
5769 ret = GetRgnBox(hrgn, &rc);
5770 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5771 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5772 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5773 DeleteObject(hrgn);
5775 ptf[0].X = 100.0;
5776 ptf[0].Y = 100.0;
5777 ptf[1].X = 200.0;
5778 ptf[1].Y = 200.0;
5779 ptf[2].X = 200.0;
5780 ptf[2].Y = 100.0;
5781 ptf[3].X = 100.0;
5782 ptf[3].Y = 200.0;
5783 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5784 expect(Ok, status);
5785 expectf(0.0, ptf[0].X);
5786 expectf(53.033005, ptf[0].Y);
5787 expectf(0.0, ptf[1].X);
5788 expectf(106.066010, ptf[1].Y);
5789 expectf(26.516491, ptf[2].X);
5790 expectf(79.549507, ptf[2].Y);
5791 expectf(-26.516520, ptf[3].X);
5792 expectf(79.549500, ptf[3].Y);
5794 GdipDeleteRegion(region);
5795 GdipDeleteGraphics(graphics);
5796 DeleteDC(hdc);
5800 static void test_GdipFillRectangles(void)
5802 GpStatus status;
5803 GpGraphics *graphics = NULL;
5804 GpBrush *brush = NULL;
5805 HDC hdc = GetDC( hwnd );
5806 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
5808 ok(hdc != NULL, "Expected HDC to be initialized\n");
5810 status = GdipCreateFromHDC(hdc, &graphics);
5811 expect(Ok, status);
5812 ok(graphics != NULL, "Expected graphics to be initialized\n");
5814 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
5815 expect(Ok, status);
5816 ok(brush != NULL, "Expected brush to be initialized\n");
5818 status = GdipFillRectangles(NULL, brush, rects, 2);
5819 expect(InvalidParameter, status);
5821 status = GdipFillRectangles(graphics, NULL, rects, 2);
5822 expect(InvalidParameter, status);
5824 status = GdipFillRectangles(graphics, brush, NULL, 2);
5825 expect(InvalidParameter, status);
5827 status = GdipFillRectangles(graphics, brush, rects, 0);
5828 expect(InvalidParameter, status);
5830 status = GdipFillRectangles(graphics, brush, rects, -1);
5831 expect(InvalidParameter, status);
5833 status = GdipFillRectangles(graphics, brush, rects, 1);
5834 expect(Ok, status);
5836 status = GdipFillRectangles(graphics, brush, rects, 2);
5837 expect(Ok, status);
5839 GdipDeleteBrush(brush);
5840 GdipDeleteGraphics(graphics);
5842 ReleaseDC(hwnd, hdc);
5845 static void test_GdipGetVisibleClipBounds_memoryDC(void)
5847 HDC hdc,dc;
5848 HBITMAP bmp;
5849 HGDIOBJ old;
5850 RECT rect;
5851 POINT pt;
5852 int width = 0;
5853 int height = 0;
5854 GpGraphics* graphics = NULL;
5855 GpRect boundRect;
5856 GpStatus status;
5858 ok(GetClientRect(hwnd, &rect), "GetClientRect should have succeeded\n");
5859 width = rect.right - rect.left;
5860 height = rect.bottom - rect.top;
5862 dc = GetDC(hwnd);
5863 hdc = CreateCompatibleDC ( dc );
5864 bmp = CreateCompatibleBitmap ( dc, width, height );
5865 old = SelectObject (hdc, bmp);
5867 /*change the window origin is the key test point*/
5868 SetWindowOrgEx (hdc, rect.left+10, rect.top+10, &pt);
5870 status = GdipCreateFromHDC(hdc, &graphics);
5871 expect(Ok, status);
5873 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
5874 expect(Ok, status);
5876 ok(boundRect.X==rect.left+10 &&
5877 boundRect.Y==rect.top+10 &&
5878 boundRect.Width==width &&
5879 boundRect.Height==height, "Expected GdipGetVisibleClipBoundsI ok\n");
5881 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
5882 expect(Ok, status);
5884 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
5885 expect(Ok, status);
5887 ok(boundRect.X==rect.left+10 &&
5888 boundRect.Y==rect.top+10 &&
5889 boundRect.Width==width-10 &&
5890 boundRect.Height==height-10, "Expected GdipGetVisibleClipBoundsI ok\n");
5892 GdipDeleteGraphics(graphics);
5894 SelectObject (hdc, old);
5895 DeleteObject (bmp);
5896 DeleteDC (hdc);
5897 ReleaseDC(hwnd, dc);
5900 START_TEST(graphics)
5902 struct GdiplusStartupInput gdiplusStartupInput;
5903 ULONG_PTR gdiplusToken;
5904 WNDCLASSA class;
5906 memset( &class, 0, sizeof(class) );
5907 class.lpszClassName = "gdiplus_test";
5908 class.style = CS_HREDRAW | CS_VREDRAW;
5909 class.lpfnWndProc = DefWindowProcA;
5910 class.hInstance = GetModuleHandleA(0);
5911 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5912 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5913 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
5914 RegisterClassA( &class );
5915 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5916 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
5917 ok(hwnd != NULL, "Expected window to be created\n");
5919 gdiplusStartupInput.GdiplusVersion = 1;
5920 gdiplusStartupInput.DebugEventCallback = NULL;
5921 gdiplusStartupInput.SuppressBackgroundThread = 0;
5922 gdiplusStartupInput.SuppressExternalCodecs = 0;
5924 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
5926 test_clipping();
5927 test_clipping_2();
5928 test_measured_extra_space();
5929 test_measure_string();
5930 test_font_height_scaling();
5931 test_transform();
5932 test_pen_thickness();
5933 test_GdipMeasureString();
5934 test_constructor_destructor();
5935 test_save_restore();
5936 test_GdipFillClosedCurve2();
5937 test_GdipFillClosedCurve2I();
5938 test_GdipDrawBezierI();
5939 test_GdipDrawArc();
5940 test_GdipDrawArcI();
5941 test_GdipDrawCurve();
5942 test_GdipDrawCurveI();
5943 test_GdipDrawCurve2();
5944 test_GdipDrawCurve2I();
5945 test_GdipDrawCurve3();
5946 test_GdipDrawCurve3I();
5947 test_GdipDrawLineI();
5948 test_GdipDrawLinesI();
5949 test_GdipDrawImagePointsRect();
5950 test_GdipFillClosedCurve();
5951 test_GdipFillClosedCurveI();
5952 test_GdipDrawString();
5953 test_GdipGetNearestColor();
5954 test_GdipGetVisibleClipBounds();
5955 test_GdipIsVisiblePoint();
5956 test_GdipIsVisibleRect();
5957 test_Get_Release_DC();
5958 test_BeginContainer2();
5959 test_transformpoints();
5960 test_get_set_clip();
5961 test_isempty();
5962 test_clear();
5963 test_textcontrast();
5964 test_fromMemoryBitmap();
5965 test_string_functions();
5966 test_get_set_interpolation();
5967 test_get_set_textrenderinghint();
5968 test_getdc_scaled();
5969 test_alpha_hdc();
5970 test_bitmapfromgraphics();
5971 test_GdipFillRectangles();
5972 test_GdipGetVisibleClipBounds_memoryDC();
5974 GdiplusShutdown(gdiplusToken);
5975 DestroyWindow( hwnd );