From 7bbb40927cdeb45908312919442ffa2bb0027ea5 Mon Sep 17 00:00:00 2001 From: Elin Waring Date: Tue, 17 Sep 2024 18:35:17 -0400 Subject: [PATCH 1/2] Only use first value when creating glyphFont. --- src/library/grDevices/R/glyph.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/library/grDevices/R/glyph.R b/src/library/grDevices/R/glyph.R index 45e9cf33128..b74a3075205 100644 --- a/src/library/grDevices/R/glyph.R +++ b/src/library/grDevices/R/glyph.R @@ -5,7 +5,7 @@ mapCharWeight <- function(x) { if (is.na(x)) x - else + else switch(as.character(x), normal=400, bold=700, @@ -19,7 +19,7 @@ mapWeight <- function(x) { x } else { sapply(x, mapCharWeight, USE.NAMES=FALSE) - } + } } fontStyles <- c("normal", "italic", "oblique") @@ -120,14 +120,14 @@ glyphFont <- function(file, index, nafile <- is.na(file) if (any(nchar(file[!nafile], "bytes") > 500)) warning("Font file longer than 500 will be truncated") - index <- as.integer(index) - family <- as.character(family) + index <- as.integer(index)[1] + family <- as.character(family)[1] nafamily <- is.na(family) if (any(nchar(family[!nafamily], "bytes") > 200)) warning("Font family longer than 200 will be truncated") - weight <- mapWeight(weight) - style <- mapStyle(style) - PSname <- as.character(PSname) + weight <- mapWeight(weight)[1] + style <- mapStyle(style)[1] + PSname <- as.character(PSname)[1] ## Missing PSname values are "estimated" naPS <- is.na(PSname) if (any(naPS)) { @@ -151,7 +151,7 @@ glyphFont <- function(file, index, names <- rle(PSname)$lengths if (!(all(families == files) && all(files == names))) stop("Font information is inconsistent") - + font <- list(file=file, index=index, family=family, weight=weight, style=style, PSname=PSname) From e45c78faaaf49500ce15067d1e0abdca28d416b3 Mon Sep 17 00:00:00 2001 From: Elin Waring Date: Tue, 17 Sep 2024 20:50:26 -0400 Subject: [PATCH 2/2] Update man page. --- src/library/grDevices/man/glyphInfo.Rd | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/library/grDevices/man/glyphInfo.Rd b/src/library/grDevices/man/glyphInfo.Rd index 9121d24c5ae..c785a9bc6d0 100644 --- a/src/library/grDevices/man/glyphInfo.Rd +++ b/src/library/grDevices/man/glyphInfo.Rd @@ -25,7 +25,7 @@ } \usage{ -glyphInfo(id, x, y, font, size, fontList, +glyphInfo(id, x, y, font, size, fontList, width, height, hAnchor, vAnchor, col=NA) @@ -42,29 +42,29 @@ glyphJust(just, ...) \method{glyphJust}{numeric}(just, which=NULL, ...) } \arguments{ - \item{id}{Numeric vector of glyph identifiers (index of glyph within - font file).} + \item{id}{Numeric glyph identifier (index of glyph within + font file). Vectors with length > 1 are truncated.} \item{x, y}{Numeric locations of glyphs in (big) points (1/72 inches).} \item{font}{Integer index into \code{fontList}.} - \item{size}{Numeric size of glyphs (in points).} - \item{fontList}{List of glyph fonts, as generated by \code{glyphFont()}.} + \item{size}{Numeric size of glyph (in points). Vectors with length > 1 are truncated.} + \item{fontList}{List of glyph fonts, as generated by \code{glyphFontList()}.} \item{width}{Overall width of glyphs. Can be a single numeric value, but can also be the result from a call to \code{glyphWidth()}.} \item{height}{Overall height of glyphs. Can be a single numeric value, but can also be the result from a call to \code{glyphHeight()}.} \item{hAnchor}{Horizontal anchors for justifying glyphs relative to the - (\code{x}, \code{y}) location. Can be a + (\code{x}, \code{y}) location. Can be a single numeric value (against which to \code{"left"} justify), but can also be result from a call to \code{glyphAnchor()}.} - \item{vAnchor}{Vertical anchors for justifying glyphs relative to the + \item{vAnchor}{Vertical anchors for justifying glyphs relative to the (\code{x}, \code{y}) location. Can be a single numeric value - (against which to \code{"bottom"} justify), + (against which to \code{"bottom"} justify), but can also be result from a call to \code{glyphAnchor()}.} \item{col}{An R colour value for each glyph. Can be \code{NA}.} - \item{file}{Character path to font file.} + \item{file}{Character path to a font file.} \item{index}{Numeric index of font within font file.} - \item{family}{Character name of font family.} + \item{family}{Character name of a font family.} \item{weight}{Numeric weight of glyphs (400 is normal, 700 is bold).} \item{style}{Character style of glyphs (\code{"normal"}, \code{"italic"}, or \code{"oblique"}).} @@ -88,6 +88,11 @@ glyphJust(just, ...) return values that can be used to specify \code{width}, \code{height}, \code{hAnchor}, and \code{vAnchor} values to \code{glyphInfo()}. } + + \code{glyphFont()} returns a single glyph font object. + + \code{glyphFontList()} returns a list of glyph fonts. + \details{ Multiple anchors can be specified so as to allow different character-based justifications of the glyphs relative to the @@ -113,7 +118,7 @@ glyphJust(just, ...) numeric-based justifications of the glyphs relative to the (\code{x}, \code{y}) location, e.g., \code{0} for left-justification and \code{1} for right-justification, but with any value in between - or even outside those limits also possible. + or even outside those limits also possible. A width with label \code{"width"}, relative to the \code{"left"} horizontal anchor, is required, but if a single numeric value is given, that is assumed to be the required width.