Mega Code Archive

 
Categories / Delphi / Examples
 

Using Resident Font

Title: Using Resident Font 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;