gdiplus: GdipDrawString: Handle either a width or height of 0 sanely.

Based on Aric's recent patch.
This commit is contained in:
Vincent Povirk 2009-04-01 14:08:12 -05:00 committed by Alexandre Julliard
parent 9993b0a079
commit 0879b767ae
2 changed files with 73 additions and 6 deletions

View File

@ -2011,20 +2011,35 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height; rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height;
transform_and_round_points(graphics, corners, rectcpy, 4); transform_and_round_points(graphics, corners, rectcpy, 4);
if(roundr(rect->Width) == 0 && roundr(rect->Height) == 0){ if (roundr(rect->Width) == 0)
rel_width = rel_height = 1.0; {
nwidth = nheight = INT_MAX; rel_width = 1.0;
nwidth = INT_MAX;
} }
else{ else
{
rel_width = sqrt((corners[1].x - corners[0].x) * (corners[1].x - corners[0].x) + 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)) (corners[1].y - corners[0].y) * (corners[1].y - corners[0].y))
/ rect->Width; / 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) + 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)) (corners[2].y - corners[1].y) * (corners[2].y - corners[1].y))
/ rect->Height; / rect->Height;
nwidth = roundr(rel_width * rect->Width);
nheight = roundr(rel_height * rect->Height); 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); rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
SelectClipRgn(graphics->hdc, rgn); SelectClipRgn(graphics->hdc, rgn);
} }

View File

@ -935,6 +935,57 @@ static void test_textcontrast(void)
ReleaseDC(0, hdc); 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) START_TEST(graphics)
{ {
struct GdiplusStartupInput gdiplusStartupInput; struct GdiplusStartupInput gdiplusStartupInput;
@ -954,6 +1005,7 @@ START_TEST(graphics)
test_GdipDrawArcI(); test_GdipDrawArcI();
test_GdipDrawLineI(); test_GdipDrawLineI();
test_GdipDrawLinesI(); test_GdipDrawLinesI();
test_GdipDrawString();
test_Get_Release_DC(); test_Get_Release_DC();
test_transformpoints(); test_transformpoints();
test_get_set_clip(); test_get_set_clip();