mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: FitFileName function under Qt and Lazarus 3.x
This commit is contained in:
parent
69ab554ba5
commit
693f0883cb
1 changed files with 18 additions and 5 deletions
|
|
@ -113,11 +113,24 @@ type
|
|||
implementation
|
||||
|
||||
uses
|
||||
LCLIntf, LCLType, LCLProc, LazUTF8, Math, LMessages,
|
||||
Types, LCLIntf, LCLType, LCLProc, LazUTF8, Math, LMessages,
|
||||
DCStrUtils, uGlobs, uPixmapManager, uKeyboard,
|
||||
uDCUtils, fMain,
|
||||
uFileFunctions;
|
||||
|
||||
{
|
||||
Workaround
|
||||
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40934
|
||||
}
|
||||
function TextFitInfo(ACanvas: TCanvas; const Text: String; MaxWidth: Integer): Integer;
|
||||
var
|
||||
lSize: TSize;
|
||||
begin
|
||||
Result:= 0;
|
||||
LCLIntf.GetTextExtentExPoint(ACanvas.Handle, PChar(Text),
|
||||
Length(Text), MaxWidth, @Result, nil, lSize);
|
||||
end;
|
||||
|
||||
function FitFileName(const AFileName: String; ACanvas: TCanvas; AFile: TFile; ATargetWidth: Integer): String;
|
||||
var
|
||||
S: String;
|
||||
|
|
@ -125,7 +138,7 @@ var
|
|||
AMaxWidth: Integer;
|
||||
begin
|
||||
Index:= UTF8Length(AFileName);
|
||||
AMaxWidth:= ACanvas.TextFitInfo(AFileName, ATargetWidth);
|
||||
AMaxWidth:= TextFitInfo(ACanvas, AFileName, ATargetWidth);
|
||||
|
||||
if Index <= AMaxWidth then
|
||||
Result:= AFileName
|
||||
|
|
@ -136,7 +149,7 @@ begin
|
|||
else begin
|
||||
S:= '..';
|
||||
end;
|
||||
Index:= ACanvas.TextFitInfo(AFileName, ATargetWidth - ACanvas.TextWidth(S));
|
||||
Index:= TextFitInfo(ACanvas, AFileName, ATargetWidth - ACanvas.TextWidth(S));
|
||||
Result:= UTF8Copy(AFileName, 1, Index) + S;
|
||||
end;
|
||||
end;
|
||||
|
|
@ -150,13 +163,13 @@ var
|
|||
AMaxWidth: Integer;
|
||||
begin
|
||||
Index:= UTF8Length(sStringToFit);
|
||||
AMaxWidth:= ACanvas.TextFitInfo(sStringToFit, ATargetWidth);
|
||||
AMaxWidth:= TextFitInfo(ACanvas, sStringToFit, ATargetWidth);
|
||||
|
||||
if Index <= AMaxWidth then
|
||||
Result:= sStringToFit
|
||||
else
|
||||
begin
|
||||
Index:= ACanvas.TextFitInfo(sStringToFit, ATargetWidth - ACanvas.TextWidth(ELLIPSIS));
|
||||
Index:= TextFitInfo(ACanvas, sStringToFit, ATargetWidth - ACanvas.TextWidth(ELLIPSIS));
|
||||
Result:= UTF8Copy(sStringToFit, 1, Index) + ELLIPSIS;
|
||||
end;
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue