Board index » delphi » Text Rotation in Windows 3.x w/ Delphi 1.0 - ?????

Text Rotation in Windows 3.x w/ Delphi 1.0 - ?????

As a fairly new programmer to Delphi, Pascal, and Windows all at
once, I am trying to create lines of text on the Form.Canvas
that will display at an angle (roughly 30-45 degrees), for column
captions in a screen report I am generating from code.

I found the CreateFont, and CreateFontIndirect WinAPI calls, but
haven't the slightest clue as to how to impliment it.  They return
a handle of type HFONT, and that has to be selected with the GDI
using SelectObject and then it has to be deleted using DeleteObject.
I can figure that out, but I would rather not.  In addition, how
do I tell the Delphi Canvas to use that new font that has been
created?

I would appreciate any comments or suggestions.

Thanks,

Kyle Mallory (kmall...@aros.net)
The Tracs Corporation
(801) 363-8378

 

Re:Text Rotation in Windows 3.x w/ Delphi 1.0 - ?????


In article <3146FBB6.3...@aros.net>,
   Kyle Mallory <kmall...@aros.net> wrote:
]-As a fairly new programmer to Delphi, Pascal, and Windows all at
]-once, I am trying to create lines of text on the Form.Canvas
]-that will display at an angle (roughly 30-45 degrees), for column
]-captions in a screen report I am generating from code.
]-
]-I found the CreateFont, and CreateFontIndirect WinAPI calls, but
]-haven't the slightest clue as to how to impliment it.  They return
]-a handle of type HFONT, and that has to be selected with the GDI
]-using SelectObject and then it has to be deleted using DeleteObject.
]-I can figure that out, but I would rather not.  In addition, how
]-do I tell the Delphi Canvas to use that new font that has been
]-created?
]-
]-I would appreciate any comments or suggestions.
]-
]-
]-Thanks,
]-
]-Kyle Mallory (kmall...@aros.net)
]-The Tracs Corporation
]-(801) 363-8378

Here is a response to your question (also asked by many others)
given previously by Steve Koterski of Borland.

------------------------------------------------------------------------

FROM: koter...@borland.com (Steve Koterski)
SUBJECT: Re: Rotating Text
DATE: Sat, 10 Feb 1996 00:09:50 GMT
ORGANIZATION: Borland International, Delphi Tech Support

On Fri, 09 Feb 1996 13:36:14 GMT, wi...@indirect.com (Bryan Warbelton)
wrote:

Quote
>  Call me crazy, but I've tried to use help to find out how
>to rotate text 90 degrees so that it prints from bottom to
>top instead of left to right.  I just can't find out how.
>  It's probably something real simple.  Can someone help
>me with this matter?

You can print at all angles to a Canvas by using a TLogFont object and
setting its lfEscapement property to the amount for the angle, expressed in
10ths of a degree. Below is an example that prints text to the form's
Canvas at an angle of 45 degrees.

procedure TForm1.Button3Click(Sender: TObject);
var
  OldFont: TFont;
  NewFont: THandle;
  LogFont: TLogFont;
begin
  OldFont := TFont.Create;
  with Canvas do begin
    {Save the current form font}
    OldFont.Assign(Font);
    {Pick the new font}
    if FD.Execute then Canvas.Font.Assign(FD.Font);
    {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 := 450;                    {Angle of print, in 10ths of
                                               degree, in this case 45
                                               degrees}
      lfOrientation := 0 ;                    {Ignored by Windows}
      lfWeight := FW_BOLD;                    {Default}
      lfItalic := 0;                          {No Italics}
      lfUnderline := 0;                       {No underline}
      lfStrikeout := 0;                       {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;
    Brush.Color := clSilver;
    {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(10, 260, 'Steve Koterski');
    TextOut(35, 260, 'Delphi Technical Support');
    TextOut(60, 260, '*** TEST PRINTING ***');
    {Restore form's original font}
    Font.Assign(OldFont);
  end;
  {Destroy temporary font}
  DeleteObject(NewFont);
end;

**************************************************************************
Steve Koterski                    "Knowledge advances by steps, and not by
Product Group Manager             leaps."
Delphi Technical Support                       -- Lord Macaulay, 1800-1859
Borland International, Inc.

Re:Text Rotation in Windows 3.x w/ Delphi 1.0 - ?????


Quote
Kyle Mallory wrote:

> As a fairly new programmer to Delphi, Pascal, and Windows all at
> once, I am trying to create lines of text on the Form.Canvas
> that will display at an angle (roughly 30-45 degrees), for column
> captions in a screen report I am generating from code.

> I found the CreateFont, and CreateFontIndirect WinAPI calls, but
> haven't the slightest clue as to how to impliment it.  They return
> a handle of type HFONT, and that has to be selected with the GDI
> using SelectObject and then it has to be deleted using DeleteObject.
> I can figure that out, but I would rather not.  In addition, how
> do I tell the Delphi Canvas to use that new font that has been
> created?

> I would appreciate any comments or suggestions.

> Thanks,

> Kyle Mallory (kmall...@aros.net)
> The Tracs Corporation
> (801) 363-8378

Try this:

unit Rotate;
{-------------------------------------------------------}
{ Draw angled text on a Canvas                          }
{  d is the angle in tenths of degrees                  }
{-------------------------------------------------------}

interface

uses
  Graphics, WinTypes, WinProcs;

procedure CanvasTextOutAngle(c: TCanvas; x,y: Integer; d: Word; const s:
string);

implementation

{-------------------------------------------------------}
{ Draw angled text on a Canvas                          }
{  d is the angle in tenths of degrees                  }
{-------------------------------------------------------}
procedure CanvasTextOutAngle(c: TCanvas; x,y: Integer; d: Word; const s:
string);
var
  LogRec: TLOGFONT;     {* Storage area for font information *}
  OldFontHandle,        {* The old font handle *}
  NewFontHandle: HFONT; {* Temporary font handle *}
begin
  GetObject(c.Font.Handle, SizeOf(LogRec), Addr(LogRec));
  LogRec.lfEscapement := d;
  NewFontHandle := CreateFontIndirect(LogRec);
  OldFontHandle := SelectObject(c.Handle,NewFontHandle);
  c.TextOut(x,y,s);
  NewFontHandle := SelectObject(c.Handle,OldFontHandle);
  DeleteObject(NewFontHandle);
end;

end.

--

-----------------------------------
Arjan Lamaker
IMAG-DLO Wageningen The Netherlands
mail: e.j.j.lama...@imag.dlo.nl
http://huizen.dds.nl/~lamaker/
------------------------------

-----

Other Threads