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
Solved

Fitting text to a curved path

Posted on 2004-04-12
5
345 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
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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…

839 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