LCL: TLabel: Win32: fixed Wordwrap loses lines when word exceeds MaxWidth. Issue #20762

git-svn-id: trunk@53732 -
This commit is contained in:
michl 2016-12-20 12:27:19 +00:00
parent ad0980dcfa
commit d749179227

View File

@ -1115,16 +1115,26 @@ begin
SetLength(s, count); SetLength(s, count);
move(str^, PChar(s)^, count); move(str^, PChar(s)^, count);
end; end;
// the length of utf8 vs Wide/Ansi the strings differ, so recalc. // the length of utf8 vs Wide/Ansi the strings differ, so recalc.
W := UTF8ToUTF16(s); W := UTF8ToUTF16(s);
len := Length(W); len := Length(W);
if (Flags and DT_MODIFYSTRING <> 0) then if (Flags and DT_MODIFYSTRING <> 0) then
SetLength(W, len+4); SetLength(W, len+4);
// Remove DT_RIGHT, if the rectangle is calculated (Windows bug), Mantis 20763
if (Flags and DT_CALCRECT = DT_CALCRECT) if (Flags and DT_CALCRECT = DT_CALCRECT) then
and (Flags and DT_RIGHT = DT_RIGHT) then begin
Flags := Flags and not DT_RIGHT; // remove DT_RIGHT, if the rectangle is calculated (Windows bug), Mantis 20763
if (Flags and DT_RIGHT = DT_RIGHT) then
Flags := Flags and not DT_RIGHT;
// if the rectangle is calculated and DT_WORDBREAK is set, longer words should
// be truncated as in Delphi, Mantis 20762
if (Flags and DT_WORDBREAK = DT_WORDBREAK) then
Flags := Flags or DT_END_ELLIPSIS;
end;
Result := Windows.DrawTextW(DC, PWideChar(W), len, @Rect, Flags); Result := Windows.DrawTextW(DC, PWideChar(W), len, @Rect, Flags);
if (Flags and DT_MODIFYSTRING <> 0) then if (Flags and DT_MODIFYSTRING <> 0) then
begin begin
W := WideString(PWideChar(W)); // trim to first #0 W := WideString(PWideChar(W)); // trim to first #0
@ -1135,7 +1145,6 @@ begin
Str^ := #0; Str^ := #0;
end; end;
// Theoretically, we need to augment the returned rect by the text overhang // Theoretically, we need to augment the returned rect by the text overhang
// The overhang is returned in the abcC field as documented in the // The overhang is returned in the abcC field as documented in the
// following article: http://support.microsoft.com/kb/94646/en-us // following article: http://support.microsoft.com/kb/94646/en-us
@ -1151,18 +1160,13 @@ begin
// but I found it's even worse with drawing bold 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 begin
GetObject(GetCurrentObject(DC, OBJ_FONT), SizeOf(LOGFONT), @lf); GetObject(GetCurrentObject(DC, OBJ_FONT), SizeOf(LOGFONT), @lf);
if lf.lfItalic <> 0 then if lf.lfItalic <> 0 then
begin begin
paABC := @aABC; paABC := @aABC;
res := GetCharABCWidthsW(DC, Uint(W[len]), Uint(W[len]), paABC); res := GetCharABCWidthsW(DC, Uint(W[len]), Uint(W[len]), paABC);
if res then if res then
Rect.Right := Rect.Right + Abs(aABC.abcC); Rect.Right := Rect.Right + Abs(aABC.abcC);
end; end;
end; end;
end; end;