From ce30f413111b2db5511c222784f3dfa8e59e0a8f Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Wed, 1 Apr 2009 14:08:12 -0500 Subject: [PATCH] gdiplus: GdipDrawString, handle either a Width or Height of 0 sanely --- dlls/gdiplus/graphics.c | 27 ++++++++++++++++---- dlls/gdiplus/tests/graphics.c | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 5d1cbd6..2a98ee5 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -2011,20 +2011,35 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height; transform_and_round_points(graphics, corners, rectcpy, 4); - if(roundr(rect->Width) == 0 && roundr(rect->Height) == 0){ - rel_width = rel_height = 1.0; - nwidth = nheight = INT_MAX; + if (roundr(rect->Width) == 0) + { + rel_width = 1.0; + nwidth = INT_MAX; } - else{ + else + { rel_width = sqrt((corners[1].x - corners[0].x) * (corners[1].x - corners[0].x) + (corners[1].y - corners[0].y) * (corners[1].y - corners[0].y)) / rect->Width; + nwidth = roundr(rel_width * rect->Width); + } + + if (roundr(rect->Height) == 0) + { + rel_height = 1.0; + nheight = INT_MAX; + } + else + { rel_height = sqrt((corners[2].x - corners[1].x) * (corners[2].x - corners[1].x) + (corners[2].y - corners[1].y) * (corners[2].y - corners[1].y)) / rect->Height; - - nwidth = roundr(rel_width * rect->Width); nheight = roundr(rel_height * rect->Height); + } + + if (roundr(rect->Width) != 0 && roundr(rect->Height) != 0) + { + /* FIXME: If only the width or only the height is 0, we should probably still clip */ rgn = CreatePolygonRgn(corners, 4, ALTERNATE); SelectClipRgn(graphics->hdc, rgn); } diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c index 8091a9a..7199151 100644 --- a/dlls/gdiplus/tests/graphics.c +++ b/dlls/gdiplus/tests/graphics.c @@ -935,6 +935,57 @@ static void test_textcontrast(void) ReleaseDC(0, hdc); } +static void test_GdipDrawString(void) +{ + GpStatus status; + GpGraphics *graphics = NULL; + GpFont *fnt = NULL; + RectF rect; + GpStringFormat *format; + GpBrush *brush; + LOGFONTA logfont; + HDC hdc = GetDC(0); + static const WCHAR string[] = {'T','e','s','t',0}; + + memset(&logfont,0,sizeof(logfont)); + strcpy(logfont.lfFaceName,"Arial"); + logfont.lfHeight = 12; + logfont.lfCharSet = DEFAULT_CHARSET; + + status = GdipCreateFromHDC(hdc, &graphics); + expect(Ok, status); + + status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt); + if (status == FileNotFound) + { + skip("Arial not installed.\n"); + return; + } + expect(Ok, status); + + status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush); + expect(Ok, status); + + status = GdipCreateStringFormat(0,0,&format); + expect(Ok, status); + + rect.X = 0; + rect.Y = 0; + rect.Width = 0; + rect.Height = 12; + + status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush); + expect(Ok, status); + + GdipDeleteGraphics(graphics); + GdipDeleteBrush(brush); + GdipDeleteFont(fnt); + GdipDeleteStringFormat(format); + + ReleaseDC(0, hdc); +} + + START_TEST(graphics) { struct GdiplusStartupInput gdiplusStartupInput; @@ -954,6 +1005,7 @@ START_TEST(graphics) test_GdipDrawArcI(); test_GdipDrawLineI(); test_GdipDrawLinesI(); + test_GdipDrawString(); test_Get_Release_DC(); test_transformpoints(); test_get_set_clip(); -- 1.5.4.3