latter uses sophisticated techniques, such as font hinting to make things look nice, especially
at small font sizes. There may also be problems with this approach if the font does not permit
copying or modifying the font outlines.
The other approach to importing text from a PostScript ﬁle is to completely ignore the font
that is being used and just import the actual character values from the ﬁle. The charpath
argument to the PostScriptTrace() function is used to trigger this option. When drawing
the resulting text, grImport attempts to get the size of the text roughly the same as the
original, but diﬀerences in fonts will mean that the location and size of text will not be
identical. The following code imports just the text from the ﬁle hello.ps and the resulting
image is approximately the right size, but uses a completely diﬀerent font (see the text on
the right of Figure13).
charpath = FALSE)
R> hellotext <- readPicture("hellotext.xml")
The vignette “Importing Text” provides more details about importing text, including some
other options for ﬁne-tuning the size and placement of imported text.
One problem that can completely stymie attempts to import text from a PostScript ﬁle is
that some font outlines are“protected”by the font creator, which means that the font outline
cannot be converted to ﬂattened paths, so they will resist grImport’s attempts to extract
As mentioned back in Section 1.2, PostScript is really a meta format rather than just a
vector graphics format, which means that a PostScript ﬁle can contain raster elements as
well as shapes and text. Currently, grImport will completely ignore any raster elements in a
3.4. Graphical parameters
The description of an image in a PostScript ﬁle consists of a description of shapes, or paths,
plus a description of whether to stroke or ﬁll each path, plus a description of what colors and
line styles to use when ﬁlling or stroking each path. This section addresses the last part: how
does grImport handle importing graphical parameters such as colors and line styles?
Whenever a path is converted from PostScript to RGML, in addition to recording the set of
locations that describe the path, PostScriptTrace() records the color, as an RGB triplet,
and the line width that are used to stroke or ﬁll the path. A minor detail is that the line
width is scaled up by a factor of 4/3 because a line width of 1 corresponds to 1/72 inches in
PostScript, but a line width of 1 corresponds to roughly 1/96 inches on R graphics devices.
By default, the colors and line widths that are recorded in the RGML ﬁle are used when draw-
ing the image in R. This was vividly demonstrated on page15 with the tiger image. However,