RotatedFont (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example creates a rotated font and displays it on the form by assigning the handle of the rotated font to the Forms Canvas Font using the Fonts Handle property. Rotating fonts is a straightforward process, as long as the Windows Font Mapper can supply a rotated font based on the font you request. If you are using a TrueType font, there is virtually no reason for failure.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  lf: LOGFONT; // Windows native font structure
begin
  Canvas.Brush.Style := bsClear; // Set the brush style to transparent.
  FillChar(lf, SizeOf(lf), Byte(0));
  lf.lfHeight := 20;
  lf.lfEscapement := 10 * 45; // Degrees to rotate
  lf.lfOrientation := 10 * 45;
  lf.lfCharSet := DEFAULT_CHARSET;
  StrCopy(lf.lfFaceName, 'Tahoma');

  Canvas.Font.Handle := CreateFontIndirect(lf);
  Canvas.TextOut(10, 100, 'Rotated text'); // Output the rotated font.
end;

Note: System.FillChar should be used with great care because untyped parameters can be the source of memory corruption.To avoid this problem, use SizeOf to find the number of bytes appropriate to fill for the data type of the first parameter.

Uses