montnaro@sprite (Skip Montanaro) (03/17/88)
I'm writing a small NeWS application that needs to put some text up and I'm having trouble setting the font size, other than by trial and error. I first tried (for instance) /Times-Italic findfont 12 scalefont in an attempt to get a 12-point font, and wound up with enormous text that sprayed itself all over the screen. My next attempt was to calculate the X dimension of the window after the user had reshaped the window (call it WinX) and the X dimension of the framebuffer (call it ScreenX) and do /Times-Italic findfont 12 WinX mul ScreenX div scalefont thinking that the ratio of the window to screen dimension would help scale things properly, but that didn't work either. So I started twiddling the "12" and came up with /Times-Italic findfont 0.05 WinX mul ScreenX div scalefont which isn't intuitive at all. Can someone give me some advice about what I'm doing wrong? Thanks, Skip Montanaro (montanaro@sprite.steinmetz.ge.com, montanaro@ge-crd.arpa)
don@BRILLIG.UMD.EDU (Don Hopkins) (03/20/88)
Here's one way to get fonts to come out the right size when using a funky coordinate system in PostScript. The trick is to save away the matrix appropriate for showing the font, set up the funky coordinate system, move to where you want to show the text, use setmatrix to get back in the font coordinate system, and then show the string! (This code is for NeWS, but the concept applies to any PostScript system, of course.) Thanks to Steve Isaac for showing me this trick! -Don ====Cut here: 8X======================================================== %!/bin/psh % % Example of how to get the right font size when changing the % coordinate system in PostScript. % /win framebuffer /new DefaultWindow send def { /PaintClient { gsave % Step onto the drawing surface! ClientCanvas setcanvas % (implies initmatrix) % Set the font to the appropriate size, in the canvas's default % coordinate system. /Times-Roman findfont 24 scalefont setfont % Get a copy of the canvas's matrix on the stack. matrix currentmatrix % CanvasMatrix % Scale the coordinate system to the unit square in the window. % Lower left = (0,0), upper right = (1,1). clippath pathbbox scale pop pop % Move to where we want to show the string (the center of the % window) in our "interesting" coordinate system. .5 .5 moveto % Now that we're there, we can go back to the coordinate system % that our font's expecting to be shown in. setmatrix % % Show the string at the right size in the window center! (<=(.5,.5)) show grestore } def } win send /reshapefromuser win send /map win send