Drawing text with different fonts

A screenshot follows the straightforward code, which demonstrates drawing with different font faces and styles. We added a PaintBox to the form then changed its Name property to pb and its Color property to $FFFFFF. (You can use the same code in the PaintView procedure of a canvas project if you omit the pb. prefix).

If you need to display a character that you cannot type, find a page such as this one that displays it and copy the character into your code.

unit Form1;

interface

uses 
  System.Types, SmartCL.System, SmartCL.Graphics, SmartCL.Components, SmartCL.Forms,
  SmartCL.Fonts, SmartCL.Borders, SmartCL.Application, SmartCL.Controls.PaintBox;

type
  TForm1=class(TW3form)
  private
    {$I 'Form1:intf'}
  protected
    procedure InitializeObject; override;
    procedure FormActivated; override;
  end;

implementation

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
end;

procedure TForm1.FormActivated;

begin
  inherited;
  {$I 'Form1:impl'}
  pb.Canvas.FillStyle := 'blue';

  pb.Canvas.Font := '12px Times';
  pb.Canvas.FillTextF('12px Times', 50, 20, MAX_INT);

  pb.Canvas.Font := 'bold italic 12px Times';
  pb.Canvas.FillTextF('bold italic 12px Times', 50, 40, MAX_INT);

  pb.Canvas.Font := '12pt Times';
  pb.Canvas.FillTextF('12pt Times', 50, 60, MAX_INT);

  pb.Canvas.Font := 'bold 12pt Times';
  pb.Canvas.FillTextF('bold 12pt Times', 50, 80, MAX_INT);

  pb.Canvas.Font := 'italic 12pt Times';
  pb.Canvas.FillTextF('italic 12pt Times', 50, 100, MAX_INT);

  pb.Canvas.Font := '12pt verdana';
  pb.Canvas.FillTextF('12pt vardana', 50, 120, MAX_INT);

  pb.Canvas.Font := 'italic 12pt verdana';
  pb.Canvas.FillTextF('italic 12pt verdana', 50, 140, MAX_INT);

  pb.Canvas.Font := 'bold 12pt verdana';
  pb.Canvas.FillTextF('bold 12pt verdana', 50, 160, MAX_INT);

  pb.Canvas.Font := '12pt arial';
  pb.Canvas.FillTextF('12pt arial', 50, 180, MAX_INT);

  pb.Canvas.Font := 'bold 12pt arial';
  pb.Canvas.FillTextF('bold 12pt arial', 50, 200, MAX_INT);

  pb.Canvas.Font := 'italic 12pt arial';
  pb.Canvas.FillTextF('italic 12pt arial', 50, 220, MAX_INT);

  pb.Canvas.Font := 'bold italic 12pt arial';
  pb.Canvas.FillTextF('bold italic 12pt arial', 50, 240, MAX_INT);

  pb.Canvas.Font := 'small-caps 12pt arial';
  pb.Canvas.FillTextF('small-caps 12pt arial', 50, 260, MAX_INT);
end;
 
initialization
  Forms.RegisterForm({$I %FILE%}, TForm1);
end.
    
Screenshot of output

Screenshot of output

Programming - a skill for life!

Commonly used routines for drawing on a canvas and the use of another unit, colour, different fonts and transforms