Article View: comp.lang.postscript
Article #66PostScript monthly FAQ v2.0 10-29-92 [7-10 of 12]
From: Jonathan Monsarrat
Date: Thu, 29 Oct 1992 21:02
Date: Thu, 29 Oct 1992 21:02
731 lines
27979 bytes
27979 bytes
Archive-name: postscript-faq/part7-10
Last-modified: 1992/10/29
Version: 2.0
Subject: 7 Programming in PostScript
Subject: 7.1 What is PostScript level 2?
PostScript Level Two is a major upgrade to PostScript Level One.
Starting from PostScript Level One as a basis, PostScript Level Two
represents the confluence of many features:
* Composite fonts -- fonts with the capability of supporting
character sets with more than 256 characters. Such fonts are
needed in the Asian marketplace, for example.
* Patterns -- provide a device-independent way to describe patterns
which tile an area. A pattern can be thought of as another kind
of ``color'' in PostScript Level Two.
* Forms -- to meet the demands of the forms market, forms describe
static information which can be repeated many times on one page
or printed on many separate pages, or both.
* Color -- the previous ill-defined color models are now enhanced
with the addition of CMYK color, support for color images, CIE
device-independent color (if anybody can understand the damned
thing).
* Halftones -- new highly accurate halftone screening methods to
meet the needs of high end typesetting equipment.
* Display PostScript -- many enhancements and efficiency
improvements to support the needs of screen rendering.
Enhancements include:
* efficient rectangle operators,
* efficient font and text operators,
* multiple contexts
* shared memory models
* hit detection
A detailed description of PostScript 2 is available in the section
on PostScript 2.
Subject: 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.
See the books section for info on what books teach level 2
PostScript.
Subject: 7.3 Where can I find examples of PostScript code?
Many other books on PostScript make example PostScript code
available. (See the section on books.)
All the examples in ``the blue book'' are available from the Adobe
file server (See the section on Adobe.)
See the question ``How can I browse through PostScript programs?''
in the section on utilities.
Subject: 7.4 How do I get the physical size of a 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).
Subject: 7.5 Why can't I do a pathforall after a charpath ?
See the section on fonts, question ``Why are Adobe fonts hidden?''.
Subject: 7.6 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'' operator includes any side
bearings in its result. It usually does not give an exact measure
of the area of the page that will be touched by its operand.
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) true 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).
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.
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 Adobe. A program
generating PostScript output can obtain metrics from these files
rather than extracting the metrics in the printer.
Subject: 7.7 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
Subject: 8 Computer-specific PostScript
This section describes PostScript information specific to a
particular type of computer or operating system.
Subject: 8.1 Sun Workstations
What is Open Look?
Open Look is Sun Microsystems ``Look and Feel'' Graphical User
Interface. Open Look is the user-visible part of Open Windows.
There is a lot of competition in industry over graphical user
interface (GUI) systems. Some of the players are Sun with OpenLook
and the Open Software Foundation (OSF) with MOTIF.
What is Open Windows?
Open Windows is Sun Microsystems window system for the Sun
Workstation. Open Windows is based on the X/NeWS window server(s)
and includes many tools and utilities. Don't confuse
OpenWindows/OpenLook with Open Desktop from Santa Cruz Operation.
Open Windows is the underpinnings of OpenLook.
What is NeWS?
NeWS is 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 is 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. Because there are few ways to design a knee joint,
NeWS has 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 is not an
Adobe product, nor is it a Sun/Adobe joint venture.
NeWS had the potential to become a world-class window system had
not a coalition of computer vendors ganged together to endorse the
X window system from MIT, sending Sun into a frenzy to support both
X and NeWS in the same window server.
One respected engineer from DEC remarked they all feared Sun would
ignore the industry X coalition and go on to make NeWS a standard.
They were overjoyed when Sun reacted by taking on X and merging it
with NeWS, causing additional work which made it harder for Sun to
make progress with NeWS. Also it made X the de facto standard;
whether or not this is a good thing depends on who you talk to.
Sun management has signed a deal to adopt Display PostScript. Will
they put NeWS aside then?
And how does PostScript run on them?
PostScript runs (mostly) on NeWS. Due to lack of support from Sun
management, NeWS never made it as 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
the lack of support for Adobe Type 1 fonts, Sun having gone with
their own font format known as F3. Given the NeWS PostScript
interpreter was not even PostScript Level One compliant, the
chances of bringing NeWS to Level Two compliance was remote,
lending further to NeWS decline.
Subject: 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.
Subject: 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.app (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?
Subject: 9 Encapsulated PostScript
Subject: 9.1 What is Encapsulated PostScript?
An Encapsulated PostScript file (EPSF) 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).
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.
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.
What is EPSI?
EPSI is EPS. 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.
Subject: 9.2 How do I convert PostScript to EPS?
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):
%!Adobe-2.0 EPSF
%%Creator: name
%%CreationDate: date
%%Title: filename
%%BoundingBox: a b c d
Note: Make sure that the first line in the file is `` 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.
Encapsulated PostScript is 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.
Subject: 9.3 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.
Subject: 10 About The Comp.Lang.PostScript FAQ (and Usenet Guide to
PostScript)
Subject: 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.
The Usenet Guide to PostScript is a larger set of help and answers
to PostScript questions, plus a tutorial for new users. It is still
in the process of being created. There is one file ``Exactly What
Does a Transformation Matrix Do?'', that is definitely not part of
the FAQ. Please send more!
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.
Subject: 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.
Subject: 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!
Subject: 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.
Subject: 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).
Subject: 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.
Subject: 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?
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?
Subject: 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?
Subject: 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. How do I make a downloaded font (ie: PFA) persistent?
6. What questions should the FAQ have?
7. What book information is wrong or missing in the FAQ?
8. What program information is wrong or missing in the FAQ?
9. What ftp site have good examples of PostScript code?
Technical Details
Message-ID:
<1992Oct29.210214.25837@cs.brown.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!brunix!brunix!jgmShow Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript,news.answers Path: arc1-ca.pugleaf.net!sparky!uunet!brunix!brunix!jgm From: jgm@cs.brown.edu (Jonathan Monsarrat) Subject: PostScript monthly FAQ v2.0 10-29-92 [7-10 of 12] Message-ID: <1992Oct29.210214.25837@cs.brown.edu> Followup-To: poster Summary: Useful facts about the PostScript graphics programming language Sender: news@cs.brown.edu Reply-To: jgm@cs.brown.edu (PostScript FAQ comments address) Organization: Brown University Department of Computer Science Date: Thu, 29 Oct 1992 21:02:14 GMT Approved: news-answers-request@MIT.Edu Lines: 733