[2/2] gdiplus: Add more tests for GdipMeasureString using device with custom resolution.

Dmitry Timoshkov dmitry at baikal.ru
Fri Jul 27 00:10:59 CDT 2012


---
 dlls/gdiplus/tests/graphics.c | 275 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 245 insertions(+), 30 deletions(-)

diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c
index e6b6513..753d49d 100644
--- a/dlls/gdiplus/tests/graphics.c
+++ b/dlls/gdiplus/tests/graphics.c
@@ -31,6 +31,49 @@
 
 static HWND hwnd;
 
+static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale)
+{
+    GpStatus status;
+    union
+    {
+        GpBitmap *bitmap;
+        GpImage *image;
+    } u;
+    GpGraphics *graphics = NULL;
+    REAL res;
+
+    status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
+    expect(Ok, status);
+
+    status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
+    expect(Ok, status);
+    status = GdipGetImageHorizontalResolution(u.image, &res);
+    expect(Ok, status);
+    expectf(res_x, res);
+    status = GdipGetImageVerticalResolution(u.image, &res);
+    expect(Ok, status);
+    expectf(res_y, res);
+
+    status = GdipGetImageGraphicsContext(u.image, &graphics);
+    expect(Ok, status);
+    status = GdipDisposeImage(u.image);
+    expect(Ok, status);
+
+    status = GdipGetDpiX(graphics, &res);
+    expect(Ok, status);
+    expectf(res_x, res);
+    status = GdipGetDpiY(graphics, &res);
+    expect(Ok, status);
+    expectf(res_y, res);
+
+    status = GdipSetPageUnit(graphics, unit);
+    expect(Ok, status);
+    status = GdipSetPageScale(graphics, scale);
+    expect(Ok, status);
+
+    return graphics;
+}
+
 static void test_constructor_destructor(void)
 {
     GpStatus stat;
@@ -3314,15 +3357,23 @@ static void test_GdipMeasureString(void)
     GpFont *font;
     HDC hdc;
     GpStringFormat *format;
-    RectF bounds, rc = { 0.0, 0.0, 0.0, 0.0 };
+    RectF bounds, rc, empty_rc = { 0.0, 0.0, 0.0, 0.0 };
     REAL rval, dpi;
+    INT res_y;
 
     hdc = CreateCompatibleDC(0);
     ok(hdc != 0, "CreateCompatibleDC failed\n");
-    status = GdipCreateFromHDC(hdc, &graphics);
+    res_y = GetDeviceCaps(hdc, LOGPIXELSY);
+    DeleteDC(hdc);
+
+    /* 96x96 dpi device, scale 1.0 */
+    graphics = create_graphics(96.0, 96.0, UnitDisplay, 1.0);
+    status = GdipGetDpiX(graphics, &dpi);
     expect(Ok, status);
+    expectf(96.0, dpi);
     status = GdipGetDpiY(graphics, &dpi);
     expect(Ok, status);
+    expectf(96.0, dpi);
     status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
     expect(Ok, status);
     status = GdipCreateFont(family, 18.0, FontStyleRegular, UnitPoint, &font);
@@ -3330,15 +3381,48 @@ static void test_GdipMeasureString(void)
     status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
     expect(Ok, status);
 
-    if (dpi == 96.0)
+    if (res_y == 96)
     {
+        /* UnitDisplay */
         status = GdipSetPageUnit(graphics, UnitDisplay);
         expect(Ok, status);
 
         status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
         expect(Ok, status);
         expectf(28.968750, rval);
+        status = GdipGetFontHeight(font, graphics, &rval);
+        expect(Ok, status);
+        expectf(28.968750, rval);
+        status = GdipGetFontSize(font, &rval);
+        expect(Ok, status);
+        expectf(18.0, rval);
+
+        rc = empty_rc;
+        status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+        expect(Ok, status);
+        expectf(0.0, bounds.X);
+        expectf(0.0, bounds.Y);
+        expectf_(102.499985, bounds.Width, 11.5);
+        expectf_(31.968744, bounds.Height, 3.1);
 
+        /* make sure it really fits */
+        bounds.Width += 1.0;
+        bounds.Height += 1.0;
+        rc = bounds;
+        status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+        expect(Ok, status);
+        expectf(0.0, bounds.X);
+        expectf(0.0, bounds.Y);
+        expectf_(102.499985, bounds.Width, 11.5);
+        expectf_(31.968744, bounds.Height, 3.1);
+
+        /* UnitPixel */
+        status = GdipSetPageUnit(graphics, UnitPixel);
+        expect(Ok, status);
+
+        status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
+        expect(Ok, status);
+        expectf(28.968750, rval);
         status = GdipGetFontHeight(font, graphics, &rval);
         expect(Ok, status);
         expectf(28.968750, rval);
@@ -3346,6 +3430,18 @@ static void test_GdipMeasureString(void)
         expect(Ok, status);
         expectf(18.0, rval);
 
+        rc = empty_rc;
+        status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+        expect(Ok, status);
+        expectf(0.0, bounds.X);
+        expectf(0.0, bounds.Y);
+        expectf_(102.499985, bounds.Width, 11.5);
+        expectf_(31.968744, bounds.Height, 3.1);
+
+        /* make sure it really fits */
+        bounds.Width += 1.0;
+        bounds.Height += 1.0;
+        rc = bounds;
         status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
         expect(Ok, status);
         expectf(0.0, bounds.X);
@@ -3356,9 +3452,13 @@ static void test_GdipMeasureString(void)
     else
         skip("screen resolution %f dpi, test runs at 96 dpi\n", dpi);
 
+    /* UnitPoint */
     status = GdipSetPageUnit(graphics, UnitPoint);
     expect(Ok, status);
 
+    status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
+    expect(Ok, status);
+    expectf(28.968750, rval);
     status = GdipGetFontHeight(font, graphics, &rval);
     expect(Ok, status);
     expectf(21.726563, rval);
@@ -3366,16 +3466,34 @@ static void test_GdipMeasureString(void)
     expect(Ok, status);
     expectf(18.0, rval);
 
+    rc = empty_rc;
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+    expect(Ok, status);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+    expectf_(76.875000, bounds.Width, 10.0);
+    expectf_(23.976563, bounds.Height, 2.1);
+
+    /* make sure it really fits */
+    bounds.Width += 1.0;
+    bounds.Height += 1.0;
+    rc = bounds;
     status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
     expect(Ok, status);
     expectf(0.0, bounds.X);
     expectf(0.0, bounds.Y);
+todo_wine
     expectf_(76.875000, bounds.Width, 10.0);
+todo_wine
     expectf_(23.976563, bounds.Height, 2.1);
 
+    /* UnitMillimeter */
     status = GdipSetPageUnit(graphics, UnitMillimeter);
     expect(Ok, status);
 
+    status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
+    expect(Ok, status);
+    expectf(28.968750, rval);
     status = GdipGetFontHeight(font, graphics, &rval);
     expect(Ok, status);
     expectf(7.664648, rval);
@@ -3383,6 +3501,7 @@ static void test_GdipMeasureString(void)
     expect(Ok, status);
     expectf(18.0, rval);
 
+    rc = empty_rc;
     status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
     expect(Ok, status);
     expectf(0.0, bounds.X);
@@ -3390,55 +3509,151 @@ static void test_GdipMeasureString(void)
     expectf_(27.119789, bounds.Width, 2.7);
     expectf_(8.458398, bounds.Height, 0.8);
 
+    /* make sure it really fits */
+    bounds.Width += 1.0;
+    bounds.Height += 1.0;
+    rc = bounds;
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+    expect(Ok, status);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(27.119789, bounds.Width, 2.7);
+todo_wine
+    expectf_(8.458398, bounds.Height, 0.8);
+
     GdipDeleteStringFormat(format);
     GdipDeleteFont(font);
     GdipDeleteFontFamily(family);
     GdipDeleteGraphics(graphics);
 
-    DeleteDC(hdc);
-}
+    /* 144x622 dpi device, scale 1.5 */
+    graphics = create_graphics(144.0, 622.0, UnitPixel, 1.5);
+    status = GdipGetDpiX(graphics, &dpi);
+    expect(Ok, status);
+    expectf(144.0, dpi);
+    status = GdipGetDpiY(graphics, &dpi);
+    expect(Ok, status);
+    expectf(622.0, dpi);
+    status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
+    expect(Ok, status);
+    status = GdipCreateFont(family, 18.0, FontStyleRegular, UnitPoint, &font);
+    expect(Ok, status);
+    status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
+    expect(Ok, status);
 
-static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale)
-{
-    GpStatus status;
-    union
-    {
-        GpBitmap *bitmap;
-        GpImage *image;
-    } u;
-    GpGraphics *graphics = NULL;
-    REAL res;
+    /* UnitPixel */
+    status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
+    expect(Ok, status);
+    expectf(187.693359, rval);
+    status = GdipGetFontHeight(font, graphics, &rval);
+    expect(Ok, status);
+    expectf(28.968746, rval);
+    status = GdipGetFontSize(font, &rval);
+    expect(Ok, status);
+    expectf(18.0, rval);
 
-    status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
+    rc = empty_rc;
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+    expect(Ok, status);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(102.499985, bounds.Width, 0.001);
+todo_wine
+    expectf_(31.968744, bounds.Height, 0.001);
+
+    /* make sure it really fits */
+    bounds.Width += 1.0;
+    bounds.Height += 1.0;
+    rc = bounds;
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
+    expect(Ok, status);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(102.499985, bounds.Width, 0.001);
+todo_wine
+    expectf_(31.968744, bounds.Height, 0.001);
+
+    /* UnitPoint */
+    status = GdipSetPageUnit(graphics, UnitPoint);
     expect(Ok, status);
 
-    status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
+    status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
     expect(Ok, status);
-    status = GdipGetImageHorizontalResolution(u.image, &res);
+    expectf(187.693359, rval);
+    status = GdipGetFontHeight(font, graphics, &rval);
     expect(Ok, status);
-    expectf(res_x, res);
-    status = GdipGetImageVerticalResolution(u.image, &res);
+todo_wine
+    expectf(14.484373, rval);
+    status = GdipGetFontSize(font, &rval);
     expect(Ok, status);
-    expectf(res_y, res);
+    expectf(18.0, rval);
 
-    status = GdipGetImageGraphicsContext(u.image, &graphics);
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
     expect(Ok, status);
-    status = GdipDisposeImage(u.image);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(51.249992, bounds.Width, 0.001);
+todo_wine
+    expectf_(15.984372, bounds.Height, 0.001);
+
+    /* make sure it really fits */
+    bounds.Width += 1.0;
+    bounds.Height += 1.0;
+    rc = bounds;
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
     expect(Ok, status);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(51.249992, bounds.Width, 0.001);
+todo_wine
+    expectf_(15.984372, bounds.Height, 0.001);
 
-    status = GdipGetDpiX(graphics, &res);
+    /* UnitMillimeter */
+    status = GdipSetPageUnit(graphics, UnitMillimeter);
     expect(Ok, status);
-    expectf(res_x, res);
-    status = GdipGetDpiY(graphics, &res);
+
+    status = GdipGetFontHeightGivenDPI(font, dpi, &rval);
     expect(Ok, status);
-    expectf(res_y, res);
+    expectf(187.693359, rval);
+    status = GdipGetFontHeight(font, graphics, &rval);
+    expect(Ok, status);
+todo_wine
+    expectf(5.109765, rval);
+    status = GdipGetFontSize(font, &rval);
+    expect(Ok, status);
+    expectf(18.0, rval);
 
-    status = GdipSetPageUnit(graphics, unit);
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
     expect(Ok, status);
-    status = GdipSetPageScale(graphics, scale);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(18.079859, bounds.Width, 0.001);
+todo_wine
+    expectf_(5.638931, bounds.Height, 0.001);
+
+    /* make sure it really fits */
+    bounds.Width += 1.0;
+    bounds.Height += 1.0;
+    rc = bounds;
+    status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, NULL, NULL);
     expect(Ok, status);
+    expectf(0.0, bounds.X);
+    expectf(0.0, bounds.Y);
+todo_wine
+    expectf_(18.079859, bounds.Width, 0.001);
+todo_wine
+    expectf_(5.638931, bounds.Height, 0.001);
 
-    return graphics;
+    GdipDeleteStringFormat(format);
+    GdipDeleteFont(font);
+    GdipDeleteFontFamily(family);
+    GdipDeleteGraphics(graphics);
 }
 
 static void test_transform(void)
-- 
1.7.11.2




More information about the wine-patches mailing list