首页  编辑  

旋转输出字体

Tags: /超级猛料/Font.字体/   Date Created:

From Borland Newsgroup: borland.public.delphi.nativeapi

Finn Tolderlund <no@spam.dk>

procedure TextOutAngle(Canvas: TCanvas; X, Y: Integer; Text: String; Angle:

Integer);

var

 OldFont: TFont;

 OldBrush: TBrush;

 NewFont: THandle;

 LogFont: TLogFont;

begin

 Angle := Angle mod 3600;

 if Angle < 0 then

   Angle := Angle + 3600;

 with Canvas do

 begin

   OldFont := TFont.Create;

   OldBrush := TBrush.Create;

   {Save the current form font}

   OldFont.Assign(Font);

   OldBrush.Assign(Brush);

   {Fill in the TLogFont fields}

   with LogFont do

   begin

     lfHeight := Font.Height;                {Srt to Canvas.Font.Height}

     lfWidth := 0;                           {Let font mapper choose width}

     lfEscapement := Angle;                  {Angle of print, in 10ths of

degree}

     lfOrientation := Angle;                 {Ignored by Windows}

     lfWeight := 0;

     if fsBold in OldFont.Style then

       lfWeight := FW_BOLD;

     lfItalic := Ord(fsItalic in OldFont.Style);  {Italics}

     lfUnderline := Ord(fsUnderline in OldFont.Style);  {Underline}

     lfStrikeout := Ord(fsStrikeOut in OldFont.Style);  {No StrikeOut}

     lfCharSet := ANSI_CHARSET;              {Default}

     lfOutPrecision := OUT_TT_ONLY_PRECIS;   {Force True Type fonts}

     lfClipPrecision := CLIP_DEFAULT_PRECIS; {Default}

     lfQuality := PROOF_QUALITY;             {Windows gets a better one if

available}

     lfPitchAndFamily := VARIABLE_PITCH;     {Default}

     StrPCopy(lfFaceName, Font.Name);        {Canvas's font name}

   end;

   {Create and get handle of temporary font}

   NewFont := CreateFontIndirect(LogFont);

   {Assign temporary font to form's Canvas}

   Font.Handle := NewFont;

   {Write text to form's Canvas}

   TextOut(X, Y, Text);

   {Restore form's original font}

   Font.Assign(OldFont);

   Brush.Assign(OldBrush);

   OldFont.Free;

   OldBrush.Free;

 end;

 {Destroy temporary font}

 DeleteObject(NewFont);

end;

img_20563.bmp (9.6KB)