From af3f20163de702536b10fdc37104458e2992735f Mon Sep 17 00:00:00 2001 From: michl Date: Mon, 19 Dec 2016 22:32:28 +0000 Subject: [PATCH] LCL: TCanvas: fixed Windows WordWrap bug. Issue: #20763 git-svn-id: trunk@53725 - --- lcl/interfaces/win32/win32winapi.inc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lcl/interfaces/win32/win32winapi.inc b/lcl/interfaces/win32/win32winapi.inc index eb46ba68e8..f8ce316be6 100644 --- a/lcl/interfaces/win32/win32winapi.inc +++ b/lcl/interfaces/win32/win32winapi.inc @@ -1120,12 +1120,16 @@ begin len := Length(W); if (Flags and DT_MODIFYSTRING <> 0) then SetLength(W, len+4); + // Remove DT_RIGHT, if the rectangle is calculated (Windows bug), Mantis 20763 + if (Flags and DT_CALCRECT = DT_CALCRECT) + and (Flags and DT_RIGHT = DT_RIGHT) then + Flags := Flags and not DT_RIGHT; Result := Windows.DrawTextW(DC, PWideChar(W), len, @Rect, Flags); if (Flags and DT_MODIFYSTRING <> 0) then begin W := WideString(PWideChar(W)); // trim to first #0 s := UTF16ToUTF8(W); - if s<>'' then + if s <> '' then Move(s[1], Str^, Length(s)+1) // the programmer has to make sure there's enough space in Str else Str^ := #0; @@ -1145,19 +1149,19 @@ begin // aligned bold italic text. The DrawText windows function is documented to // clip out text in some special cases, specially when drawing italic text, // but I found it's even worse with drawing bold italic text. - if (len>0) and (flags and DT_CALCRECT = DT_CALCRECT) then + if (len > 0) and (Flags and DT_CALCRECT = DT_CALCRECT) then begin GetObject(GetCurrentObject(DC, OBJ_FONT), SizeOf(LOGFONT), @lf); - if lf.lfItalic<>0 then + if lf.lfItalic <> 0 then begin paABC := @aABC; res := GetCharABCWidthsW(DC, Uint(W[len]), Uint(W[len]), paABC); - if res then - Rect.Right := Rect.Right + Abs(aABC.abcC); + if res then + Rect.Right := Rect.Right + Abs(aABC.abcC); end; end;