shape_text | R Documentation |
Do basic text shaping of strings. This function will use freetype to
calculate advances, doing kerning if possible. It will not perform any font
substitution or ligature resolving and will thus be much in line with how
the standard graphic devices does text shaping. Inputs are recycled to the
length of strings
.
shape_text(
strings,
id = NULL,
family = "",
italic = FALSE,
weight = "normal",
width = "normal",
features = font_feature(),
size = 12,
res = 72,
lineheight = 1,
align = "left",
hjust = 0,
vjust = 0,
max_width = NA,
tracking = 0,
indent = 0,
hanging = 0,
space_before = 0,
space_after = 0,
path = NULL,
index = 0,
bold = deprecated()
)
strings |
A character vector of strings to shape |
id |
A vector grouping the strings together. If strings share an id the shaping will continue between strings |
family |
The name of the font families to match |
italic |
logical indicating the font slant |
weight |
The weight to query for, either in numbers ( |
width |
The width to query for either in numbers ( |
features |
A |
size |
The size in points to use for the font |
res |
The resolution to use when doing the shaping. Should optimally match the resolution used when rendering the glyphs. |
lineheight |
A multiplier for the lineheight |
align |
Within text box alignment, either |
hjust , vjust |
The justification of the textbox surrounding the text |
max_width |
The requested with of the string in inches. Setting this to
something other than |
tracking |
Tracking of the glyphs (space adjustment) measured in 1/1000 em. |
indent |
The indent of the first line in a paragraph measured in inches. |
hanging |
The indent of the remaining lines in a paragraph measured in inches. |
space_before , space_after |
The spacing above and below a paragraph, measured in points |
path , index |
path an index of a font file to circumvent lookup based on family and style |
bold |
logical indicating whether the font weight |
A list with two element: shape
contains the position of each glyph,
relative to the origin in the enclosing textbox. metrics
contain metrics
about the full strings.
shape
is a data.frame with the following columns:
The glyph as a character
The index of the glyph in the font file
The index of the string the glyph is part of (referencing a row in the metrics
data.frame)
The index of the string the glyph came from (referencing an element in the strings
input)
The x offset in pixels from the origin of the textbox
The y offset in pixels from the origin of the textbox
The x offset in pixels to the middle of the glyph, measured from the origin of the glyph
metrics
is a data.frame with the following columns:
The text the string consist of
The width of the string
The height of the string
The distance from the left edge of the textbox and the leftmost glyph
The distance from the right edge of the textbox and the rightmost glyph
The distance from the top edge of the textbox and the topmost glyph
The distance from the bottom edge of the textbox and the bottommost glyph
The position of the leftmost edge of the textbox related to the origin
The position of the topmost edge of the textbox related to the origin
The horizontal position of the next glyph after the string
The vertical position of the next glyph after the string
string <- "This is a long string\nLook; It spans multiple lines\nand all"
# Shape with default settings
shape_text(string)
# Mix styles within the same string
string <- c(
"This string will have\na ",
"very large",
" text style\nin the middle"
)
shape_text(string, id = c(1, 1, 1), size = c(12, 24, 12))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.