* Use WideString functions in ShortenString to avoid invalid UTF8 strings

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@671 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
blikblum
2009-01-24 11:03:39 +00:00
parent 46955c2cdf
commit a67f6b2ab5

View File

@ -4160,9 +4160,13 @@ var
Size: TSize; Size: TSize;
Len: Integer; Len: Integer;
L, H, N, W: Integer; L, H, N, W: Integer;
WideStr: WideString;
begin begin
Len := Length(S); //todo: this need to be adjusted to work with UTF8 strings since the current algorithm
// when direct ported to use UTF8 functions leads to invalid UTF8 strings.
// for now use a WideString as a bridge
WideStr := UTF8Decode(S);
Len := Length(WideStr);
if (Len = 0) or (Width <= 0) then if (Len = 0) or (Width <= 0) then
Result := '' Result := ''
else else
@ -4184,14 +4188,14 @@ begin
while L < H do while L < H do
begin begin
N := (L + H + 1) shr 1; N := (L + H + 1) shr 1;
GetTextExtentPoint32(DC, PChar(S), N, Size); GetTextExtentPoint32W(DC, PWideChar(WideStr), N, Size);
W := Size.cx + EllipsisWidth; W := Size.cx + EllipsisWidth;
if W <= Width then if W <= Width then
L := N L := N
else else
H := N - 1; H := N - 1;
end; end;
Result := Copy(S, 1, L) + '...' Result := UTF8Encode(Copy(WideStr, 1, L) + '...');
end; end;
end; end;
end; end;