paynter@ast.dsd.northrop.com (paynter ann m.) (01/17/91)
I am having trouble with PostScript when using certain escape sequences (\). The ones that don't work for me are \b, \r, and \n. Also, when I print a multi-line string, it all ends up on one line. I have looked in numerous PostScript books (including pages 22 - 24 of the red book - possibly first addition, copyright 1985). I'd like to know if anyone else has had this problem, and if so how it was solved. Or, if anyone knows the solution to my mystery. Thanks in advance for the help! The following is my file and the results. MY POSTSCRIPT: %! /Courier findfont 12 scalefont setfont %----- Translate Origin to Upper Left Corner ----- 0 792 translate %----- Translate Origin to Inside Corner of Margins ----- 22.000000 -18.000000 translate %----- End Page Initialization ----- 43.200001 -72.000000 moveto (This is testing \nthe back-slash n \nas a means of creating new lines) show 43.200001 -110.000000 moveto (This is testing the return as a means of creating new lines) show 43.200001 -150.000000 moveto (This is testing \rthe carriage return) show 43.200001 -270.000000 moveto (This is testing\ the return with a backslash\ as a means of connecting lines) show 43.200001 -310.000000 moveto (This is testing the occurance of a \backslash b in the string) show 43.200001 -330.000000 moveto (This is testing\nthe slash n\nas a means of creating new lines) show showpage MY RESULTS: This is testing the back-slash n as a means of creating new lines This is testing the return as a means of creating new lines This is testing the carriage return This is testingthe return with a backslashas a means of connecting lines This is testing the occurance of a ackslash b in the string This is testing the slash n as a means of creating new lines --------------------------------------------------------------------- ann paynter paynter@ast.dsd.northorp.com ---------------------------------------------------------------------
phillips@tegra.COM (Steve Phillips) (01/18/91)
In article <663@ast.dsd.northrop.com> paynter@ast.dsd.northrop.com (paynter ann m.) writes: >I am having trouble with PostScript when using certain escape sequences (\). >The ones that don't work for me are \b, \r, and \n. Also, when I print a >multi-line string, it all ends up on one line. I have looked in numerous >PostScript books (including pages 22 - 24 of the red book - possibly first >edition, copyright 1985). I'd like to know if anyone else has had this >problem, and if so how it was solved. Or, if anyone knows the solution to my >mystery. > > ..... > >(This is testing \nthe back-slash n \nas a means of creating new lines) >show > >43.200001 -110.000000 moveto >(This is testing >the return >as a means of creating new lines) >show > ..... The problem isn't with the escape sequences you're using. It's that PostScript doesn't interpret a \n to mean "go to the beginning of the next line." It's merely a character in the font which gets drawn on the page. Most PostScript fonts don't do anything when a special character like \n is encountered - they just ignore the character. [More specifically, that position in the font's encoding vector contains the /.notdef entry which draws nothing]. One reason for this is that, on a PostScript printer, as opposed to a dot matrix printer, for example, there really isn't a clearly defined place to go when you say, "go to the beginning of the next line." What if I do a 100 100 moveto and then a show? Should the next line start right below the current line (e.g. 100 90) or should it go to the left edge of the page (e.g. 0 90)? What happens with rotated or reversed text? How much vertical spacing (leading) should be used between lines? So, to sum up, if you want to draw text on successive lines, you have to manually position the current point yourself. To make this easier, you could define a routine like "lineshow" which looks through the string, calls show for regular characters, and does a moveto to the next line each time a \n is encountered. That way, you can define "go to the beginning of the next line" any way you want to. Hope this helps - Steve -- ============================================================================ Steve Phillips "Never put off until tomorrow what Tegra-Varityper, Inc., Billerica, MA you can do the day after tomorrow" tegra!phillips@uunet.com - Mark Twain
rberlin@birdland.eng.sun.com (Rich Berlin) (01/18/91)
Ann: The short answer to your question is that \n, \r etc. are not the way to render multiple lines in PostScript. If you need output that looks like this you need to position each line with its own moveto, e.g. 200 200 moveto (looks) show 200 180 moveto (like) show 200 160 moveto (this) show The escapes actually *do* work in the sense that the characters they describe end up in the string. If your printer and your computer have a bi-directional link, you can see what I mean: rather than rendering a string onto the page, you send them back from the printer to the computer along the i/o channel. If you do (one line) print (another line) print what will come back is one lineanother line while if you do (one line\nanother line) print what will come back is one line another line. ------ If you read up on how "show" works, you'll see that when it encounters the \n in the string, it looks up the character encoded by \n and comes up empty-handed; what I think is likely is that in the encoding vector for most fonts, slot #10 (integer value of ascii newline) contains ".notdef". I don't really have time to explain this in detail, so pardon me for referring you to the manual for a more complete explanation. In the 1st ed. redbook, Read section 5.4, beginning on page 93. -- Rich