• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Fitting text to a curved path

In Postscript, you can force text to follow a curved path. Can some one point me to some examples of how that is done with TextOut?
0
rfedyk
Asked:
rfedyk
  • 3
1 Solution
 
sftwengCommented:
All you have to do is derive the x and y coordinates within the canvas of the target. For example, the following code writes the lowercase alphabetic characters in a parabolic curve:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  txt = 'abcdefghijklmnopqrstuvwxyz';
var
  i, xPos, yPos : INTEGER;
begin
  for i := 1 to 26 do
  begin
    xPos := 100+i*i*2;
    yPos := i*20+50;
    Image1.Canvas.TextOut(xPos,yPos,txt[i]);
  end {for};
end;

end.
0
 
rfedykAuthor Commented:
Hi sftweng

That's pretty nifty but it is missing something because I have not explained my self well enough.  

The baseline of the characters need to follow the tangent of the curve which requires the characters to be rotated by the required angle.
I realize that it could be done with a second canvas and a ROTATE transform. I'm in a hurry so I was hoping someone had done the coding already.

Regards
Roger Fedyk
0
 
gandalf_the_whiteCommented:
this one i had in my personal FAQ
i searched but i couldn't fint the original post here on ee.
i don't know if it will feed your needs but it is an alternative way to solve the problem





    Question History

                            Comment

                            From: Workshop_Alex
                                                                         Date: Wednesday, October 11 2000 - 12:37AM CEST

                            You just rotate the font you're using... I once knew how to do this, but can't find it anymore... Had something to do with lfEscapement...

                            WAIT! Here it is, from the "Tomes of Delphi Graphical API":

                            unit CreateFontIndirectU;

                            interface

                            uses
                              Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
                              StdCtrls, ComCtrls;

                            type
                              TForm1 = class(TForm)
                                Label1: TLabel;
                                Label2: TLabel;
                                Label3: TLabel;
                                Label4: TLabel;
                                TrackBar1: TTrackBar;
                                TrackBar2: TTrackBar;
                                procedure FormPaint(Sender: TObject);
                                procedure TrackBar1Change(Sender: TObject);
                              private
                                { Private declarations }
                              public
                                { Public declarations }
                              end;

                            var
                              Form1: TForm1;

                            implementation

                            {$R *.DFM}

                            procedure TForm1.FormPaint(Sender: TObject);
                            var
                              FontInfo: TLogFont;        // the logical font information
                              NewFont, OldFont: HFont;   // holds the old and new fonts
                            begin
                              {set the background mode for transparency}
                              SetBkMode(Form1.Canvas.Handle, TRANSPARENT);

                              {initialize the logical font information, setting the weight and escapement
                               values to those specified by the trackbars.}
                              with FontInfo do
                              begin
                                lfHeight := 24;
                                lfWidth := 0;
                                lfEscapement := TrackBar1.Position*10;
                                lfOrientation := TrackBar1.Position*10;
                                lfWeight := TrackBar2.Position;
                                lfItalic := 0;
                                lfUnderline := 0;
                                lfStrikeOut := 0;
                                lfFaceName := 'Arial';
                              end;

                              {create the new font}
                              NewFont := CreateFontIndirect(FontInfo);

                              {select the new font into the form's device context}
                              OldFont := SelectObject(Form1.Canvas.Handle, NewFont);

                              {output a string of rotated text}
                              TextOut(Form1.Canvas.Handle, Form1.Width div 2, 140, 'Delphi Rocks!',
                              Length('Delphi Rocks!'));

                              {select the original font back into the device context,
                               and delete the new one}
                              SelectObject(Form1.Canvas.Handle, OldFont);
                              DeleteObject(NewFont);
                            end;

                            procedure TForm1.TrackBar1Change(Sender: TObject);
                            begin
                              {indicate the new trackbar positions}
                              Label2.Caption := IntToStr(TrackBar1.Position);
                              Label4.Caption := IntToStr(TrackBar2.Position);

                              {redraw the font}
                              Form1.Refresh;
                            end;

                            end.



regards
0
 
rfedykAuthor Commented:
Gandalf

I will try this tomorrow and let you know.
Thanks
0
 
rfedykAuthor Commented:
Gandalf,

That's works just fine.

Regards
Roger Fedyk
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now