grid::grobTree
object or data.frame
R/svg-parse.R
read_svg.Rd
Read an svg file (or text) into a grid::grobTree
object or data.frame
either a filename, or a single character string containing all the text of
an SVG. Filenames may either be '.svg'
or '.svgz'
(gzip
compressed SVG)
Extra offsets to element coordinates applied in the grob coordinate system (not the SVG coordinate system). Default: (0, 0)
number of segmentation points per section of bezier, arc, circle or ellipse. Default 30 Increase this number if the curves look too jaggy for your use case.
Scale factor to apply to all coordinates. Default: 1.
the grid units to use throughout. The default ('snpc'
)
is a pretty safe bet that will give you an auto-resizing vector object.
Uou could also set it to an absolute
unit (like 'mm'
) and then play with the scale
argument
to get a fixed size grid object.
Default: 1. Multiplication factor for width of strokes. The value to use here is heavily dependent upon what size output you are rendering to.
extra scaling applied to font parameters. Default: 1. The value to use here is heavily dependent upon the output size you are rendering to.
a named list of CSS properties which should override
the defaults. default: list()
. E.g. set style_default =
list(fill = 'red')
to set the default fill style for all elements
to 'red'. This style will still be overridden by inline styles, css styles,
or presentation attributes. It is a useful way of setting the 'color'
property which is often used in SVG icon sets (which make heavy use of
the 'currentColor' property)
single string containing CSS text e.g. "circle { fill: red !important; }".
Note: Normal cascading style rules apply i.e. more specific rules override
those with lower specificity, and inline style specifications have the highest specificty.
You may need to use !important
to override styles consistently.
What kind of R object to return - choices
c('grob', 'data.frame', 'list', 'debug')
. Default: 'grob'.
The 'list' and 'data.frame' options are for advanced/debugging use, but some users may find them useful if trying to extract coordinate information etc.
The data.frame
option could be used to recreate much of the SVG
but it is missing key information such as clipping paths, and gradients
(as these are pretty difficult to capture nicely in a data.frame).
The debug
option returns all the possible information. Currently
this returned object is undocumented. Use at your peril!
The list
option returns a list containing the following elements
for each parsed SVG element
svg - the SVG string for this element
tag - the SVG tag e.g. "path", "circle"
svg_df - data.frame of coordinates in SVG coordinate system
transform - the transform matrix for this element
grid_df - the transformed coordinates in R/grid coordinate space
style - caclculated style for this element. Named list of sttyle attributes
gp - the gpar()
equivalent of the style
grob - the final generated grob for this element
Use false colouring on all elements, by selecting random
colours from palettes in grDevices
Default: NULL means to use actual colours.
Possible values: 'rainbow', 'hcl', 'heat',
'terrain', 'topo', 'cm'
Return type determined by obj_type
argument