The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27442 ripley 1
\name{postscript}
2
\alias{postscript}
3
\alias{ps.options}
27526 ripley 4
%\alias{.PostScript.Options}
27442 ripley 5
\alias{.ps.prolog}
27943 ripley 6
\concept{encoding}
27442 ripley 7
\title{PostScript Graphics}
8
\description{
9
  \code{postscript} starts the graphics device driver for producing
10
  PostScript graphics.
11
 
12
  The auxiliary function \code{ps.options} can be used to set and view
13
  (if called without arguments) default values for the arguments to
14
  \code{postscript}.
15
}
16
\synopsis{
17
postscript(file = ifelse(onefile, "Rplots.ps", "Rplot\%03d.ps"),
18
           onefile = TRUE, family, title = "R Graphics Output", \dots)
19
ps.options(\dots, reset = FALSE, override.check = FALSE)
20
}
21
%% The definitive doc is the source :-)
22
%% 	../../../main/devices.c  &   ../../../unix/devPS.c
23
\usage{
24
postscript(file = ifelse(onefile, "Rplots.ps", "Rplot\%03d.ps"),
25
           onefile = TRUE,
26
           paper, family, encoding, bg, fg,
27
           width, height, horizontal, pointsize,
28
           pagecentre, print.it, command, title = "R Graphics Output")
29
 
30
% paper, horizontal, width, height, family, pointsize, bg, fg)
31
ps.options(paper, horizontal, width, height, family, encoding,
32
           pointsize, bg, fg,
33
           onefile = TRUE, print.it = FALSE, append = FALSE,
34
           reset = FALSE, override.check = FALSE)
35
}
36
\arguments{
37
  \item{file}{a character string giving the name of the file.  If it is
38
    \code{""}, the output is piped to the command given by
39
    the argument \code{command}.
40
#ifdef unix
41
    If it is \code{"|cmd"}, the output is piped to the command given
42
    by \file{cmd}.
43
#endif
44
 
45
    For use with \code{onefile=FALSE} give a \code{printf} format such
46
    as \code{"Rplot\%03d.ps"} (the default in that case).
47
  }
48
%  \item{\dots}{further options for \code{postscript()}.}
49
  \item{paper}{the size of paper in the printer.  The choices are
50
    \code{"a4"}, \code{"letter"}, \code{"legal"} and
51
    \code{"executive"} (and these can be capitalized).
52
    Also, \code{"special"} can be used, when the \code{width}
53
    and \code{height} specify the paper size.  A further choice is
54
    \code{"default"}, which is the default.  If this is selected, the
55
    papersize is taken from the option \code{"papersize"}
56
    if that is set and to \code{"a4"} if it is unset or empty.}
57
  \item{horizontal}{the orientation of the printed image, a
58
    logical. Defaults to true, that is landscape orientation on paper
59
    sizes with width less than height.}
60
  \item{width, height}{the width and height of the graphics region in
61
    inches.  The default is to use the entire page less a 0.25 inch
62
    border on each side.}
63
  \item{family}{the font family to be used.  EITHER a single character
64
    string OR a character vector of length
65
    four or five.  See the section \sQuote{Families}.}
66
  \item{encoding}{the name of an encoding file. Defaults to
67
#ifdef unix
68
"ISOLatin1.enc"
69
#endif
70
#ifdef windows
71
"WinAnsi.enc"
72
#endif
73
    in the \file{R\_HOME/afm} directory, which is used
74
    if the path does not contain a path separator.  An extension
75
    \code{".enc"} can be omitted.}
76
  \item{pointsize}{the default point size to be used.}
77
  \item{bg}{the default background color to be used.
78
    If \code{"transparent"} (or an equivalent specification), no
79
    background is painted.}
80
  \item{fg}{the default foreground color to be used.}
81
  \item{onefile}{logical: if true (the default) allow multiple figures
82
    in one file.  If false, generate a file name containing the page
83
    number and use an EPSF header and no \code{DocumentMedia} comment.}
84
  \item{pagecentre}{logical: should the device region be centred on the
85
    page: defaults to true.}
86
  \item{print.it}{logical: should the file be printed when the device is
87
    closed?  (This only applies if \code{file} is a real file name.)}
88
  \item{command}{the command to be used for \dQuote{printing}.  Defaults to
89
    option \code{"printcmd"}; this can also be selected as
90
    \code{"default"}.}
91
  \item{append}{logical; currently \bold{disregarded}; just there for
92
    compatibility reasons.}
93
  \item{reset, override.check}{logical arguments passed to
94
    \code{\link{check.options}}.  See the Examples.}
95
  \item{title}{title string to embed in the file.}
96
}
97
\details{
98
  \code{postscript} opens the file \code{file} and the PostScript
99
  commands needed to plot any graphics requested are stored in that
100
  file.  This file can then be printed on a suitable device to obtain
101
  hard copy.
102
 
103
  A postscript plot can be printed via \code{postscript} in two ways.
104
  \enumerate{
105
    \item Setting \code{print.it = TRUE} causes the command given in
106
    argument \code{command} to be called with argument \code{"file"}
107
    when the device is closed.
108
    Note that the plot file is not deleted unless \code{command} arranges to
109
    delete it.
110
 
111
    \item \code{file=""} or \code{file="|cmd"} can be used to print
112
    using a pipe on systems that support \file{popen}.  Failure to open the
113
    command will probably be reported to the terminal but not to
114
    \file{popen}, in which case close the device by \code{dev.off}
115
    immediately.
116
  }
117
#ifdef windows
118
  Only the first of these will work on Windows, and the default
119
  \code{"printcmd"} is empty and will give an error if \code{print.it=TRUE}
120
  is used.  Suitable commands to spool a PostScript file to a printer
121
  can be found in \file{RedMon} suite available from
122
  \url{http://www.cs.wisc.edu/~ghost/index.html}.  The command will be run
123
  in a minimized window.   GSView 4.x provides
124
  \file{gsprint.exe} which may be even more convenient (it requires
125
  GhostScript version 6.0 or later).
126
#endif
127
 
128
  The postscript produced by \R is EPS (\emph{Encapsulated PostScript})
129
  compatible, and can be included into other documents, e.g., into
130
  LaTeX, using \code{\includegraphics{<filename>}}.  For use in this way
131
  you will probably want to set \code{horizontal = FALSE, onefile = FALSE,
132
    paper = "special"}.
133
 
134
  Most of the PostScript prologue used is taken from the \R character
135
  vector \code{.ps.prolog}.  This is marked in the output, and can be
136
  changed by changing that vector.  (This is only advisable for
27536 ripley 137
  PostScript experts: the standard version is in
138
  \code{namespace:graphics}.)
27442 ripley 139
 
140
  \code{ps.options} needs to be called before calling \code{postscript},
141
  and the default values it sets can be overridden by supplying
142
  arguments to \code{postscript}.
143
}
144
 
145
\section{Families}{
146
  The argument \code{family} specifies the font family to be used.
147
  In normal use it is one of \code{"AvantGarde"},
148
  \code{"Bookman"}, \code{"Courier"}, \code{"Helvetica"},
149
  \code{"Helvetica-Narrow"}, \code{"NewCenturySchoolbook"},
150
  \code{"Palatino"} or \code{"Times"}, and refers to the standard
151
  Adobe PostScript fonts of those names which are included (or cloned)
152
  in all common PostScript devices.
153
 
154
  Many PostScript emulators (including those based on
155
  \code{ghostscript}) use the URW equivalents of these fonts, which are
156
  \code{"URWGothic"}, \code{"URWBookman"}, \code{"NimbusMon"},
157
  \code{"NimbusSan"}, \code{"NimbusSanCond"}, \code{"CenturySch"},
158
  \code{"URWPalladio"} and \code{"NimbusRom"} respectively.  If your
159
  PostScript device is using URW fonts, you will obtain access to more
27625 ripley 160
  characters and more appropriate metrics by using these names.  To make
27442 ripley 161
  these easier to remember, \code{"URWHelvetica" == "NimbusSan"} and
162
  \code{"URWTimes" == "NimbusRom"} are also supported.
163
 
164
  It is also possible to specify \code{family="ComputerModern"}. This
165
  is intended to use with the Type 1 versions of the TeX CM fonts.  It
166
  will normally be possible to include such output in TeX or LaTeX
167
  provided it is processed with \code{dvips -Ppfb -j0} or the equivalent
168
  on your system. (\code{-j0} turns off font subsetting.)
169
 
170
  If the second form of argument \code{"family"} is used, it should be a
171
  character vector of four or five paths to Adobe Font Metric files for
172
  the regular, bold, italic, bold italic and (optionally) symbol fonts to
173
  be used.  If these paths do not contain the file separator, they are
174
  taken to refer to files in the \R directory \file{R\_HOME/afm}.  Thus the
175
  default Helvetica family can be specified by \code{family =
176
    c("hv______.afm",
177
    "hvb_____.afm", "hvo_____.afm", "hvbo____.afm", "sy______.afm")}.
178
  It is the user's responsibility to check that suitable fonts are made
179
  available, and that they contain the needed characters when
180
  re-encoded.  The fontnames used are taken from the \code{FontName}
181
  fields of the afm files.  The software including the PostScript plot
182
  file should either embed the font outlines (usually from \file{.pfb}
183
  or \file{.pfa} files) or use DSC comments to instruct the print
184
  spooler to do so.
185
}
186
 
187
\section{Encodings}{
188
  Encodings describe which glyphs are used to display the character codes
189
  (in the range 0--255).  By default \R uses ISOLatin1 encoding, and
190
  the examples for \code{\link{text}} are in that encoding.  However,
191
  the encoding used on machines running \R may well be different, and by
192
  using the \code{encoding} argument the glyphs can be matched to
193
  encoding in use.
194
 
195
  None of this will matter if only ASCII characters (codes 32--126) are
196
  used as all the encodings agree over that range.  Some encodings are
197
  supersets of ISOLatin1, too.  However, if accented and special
198
  characters do not come out as you expect, you may need to change the
199
  encoding.  Three other encodings are supplied with \R:
200
  \code{"WinAnsi.enc"} and \code{"MacRoman.enc"} correspond to the
201
  encodings normally used on Windows and MacOS (at least by Adobe), and
202
  \code{"PDFDoc.enc"} is the first 256 characters of the Unicode
203
  encoding, the standard for PDF.
204
 
205
  If you change the encoding, it is your responsibility to ensure that
206
  the PostScript font contains the glyphs used.  One issue here is the Euro
207
  symbol which is in the WinAnsi and MacRoman encodings but may well not
208
  be in the PostScript fonts.  (It is in the URW variants; it is not in
209
  the supplied Adobe Font Metric files.)
210
 
211
  There is one exception.  Character 45 (\code{"-"}) is always set
212
  as minus (its value in Adobe ISOLatin1) even though it is hyphen in
213
  the other encodings.  Hyphen is available as character 173 (octal
214
  0255) in ISOLatin1.
215
}
216
\references{
217
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
218
  \emph{The New S Language}.
219
  Wadsworth \& Brooks/Cole.
220
}
221
\seealso{
222
  \code{\link{Devices}},
223
  {\code{\link{check.options}} which is called from both
224
    \code{ps.options} and \code{postscript}}.
225
}
226
\author{
227
  Support for Computer Modern fonts is based on a contribution by
228
  Brian D'Urso \email{durso@hussle.harvard.edu}.
229
}
230
\examples{
231
\dontrun{
232
# open the file "foo.ps" for graphics output
233
postscript("foo.ps")
234
# produce the desired graph(s)
235
dev.off()              # turn off the postscript device
236
#ifdef unix
237
postscript("|lp -dlw")
238
# produce the desired graph(s)
239
dev.off()              # plot will appear on printer
240
#endif
241
#ifdef windows
242
options(printcmd='redpr -P"\\\\markov\\lw"')
243
postscript(file=tempfile("Rps."), print.it=TRUE)
244
# produce the desired graph(s)
245
dev.off()              # send plot file to the printer
246
#endif
247
 
248
# for URW PostScript devices
249
postscript("foo.ps", family = "NimbusSan")
250
 
251
## for inclusion in Computer Modern TeX documents, perhaps
252
postscript("cm_test.eps", width = 4.0, height = 3.0,
253
           horizontal = FALSE, onefile = FALSE, paper = "special",
254
           family = "ComputerModern")
255
## The resultant postscript file can be used by dvips -Ppfb -j0.
256
 
257
## To test out encodings, you can use
258
TestChars <- function(encoding="ISOLatin1", family="URWHelvetica")
259
{
260
    postscript(encoding=encoding, family=family)
261
    par(pty="s")
262
    plot(c(0,15), c(0,15), type="n", xlab="", ylab="")
263
    title(paste("Centred chars in encoding", encoding))
264
    grid(15, 15, lty=1)
265
    for(i in c(32:255)) {
266
	x <- i %% 16
267
	y <- i %/% 16
268
	points(x, y, pch=i)
269
    }
270
    dev.off()
271
}
272
## there will be many warnings. We use URW to get a complete enough
273
## set of font metrics.
274
TestChars()
275
TestChars("ISOLatin2")
276
TestChars("WinAnsi")
277
}
278
\dontshow{
279
xx <- seq(0, 7, length=701)
280
yy <- sin(xx)/xx; yy[1] <- 1
281
plot(xx,yy)                     # produce the desired graph(s)
282
}
283
 
284
ps.options(bg = "pink")
27713 ripley 285
utils::str(ps.options(reset = TRUE))
27442 ripley 286
 
287
### ---- error checking of arguments: ----
288
ps.options(width=0:12, onefile=0, bg=pi)
289
# override the check for 'onefile', but not the others:
27713 ripley 290
utils::str(ps.options(width=0:12, onefile=1, bg=pi,
291
                      override.check = c(FALSE,TRUE,FALSE)))
27442 ripley 292
}
293
\keyword{device}