Solved

Fitting text to a curved path

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 65
code issue 8 133
Making delphi communicate with a c# service 16 104
scroll down TListBox component in Delphi 1 11
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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

832 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