You get some help from VCL, as the TCanvas.TextOut method increases the x coordinate of the handle position by the width of the output line:
procedure TForm1.FormPaint(Sender: TObject); begin Canvas.MoveTo(20, 100); Canvas.Font.Name := 'Segoe UI'; Canvas.Font.Color := clMaroon; Canvas.Font.Style := []; Canvas.Font.Height := 64; Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'This '); Canvas.Font.Color := clNavy; Canvas.Font.Style := [fsBold]; Canvas.Font.Height := 64; Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'is '); Canvas.Font.Name := 'Bookman Old Style'; Canvas.Font.Color := clBlack; Canvas.Font.Style := [fsItalic]; Canvas.Font.Height := 64; Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'a '); Canvas.Font.Name := 'Courier New'; Canvas.Font.Color := clSilver; Canvas.Font.Style := []; Canvas.Font.Height := 64; Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'test!'); end;

In any case, if you need more complex text output procedures, why not take a look at DirectWrite ?
Andreas Rejbrand
source share