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
100 100 moveto
/Times-Roman findfont
**** 45 rotate ****
(Hello) show
Cheers
Colin
--
----------------------------------------------------------------------
Colin Brough Colin....@blueyonder.invalid
(Replace .invalid with .co.uk to reply)
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).
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
--
yves piel
> 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
> > 100 100 moveto
> > /Times-Roman findfont
gsave 45 rotate
> > (Hello) show
grestore
of course grestore will put the currentpoint back at 100 100 too
--
----------------------------------------------------------------------
nos...@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.
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?"
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!!
Did you try the method given elsewhere in the thread by sjprouty?
http://groups.google.com/group/comp.lang.postscript/msg/da9c0d7b35873781
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.
...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.
> ...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
...
> 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.)
(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz)
{
(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)
Not quite ready for prime time, but close. It rotates the letters
clockwise, when CCW is probably what was wanted; but changing the -90
to 90 doesn't do it right, because then the horizontal advance is
backwards.
Changing -90 to 90, and changing [0 0 0 1000] to [0 0 0 -1000] gives
the desired effect! Hooray!
Using 0 instead of 90 is interesting, too: it gives the often-requested
"print a string vertically" effect.