function GetEllipsisText(S:
String; MaxWidth: Integer; MaxHeight: Integer = 0; Canvas: TCanvas =
nil; Font: TFont =
nil;
PathEllipsis: Boolean = False; TextFormat: TTextFormat = []):
String;
var
R: TRect;
C: TCanvas;
begin
C :=
nil;
try
Result := S;
UniqueString(Result);
if MaxHeight <= 0
then
MaxHeight := 1000;
R := Rect(1, 1, MaxWidth, MaxHeight);
if not Assigned(Canvas)
then begin
C := TCanvas.Create;
Canvas := C;
end;
if Assigned(Font)
then
Canvas.Font.Assign(Font);
TextFormat := TextFormat + [tfCalcRect, tfModifyString];
if PathEllipsis
then
TextFormat := TextFormat + [tfPathEllipsis];
if TextFormat * [tfEndEllipsis, tfPathEllipsis] = []
then
TextFormat := TextFormat + [tfEndEllipsis];
Canvas.TextRect(R, Result, TextFormat);
finally
C.Free;
end;
end;
function GetEllipsisText(S:
String; MaxWidth: Integer; Canvas: TCanvas; Font: TFont =
nil;
PathEllipsis: Boolean = False; TextFormat: TTextFormat = []):
String;
begin
Result := GetEllipsisText(S, MaxWidth, 0, Canvas, Font, PathEllipsis, TextFormat);
end;
function GetEllipsisText(S:
String; MaxWidth: Integer; Font: TFont;
PathEllipsis: Boolean = False; TextFormat: TTextFormat = []):
String;
begin
Result := GetEllipsisText(S, MaxWidth, 0,
nil, Font, PathEllipsis, TextFormat);
end;
function GetEllipsisText(
Handle: HDC; S:
String; MaxWidth: Integer; MaxHeight: Integer = 0;
PathEllipsis: Boolean = False; TextFormat: LongWord = 0):
String;
var
R: TRect;
begin
Result := S;
UniqueString(Result);
if MaxHeight <= 0
then
MaxHeight := 1000;
R := Rect(1, 1, MaxWidth, MaxHeight);
TextFormat := TextFormat
or DT_CALCRECT
or DT_MODIFYSTRING;
if PathEllipsis
then
TextFormat := TextFormat
or DT_PATH_ELLIPSIS;
if TextFormat
and (DT_END_ELLIPSIS
or DT_PATH_ELLIPSIS) = 0
then
TextFormat := TextFormat
or DT_END_ELLIPSIS;
DrawTextEx(
Handle, PChar(Result), Length(Result), R, TextFormat,
nil);
SetLength(Result, StrLen(PChar(Result)));
end;