Skip to content

Instantly share code, notes, and snippets.

@helix84
Created January 12, 2016 17:38
Show Gist options
  • Save helix84/f4f3e388a10cf04a0fe2 to your computer and use it in GitHub Desktop.
Save helix84/f4f3e388a10cf04a0fe2 to your computer and use it in GitHub Desktop.
procedure ShowText(Canvas: TCanvas; Text: string)
var
LogFont: TLogFont;
begin
GetObject(Canvas.Font.Handle, SizeOf(LogFont), Addr(LogFont));
with LogFont do
begin
lfQuality := ANTIALIASED_QUALITY;
lfOutPrecision := Out_TT_Only_Precis;
end;
Canvas.Font.Handle := CreateFontIndirect(LogFont);
end;
function GetTextWidth(Canvasowner: TForm; Text: string; TextFint: TFont): integer;
var OldFont: TFont;
begin
OldFont := TFont.Create;
try
OldFont.Assign(CanvasOwner.Font);
CanvasOwner.Font.Assign(TextFont);
Result := CanvasOwner.Font.TextWidth(Text);
CanvasOwner.Font.Assign(OldFont);
finally
OldFont.Free;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment