Not all glyphs are encoded as vector outlines (emojis often not). Even for
fonts that provide an outline you might be interested in a raster version.
This function gives you just that. It converts a glyph into an optimized
raster object that can be plotted with e.g. graphics::rasterImage()
or
grid::grid.raster()
. For convenience, you can also use
glyph_raster_grob()
for plotting the result.
glyph_raster(
glyph,
path,
index = 0,
size = 12,
res = 300,
col = "black",
verbose = FALSE
)
The index of the glyph in the font file
The path to the font file encoding the glyph
The index of the font in the font file
The size of the font in big points (1/72 inch)
The resolution to render the glyphs to
The color of the glyph assuming the glyph doesn't have a native coloring
Should font and glyph loading errors be reported as warnings
A list of nativeRaster objects (or NULL
if it failed to render a
given glyph). The nativeRasters have additional attributes attached. "size"
will give the size of the glyph in big points and "offset"
will give the
location of the top-left corner of the raster with respect to where it should
be rendered.
font <- font_info()
glyph <- glyph_info("R", path = font$path, index = font$index)
R <- glyph_raster(glyph$index, font$path, font$index, size = 150)
plot.new()
plot.window(c(0,150), c(0, 150), asp = 1)
rasterImage(R[[1]], 0, 0, attr(R[[1]], "size")[2], attr(R[[1]], "size")[1])