?
Solved

Fitting text to a curved path

Posted on 2004-04-12
5
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 10811037
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
ID: 10811112
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 2000 total points
ID: 10823891
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
ID: 10824448
Gandalf

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

Author Comment

by:rfedyk
ID: 10852828
Gandalf,

That's works just fine.

Regards
Roger Fedyk
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

765 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