DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Drawing text with angle

 
   Reply to topic    DELPHI AREA Forum Index -> Delphi Programming
View previous topic :: View next topic  
Author Message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 408
Location: Tehran, Iran

PostPosted: 24/05/03 12:43    Post subject: Drawing text with angle Reply with quote

The following function writes a string on the canvas with the specified angle.

Code:
procedure DrawAngledText(Canvas: TCanvas; X, Y: Integer;
  const Angle: Double; Alignment: Integer; const Text: String);
var
  LogFont: TLogFont;
  FontHandle: THandle;
  TextAlign: Integer;
begin
  GetObject(Canvas.Font.Handle, SizeOf(LogFont), @LogFont);
  LogFont.lfEscapement := Round(Angle * 10);
  LogFont.lfOrientation := LogFont.lfEscapement;
  LogFont.lfQuality := PROOF_QUALITY;
  FontHandle := SelectObject(Canvas.Handle, CreateFontIndirect(LogFont));
  TextAlign := SetTextAlign(Canvas.Handle, Alignment);
  Canvas.TextOut(X, Y, Text);
  SetTextAlign(Canvas.Handle, TextAlign);
  DeleteObject(SelectObject(Canvas.Handle, FontHandle));
end;


The Angle parameter is in degrees and the Alignment parameter specifies the text alignment by using a mask of the values in the following list. Only one flag can be chosen from those that affect horizontal and vertical alignment.

    TA_BASELINE
    The reference point will be on the base line of the text.

    TA_BOTTOM
    The reference point will be on the bottom edge of the bounding rectangle.

    TA_TOP
    The reference point will be on the top edge of the bounding rectangle.

    TA_CENTER
    The reference point will be aligned horizontally with the center of the bounding rectangle.

    TA_LEFT
    The reference point will be on the left edge of the bounding rectangle.

    TA_RIGHT
    The reference point will be on the right edge of the bounding rectangle.
Here is also an example of usage:

Code:
procedure TForm1.FormPaint(Sender: TObject);
begin
  DrawAngledText(Canvas, ClientWidth div 2, ClientHeight div 2,
  45, TA_BOTTOM or TA_CENTER, 'Powered by Borland Delphi.');
end;


By the way, the canvas' font should be a TrueType font.

Cheers,
Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> Delphi Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group