Skip to content

Commit

Permalink
Upkeep 2024-10 (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 authored Oct 24, 2024
1 parent bac2af8 commit ec2ef7f
Show file tree
Hide file tree
Showing 22 changed files with 1,106 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ inst/doc
docs
compile_commands.json
.cache

/.quarto/
14 changes: 9 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ License: GPL (>= 2)
URL: https://svglite.r-lib.org, https://github.com/r-lib/svglite
BugReports: https://github.com/r-lib/svglite/issues
Depends:
R (>= 3.5.0)
R (>= 4.0)
Imports:
cli,
lifecycle,
rlang (>= 1.1.0),
systemfonts (>= 1.0.0)
Suggests:
covr,
Expand All @@ -39,12 +42,13 @@ Suggests:
LinkingTo:
cpp11,
systemfonts
VignetteBuilder:
VignetteBuilder:
knitr
Config/build/compilation-database: true
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Config/usethis/last-upkeep: 2024-10-23
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
SystemRequirements: libpng
Config/testthat/edition: 3
Config/build/compilation-database: true
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export(stringSVG)
export(svglite)
export(svgstring)
export(xmlSVG)
import(rlang)
importFrom(lifecycle,deprecated)
importFrom(systemfonts,font_feature)
importFrom(systemfonts,font_info)
importFrom(systemfonts,match_font)
Expand Down
2 changes: 1 addition & 1 deletion R/SVG.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ svglite <- function(filename = "Rplot%03d.svg", width = 10, height = 8,
filename <- file
}
if (invalid_filename(filename)) {
stop("invalid 'file': ", filename)
cli::cli_abort("{.arg filename} does not provide a valid name ({.val {filename}}): ")
}
aliases <- validate_aliases(system_fonts, user_fonts)
web_fonts <- validate_web_fonts(web_fonts)
Expand Down
38 changes: 12 additions & 26 deletions R/fonts.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ validate_aliases <- function(system_fonts, user_fonts) {

aliases <- c(names(system_fonts), names(user_fonts))
if (any(duplicated(aliases))) {
stop("Cannot supply both system and font alias", call. = FALSE)
cli::cli_abort(c("Cannot provided multiple fonts with the same alias",
i = "Problematic aliases: {unique(aliases[duplicated(aliases)])}"
))
}

# Add missing system fonts for base families
Expand All @@ -46,17 +48,11 @@ validate_aliases <- function(system_fonts, user_fonts) {
}

validate_system_alias <- function(alias) {
if (!is_scalar_character(alias)) {
stop("System fonts must be scalar character vector", call. = FALSE)
}
check_string(alias, allow_empty = FALSE)

matched <- match_family(alias)
if (alias != matched) {
warning(
call. = FALSE,
"System font `", alias, "` not found. ",
"Closest match: `", matched, "`"
)
cli::cli_warn("System font {.val {alias}} not found. Closest match is {.val {matched}}")
}
matched
}
Expand All @@ -69,21 +65,15 @@ is_user_alias <- function(x) {

validate_user_alias <- function(default_name, family) {
if (!all(names(family) %in% r_font_faces)) {
stop("Faces must contain only: `plain`, `bold`, `italic`, `bolditalic`, `symbol`",
call. = FALSE
)
cli::cli_abort("{.arg family} must can only include elements named {r_font_faces}")
}

is_alias_object <- vapply_lgl(family, is_user_alias)
is_alias_plain <- vapply_lgl(family, is_scalar_character)
is_alias_object <- vapply(family, is_user_alias, logical(1))
is_alias_plain <- vapply(family, is_scalar_character, logical(1))

is_valid_alias <- is_alias_object | is_alias_plain
if (any(!is_valid_alias)) {
stop(
call. = FALSE,
"The following faces are invalid for `", default_name, "`: ",
paste0(names(family)[!is_valid_alias], collapse = ", ")
)
cli::cli_abort("The following faces are invalid for {.val {default_name}}: {.val {names(family)[!is_valid_alias]}}")
}

names <- ifelse(is_alias_plain, default_name, family)
Expand All @@ -94,14 +84,10 @@ validate_user_alias <- function(default_name, family) {
obj$file %||% obj$ttf
})

file_exists <- vapply_lgl(files, file.exists)
file_exists <- vapply(files, file.exists, logical(1))
if (any(!file_exists)) {
missing <- unlist(files)[!file_exists]
stop(
call. = FALSE,
"Could not find font file: ",
paste0(missing, collapse = ", ")
)
cli::cli_abort("Could not find the following font file{?s}: {missing}")
}

zip(list(name = names, file = files))
Expand Down Expand Up @@ -156,7 +142,7 @@ font_face <- function(family, woff2 = NULL, woff = NULL, ttf = NULL, otf = NULL,
if (!is.null(svg)) paste0('url("', svg, '") format("woff")')
)
if (length(sources) == 0) {
stop("At least one font source must be given")
cli::cli_abort("At least one font source must be given")
}

x <- c(
Expand Down
Loading

0 comments on commit ec2ef7f

Please sign in to comment.