Solved

Fitting text to a curved path

Posted on 2004-04-12
5
338 Views
Last Modified: 2013-12-03
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
Comment
Question by:rfedyk
  • 3
5 Comments
 
LVL 7

Expert Comment

by:sftweng
Comment Utility
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
 
LVL 1

Author Comment

by:rfedyk
Comment Utility
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
 
LVL 3

Accepted Solution

by:
gandalf_the_white earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:rfedyk
Comment Utility
Gandalf

I will try this tomorrow and let you know.
Thanks
0
 
LVL 1

Author Comment

by:rfedyk
Comment Utility
Gandalf,

That's works just fine.

Regards
Roger Fedyk
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now