Главная страница | назад





Article #16133: Using Resident Font

 Question and Answer Database
FAQ1133D.txt Using Resident Font
Category :VCL
Platform :All
Product :All 32 bit
Question:
Instead of printing graphics, how can I get TPrinter to use the
default resident font in the printer?
Answer:
Use the Windows API function GetStockObject() to retrieve the
device default font handle, and assign it to Printer.Font.Handle.
Example:
uses Printers;
procedure TForm1.Button1Click(Sender: TObject);
var
tm : TTextMetric;
i : integer;
begin
if PrintDialog1.Execute then begin
Printer.BeginDoc;
Printer.Canvas.Font.Handle := GetStockObject(DEVICE_DEFAULT_FONT);
GetTextMetrics(Printer.Canvas.Handle, tm);
for i := 1 to 10 do begin
Printer.Canvas.TextOut(100,
i * tm.tmHeight +
tm.tmExternalLeading,
'Test');
end;
Printer.EndDoc;
end;
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99