Title: | Importing 'SVG' Graphics |
---|---|
Description: | Functions for importing external vector images and drawing them as part of 'R' plots. This package is different from the 'grImport' package because, where that package imports 'PostScript' format images, this package imports 'SVG' format images. Furthermore, this package imports a specific subset of 'SVG', so external images must be preprocessed using a package like 'rsvg' to produce 'SVG' that this package can import. 'SVG' features that are not supported by 'R' graphics, e.g., gradient fills, can be imported and then exported via the 'gridSVG' package. |
Authors: | Simon Potter [aut], Paul Murrell [aut, cre] |
Maintainer: | Paul Murrell <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.3-3 |
Built: | 2024-12-22 04:32:51 UTC |
Source: | https://github.com/r-forge/grimport |
Transforms a "Picture"
object (or indeed "PictureContent"
objects) using a 3x3 transformation matrix.
applyTransform(object, tm)
applyTransform(object, tm)
object |
Either a |
tm |
A 3x3 numeric transformation matrix. |
The transformed object.
Simon Potter
gpar
object Transform a grid gpar
object.
signature(object = "gpar", tm = "matrix")
Transforms the
"lwd"
and "lty"
components of a gpar
object
(if present) by a 3x3 transformation matrix and returns the
modified gpar object.
Simon Potter
These function take a "Picture"
object and either draw the
picture or create a grid graphical object representing the picture.
pictureGrob(picture, x = unit(0.5, "npc"), y = unit(0.5, "npc"), width = NULL, height = NULL, just = "centre", hjust = NULL, vjust = NULL, default.units = "npc", expansion = 0.05, xscale = NULL, yscale = NULL, distort = FALSE, gpFUN = identity, ..., ext = c("none", "clipbbox", "gridSVG"), delayContent = match.arg(ext) == "gridSVG", name = NULL, prefix = NULL, clip = "on") grid.picture(...)
pictureGrob(picture, x = unit(0.5, "npc"), y = unit(0.5, "npc"), width = NULL, height = NULL, just = "centre", hjust = NULL, vjust = NULL, default.units = "npc", expansion = 0.05, xscale = NULL, yscale = NULL, distort = FALSE, gpFUN = identity, ..., ext = c("none", "clipbbox", "gridSVG"), delayContent = match.arg(ext) == "gridSVG", name = NULL, prefix = NULL, clip = "on") grid.picture(...)
picture |
A |
x |
A single numeric value or unit object specifying an x-value. |
y |
A single numeric value or unit object specifying a y-value. |
width |
A single numeric value or unit object specifying a width.
May also be |
height |
A single numeric value or unit object specifying a height.
May also be |
just |
The justification of the picture relative to its (x, y) location.
If there are two values, the first value specifes horizontal
justification and the second value specifies vertical justification.
Possible string values are: |
hjust |
A numeric vector specifying horizontal justification. If specified,
overrides the |
vjust |
A numeric vector specifying vertical justification. If specified,
overrides the |
default.units |
A string indicating the default units to use if |
expansion |
An expansion factor; determines whether any space is left between the extent of the picture and the bounding rectangle it is drawn within. |
xscale |
A numeric vector of length two indicating the minimum and maximum on the x-scale. |
yscale |
A numeric vector of length two indicating the minimum and maximum on the y-scale. |
distort |
A logical value indicating whether the image should preserve its aspect ratio or distort to fit the area it is being drawn within. |
gpFUN |
A function that takes in a grid |
... |
For |
ext |
A character vector. Selects from one of three possible extensions
for drawing imported pictures. |
delayContent |
If |
name |
A character identifier. |
prefix |
A character string. A prefix to add to referenced gridSVG content
(e.g. pattern fills). Only used when |
clip |
Clipping setting passed to the viewport that is set up for drawing the imported image. |
If width
or height
is NULL
, and
distort=FALSE
,
the aspect ratio of the image will be respected.
By default, the image will match the width/height of the current viewport,
(if distort=FALSE
, as much as the aspect ratio allows),
less any expansion
.
A grid gTree.
Simon Potter
These functions take a "Picture"
object and either draw the
picture at several locations or create a grid graphical object
representing the picture (drawn at several locations).
symbolsGrob(picture, x = stats::runif(10), y = stats::runif(10), size = unit(1, "char"), default.units = "native", gpFUN = identity, ext = c("none", "clipbbox", "gridSVG"), prefix = NULL, ..., name = NULL) grid.symbols(...)
symbolsGrob(picture, x = stats::runif(10), y = stats::runif(10), size = unit(1, "char"), default.units = "native", gpFUN = identity, ext = c("none", "clipbbox", "gridSVG"), prefix = NULL, ..., name = NULL) grid.symbols(...)
picture |
A |
x |
A numeric vector or unit object specifying x-locations. |
y |
A numeric vector or unit object specifying y-locations. |
size |
A numeric vector or unit object specifying symbol sizes. |
default.units |
A string indicating the default units to use if |
gpFUN |
A function that takes a grid |
ext |
A character vector. Selects from one of three possible extensions
for drawing imported pictures. |
prefix |
A character string. A prefix to add to referenced gridSVG content
(e.g. pattern fills). Only used when |
... |
For |
name |
A character identifier. |
A grid grob.
Simon Potter
Converts "Picture"
objects and pieces of a picture
(i.e. objects inheriting from "PictureContent"
objects) into
grid grobs.
grobify(object, ...)
grobify(object, ...)
object |
An object that contains |
... |
Further arguments to specific |
Although not required by some grobify methods, there are further arguments that may be used, which will be described here.
defs
This argument should take a "PictureDefinitions"
object
that contains definitions of referenced content. This is only useful
when the gridSVG
is set to TRUE
.
clip
This argument is supplied in the form of a character vector. It
usually only applies when grobifying a "PictureGroup"
object. There are three possible values for clip
:
none
No clipping will be applied to the object.
bbox
The clipping will be applied to the rectangular region that
bounds the clipping path's content. This argument is
particularly useful as R graphics can only use rectangular
clipping regions. If we want more complex clipping regions,
the value of gridSVG
must be used instead.
gridSVG
When this value is set, we are no longer restricted to clipping to rectangular regions, and many images will require it to be set to display correctly. This argument requires the gridSVG package to be installed.
gridSVG
This is a logical value that, when TRUE
, allows graphical
features to be drawn that are not possible in R graphics. This
requires the gridSVG package. When this argument is TRUE
we can correctly import and render patterns, masks, filters and
gradients.
A grid grob.
Simon Potter
These functions are convenience constructors for path segment objects
of classes "PathMoveTo"
, "PathLineTo"
,
"PathCurveTo"
and "PathClosePath"
.
moveTo(x, y) lineTo(x, y) curveTo(x, y) closePath(x, y)
moveTo(x, y) lineTo(x, y) curveTo(x, y) closePath(x, y)
x |
A numeric vector representing x-locations. |
y |
A numeric vector representing y-locations. |
For x
and y
, they should each be of length one so that
they represent a single point location except in the case of
curveTo
. In the case of curveTo
, it expects x
and
y
vectors of length four, which represent control points in a
cubic bezier curve.
For moveTo
, an object of class "PathMoveTo"
.
For lineTo
, an object of class "PathLineTo"
.
For curveTo
, an object of class "PathCurveTo"
.
For closePath
, an object of class "PathClosePath"
.
Simon Potter
"PathClosePath"
A description of a path close path operator ("Z"
in SVG
parlance) that is meant to be used as part of a path.
x
:Object of class "numeric"
. The x-location that the path is
going to close to.
y
:Object of class "numeric"
. The y-location that the path is
going to close to.
Class PathSegment
, directly.
Simon Potter
PathData
, PathMoveTo
,
PathLineTo
, PathCurveTo
.
"PathCurveTo"
A description of a path curve to operator ("C"
in SVG parlance)
that is meant to be used as part of a path.
x
:Object of class "numeric"
. A vector of length four that
represent the x-locations of the control points of a cubic bezier
curve.
y
:Object of class "numeric"
. A vector of length four that
represent the y-locations of the control points of a cubic bezier
curve.
Class PathSegment
, directly.
Simon Potter
PathData
, PathMoveTo
,
PathLineTo
, PathClosePath
.
"PathData"
An object that represents a sequence of path data segments in an SVG path.
segments
:Object of class "list"
~~
signature(object = "PathData", tm =
"matrix")
: A transformation matrix to apply to all path
segments in the path that object
contains. Returns a new
"PathData"
object with each path segment transformed to
their new locations.
Simon Potter
PathData
, PathMoveTo
,
PathLineTo
, PathCurveTo
.
"PathLineTo"
A description of a path line to operator ("L"
in SVG parlance)
that is meant to be used as part of a path.
x
:Object of class "numeric"
. The x-location that the path is
going to draw a line to.
y
:Object of class "numeric"
. The y-location that the path is
going to draw a line to.
Class PathSegment
, directly.
Simon Potter
PathData
, PathMoveTo
,
PathClosePath
, PathCurveTo
.
"PathMoveTo"
A description of a path move to operator ("M"
in SVG parlance)
that is meant to be used as part of a path.
x
:Object of class "numeric"
. The x-location that the path is
going to move to.
y
:Object of class "numeric"
. The y-location that the path is
going to move to.
Class PathSegment
, directly.
Simon Potter
PathData
, PathClosePath
,
PathLineTo
, PathCurveTo
.
"PathSegment"
A segment of a path that is not intended to be used directly, merely as a convenience base class for path segment operators.
x
:Object of class "numeric"
. An x-location.
y
:Object of class "numeric"
. A y-location.
signature(object = "PathSegment", tm =
"matrix")
: When given a 3x3 numeric transformation matrix, the
points in the segment are transformed, and produce a new object
representing a path segment. Not intended to be used directly on
path segments, but objects that inherit from path segments
(e.g. the "M"
, "L"
, "C"
, and "Z"
operators.
Simon Potter
PathMoveTo
, PathClosePath
,
PathLineTo
, PathCurveTo
.
A collection of paths, polylines, rectangles and other graphical content and features that together describe a picture.
Objects can be created by calls of the form new("Picture",
...)
.
content
:A list of objects of class "PictureContent"
that are paths,
groups rectangles and other related objects.
defs
:Object of class "PictureDefinitions"
that contain all
referenced content in the image. These are only used by the
gridSVG package when "grobifying" an image.
summary
:Object of class "PictureSummary"
that describes the scales
applied to this picture.
signature(x = "Picture")
: subset the content of a picture
to produce a new picture (including a new, updated summary).
signature(x = "Picture")
: extract a single piece of a
picture object, to produce a new picture (including a new, updated
summary).
signature(object = "Picture", tm = "matrix")
:
transforms each element of the picture by a 3x3
transformation matrix and returns a new "Picture"
object with the newly transformed locations.
signature(object = "Picture")
: convert a picture
into a grid grob (for use as a one-off image).
This method contains two additional arguments:
gpFUN
This argument expects to take a function that modifies a
gpar
object. For its input, this function should take a
gpar
object, modify that object, and then return it. By
default the value of this argument is the identity function.
ext
A character vector. See grid.picture
for more
information on what this extension selection parameter means,
in addition to the valid values this argument takes.
Simon Potter
readPicture
,
grid.picture
,
PictureSummary-class
.
"PictureClipPath"
A description of a clipping path that is meant to be used as part of a larger picture (as it does not directly draw anything itself). This is primarily used for determining the bounding box of the clipping region (because R graphics only supports rectangular clipping regions). This object will have a greater effect with it is used in conjunction with the gridSVG package as it can apply non-rectangular clipping regions.
content
:Object of class "list"
. A list of "PictureContent"
objects that describe the outline(s) of the clipping region(s).
label
:Object of class "character"
. A label to identify the
clipping path by so that it may be referred to by content within
the image.
Class PictureContent
, directly.
signature(object = "PictureClipPath", tm = "matrix")
:
transforms the locations described by contents of the clip path object
by a 3x3 transformation matrix and returns a "PictureClipPath"
object whose children have had locations transformed by the matrix.
signature(object = "PictureClipPath")
:
convert the clipping path into a grid grob. Useful only in
conjunction with the gridSVG package for non-rectangular paths.
This grobify
method takes three arguments:
defs
Required. This argument expects a "PictureDefinitions"
object that contains referenced content.
gpFUN
A function that takes a gpar
object and returns a
modified gpar
object. The default value for this
arugment is the identity function.
ext
A character vector. See grid.picture
for more
information on what this extension selection parameter means,
in addition to the valid values this argument takes.
Simon Potter
"PictureContent"
A virtual class that is used for verifying validity of
"Picture"
objects.
Simon Potter
PicturePath
, PictureRect
,
PictureGroup
, etc.
"PictureDefinitions"
A collection of graphical content and features that are to be referenced by the rest of the image. These definitions are not intended to draw anything themselves, but describe how other pieces of graphical content will be drawn (or in the case of clipping paths, not drawn).
content
:Object of class "list"
. A list of "PictureContent"
objects.
signature(id = "character")
:
retrieves an object that is referred to by a
given label.
signature(id = "character", value = "PictureContent")
:
Not intended to be used by regular
users, but this is a method for assigning a definition to be
referenced later by "PictureContent"
objects. This method
stores a new definition (value
) with a given label
(id
). The result is that a new "PictureDefinitions"
object is returned with the new definition added to it.
Simon Potter
"PictureFeColorMatrix"
A description of a colour transformation matrix filter effect primitive. To be used in conjunction with the gridSVG package.
type
:Object of class "character"
~~
input
:Object of class "character"
~~
values
:Object of class "matrix"
~~
colorspace
:Object of class "character"
~~
Class PictureContent
, directly.
signature(object = "PictureFeColorMatrix")
: creates an
feColorMatrix
object to include in a filter effect object
for use with the gridSVG package.
Simon Potter
"PictureFeComposite"
A description of a colour transformation matrix filter effect primitive. To be used in conjunction with the gridSVG package.
input1
:Object of class "character"
~~
input2
:Object of class "character"
~~
operator
:Object of class "character"
~~
k1
:Object of class "numeric"
~~
k2
:Object of class "numeric"
~~
k3
:Object of class "numeric"
~~
k4
:Object of class "numeric"
~~
colorspace
:Object of class "character"
~~
Class PictureContent
, directly.
signature(object = "PictureFeComposite")
: creates an
feComposite
object to include in a filter effect object
for use with the gridSVG package.
Paul Murrell
"PictureFeImage"
A description of a colour transformation matrix filter effect primitive. To be used in conjunction with the gridSVG package.
href
:Object of class "character"
~~
result
:Object of class "character"
~~
x
:Object of class "numeric"
~~
y
:Object of class "numeric"
~~
width
:Object of class "numeric"
~~
height
:Object of class "characternumeric"
~~
Class PictureContent
, directly.
signature(object = "PictureFeImage")
: creates an
feImage
object to include in a filter effect object
for use with the gridSVG package.
Paul Murrell
"PictureFilter"
A description of a filter effect. To be used in conjunction with the gridSVG package.
filterUnits
:Object of class "character"
. The units that the filter
effect should be positioned against. This should always be
"bbox"
.
primitiveUnits
:Object of class "character"
. The units that the filter
effect should be relative to. This should always be
"coords"
.
x
:Object of class "numeric"
. A vector of length one
representing the x-location of the bottom-left corner of the
filter effect region.
y
:Object of class "numeric"
. A vector of length one
representing the y-location of the bottom-left corner of the
filter effect region.
width
:Object of class "numeric"
. A vector of length one
representing the width of the filter effect region.
height
:Object of class "numeric"
. A vector of length one
representing the height of the filter effect region.
content
:Object of class "PictureFeColorMatrix"
. A description of
the colour transformation matrix applied to a filter target.
Class PictureContent
, directly.
signature(object = "PictureFilter")
: Creates a filter
effect object for use with the gridSVG package.
Simon Potter
"PictureGradientStop"
A description of a gradient stop that is meant to be used as part of a larger picture (as it does not directly draw anything itself). This object will have no effect unless it is used in conjunction with the gridSVG package.
offset
:Object of class "numeric"
. The offset (usually between 0
and 1) from the start of the gradient. These represent locations
to place the colours (col
) at.
col
:Object of class "character"
. A colour in the form
"#RRGGBBAA"
.
signature(object = "PictureGradientStop")
:
convert to a gradient stop object for use with the gridSVG
package.
Simon Potter
PictureLinearGradient
,
PictureRadialGradient
.
"PictureGroup"
A grouped collection of picture pieces.
content
:Object of class "list"
that is a list of objects of class
"PictureContent"
.
clip
:Object of class "ANY"
. Either NULL
or an object of
class "PictureClipPath"
.
filterRef
:Object of class "ANY"
. A character reference to an object
that will apply a filter effect to this group. Not intended to be
used directly (so can be NULL
.
maskRef
:Object of class "ANY"
. A character reference to an object
that will mask this group. Not intended to be used directly (so
can be NULL
.
gp
:Object of class "gpar"
. A grid gpar
object to apply
to the group.
Class "PictureContent"
, directly.
signature(x = "PictureGroup")
: subset the content of the
group to produce a new picture.
signature(x = "PictureGroup")
: extract a single piece of a
picture group. Each piece will be an object of class
"PictureContent"
.
signature(object = "PictureGroup", tm = "matrix")
:
transforms the locations described by contents of the group object
by a 3x3 transformation matrix and returns a "PictureGroup"
object whose children have had locations transformed by the matrix.
signature(object = "PictureGroup")
: convert to a grid grob
(for use as a one-off image) for drawing.
This method is typically not called directly but can take three additional arguments.
defs
This argument takes an object of class
"PictureDefinitions"
. This object allows us to make use
of referenced content features in the gridSVG package.
gpFUN
This arugment takes a function that modifies a gpar
object. The function should take a single argument that is a
gpar
object, modify that gpar
object, and then
return it. By default this argument is assigned the value of
the identity function.
ext
A character vector. This argument can partially match to one
of off
, clipbbox
, or gridSVG
. When
off
, no clipping is applied to the group. When
clipbbox
, the contents of the group will be clipped to
the bounding box of the clipping definition. When
gridSVG
, the contents of the group will be clipped to
the non-zero region defined by the clipping definition, in
addition to using gridSVG features (i.e. gradients, filters),
when required. bbox
is restricted to rectangular
clipping regions, while gridSVG
has no such restriction
and can clip to any arbitrary region.
Simon Potter
"PictureImage"
A description of a raster image.
x
:Object of class "numeric"
. A vector of length one
representing the x-location of the top-left corner of the
image.
y
:Object of class "numeric"
. A vector of length one
representing the y-location of the top-left corner of the
image.
width
:Object of class "numeric"
. A vector of length one
representing the width of the image.
height
:Object of class "numeric"
. A vector of length one
representing the height of the image.
image
:Object of class "nativeRaster"
. A description of the raster
image as an array of integers representing pixel colours. Not
intended to be created directly, but as a result of calling the
jpeg
and png
packages read*()
functions.
angle
:Object of class "numeric"
. A vector of length one
representing the angle applied to the image. Corresponds to grid's
viewport angles.
maskRef
:Object of class "ANY"
. A character reference to an object
that will mask this image. Not intended to be used directly (so
can be NULL
.
bbox
:Object of class "numeric"
. Represented as [xmin,
xmax, ymin, ymax]
. The bounding box of the image. Used for
features such as clipping.
Class PictureContent
, directly.
signature(object = "PictureImage", tm = "matrix")
:
transforms each location described by the image by a 3x3
transformation matrix and returns a new "PictureImage"
object with the newly transformed locations.
signature(object = "PictureImage")
: converts the image
description into a grid raster grob that represents the
image. Typically used in conjunction with a pattern.
While not intended to be used directly, this function contains a
single optional argument, ext
, which is a character vector.
See grid.picture
for more information on what this
extension selection parameter means, in addition to the valid
values this argument takes.
Simon Potter
A description of a linear gradient that is meant to be used as part of a larger picture (as it does not directly draw anything itself). This object will have no effect unless it is used in conjunction with the gridSVG package.
x0
:Object of class "numeric"
. The starting x-location of the
linear gradient.
y0
:Object of class "numeric"
. The starting y-location of the
linear gradient.
x1
:Object of class "numeric"
. The ending x-location of the
linear gradient.
y1
:Object of class "numeric"
. The ending y-location of the
linear gradient.
spreadMethod
:Object of class "character"
that specifies what happens
when a gradient ends within its bounds. Must be one of "pad",
"reflect" or "repeat". See "linearGradient"
in the gridSVG
package for more information.
stops
:Object of class "list"
that is a list of objects of class
"PictureGradientStop"
.
Class "PictureContent"
.
signature(object = "PictureLinearGradient", tm = "matrix")
:
transform the locations that represent the bounds and direction of
the gradient by a 3x3 transformation matrix.
signature(object = "PictureLinearGradient")
:
convert to a gradient object for use with the gridSVG package.
Simon Potter
"PictureMask"
A description of a luminance mask.
content
:Object of class "list"
. A list of "PictureContent"
objects that are use to define the mask. Typically objects that
actually draw content (e.g. a path or a rect).
Class PictureContent
, directly.
signature(object = "PictureMask", tm = "matrix")
:
transforms the locations described by contents of the mask object
by a 3x3 transformation matrix and returns a "PictureMask"
object whose children have had locations transformed by the matrix.
signature(object = "PictureMask")
: creates a mask object
for use with the gridSVG package. Not intended to be used
directly.
There are three arguments to this grobify
method:
defs
An object of class "PictureDefinitions"
. This object is
primarily useful in conjunction with the gridSVG package.
gpFUN
This argument takes a function that takes a gpar
object
and returns a modified gpar
object. The default value
is the identity function.
ext
A character vector. See grid.picture
for more
information on what this extension selection parameter means,
in addition to the valid values this argument takes.
Simon Potter
"PicturePath"
A description of a path.
d
:Object of class "PathData"
. A description of how the path
draws and where it draws.
rule
:Object of class "character"
. A single element vector
specifying the fill rule of the path.
gp
:Object of class "gpar"
. A grid gpar
object that
describes graphical parameters applied to the path.
bbox
:Object of class "numeric"
. The bounding box of the
path. Represented as [xmin, xmax, ymin, ymax]
. Used for
features such as clipping.
Class linkS4class{PictureContent}
, directly.
signature(object = "PicturePath", tm = "matrix")
:
transforms each location described by the path's data by a 3x3
transformation matrix and returns a new "PicturePath"
object with the newly transformed locations.
signature(object = "PicturePath")
: converts the path
description into a grid grob that represents the path.
Although not expected to be called directly, this method contains three arguments.
defs
An object of class "PictureDefinitions"
. This object
holds definitions of advanced graphical content, primarily for
use with the gridSVG package.
gpFUN
This argument expects to take a function that modifies a
gpar
object. This function should take a gpar
object and return a modified gpar
object. By default
this argument is the identity function.
ext
A character vector. See grid.picture
for more
information on what this extension selection parameter means,
in addition to the valid values this argument takes.
Simon Potter
"PicturePattern"
A description of a pattern to be referenced (and used) by graphical content.
x
:Object of class "numeric"
. A vector of length one
representing the x-location of the top-left corner of the
pattern.
y
:Object of class "numeric"
. A vector of length one
representing the y-location of the top-left corner of the
pattern.
width
:Object of class "numeric"
. A vector of length one
representing the width of the pattern.
height
:Object of class "numeric"
. A vector of length one
representing the height of the pattern.
angle
:Object of class "numeric"
. A vector of length one
representing the angle applied to the image. Corresponds to grid's
viewport angles.
definition
:Object of class "list"
. A list of "PictureContent"
objects that define the content of the pattern "tile".
Class PictureContent
, directly.
signature(object = "PicturePattern", tm = "matrix")
:
transforms the locations described by the pattern object by a
3x3 transformation matrix and returns a "PicturePattern"
object with the transformed locations.
signature(object = "PicturePattern")
:
convert the pattern description into a gridSVG pattern
object. Useful only in conjunction with the gridSVG package. The
pattern object will store the definition of the pattern (almost
certainly a raster of some sort) as a grob too.
While not intended to be used directly, this method contains a
single optional argument. This argument is ext
, a character
vector. See grid.picture
for more information on
what this extension selection parameter means, in addition to the
valid values this argument takes.
Simon Potter
A description of a radial gradient that is meant to be used as part of a larger picture (as it does not directly draw anything itself). This object will have no effect unless it is used in conjunction with the gridSVG package.
x
:Object of class "numeric"
. The x-location of the radial
gradient.
y
:Object of class "numeric"
. The y-location of the radial
gradient.
r
:Object of class "numeric"
. The radius of the radial
gradient.
fx
:Object of class "numeric"
. The x-location of the focal
point of the radial gradient.
fy
:Object of class "numeric"
. The y-location of the focal
point of the radial gradient.
spreadMethod
:Object of class "character"
that specifies what happens
when a gradient ends within its bounds. Must be one of "pad",
"reflect" or "repeat". See "radialGradient"
in the gridSVG
package for more information.
stops
:Object of class "list"
that is a list of objects of class
"PictureGradientStop"
.
Class "PictureContent"
.
signature(object = "PictureRadialGradient", tm = "matrix")
:
transform the locations that represent the bounds and direction of
the gradient by a 3x3 transformation matrix.
signature(object = "PictureRadialGradient")
:
convert to a gradient object for use with the gridSVG package.
Simon Potter
"PictureRect"
A description of a rectangle.
x
:Object of class "numeric"
. A vector of length one
representing the x-location of the top-left corner of the
rectangle.
y
:Object of class "numeric"
. A vector of length one
representing the y-location of the top-left corner of the
rectangle.
width
:Object of class "numeric"
. A vector of length one
representing the width of the rectangle.
height
:Object of class "numeric"
. A vector of length one
representing the height of the rectangle.
angle
:Object of class "numeric"
. A vector of length one
representing the angle applied to the image. Corresponds to grid's
viewport angles.
gp
:Object of class "gpar"
. A grid gpar
object.
bbox
:Object of class "numeric"
. Represented as [xmin,
xmax, ymin, ymax]
. The bounding box of the rectangle. Used for
features such as clipping.
Class PictureContent
, directly.
signature(object = "PictureRect", tm = "matrix")
:
transforms the locations described by the rectangle object by a
3x3 transformation matrix and returns a "PictureRect"
object with the transformed locations.
signature(object = "PictureRect")
:
converts the object into a grid rectangle grob.
While not intended to be used directly, this method contains three arguments:
defs
An object of class "PictureDefinitions"
that contains
definitions of graphical content, primarily for use with the
gridSVG package.
gpFUN
This argument takes a function that should expect to take a
single gpar
object and return a modified gpar
object. By default, the value of this argument is the identity
function.
ext
A character vector. See grid.picture
for more
information on what this extension selection parameter means,
in addition to the valid values this argument takes.
Simon Potter
Summary information about a picture regarding the scales of its bounding box.
xscale
:Object of class "numeric"
range of x-values in picture.
yscale
:Object of class "numeric"
range of y-values in picture.
Simon Potter
"PictureSymbol"
A description of a symbol that is meant to be used (perhaps
repeatedly) as part of a larger picture (as it does not directly draw
anything itself). This object only has an effect while parsing a
picture (via readPicture
), so is not intended to be used
directly by any user.
definition
:Object of class "list"
. A list of "PictureContent"
objects.
Class PictureContent
, directly.
Simon Potter
This function reads in an SVG image file and creates a
"Picture"
object.
readPicture(file, warn = TRUE, initDefs = TRUE)
readPicture(file, warn = TRUE, initDefs = TRUE)
file |
The filename of a Cairo SVG image. |
warn |
Logical. If |
initDefs |
Logical. If |
This function is designed to read SVG files that have been generated by the Cairo graphics system.
There are several ways to generate Cairo SVG files: The R SVG
graphics device, provided by the svg
function,
produces Cairo SVG; the grConvert package (Linux-only) can convert
PostScript, or PDF, or SVG files to Cairo SVG; and the
rsvg package can convert many different graphics formats to
Cairo SVG.
It is very unlikely that an SVG file that was NOT generated by Cairo
will import properly. This function may read the file without error,
but the render (via grid.picture
) is very unlikely
to faithfully reproduce the original image.
An object of class "Picture"
.
Simon Potter
The Cairo graphics library, https://cairographics.org/
options(warn=1) ## NOT a Cairo SVG file badfile <- system.file("SVG", "lwd.svg", package="grImport2") ## A Cairo SVG file goodfile <- system.file("SVG", "lwd-rsvg.svg", package="grImport2") ## Warning because NOT a Cairo SVG file ## (and it will not render correctly) img <- readPicture(badfile) ## No warning ## (and it will render correctly) img <- readPicture(goodfile) if (require("rsvg")) { ## Generate a Cairo SVG file goodfile <- tempfile(fileext = ".svg") rsvg_svg(badfile, goodfile) ## No warning ## (and it will render correctly) img <- readPicture(goodfile) } options(warn=0)
options(warn=1) ## NOT a Cairo SVG file badfile <- system.file("SVG", "lwd.svg", package="grImport2") ## A Cairo SVG file goodfile <- system.file("SVG", "lwd-rsvg.svg", package="grImport2") ## Warning because NOT a Cairo SVG file ## (and it will not render correctly) img <- readPicture(badfile) ## No warning ## (and it will render correctly) img <- readPicture(goodfile) if (require("rsvg")) { ## Generate a Cairo SVG file goodfile <- tempfile(fileext = ".svg") rsvg_svg(badfile, goodfile) ## No warning ## (and it will render correctly) img <- readPicture(goodfile) } options(warn=0)