» Help

Code Snippets Database

Control Box
 
 

Requested snippet

This page displays the requested DrawAngledText snippet.

You can choose a category, perform a search or generate a Pascal unit containing the snippet by using the Control Box.

DrawAngledText
Draws angled text on a canvas at position X,Y. Angle is in degrees and is accurate to one tenth of a degree.
procedure DrawAngledText(const ACanvas: Graphics.TCanvas; const X, Y: Integer;
  const Angle: Double; const Text: string);
var
  AngledFontH: Windows.HFONT; // handle to rotated font
  OrigFontH: Windows.HFONT;   // handle to original font
  FontInfo: Windows.TLogFont; // font definition structure
begin
  // Configure logical font structure
  if Windows.GetObject(
    ACanvas.Font.Handle, SizeOf(FontInfo), @FontInfo
  ) = 0 then
    Exit;
  FontInfo.lfEscapement := Round(Angle * 10);
  FontInfo.lfOrientation := FontInfo.lfEscapement;
  // Create angled font
  AngledFontH := Windows.CreateFontIndirect(FontInfo);
  if AngledFontH = 0 then
    Exit;
  // Use angled font to write text
  OrigFontH := Windows.SelectObject(ACanvas.Handle, AngledFontH);
  ACanvas.TextOut(X, Y, Text);
  // Restore old unrotated font
  Windows.SelectObject(ACanvas.Handle, OrigFontH);
  // Dispose of angled font
  Windows.DeleteObject(AngledFontH);
end;
Kind of Snippet: Routine
Required units: Windows, Graphics.
Required snippets: None.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
The canvas' current font must be a vector font otherwise the text is not angled.