From: David Kahurani k.kahurani@gmail.com
Always write the first line regardless of the whether it fits but don't write any more if there's not enough room.
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/gdiplus/graphics.c | 18 +++++++++-- dlls/gdiplus/tests/stringformat.c | 51 +++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 6dc34707bbf..647e2b03df4 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -5309,8 +5309,9 @@ GpStatus gdip_format_string(HDC hdc, if(height + size.cy > nheight) { if (format->attr & StringFormatFlagsLineLimit) - break; - bounds.Height = nheight - (height + size.cy); + bounds.Height = nheight; + else + bounds.Height = nheight - (height + size.cy); } else bounds.Height = size.cy; @@ -5343,6 +5344,8 @@ GpStatus gdip_format_string(HDC hdc, if (stat != Ok) break;
+ if ((format->attr & StringFormatFlagsLineLimit) && height + size.cy > nheight) + break;
if (unixstyle_newline) { @@ -5537,7 +5540,16 @@ static GpStatus measure_string_callback(HDC hdc, *args->codepointsfitted = index + length;
if (args->linesfilled) - (*args->linesfilled)++; + { + SIZE size; + int fit; + + GetTextExtentExPointW(hdc, string, length, + bounds->Width, &fit, NULL, &size); + + if (bounds->Height >= size.cy) + (*args->linesfilled)++; + }
return Ok; } diff --git a/dlls/gdiplus/tests/stringformat.c b/dlls/gdiplus/tests/stringformat.c index 71fb860e474..938fbf817c6 100644 --- a/dlls/gdiplus/tests/stringformat.c +++ b/dlls/gdiplus/tests/stringformat.c @@ -373,12 +373,26 @@ static void test_getgenericdefault(void) expect(Ok, stat); }
+void set_rect_empty(RectF *rect) +{ + rect->X = 0; + rect->Y = 0; + rect->Width = 0; + rect->Height = 0; +} + static void test_stringformatflags(void) { GpStringFormat *format; GpStatus stat; - - INT flags; + HDC hdc; + GpGraphics *graphics; + LOGFONTA lf; + GpFont *font; + RectF rect, bounds; + REAL height; + const WCHAR *string = L"Hello"; + INT flags, linesfilled;
stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format); expect(Ok, stat); @@ -430,6 +444,39 @@ static void test_stringformatflags(void) expect(Ok, stat); expect(0xdeadbeef, flags);
+ hdc = CreateCompatibleDC(0); + GdipCreateFromHDC(hdc, &graphics); + memset(&lf, 0, sizeof(lf)); + + lstrcpyA(lf.lfFaceName, "Tahoma"); + lf.lfHeight = -100; + stat = GdipCreateFontFromLogfontA(hdc, &lf, &font); + expect(Ok, stat); + stat = GdipGetFontHeight(font, graphics, &height); + stat = GdipSetStringFormatFlags(format, StringFormatFlagsLineLimit); + expect(Ok, stat); + stat = GdipGetStringFormatFlags(format, &flags); + expect(Ok, stat); + expect(StringFormatFlagsLineLimit, flags); + /* Get an estimate of line height */ + set_rect_empty(&rect); + set_rect_empty(&bounds); + stat = GdipMeasureString(graphics, string, 5, font, &rect, format, &bounds, NULL, NULL); + expect(Ok, stat); + + /* request to draw in a shallow rectangle with half the line height */ + rect.Height = (int)bounds.Height / 2; + rect.Width = 600; + set_rect_empty(&bounds); + stat = GdipMeasureString(graphics, string, 5, font, &rect, format, &bounds, NULL, &linesfilled); + expect(Ok, stat); + expect(0, linesfilled); + expectf(rect.Height, bounds.Height); + + DeleteObject(hdc); + GdipDeleteGraphics(graphics); + GdipDeleteFont(font); + stat = GdipDeleteStringFormat(format); expect(Ok, stat); }