Rev 79226 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/grDevices/man/postscript.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2019 R Core Team% Distributed under GPL 2 or later\name{postscript}\alias{postscript}\alias{.ps.prolog}\concept{encoding}\title{PostScript Graphics}\description{\code{postscript} starts the graphics device driver for producingPostScript graphics.}%% The definitive doc is the source :-)%% ../../../main/devices.c & ../../../unix/devPS.c\usage{postscript(file = if(onefile) "Rplots.ps" else "Rplot\%03d.ps",onefile, family, title, fonts, encoding, bg, fg,width, height, horizontal, pointsize,paper, pagecentre, print.it, command,colormodel, useKerning, fillOddEven)}\arguments{\item{file}{a character string giving the file path. If it is\code{""}, the output is piped to the command given by the argument\code{command}.If it is of the form \code{"|cmd"}, the output is piped to thecommand given by \command{cmd}.For use with \code{onefile = FALSE} give a \code{printf} format suchas \code{"Rplot\%03d.ps"} (the default in that case). The stringshould not otherwise contain a \code{\%}: if it is really necessary,use \code{\%\%} in the string for \code{\%} in the file name.A single integer format matching the \link{regular expression}\code{"\%[#0 +=-]*[0-9.]*[diouxX]"} is allowed.Tilde expansion (see \code{\link{path.expand}}) is done. An input witha marked encoding is converted to the native encoding or an error isgiven.}\item{onefile}{logical: if true (the default) allow multiple figuresin one file. If false, generate a file name containing the pagenumber for each page and use an EPSF header and no\code{DocumentMedia} comment. Defaults to \code{TRUE}.}\item{family}{the initial font family to be used, normally as acharacter string. See the section \sQuote{Families}. Defaults to\code{"Helvetica"}.}\item{title}{title string to embed as the \code{Title} comment in thefile. Defaults to \code{"R Graphics Output"}.}\item{fonts}{a character vector specifying additional \R graphics fontfamily names for font families whose declarations will be includedin the PostScript file and are available for use with the device.See \sQuote{Families} below. Defaults to \code{NULL}.}\item{encoding}{the name of an encoding file. Defaults to\code{"default"}. The latter is interpreted\describe{\item{on Unix-alikes}{as \file{"ISOLatin1.enc"} unless the locale is recognized ascorresponding to a language using ISO 8859-\{2,5,7,13,15\} or KOI8-\{R,U\}.}\item{on Windows}{as \file{"CP1250.enc"} (Central European), \code{"CP1251.enc"} (Cyrillic),\code{"CP1253.enc"} (Greek) or \code{"CP1257.enc"} (Baltic) if oneof those codepages is in use, otherwise \file{"WinAnsi.enc"}(codepage 1252).}}The file is looked for in the \file{enc} directory of package\pkg{grDevices} if the path does not contain a path separator. Anextension \code{".enc"} can be omitted.}\item{bg}{the initial background color to be used. If\code{"transparent"} (or any other non-opaque colour), no backgroundis painted. Defaults to \code{"transparent"}.}\item{fg}{the initial foreground color to be used. Defaults to\code{"black"}.}\item{width, height}{the width and height of the graphics region ininches. Default to \code{0}.If \code{paper != "special"} and \code{width} or \code{height} is lessthan \code{0.1} or too large to give a total margin of 0.5 inch, thegraphics region is reset to the corresponding paper dimension minus 0.5.}\item{horizontal}{the orientation of the printed image, a logical.Defaults to true, that is landscape orientation on paper sizeswith width less than height.}\item{pointsize}{the default point size to be used. Strictlyspeaking, in bp, that is 1/72 of an inch, but approximately inpoints. Defaults to \code{12}.}\item{paper}{the size of paper in the printer. The choices are\code{"a4"}, \code{"letter"} (or \code{"us"}), \code{"legal"} and\code{"executive"} (and these can be capitalized).Also, \code{"special"} can be used, when arguments \code{width}and \code{height} specify the paper size. A further choice is\code{"default"} (the default): If this is selected, the papersizeis taken from the option \code{"papersize"} if that is set and to\code{"a4"} if it is unset or empty.}\item{pagecentre}{logical: should the device region be centred on thepage? Defaults to true.}\item{print.it}{logical: should the file be printed when the device isclosed? (This only applies if \code{file} is a real file name.)Defaults to false.}\item{command}{the command to be used for \sQuote{printing}. Defaultsto \code{"default"}, the value of option \code{"printcmd"}. Thelength limit is \code{2*PATH_MAX},typically 8096 bytes on Unix-alikes and 520 bytes on Windows.}\item{colormodel}{a character string describing the color model:currently allowed values as \code{"srgb"}, \code{"srgb+gray"},\code{"rgb"}, \code{"rgb-nogray"}, \code{"gray"} (or \code{"grey")} and\code{"cmyk"}. Defaults to \code{"srgb"}. See section\sQuote{Color models}.}\item{useKerning}{logical. Should kerning corrections be included insetting text and calculating string widths? Defaults to \code{TRUE}.}\item{fillOddEven}{logical controlling the polygon fill mode: see\code{\link{polygon}} for details. Default \code{FALSE}.}}\details{All arguments except \code{file} default to values given by\code{\link{ps.options}()}. The ultimate defaults are quoted in thearguments section.\code{postscript} opens the file \code{file} and the PostScriptcommands needed to plot any graphics requested are written to thatfile. This file can then be printed on a suitable device to obtainhard copy.The \code{file} argument is interpreted as a C integer format as usedby \code{\link{sprintf}}, with integer argument the page number.The default gives files \file{Rplot001.ps}, \dots, \file{Rplot999.ps},\file{Rplot1000.ps}, \dots.The postscript produced for a single \R plot is EPS (\emph{EncapsulatedPostScript}) compatible, and can be included into other documents,e.g., into LaTeX, using \code{\\includegraphics{<filename>}}. For usein this way you will probably want to use \code{\link{setEPS}()} toset the defaults as \code{horizontal = FALSE, onefile = FALSE, paper ="special"}. Note that the bounding box is for the \emph{device}region: if you find the white space around the plot region excessive,reduce the margins of the figure region via \code{\link{par}(mar = )}.Most of the PostScript prologue used is taken from the \R charactervector \code{.ps.prolog}. This is marked in the output, and can bechanged by changing that vector. (This is only advisable forPostScript experts: the standard version is in\code{namespace:grDevices}.)A PostScript device has a default family, which can be set by the uservia \code{family}. If other font families are to be used when drawingto the PostScript device, these must be declared when the device iscreated via \code{fonts}; the font family names for this argument are\R graphics font family names (see the documentation for\code{\link{postscriptFonts}}).Line widths as controlled by \code{par(lwd = )} are in multiples of1/96 inch: multiples less than 1 are allowed. \code{pch = "."} with\code{cex = 1} corresponds to a square of side 1/72 inch, which isalso the \sQuote{pixel} size assumed for graphics parameters such as\code{"cra"}.When the background colour is fully transparent (as is the initialdefault value), the PostScript produced does not paint thebackground. Almost all PostScript viewers will use a white canvas sothe visual effect is if the background were white. This will not bethe case when printing onto coloured paper, though.}\section{Families}{Font families are collections of fonts covering the five font faces,(conventionally plain, bold, italic, bold-italic and symbol) selectedby the graphics parameter \code{\link{par}(font = )} or the gridparameter \code{\link{gpar}(fontface = )}. Font families can bespecified either as an initial/default font family for the devicevia the \code{family} argument or after the device is opened bythe graphics parameter \code{\link{par}(family = )} or the gridparameter \code{\link{gpar}(fontfamily = )}. Families which will beused in addition to the initial family must be specified in the\code{fonts} argument when the device is opened.Font families are declared via a call to \code{\link{postscriptFonts}}.The argument \code{family} specifies the initial/default font familyto be used. In normal use it is one of \code{"AvantGarde"},\code{"Bookman"}, \code{"Courier"}, \code{"Helvetica"},\code{"Helvetica-Narrow"}, \code{"NewCenturySchoolbook"},\code{"Palatino"} or \code{"Times"}, and refers to the standard AdobePostScript fonts families of those names which are included (orcloned) in all common PostScript devices.Many PostScript emulators (including those based on\code{ghostscript}) use the URW equivalents of these fonts, which are\code{"URWGothic"}, \code{"URWBookman"}, \code{"NimbusMon"},\code{"NimbusSan"}, \code{"NimbusSanCond"}, \code{"CenturySch"},\code{"URWPalladio"} and \code{"NimbusRom"} respectively. If yourPostScript device is using URW fonts, you will obtain access to morecharacters and more appropriate metrics by using these names. To makethese easier to remember, \code{"URWHelvetica" == "NimbusSan"} and\code{"URWTimes" == "NimbusRom"} are also supported.Another type of family makes use of CID-keyed fonts for East Asianlanguages -- see \code{\link{postscriptFonts}}.The \code{family} argument is normally a character string naming afont family, but family objects generated by \code{\link{Type1Font}}and \code{\link{CIDFont}} are also accepted. For compatibility withearlier versions of \R, the initial family can also be specified as avector of four or five afm files.Note that \R does not embed the font(s) used in the PostScript output:see \code{\link{embedFonts}} for a utility to help do so.Viewers and embedding applications frequently substitute fonts forthose specified in the family, and the substitute will often haveslightly different font metrics. \code{useKerning = TRUE} spaces theletters in the string using kerning corrections for the intendedfamily: this may look uglier than \code{useKerning = FALSE}.}\section{Encodings}{Encodings describe which glyphs are used to display the character codes(in the range 0--255). Most commonly \R uses ISOLatin1 encoding, andthe examples for \code{\link{text}} are in that encoding. However,the encoding used on machines running \R may well be different, and byusing the \code{encoding} argument the glyphs can be matched toencoding in use. This suffices for European and Cyrillic languages,but not for East Asian languages. For the latter, composite CID fonts areused. These fonts are useful for other languages: for example theymay contain Greek glyphs. (The rest of this section applies only when CIDfonts are not used.)None of this will matter if only ASCII characters (codes 32--126) areused as all the encodings (except \code{"TeXtext"}) agree over thatrange. Some encodings are supersets of ISOLatin1, too. However, ifaccented and special characters do not come out as you expect, you mayneed to change the encoding. Some other encodings are supplied with\R: \code{"WinAnsi.enc"} and \code{"MacRoman.enc"} correspond to theencodings normally used on Windows and Classic Mac OS (at least byAdobe), and \code{"PDFDoc.enc"} is the first 256 characters of theUnicode encoding, the standard for PDF. There are also encodings\code{"ISOLatin2.enc"}, \code{"CP1250.enc"}, \code{"ISOLatin7.enc"}(ISO 8859-13), \code{"CP1257.enc"}, and \code{"ISOLatin9.enc"} (ISO8859-15), \code{"Cyrillic.enc"} (ISO 8859-5), \code{"KOI8-R.enc"},\code{"KOI8-U.enc"}, \code{"CP1251.enc"}, \code{"Greek.enc"} (ISO8859-7) and \code{"CP1253.enc"}. Note that many glyphs in theseencodings are not in the fonts corresponding to the standard families.(The Adobe ones for all but Courier, Helvetica and Times cover littlemore than Latin-1, whereas the URW ones also cover Latin-2, Latin-7,Latin-9 and Cyrillic but no Greek. The Adobe exceptions cover theLatin character sets, but not the Euro.)If you specify the encoding, it is your responsibility to ensure thatthe PostScript font contains the glyphs used. One issue here is the Eurosymbol which is in the WinAnsi and MacRoman encodings but may well notbe in the PostScript fonts. (It is in the URW variants; it is not inthe supplied Adobe Font Metric files.)There is an exception. Character 45 (\code{"-"}) is always setas minus (its value in Adobe ISOLatin1) even though it is hyphen inthe other encodings. Hyphen is available as character 173 (octal0255) in all the Latin encodings, Cyrillic and Greek. (This can beentered as \code{"\uad"} in a UTF-8 locale.) There are somediscrepancies in accounts of glyphs 39 and 96: the supplied encodings(except CP1250 and CP1251) treat these as \sQuote{quoteright} and\sQuote{quoteleft} (rather than \sQuote{quotesingle}/\sQuote{acute}and \sQuote{grave} respectively), as they are in the Adobedocumentation.}\section{TeX fonts}{TeX has traditionally made use of fonts such as Computer Modern whichare encoded rather differently, in a 7-bit encoding. This encodingcan be specified by \code{encoding = "TeXtext.enc"}, taking care thatthe ASCII characters \code{< > \\ _ \{ \}} are not available in thosefonts.There are supplied families \code{"ComputerModern"} and\code{"ComputerModernItalic"} which use this encoding, and which areonly supported for \code{postscript} (and not \code{pdf}). They areintended to use with the Type 1 versions of the TeX CM fonts. It willnormally be possible to include such output in TeX or LaTeX providedit is processed with \code{dvips -Ppfb -j0} or the equivalent on yoursystem. (\code{-j0} turns off font subsetting.) When \code{family ="ComputerModern"} is used, the italic/bold-italic fonts used areslanted fonts (\code{cmsl10} and \code{cmbxsl10}). To use text italicfonts instead, set \code{family = "ComputerModernItalic"}.These families use the TeX math italic and symbol fonts for acomprehensive but incomplete coverage of the glyphs covered by theAdobe symbol font in other families. This is achieved byspecial-casing the postscript code generated from the supplied\file{CM_symbol_10.afm}.}\section{Color models}{The default color model (\code{"srgb"}) is sRGB.The alternative \code{"srgb+gray"} uses sRGB for colors, but with puregray colors (including black and white) expressed as greyscales (whichresults in smaller files and can be advantageous with some printerdrivers). Conversely, its files can be rendered much slower on someviewers, and there can be a noticeable discontinuity in colorgradients involving gray or white.Other possibilities are \code{"gray"} (or \code{"grey"}) which usedonly greyscales (and converts other colours to a luminance), and\code{"cmyk"}. The simplest possible conversion from sRGB to CMYK isused(\url{https://en.wikipedia.org/wiki/CMYK_color_model#Mapping_RGB_to_CMYK}),and raster images are output in RGB.Color models provided for backwards compatibility are \code{"rgb"}(which is RGB+gray) and \code{"rgb-nogray"} which use uncalibrated RGB(as used in \R prior to 2.13.0). These result in slightly smallerfiles which may render faster, but do rely on the viewer beingproperly calibrated.}\section{Printing}{A postscript plot can be printed via \code{postscript} in two ways.\enumerate{\item Setting \code{print.it = TRUE} causes the command given inargument \code{command} to be called with argument \code{"file"}when the device is closed. Note that the plot file is not deletedunless \code{command} arranges to delete it.\item \code{file = ""} or \code{file = "|cmd"} can be used to printusing a pipe. Failure to open the command will probably be reportedto the terminal but not to \R, in which case close thedevice by \code{dev.off} immediately.}On Windows the default\code{"printcmd"} is empty and will give an error if\code{print.it = TRUE} is used. Suitable commands to spool a PostScriptfile to a printer can be found in \file{RedMon} suite available from\url{http://pages.cs.wisc.edu/~ghost/index.html}. The command will berun in a minimized window. GSView 4.x provides \file{gsprint.exe}which may be more convenient (it requires Ghostscript version 6.50or later).}\section{Conventions}{This section describes the implementation of the conventions forgraphics devices set out in the \sQuote{R Internals} manual.\itemize{\item The default device size is 7 inches square.\item Font sizes are in big points.\item The default font family is Helvetica.\item Line widths are as a multiple of 1/96 inch, with a minimumof 0.01 enforced.\item Circle of any radius are allowed.\item Colours are by default specified as sRGB.}At very small line widths, the line type may be forced to solid.Raster images are currently limited to opaque colours.}\note{If you see problems with postscript output, do remember that theproblem is much more likely to be in your viewer than in \R. Tryanother viewer if possible. Symptoms for which the viewer has been atfault are apparent grids on image plots (turn off graphicsanti-aliasing in your viewer if you can) and missing or incorrect glyphsin text (viewers silently doing font substitution).Unfortunately the default viewers on most Linux and macOS systemshave these problems, and no obvious way to turn off graphics anti-aliasing.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth & Brooks/Cole.}\seealso{\code{\link{postscriptFonts}},\code{\link{Devices}},and \code{\link{check.options}} which is called from both\code{\link{ps.options}} and \code{postscript}.\code{\link{cairo_ps}} for another device that can produce PostScript.More details of font families and encodings and especially handlingtext in a non-Latin-1 encoding and embedding fonts can be found inPaul Murrell and Brian Ripley (2006).\dQuote{Non-standard fonts in PostScript and PDF graphics.}\emph{R News}, \bold{6}(2), 41--47.\url{https://www.r-project.org/doc/Rnews/Rnews_2006-2.pdf}.}\author{Support for Computer Modern fonts is based on a contribution byBrian D'Urso \email{durso@hussle.harvard.edu}.}\examples{require(graphics)\dontrun{# open the file "foo.ps" for graphics outputpostscript("foo.ps")# produce the desired graph(s)dev.off() # turn off the postscript device## On Unix-alikes only:postscript("|lp -dlw")# produce the desired graph(s)dev.off() # plot will appear on printer## On Windows:options(printcmd = 'redpr -P"\\\\printhost\\lw"')postscript(file = tempfile("Rps."), print.it = TRUE)# produce the desired graph(s)dev.off() # send plot file to the printer## alternative using GSView 4.x :options(printcmd = '/GhostGum/gsview/gsprint -query')# for URW PostScript devicespostscript("foo.ps", family = "NimbusSan")## for inclusion in Computer Modern TeX documents, perhapspostscript("cm_test.eps", width = 4.0, height = 3.0,horizontal = FALSE, onefile = FALSE, paper = "special",family = "ComputerModern", encoding = "TeXtext.enc")## The resultant postscript file can be used by dvips -Ppfb -j0.## To test out encodings, you can useTestChars <- function(encoding = "ISOLatin1", family = "URWHelvetica"){postscript(encoding = encoding, family = family)par(pty = "s")plot(c(-1,16), c(-1,16), type = "n", xlab = "", ylab = "",xaxs = "i", yaxs = "i")title(paste("Centred chars in encoding", encoding))grid(17, 17, lty = 1)for(i in c(32:255)) {x <- i \%\% 16y <- i \%/\% 16points(x, y, pch = i)}dev.off()}## there will be many warnings. We use URW to get a complete enough## set of font metrics.TestChars()TestChars("ISOLatin2")TestChars("WinAnsi")}\dontshow{xx <- seq(0, 7, length = 701)yy <- sin(xx)/xx; yy[1] <- 1plot(xx,yy) # produce the desired graph(s)}}\keyword{device}