-- PostScript -- Answers to Questions (the comp.lang.postscript FAQ v2.4) Allen Braunsdorf [email protected] This FAQ is formatted as a digest. Most news readers can skip from one question to the next by pressing control-G. GNUs uses C-c C-n to skip to the next question. Changes since the last version are marked with a '|' in the table of contents and in the sections in the text-only format of the FAQ. Now that there is Linux and NetBSD and BSD 386 UNIX IBM PC (and clone) users can run any of the X-windows and UNIX programs in the utilities section. See any of comp.os.linux.{ admin,development,help,misc}. Also, there is now GhostScript for the Macintosh. Many thanks to Dan Carrigan for reformatting the books and publishers section. The utilities index from the comp.sources.postscript FAQ will be posted in comp.lang.postscript now too. Please help fix the FAQ! All comments should be mailed to [email protected]. My favorite way to receive a change suggestion is when it is accompanied by a section of the FAQ that is edited and mailed to me verbatim as an example. If you would like to contribute, please read the section ``about the FAQ'' first. Thank you! Books and programs are referred to by name only. See the book sections for book information, and the comp.sources.postscript FAQ for a full list of all PostScript related programs. I have archived a number of the small utilities in wilma.cs.brown.edu:pub/postscript. You can get the comp.sources.postscript FAQ from wilma.cs.brown.edu:pub/comp.sources.postscript. Related FAQs: comp.text, comp.text.tex, comp.fonts, comp.graphics, comp.sys.mac.apps, comp.sources.postscript. 7 Programming in PostScript 7.1 What is PostScript level 2? (See the Section 11, ``About PostScript 2''.) 7.2 Should I learn level 2 PostScript? Yes, because Level Two will soon become the standard. Application developers using PostScript need to become aware of the new capabilities and how to take advantage of them. There are many good books on PostScript 2. (See Section 5, ``Books''.) 7.3 Where can I find examples of PostScript code? Many other books on PostScript make example PostScript code available. ``Thinking in PostScript'', by Glenn Reid, is the only book I know of that allows its examples to be freely distributed. (See Section 5, ``Books''.) All the examples in ``the blue book'' are available from the Adobe file server (See Section 5, ``Books''.) See the question ``How can I browse through PostScript programs?'' in the comp.sources.postscript FAQ. 7.4 What is the physical size of the page? This depends on what print medium you are using. Paper comes in a number of standard sizes: Paper Size Dimension (in points) ------------------------------ --------------------- Comm #10 Envelope 297 x 684 C5 Envelope 461 x 648 DL Envelope 312 x 624 Folio 595 x 935 Executive 522 x 756 Letter 612 x 792 Legal 612 x 1008 Ledger 1224 x 792 Tabloid 792 x 1224 A0 2384 x 3370 A1 1684 x 2384 A2 1191 x 1684 A3 842 x 1191 A4 595 x 842 A5 420 x 595 A6 297 x 420 A7 210 x 297 A8 148 x 210 A9 105 x 148 B0 2920 x 4127 B1 2064 x 2920 B2 1460 x 2064 B3 1032 x 1460 B4 729 x 1032 B5 516 x 729 B6 363 x 516 B7 258 x 363 B8 181 x 258 B9 127 x 181 B10 91 x 127 To determine what print mediums are available, check the PPD file for your printer, under the PageSize keyword. 7.5 What is the Imagable Area of the page The initial clipping path gives you the size of the imagable area. Use ``clippath pathbbox'' to get these coordinates. If you must know the size of the device's imageable area, use the sequence ``gsave initclip clippath pathbbox grestore'', but this will prevent an enclosing application from using the clippath to achieve some special effects (such as multiple pages per page). PPD files (see section 2 of the FAQ, printers) contain information on what paper sizes, as well as the Imagable Area for each, specific to each printer. A Postscript code fragment (called ``?ImageableArea'') is described in a PPD file, which determines the current Imageable Area for that printer. 7.6 Why can't I do a pathforall after a charpath ? (See Section 4, ``Fonts'', question ``Why are Adobe fonts hidden?''.) 7.7 How do I center a string of text around a point? Level 1 PostScript has two operators that can extract information about the metrics of characters: ``stringwidth'' and ``charpath''. The ``stringwidth'' operator returns the advance width of its string operand. This is the distance the current point would be moved by a ``show'' operation on the same string. ``stringwidth'' returns two numbers on the stack, representing the x and y components of the advance width. Usually the y component is zero because most fonts are displayed along a horizontal line, moving the current point only in the x direction. Also note that the ``stringwidth'' usually does not give an exact measure of the area of the page that will be touched by its operand. The letters can either project a little over the boundaries or fall a little within (leaving a touch of whitespace). If all that an application requires is horizontal centering of a long string of text, the result returned by ``stringwidth'' is sufficient. A common technique is x y moveto (string) dup stringwidth pop 2 div neg 0 rmoveto show (This code makes the assumption that the y component of advance width is irrelevant.) The ``charpath'' operator extracts the graphic shapes of its string operand and appends them to the current path in the graphic state. These shapes can then be processed by other PostScript operators. To get the actual size of the area touched by a character a simple approach is gsave newpath 0 0 moveto (X) false charpath flattenpath pathbbox grestore This code places four numbers on the stack, representing the coordinates of the lower left and upper right corners of the bounding box enclosing the character ``X'' rendered with the current point at (0,0). Leaving the flattenpath out will cause it to be less accurate, but it will take up less memory and be faster. There are two things to be careful about when using the code shown above: 1. There are severe limits on the size of the string operand, related to the limit on the number of elements in a graphic path. The PostScript Language Reference Manual recommends taking ``charpath''s one character at a time. 2. If user space is rotated or skewed with respect to device space, the result from ``pathbbox'' may be larger than expected; ``pathbbox'' returns a rectangle oriented along the user space coordinate axes, which fully encloses a (possibly smaller) rectangle oriented along the coordinate axes of device space. If user space is rotated at an integer multiple of 90 degrees these two rectangles will be the same, otherwise the rectangle in user space will be larger. So, to center text vertically one must get the bounding boxes of all the characters in the string to be displayed, find the minimum and maximum y coordinate values, and use half the distance between them to displace the text vertically. This still may not do a very good job, since this provides centering based on extrema, not on the optical center of the string (which is more related to a sort of ``center of mass'' of the text). If an application does this repeatedly, it would be wise to store the bounding boxes in an array indexed by character code, since ``charpath'' is a slow operation. Font metric information is available outside of a PostScript printer in font metrics files, available from the font vendor. A program generating PostScript output can obtain metrics from these files rather than extracting the metrics in the printer. 7.8 How can I concatenate two strings together? %% string1 string2 append string % Function: Concatenates two strings together. /append { 2 copy length exch length add % find the length of the new. string dup % string1 string2 string string 4 2 roll % string string string1 string2 2 index 0 3 index % string string string1 string2 string 0 string1 putinterval % stuff the first string in. % string string string1 string2 exch length exch putinterval } bind def 7.9 What do I do when I get stack overflow/underflow? These errors are among the most common in PostScript. When I get a stack overflow, that is usually a sign that a routine is leaving an object on the stack. If this routine gets called 2000 times, it leaves 2000 objects on the stack, which is too many. When I get a stack underflow, that is a sign that either: (A) one of the routines in the program doesn't work, and never has or (B) one of the routines in the program works, but expects to be called with some arguments left on the stack. There is no such thing as a PostScript debugger right now. For now, the best that you can do to debug your program is to put in lots of print statements. Learn to use the PostScript pstack command, and use an online interpreter so you don't have to run to the printer for each debugging cycle. Use an error handler to learn more about what exactly is happening when your program crashes. (see the comp.sources.postscript FAQ for a list of all PostScript related programs.) If your code has never worked yet (i.e. you are still writing it) then I find that it helps to put little comments in the margin about the state of the stack. Like this: Heart pathbbox % lowerx lowery upperx uppery exch 4 -1 roll % lowery uppery upperx lowerx I generally put these comments in originally, and then take them out when the program works. Maybe this is a bad practice, in case I ever want to go back and look at the code to modify it!! 7.10 How can I print in landscape mode? Landscape (the opposite of portrait) means that the page is turned on its side. You can redefine showpage in terms of the current definition of showpage. Do something like: /oldshowpage /showpage load def 90 rotate llx neg ury neg translate % for the first page /showpage { oldshowpage 90 rotate llx neg ury neg translate } def This won't work if the PostScript file you're editing uses initgraphics or grestoreall. Also note that the method described (redefining showpage) does not conform to the document structuring conventions. The Adobe recommended method involves performing the transformaton as part of the setup for each page. 8 Computer-specific PostScript This section describes PostScript information specific to a particular type of computer or operating system. 8.1 Sun Workstations What is NeWS? NeWS (R.I.P.) was Sun Microsystems PostScript-based window system for the Sun Workstation. NeWS was a project within Sun (started around 1985) to create a window system to supplant SunView (a very successful kernel-based window system). NeWS was a client-server model window system (like X) but among many of NeWS novel features was the use of PostScript as the language to describe the appearance of objects on the screen. NeWS had many features in common with Display PostScript, but NeWS predates Adobe Display PostScript and was neither connected with Adobe Display PostScript nor endorsed by Adobe. NeWS was not an Adobe product, nor was it a Sun/Adobe joint venture. As of October 1992, Sun management signed a deal with Adobe to adopt Display PostScript for the Sun. In 1993, Sun finally dropped NeWS altogether. The Sun window system is supposed to start shipping a Display PostScript environment in late 1993. And how does PostScript run on them? PostScript runs on NeWS, although NeWS was not a fully-compliant PostScript interpreter. There were incompatibilities between the NeWS PostScript interpreter and ``official'' PostScript interpreters as defined by Adobe and the Apple LaserWriter family of printers, such that many PostScript files which would print fine on a LaserWriter would not render under NeWS. The most critical incompatibility was lack of support for Adobe Type 1 fonts, Sun having gone with their own font format known as F3. F3 fonts have now gone the way of the zumbooruk and will be supplanted by Type 1 fonts. 8.2 IBM PC You can find nenscript for OS/2 1.x--2.0 and MSDOS on ftp-os2.nmsu.edu in pub/uploads/nensc113.zip. Microsoft Word for Windows can produce files with incorrect DSC comments. To fix this, from the Control Panel, select Printers, Options..., Advanced, and then check 'Conform to Adobe Document Structuring conventions'. This is not enough to produce a valid DSC document - you also need to remove the leading Ctrl-D as documented in PRINTERS.WRI. There are rumors that Word Perfect and Microsoft Word don't produce ``clean'' PostScript that follows the DSC conventions (See Section 9, ``Encapsulated PostScript''). This means that a lot of PostScript utilities like Ghostview and psnup, etc., that require the DSC conventions, will not work on them. Creating a PostScript file from MS Word Install the LaserWriter driver that comes with Windows.In the printer setup, select a PostScript printer. Then click on the setup button to get that pop-up. Then clik the Options button. Then select the print to Encapsulated PostScript File. If you don't specify a file name, Word will prompt you for one when you tell it to print. When printing Microsoft Windows files that have been captured on a PC's LPT port, you mostly need to define two ctrl-d's in a row as well to remove all of them in the document: (\004\004) cvn {} def 8.3 Apple Macintosh For more details about printing with the Macintosh, read the comp.sys.mac.apps FAQ. How can I convert a PostScript file created with a UNIX program to the Mac? A way that is clumsy, but works, is this: 1. Display the UNIX-based PostScript file on screen 2. Use window dumping facility to get a bitmap file 3. Convert the above bitmap file to TIFF format and then export it to Adobe Illustrator on the Mac. The PostScript section of the FAQ for the Macintosh newsgroup comp.sys.mac.apps (maintained by Elliotte Harold) answers the following questions: * How do I make a PostScript file? * How do I print a PostScript file? * Why won't my PostScript file print on my mainframe's printer? Full documentation of this process provided with a utility called macps. * Why are my PostScript files so big? 8.4 NEXTSTEP NEXTSTEP, the system software from NeXT Computer, Inc. uses Display PostScript as one of its primary components. Because of this, most PostScript activities are very easy and supported by many applications. For more information on NeXT and NEXTSTEP, please see http://www.next.com. 9 Encapsulated PostScript 9.1 What is Encapsulated PostScript? Encapsulated PostScript (EPS) is a standard format for importing and exporting PostScript language files in all environments. It is usually a single page PostScript language program that describes an illustration. The purpose of the EPS file is to be included as an illustration in other PostScript language page descriptions. The EPS file can contain any combination of text, graphics, and images. An EPS file is the same as any other PostScript language page description, with some restrictions. EPS files can optionally contain a bitmapped image preview, so that systems that can't render PostScript directly can at least display a crude representation of what the graphic will look like. There are three preview formats: Mac (PICT), IBM (tiff), and a platform independent preview called EPSI. An EPS file must be a conforming file, that is, it must conform to the Adobe Document Structuring Conventions (DSC). At a minimum, it must include a header comment,%!PS-Adobe-3.0 EPSF-3.0, and a bounding box comment,%%BoundingBox: llx lly urx ury, that describes the bounds of the illustration. (The specification does not require the EPSF version, but many programs will reject a file that does not have it.) The EPS program must not use operators that initialize or permanently change the state of the machine in a manner that cannot be undone by the enclosing application's use of save and restore (eg. the operators starting with ``init'' like initgraphics). As a special case, the EPS program may use the showpage operator. The importing application is responsible for disabling the normal effects of showpage. The EPS program should make no environment-sensitive decisions (the importing application may be trying to attain some special effect, and the EPS program shouldn't screw this up), although it can use some device-dependent tricks to improve appearance such as a snap-to-pixel algorithm. The complete EPS specification is available from Adobe (see the section on Adobe). Read Appendix G (Document Structuring Conventions, V3.0) and Appendix H (Encapsulated PostScript File Format, V3.0) in the new PostScript red book: PostScript Language Reference Manual, Second Edition. An optional component of an EPS file is a ``preview'' image of the file's content. The preview image is a bitmapped representation of the image which may be displayed by programs using the EPS file without having to actually interpret the PostScript code. The recommended form for a preview image is ``Interchange'' format and is described fully in the ``red book'', second edition. Interchange format represents the image as a series of hex strings placed in the EPS file as PostScript comments. The entire file remains an ASCII file. That book contains all of the information that you need to fix your program to correctly output EPS. It is what I use for our software. A variation of EPS embeds the preview image and PostScript text in a binary file which contains a header and the preview image in either a TIFF or MetaFile format. The header defines where in the file each section (EPS, TIFF, or MetaFile) starts and ends. On the Macintosh, the preview is stored as a PICT in the file's resource fork. 9.2 What are EPSI and EPSF? EPSI is EPS with a device independent bitmap preview. EPSI is an all ASCII (no binary data or headers) version of EPS. EPSI provides for a hexadecimal encoded preview representation of the image that will be displayed or printed. EPSI files were documented by Adobe as a means of providing a preview for EPS files which would be cross-platform. In reality though DOS machines and Windows favour embedding TIFF or even Windows Metafiles in the PostScript. I don't know of any Mac packages that support EPSI files. The Macintosh has always favoured EPSF files with the data fork of the file containing the PostScript code, and the resource fork containing a PICT preview of the file. This is how typically when you import an EPSF file into a program (Quark, Persuasion etc.) you get to see the PICT preview from the file. It is still possible to have an EPSF file without a preview though, in this case the imported artwork is displayed usually as a box with diagonal lines running through it. Note the term EPSF really means that the image is independant of an output device, in other words the image would need to be embedded inside other PostScript code to be usable (printable). The old command-lk files from the PS driver on the Mac are not EPSF files as they are produced for a specific output device (LaserWriter). Therefore they cannot be imported into other applications for printing. ESPF must be given resource number 256. 9.3 How do I convert PostScript to EPS? Use pstoepsi, or do it by hand. GhostScript's program ps2epsi does this also, as does LaserWriter 8 for the Mac. GhostScript on the Mac can output EPS also, I believe. To convert from PostScript to EPS, one must guarantee that the PostScript file meets the above requirements. If the actual program conforms to the programming requirements, then one can simply add the required comments at the top of the file saying that the file is EPS and giving its BoundingBox dimensions. Optional comments include font usage (%%DocumentFonts: or%% DocumentNeededResources: font), EPSI preview comments (%% Begin(End)Preview:) extensions (%%Extensions:) and language level (%%LanguageLevel:). There are some operators that should not be used within an EPS file: banddevice cleardictstack copypage erasepage exitserver framedevice grestoreall initclip initgraphics initmatrix quit renderbands setglobal setpagedevice setshared startjob These also include operators from statusdict and userdict operators like legal, letter, a4, b5, etc. There are some operators that should be carefully used: nulldevice setgstate sethalftone setmatrix setscreen settransfer undefinefont To convert a PostScript file to EPS format, you must edit the file using a text editor or word processor to add lines that will define the file as an EPS-format file. 1. Using your normal method of printing, print the PostScript file to a PostScript printer. You can choose to view it on the screen instead, but keep in mind that all the below distance measurements assume that you are printing on a normal-sized piece of paper. NOTE: If the PostScript image does not get displayed properly, it probably will not work either once you have converted it to EPS format. Correct the PostScript program so that it works before you convert it to EPS format. 2. Use a tool (see below) to find the bounding box, which shows how much space the PostScript image occupies when printed. You specify the dimensions of the bounding box when you convert the PostScript file to EPS format. 3. If you don't have a bounding box tool, you can just use a ruler and draw one on your printout. With two horizontal lines and two vertical lines, draw a box around the image that includes the entire image while minimizing white space. This box represents your bounding box. You may want to leave a small amount of white space around the image as a precautionary measure against minor printing problems, such as paper stretching and paper skewing. 4. Measure distance ``a'' from the lower-left corner of the image to the left edge of the paper. 5. Write the measurement in points. If your ruler does not show points, calculate the total number of points: 1 inch = 72 points, 1 cm = 28.3 points, and 1 pica = 12 points. Designate this measurement as ``measurement a.'' 6. Measure distance ``b'' from the lower-left corner of the image to the bottom edge of the paper. Designate this measurement in points as ``measurement b.'' 7. Measure distance ``c'' from the upper-right corner of the image to the left edge of the paper. Designate this measurement in points as ``measurement c.'' 8. Measure distance ``d' from the upper-right corner of the image to the bottom edge of the paper. Designate this measurement in points as ``measurement d.'' 9. Using any text editor, open the PostScript file for editing. You'll see several lines of text. These lines are the PostScript description of the image. The lines at the top of the file are the header. 10. Add these lines to, or modify existing lines in, the header (the first group of lines in any PostScript file): %!PS-Adobe-2.0 EPSF-2.0 %%Creator: name %%CreationDate: date %%Title: filename %%BoundingBox: a b c d Note: Make sure that the first line in the file is ``% !PS-Adobe-2.0-EPSF-2.0''. Also, do not separate the header lines with a blank line space. The first blank line that PostScript encounters tells it that the the next line begins the body of the program. For ``name,'' type your name or initials. For ``date,'' type today's date using any format (for example, MM-DD-YY, MM/DD/YY, July 5, 1987, and so on). For ``filename,'' type the name of the PostScript file. After ``BoundingBox: ,'' type the measurements you took in steps 3, 4, 5, and 6, separating each with a space: ``a'' is the measurement from Step 3, ``b'' is the measurement from Step 4, ``c'' is the measurement from Step 5, and ``d'' is the measurement from Step 6. 11. Save the file in text-only format. If you are interested in learning how to further edit your PostScript files, these books are available at most bookstores: Understanding PostScript Programming and the green book. The Document Structuring Conventions (DSC), version 1.0, are discussed in Appendix C of the old red book. The new red book has a lot of information about Encapsulated PostScript. There will be a technical note available from Adobe called ``Guidelines for Specific Operators'' that will talk about why some operators are prohibited and how to use the others. 9.4 How do I get the bounding box of a PostScript picture? Use bbfig or epsinfo.ps. Or if you would rather construct the bounding box by hand, use Ghostview, which has a continuous readout of the mouse cursor in the default user coordinate system. You simply place the mouse in the corners of the figure and read off the coordinates. 10 About The Comp.Lang.PostScript FAQ 10.1 The PostScript FAQ: What is it? The PostScript FAQ is a set of answers to frequently asked questions (FAQs) that have appeared on the Usenet newsgroup comp.lang.postscript. It is broken into many useful sections. There is a companion file which is not posted to USENET called ``Exactly What Does a Transformation Matrix Do?''. You can get it from wilma.cs.brown.edu:pub/comp.lang.postscript/transform.tex. I need help writing and revising answers for common questions relating to PostScript. Almost all of the information in the documents has been written by kind volunteers. The answers will be published in either or both documents. A very long answer in the Usenet Guide may be summarized, referred to briefly, or not mentioned at all in the FAQ. 10.2 How to get the FAQ files The FAQ is available by anonymous ftp to wilma.cs.brown.edu:pub/comp.lang.postscript/ You can get it formatted in plain text ASCII, LaTeX, or PostScript. I would be happy to email a copy of the FAQ in any format to you if you do not have FTP (or a Web browser that supports FTP). 10.3 How to write a FAQ answer I greatly appreciate your time and effort to help improve the quality of the FAQ. Thank you for being willing to contribute! * Please check to see if the topic is already in an FAQ. Perhaps you really mean to submit a revision to an existing section. * Start with a clear statement about what problem you are solving. * Write for novice users, in ``tutorial format'', even if the answer is meant for experienced programmers. * Be specific when you make references. * Be complete, and take the time to look over your draft and revise. * Answers should not be too wordy, unless you intend to write a long answer for the Usenet Guide and have a shorter summary or a pointer to the description placed in the FAQ. If you want to write the summary yourself, thanks! * Obviously, I cannot accept copyrighted material without permission. Don't write the FAQ by paraphrasing from a copyrighted book! 10.4 The FAQ can contain LaTeX and PostScript inserts The FAQ is actually written with LaTeX, so feel free to submit with that text formatting language. There is a PostScript version of the FAQ also, so feel free to send along PostScript pictures to include. 10.5 Revising the FAQ Suggestions and comments are welcomed. My favorite way of receiving a change suggestion is if you make a copy of the FAQ, edit the copy, and mail me the modification, or a context diff (include the version number). 10.6 How to submit new information If you know something that you think is worthwhile to be put in a FAQ, definitely send it to me! Don't hold back if your information is very specific. If there's too much information to post I will archive it at an ftp site and place a pointer to it in the FAQ. 10.7 How to add a program description to the FAQ index If the program is original, please send it to me, or tell me where I can get it. Please put your name and email address at the top of each file. Your program will be doubly useful if you clean up the program so that other people can use it as an example to learn. If the program was written by someone else, please send me just the title, description, and where to get it. I may already have it. For programs the FAQ needs to know: * What is the name of the program? * What does it claim to do, and does it do it well? Is it worth using? * Where is it available? What ftp sites can I get it from? * How much does it cost? Is it free? * What kinds of computers does it run on? * Who is the author and does the author give an email address? * Does it handle PostScript 2? * What packages does it rely on? If the program is a PostScript interpreter, then the FAQ also needs to know: * Does it let you go backwards one page? * Does it display the number of pages in the document? * Does it let you print PostScript to a non-PostScript printer? * What formats can it convert to? 10.8 How to add a book description to the FAQ For books the FAQ needs to know: * What is the name of the book or document? * What does it claim to do, and does it do it well? Is it worth using? * Can I get it on-line? * Who wrote it? Does the author give an email address? * Who is the publisher, and what is the copyright date? * Does the publisher list an address and phone number or fax number? * What is the ISBN number of the book? * What is the library call number of the book? * How much does the book cost? * Does it cover PostScript 2? * Are coding examples from the book available by email or anonymous ftp? * Do the authors sell the coding examples on a diskette? 10.9 Questions that need answers 1. Where are ftp sites that have PostScript freeware? 2. What vendors sell fonts for PostScript printers? Where are the free ftp sites for them? 3. Are there any free encapsulated PostScript converters? 4. What is the charter for comp.lang.postscript? 5. What questions should the FAQ have? 6. What book information is wrong or missing in the FAQ? 7. What program information is wrong or missing in the FAQ? 8. What ftp site have good examples of PostScript code?
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |