Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upkeep 2024-10 #181

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
filename <- file
}
if (invalid_filename(filename)) {
stop("invalid 'file': ", filename)
cli::cli_abort("{.arg filename} does not provide a valid name ({.val {filename}}): ")

Check warning on line 87 in R/SVG.R

View check run for this annotation

Codecov / codecov/patch

R/SVG.R#L87

Added line #L87 was not covered by tests
}
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 @@

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)])}"
))

Check warning on line 37 in R/fonts.R

View check run for this annotation

Codecov / codecov/patch

R/fonts.R#L35-L37

Added lines #L35 - L37 were not covered by tests
}

# Add missing system fonts for base families
Expand All @@ -46,17 +48,11 @@
}

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}}")

Check warning on line 55 in R/fonts.R

View check run for this annotation

Codecov / codecov/patch

R/fonts.R#L55

Added line #L55 was not covered by tests
}
matched
}
Expand All @@ -69,21 +65,15 @@

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}")

Check warning on line 68 in R/fonts.R

View check run for this annotation

Codecov / codecov/patch

R/fonts.R#L68

Added line #L68 was not covered by tests
}

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]}}")

Check warning on line 76 in R/fonts.R

View check run for this annotation

Codecov / codecov/patch

R/fonts.R#L76

Added line #L76 was not covered by tests
}

names <- ifelse(is_alias_plain, default_name, family)
Expand All @@ -94,14 +84,10 @@
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}")

Check warning on line 90 in R/fonts.R

View check run for this annotation

Codecov / codecov/patch

R/fonts.R#L90

Added line #L90 was not covered by tests
}

zip(list(name = names, file = files))
Expand Down Expand Up @@ -156,7 +142,7 @@
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")

Check warning on line 145 in R/fonts.R

View check run for this annotation

Codecov / codecov/patch

R/fonts.R#L145

Added line #L145 was not covered by tests
}

x <- c(
Expand Down
Loading
Loading