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