| force(code_font_family) | force(code_font_family) | ||||
| force(code_font_url) | force(code_font_url) | ||||
| force(code_font_family_fallback) | force(code_font_family_fallback) | ||||
| # the defaults are google fonts | # the defaults are google fonts | ||||
| is_default <- function(type, suffix) { | is_default <- function(type, suffix) { | ||||
| # check if font arg value is from xaringanthemer_font_default | # check if font arg value is from xaringanthemer_font_default | ||||
| r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}") | r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}") | ||||
| eval(parse(text = r_set_font_is_google)) | eval(parse(text = r_set_font_is_google)) | ||||
| } | } | ||||
| # Make sure font names are wrapped in quotes if they have spaces | # Make sure font names are wrapped in quotes if they have spaces | ||||
| f_args <- names(formals(sys.function())) | f_args <- names(formals(sys.function())) | ||||
| for (var in f_args[grepl("font_family$", f_args)]) { | for (var in f_args[grepl("font_family$", f_args)]) { | ||||
| eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")"))) | eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")"))) | ||||
| } | } | ||||
| } | } | ||||
| # Warn if base_font_size isn't absolute | # Warn if base_font_size isn't absolute | ||||
| css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px") | css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px") | ||||
| if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) { | if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) { | ||||
| immediate. = TRUE | immediate. = TRUE | ||||
| ) | ) | ||||
| } | } | ||||
| # If certain colors aren't in hexadecimal it may cause problems with theme_xaringan() | # If certain colors aren't in hexadecimal it may cause problems with theme_xaringan() | ||||
| # TODO: at some point I'd rather be able to process CSS colors or variables | # TODO: at some point I'd rather be able to process CSS colors or variables | ||||
| colors_used_by_theme_xaringan <- list( | colors_used_by_theme_xaringan <- list( | ||||
| ) | ) | ||||
| colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null) | colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null) | ||||
| colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL) | colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL) | ||||
| if (any(!colors_are_hex)) { | if (any(!colors_are_hex)) { | ||||
| colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex] | colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex] | ||||
| colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ") | colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ") | ||||
| warning( | warning( | ||||
| glue::glue("Colors that will be used by `theme_xaringan()` need to be in ", | glue::glue("Colors that will be used by `theme_xaringan()` need to be in ", | ||||
| "hexadecimal format: {colors_better_as_hex}"), | |||||
| "hexadecimal format: {colors_better_as_hex}"), | |||||
| immediate. = TRUE, | immediate. = TRUE, | ||||
| call. = FALSE | call. = FALSE | ||||
| ) | ) | ||||
| } | } | ||||
| # Use font_..._google args to overwrite font args | # Use font_..._google args to overwrite font args | ||||
| for (var in f_args[grepl("font_google$", f_args)]) { | for (var in f_args[grepl("font_google$", f_args)]) { | ||||
| gf <- eval(parse(text = var)) | gf <- eval(parse(text = var)) | ||||
| } | } | ||||
| eval(parse(text = paste0(group, "_font_is_google <- 1"))) | eval(parse(text = paste0(group, "_font_is_google <- 1"))) | ||||
| } | } | ||||
| extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts) | extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts) | ||||
| extra_font_imports <- paste(extra_font_imports, collapse = "\n") | extra_font_imports <- paste(extra_font_imports, collapse = "\n") | ||||
| # convert NA arguments to NULL | # convert NA arguments to NULL | ||||
| for (var in f_args) { | for (var in f_args) { | ||||
| val <- eval(parse(text = var)) | val <- eval(parse(text = var)) | ||||
| is_na <- length(val) == 0 | is_na <- length(val) == 0 | ||||
| if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe())) | if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe())) | ||||
| } | } | ||||
| # prepare variables for template | # prepare variables for template | ||||
| body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ") | body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ") | ||||
| background_size_fallback <- if (is.null(background_position)) "cover" else "100%" | background_size_fallback <- if (is.null(background_position)) "cover" else "100%" | ||||
| title_slide_background_image %??% "cover" | title_slide_background_image %??% "cover" | ||||
| ) | ) | ||||
| table_row_even_background_color <- table_row_even_background_color %||% background_color | table_row_even_background_color <- table_row_even_background_color %||% background_color | ||||
| # stash theme settings in package env | # stash theme settings in package env | ||||
| lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env)) | lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env)) | ||||
| for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) { | for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) { | ||||
| envir = xaringanthemer_env | envir = xaringanthemer_env | ||||
| ) | ) | ||||
| } | } | ||||
| xaringanthemer_version <- utils::packageVersion("xaringanthemer") | xaringanthemer_version <- utils::packageVersion("xaringanthemer") | ||||
| # prepare header background object | # prepare header background object | ||||
| needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes) | needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes) | ||||
| header_background_ignore_classes[needs_leading_dot] <- paste0( | header_background_ignore_classes[needs_leading_dot] <- paste0( | ||||
| content_padding_top = header_background_content_padding_top, | content_padding_top = header_background_content_padding_top, | ||||
| ignore = header_background_ignore_classes | ignore = header_background_ignore_classes | ||||
| ) | ) | ||||
| colors <- prepare_colors(colors) | colors <- prepare_colors(colors) | ||||
| tf <- system.file("resources", "template.css", package = "xaringanthemer") | tf <- system.file("resources", "template.css", package = "xaringanthemer") | ||||
| template <- readLines(tf, warn = FALSE) | template <- readLines(tf, warn = FALSE) | ||||
| template <- paste(template, collapse = "\n") | template <- paste(template, collapse = "\n") |