From 137128fa50dc6e7cb69ba47d305c1b2271977605 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Fri, 20 Mar 2015 16:04:39 -0500 Subject: [PATCH] gdiplus: Fonts in UnitWorld shouldn't be scaled to the page unit. --- dlls/gdiplus/font.c | 2 +- dlls/gdiplus/graphics.c | 2 +- dlls/gdiplus/tests/graphics.c | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c index f485058a937..850f44a7139 100644 --- a/dlls/gdiplus/font.c +++ b/dlls/gdiplus/font.c @@ -465,7 +465,7 @@ GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics, LOGFONTW matrix = graphics->worldtrans; - if (font->unit == UnitPixel) + if (font->unit == UnitPixel || font->unit == UnitWorld) { height = units_to_pixels(font->emSize, graphics->unit, graphics->yres); if (graphics->unit != UnitDisplay) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 5284b99edaa..7485a3c401f 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -2123,7 +2123,7 @@ static void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, HFONT unscaled_font; TEXTMETRICW textmet; - if (font->unit == UnitPixel) + if (font->unit == UnitPixel || font->unit == UnitWorld) font_height = font->emSize; else { diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c index 77de9e41df3..f237090192d 100644 --- a/dlls/gdiplus/tests/graphics.c +++ b/dlls/gdiplus/tests/graphics.c @@ -3695,6 +3695,62 @@ todo_wine GdipDeleteFont(font); } + /* Font with units = UnitWorld */ + for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) + { + GpPointF pt = {0.0, 100.0}; + GpImage* image; + REAL expected_width, expected_height; + + graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image); + + status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1); + expect(Ok, status); + + status = GdipCreateFont(family, pt.Y, FontStyleRegular, UnitWorld, &font); + expect(Ok, status); + + status = GdipGetFontUnit(font, &font_unit); + expect(Ok, status); + expect(UnitWorld, font_unit); + + lf.lfHeight = 0xdeadbeef; + status = GdipGetLogFontW(font, graphics, &lf); + expect(Ok, status); + ok(lf.lfHeight == -100, "%u: expected -100, got %d\n", i, lf.lfHeight); + + set_rect_empty(&rc); + set_rect_empty(&bounds); + status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines); + expect(Ok, status); + + if (i == 0) + { + base_cx = bounds.Width; + base_cy = bounds.Height; + } + + pt.X = 1.0; + pt.Y = 1.0; + + status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1); + expect(Ok, status); + + /* height is constant in device space, width is proportional to height in world space */ + expected_width = base_cx * pt.Y; + expected_height = base_cy * pt.Y; + + if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel) + ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width); + else + todo_wine ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width); + ok(fabs(expected_height - bounds.Height) <= 0.001, "%u: expected %f, got %f\n", i, expected_height, bounds.Height); + + GdipDeleteGraphics(graphics); + GdipDisposeImage(image); + GdipDeleteFont(font); + } + GdipDeleteFontFamily(family); GdipDeleteStringFormat(format); }