Преглед изворни кода

Ask before downloading "Droid Serif" to a temporary file

tags/v0.3.0
Garrick Aden-Buie пре 6 година
родитељ
комит
21c6d0e83f
1 измењених фајлова са 28 додато и 10 уклоњено
  1. +28
    -10
      R/ggplot2.R

+ 28
- 10
R/ggplot2.R Прегледај датотеку

if (!requires_package(pkg = "sysfonts", fn, required = FALSE)) { if (!requires_package(pkg = "sysfonts", fn, required = FALSE)) {
return(family) return(family)
} else if (family == "Droid Serif") { } else if (family == "Droid Serif") {
dstmp <- tempfile("droid-serif", fileext = "ttf")
utils::download.file(
"https://github.com/google/fonts/raw/feb15862e0c66ec0e7531ca4c3ef2607071ea700/apache/droidserif/DroidSerif-Regular.ttf",
dstmp,
quiet = TRUE
)
sysfonts::font_add(
family = "Droid Serif",
regular = dstmp
)
dstmp <- download_tmp_droid_serif()
if (!is.null(dstmp)) {
sysfonts::font_add(
family = "Droid Serif",
regular = dstmp
)
}
} else if (!family %in% sysfonts::font_families()) { } else if (!family %in% sysfonts::font_families()) {
is_default_font <- family %in% c( is_default_font <- family %in% c(
"Roboto", "Roboto",
family family
} }


download_tmp_droid_serif <- function() {
if (isTRUE(xaringanthemer_env[["declined_droid_serif"]])) return(NULL)
message(
"Using 'Droid Serif' in `theme_xaringan()` requires downloading the font from Google Fonts into a temporary file. "
)
ok_to_download <- utils::askYesNo("Do you want to try to download this font now?")
if (identical(ok_to_download, FALSE)) {
xaringanthemer_env[["declined_droid_serif"]] <- TRUE
}
if (!isTRUE(ok_to_download)) {
return(NULL)
}
dstmp <- tempfile("droid-serif", fileext = "ttf")
utils::download.file(
"https://github.com/google/fonts/raw/feb15862e0c66ec0e7531ca4c3ef2607071ea700/apache/droidserif/DroidSerif-Regular.ttf",
dstmp,
quiet = TRUE
)
dstmp
}

verify_fig_showtext <- function(fn = "theme_xaringan_base") { verify_fig_showtext <- function(fn = "theme_xaringan_base") {
if (is.null(knitr::current_input())) return() if (is.null(knitr::current_input())) return()
# Try to set fig.showtext automatically # Try to set fig.showtext automatically

Loading…
Откажи
Сачувај