pts@faraday.clas.Virginia.EDU (Paul T. Shannon) (03/22/91)
I sent this to the next programmers' mailing list, but it doesn't seem to have been distributed -- it didn't come back to me as my messages have before. I apologize if you're seeing this for the second time. I'm doing some very straightforward postscript programming, using single- operator functions from Objective-C. My problem comes when I need to return to a specific point on the screen (or page) after drawing a string. The length of the string is only known at run-time. I've tried two techniques: 1. calling PScurrentpoint (&x, &y) before drawing the string 2. calling PSstringwidth (string, &width, &height), so that I can then call PSrmoveto (-width, 0.0) after the string is drawn. Both of these work fine with Display PostScript. However neither work with a printer or with Preview. The printer (an Apple LaserWriter) prints nothing; Preview gives this error message: The PostScript code of the document erroneously tried to return values to the application... So it seems that while it's no problem for DPS to tell my application what it asks for (either current position or a string's width), it's impossible for either the LaserWriter or Previewer to send this information back to me. Can someone suggest an approach that works in all 3 contexts, DPS, Previewer, and a printer? Thanks. - Paul Shannon pts@Virginia.EDU
aozer@next.com (Ali Ozer) (03/23/91)
In article <1991Mar21.160137.13875@murdoch.acc.Virginia.EDU> Paul T. Shannon writes: >I'm doing some very straightforward postscript programming, using single- >operator functions from Objective-C. My problem comes when I need to >return to a specific point on the screen (or page) after drawing a string. >The length of the string is only known at run-time. >I've tried two techniques: > 1. calling PScurrentpoint (&x, &y) before drawing the string > 2. calling PSstringwidth (string, &width, &height), so that I > can then call PSrmoveto (-width, 0.0) after the string is > drawn. >Both of these work fine with Display PostScript. However neither work >with a printer or with Preview. When you're dealing with fonts from a NeXTstep application, it's best to deal with the Font object. This way you will be able to obtain afm info, string widths, etc, and also have your application cache and keep track of what Fonts are being used so that they can listed in your .eps and .ps files when you generate PostScript (for instance, when you're printing). The Font object is easy to use; use the newFont:size:matrix: method to get new fonts, and the set method to make it the current font. The getWidthOf: method will return the width of a string, and will work in any context (DPS, printer, etc), as it gets the values from the AFM files instead of the PostScript interpreter. As an added bonus, you can also obtain kerning and ligature information (among other things) from the Font object. If you don't want to do this for some reason, you might also be able to accomplish what you are trying to do by wrapping a gsave/grestore around your text drawing: // you want to remember where you are at this point... PSgsave (); PSshow ("Hello, world."); PSgrestore (); // Well, you're back there! Ali, Ali_Ozer@NeXT.com