For Programmers: Free Programming Magazines  


Home > Archive > PostScript > March 2006 > [FONT][ROTATE] How to rotate a text string ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [FONT][ROTATE] How to rotate a text string ?
yvespielusenet@free.fr

2006-02-17, 6:59 pm

Hello,
I want to rotate text in postcript. I see that the font matrix can do
this but I don't understand how :(
I do this to rotate :

100 100 moveto
/Times-Roman findfont
[w a b h x y] makefont setfont
(Hello) show

s : width of the caracter font
h : heigth of the caracter font
a = s*atan(angle)
b = s*atan(angle)
x : x decal
y = y decal

I always set '0' to x and y

But I dont succeed to rotate :( I must set a bad angle...

Can you tell me how do you rotate text to have 0, 45, 90, 135, 180,
215, 270, 315 rotation ?

thank you :)
--
yves piel

Colin Brough

2006-02-17, 6:59 pm

On 17 Feb 2006 07:47:48 -0800, yvespielusenet@free.fr wrote:
> Can you tell me how do you rotate text to have 0, 45, 90, 135, 180,
> 215, 270, 315 rotation ?


100 100 moveto
/Times-Roman findfont
**** 45 rotate ****
(Hello) show

Cheers

Colin

--

----------------------------------------------------------------------
Colin Brough Colin.Brough@blueyonder.invalid
(Replace .invalid with .co.uk to reply)
Ross Presser

2006-02-17, 6:59 pm


Colin Brough wrote:
> On 17 Feb 2006 07:47:48 -0800, yvespielusenet@free.fr wrote:
>
> 100 100 moveto
> /Times-Roman findfont
> **** 45 rotate ****
> (Hello) show


Colin, you should be aware that after you rotate, everything you put
down on the page will continue to be rotated that amount until you
rotate back (with -45 rotate).

sjprouty

2006-02-17, 6:59 pm

I think the matrix values are incorrect. Given:

w = width to scale font
h = height to scale font
a = angle to rotate font (positive is counter-clockwise)

Then the matrix passed to makefont should be:

[
w * cos(a)
w * sin(a)
h * -sin(a)
h * cos(a)
0
0
]

Or in full PostScript syntax:

/w 10 def % Scale font width
/h 15 def % Scale font height
/a 30 def % Rotate font counter-clockwise

[
w a cos mul
w a sin mul
h a sin neg mul
h a cos mul
0
0
]


Thanks
Scott Prouty


LC's NoSpam Newsreading account

2006-02-24, 6:59 pm

On Fri, 17 Feb 2006, Ross Presser wrote:
> Colin Brough wrote:


> Colin, you should be aware that after you rotate, everything you put
> down on the page will continue to be rotated that amount until you
> rotate back (with -45 rotate).


not if you bracket it with a gsave and grestore
[color=darkred]
gsave 45 rotate[color=darkred]
grestore

of course grestore will put the currentpoint back at 100 100 too

--
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
VAXman- @SendSpamHere.ORG

2006-02-24, 6:59 pm

In article <Pine.LNX.4.61.0602241559230.28860@cbfrvqba.ynzoengr.vans.vg>, LC's NoSpam Newsreading account <nospam@mi.iasf.cnr.it> writes:
>
>
>On Fri, 17 Feb 2006, Ross Presser wrote:
>
>
>not if you bracket it with a gsave and grestore
>
> gsave 45 rotate
> grestore
>
>of course grestore will put the currentpoint back at 100 100 too


I posted a query here a few days ago regarding fonts and rotation.

I don't want to rotate, as in this example, the entire (Hello) string,
I'm looking for a way to rotate the individual characters in the font.
(look for thread with "lazy" in the title) What I'd like is a way to
rotate a character 90 deg. and then issue (Hello) show -- with the re-
sult being "Hello" printed out normally but all the character lying on
their side.

Any suggestions welcome.

--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)COM

"Well my son, life is like a beanstalk, isn't it?"
Colin Brough

2006-02-24, 6:59 pm

On Fri, 24 Feb 2006 16:09:09 GMT, VAXman- @SendSpamHere.ORG wrote:
> I posted a query here a few days ago regarding fonts and rotation.
>
> I don't want to rotate, as in this example, the entire (Hello) string,
> I'm looking for a way to rotate the individual characters in the font.
> (look for thread with "lazy" in the title) What I'd like is a way to
> rotate a character 90 deg. and then issue (Hello) show -- with the re-
> sult being "Hello" printed out normally but all the character lying on
> their side.
>
> Any suggestions welcome.


A string is just an array of characters, so you could just write a new
routine to do this 'rotated show':

/rotatedshow {
/String exch def
/Letter 2 string def
0 1 String length 1 sub {
/I exch def
gsave
90 rotate
Letter 0 String I get put Letter show
grestore
10 0 rmoveto % Something better to move currentpoint...
} for
} def

(Hello) rotateshow

This is rough, but it gives the idea. You'd want to put something in
to move currentpoint in a more intelligent manner!!

Cheers

Colin

--

----------------------------------------------------------------------
Colin Brough Colin.Brough@blueyonder.invalid
(Replace .invalid with .co.uk to reply)
Ross Presser

2006-02-24, 6:59 pm


VAXman-@SendSpamHere.ORG wrote:
> I posted a query here a few days ago regarding fonts and rotation.
>
> I don't want to rotate, as in this example, the entire (Hello) string,
> I'm looking for a way to rotate the individual characters in the font.
> (look for thread with "lazy" in the title) What I'd like is a way to
> rotate a character 90 deg. and then issue (Hello) show -- with the re-
> sult being "Hello" printed out normally but all the character lying on
> their side.
>
> Any suggestions welcome.


Did you try the method given elsewhere in the thread by sjprouty?
http://groups.google.com/group/comp...a9c0d7b35873781

VAXman- @SendSpamHere.ORG

2006-02-24, 6:59 pm

In article <r0s3d3-3k1.ln1@brough.bd>, Colin Brough <Colin.Brough@blueyonder.invalid> writes:
>
>
>On Fri, 24 Feb 2006 16:09:09 GMT, VAXman- @SendSpamHere.ORG wrote:
>
>A string is just an array of characters, so you could just write a new
>routine to do this 'rotated show':
>
> /rotatedshow {
> /String exch def
> /Letter 2 string def
> 0 1 String length 1 sub {
> /I exch def
> gsave
> 90 rotate
> Letter 0 String I get put Letter show
> grestore
> 10 0 rmoveto % Something better to move currentpoint...
> } for
> } def
>
> (Hello) rotateshow
>
>This is rough, but it gives the idea. You'd want to put something in
>to move currentpoint in a more intelligent manner!!


What I was after was a way to have stringwidth function so that I could
justify the text. I know I could rotate the characters with a routine
such as you've illustrated.


--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)COM

"Well my son, life is like a beanstalk, isn't it?"
VAXman- @SendSpamHere.ORG

2006-02-24, 6:59 pm

In article <1140804401.789252.248520@p10g2000cwp.googlegroups.com>, "Ross Presser" <rpresser@gmail.com> writes:
>
>
>
>VAXman-@SendSpamHere.ORG wrote:
>
>Did you try the method given elsewhere in the thread by sjprouty?
>http://groups.google.com/group/comp...a9c0d7b35873781
>


....and which matrix is being rotated? I tried redefining the font's
FontMatrix but doing so rotates the entire translation martix when a
font modified as such is used.

--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)COM

"Well my son, life is like a beanstalk, isn't it?"
Ross Presser

2006-02-24, 6:59 pm


VAXman-@SendSpamHere.ORG wrote:

> ...and which matrix is being rotated? I tried redefining the font's
> FontMatrix but doing so rotates the entire translation martix when a
> font modified as such is used.


No, it doesn't. It rotates the entire fontmatrix, including the
spacing that goes between characters, but it doesn't touch the CTM.

%!PS
/angle 90 def
/Times-Roman findfont
24 scalefont [angle cos angle sin angle neg sin angle cos 0 0] makefont
setfont
100 100 moveto
(Angled) show

/Helvetica findfont 24 scalefont setfont
100 150 moveto

(Normal) show


This doesn't help you on its own, because you don't want the letters
following each other vertically. You can do it crudely as said earlier
in the thread with something like this:

/fontsize 24 def
/spacer fontsize 5 sub def
/angle 90 def
/Times-Roman findfont fontsize scalefont
[angle cos angle sin angle neg sin angle cos 0 0] makefont setfont
/sc { currentpoint 3 -1 roll show moveto spacer 0 rmoveto } def
(L) sc
(a) sc
(z) sc
(y) sc

The next improvement would require a "stringheight" primitive, which
would measure the vertical space used by each character (actually, the
space used perpendicular to the baseline). It's probably buried in the
font metrics somewhere but I don't know where. If it was there, we
could do

/sc {
dup currentpoint 4 -1 roll show moveto stringheight exch pop 0
rmoveto } def
(L) sc
(a) sc
(z) sc
(y) sc

François Robert

2006-03-08, 3:57 am

"Ross Presser" <rpresser@gmail.com> wrote in
news:1140827231.577940.186270@p10g2000cwp.googlegroups.com:

....
> This doesn't help you on its own, because you don't
> want the letters following each other vertically.
> You can do it crudely as said earlier in the
> thread with something like this:

....
A custom /Metrics dictionnary will enable you to get the result you want
(that is, effortless 'show' + 'stringwidth' with individual glyphs
rotated but the baseline untouched ) :
The code by the previous poster can be modified as follow (many
improvements are possible and indeed desirable. This is a proof of
concept) :

%!PS
/Times-Roman findfont

% scale to font designer's original size (?)
1000 scalefont setfont

% Make a R/W copy of the font
currentfont length dict begin
currentfont
{ 1 index /FID eq
{ pop pop
}{ def
} ifelse
} forall

% Create a Metrics dictionnary (one entry per glyph name)
currentfont /CharStrings get length dict begin

% For all the glyphs we are interested in (for the sake
% of simplifying the code, we assume glyphname == character code,
% which is usually true for plain text letters.)
(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm
nopqrstuvwxyz)
{
(x) dup 0 4 3 roll % (x) (x) 0 <code>
put cvn [0 0 0 1000] % <gname> [metrics]
def % -
} forall
currentdict end % <newfont> <metrics>

% (Re)define the font metrics. (exchanging H and V advance)
/Metrics exch def
currentdict end
/LazyFont exch definefont

/angle -90 def
0.001 24 mul scalefont [angle cos angle sin angle neg sin angle cos 0 0]
makefont

setfont
100 500 moveto
(Lazy) show

/Helvetica findfont 24 scalefont setfont
100 550 moveto

(Normal) show
%%EOF

Improvements include (in increasing order of difficulty, I would say) :
- Handle all glyphs (not merely letters)
- Tighter fitting to glyph for the new metrics (it is constant here)
- Arbitrary rotation angle instead of 90°. That is, each glyp is rotated
by X, but the 'baseline' (if we can still speak of a baseline...)
remains untouched and horizontal.

Enjoy.
________________________________________
_______________
François Robert
(to mail me, reverse character order in reply address)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com