Przeglądaj źródła

Add use_showtext option to theme_xaringan_base()

Fixes #31
tags/v0.3.0
Garrick Aden-Buie 6 lat temu
rodzic
commit
85cd8124db
4 zmienionych plików z 33 dodań i 8 usunięć
  1. +18
    -7
      R/ggplot2.R
  2. +4
    -0
      man/theme_xaringan.Rd
  3. +7
    -1
      man/theme_xaringan_base.Rd
  4. +4
    -0
      man/theme_xaringan_inverse.Rd

+ 18
- 7
R/ggplot2.R Wyświetl plik

#' Fonts](https://fonts.google.com)? #' Fonts](https://fonts.google.com)?
#' @param title_font_size Base text font size, inherits from `title_font_size`, #' @param title_font_size Base text font size, inherits from `title_font_size`,
#' or defaults to 14. #' or defaults to 14.
#' @param use_showtext If `TRUE` (default) the \pkg{showtext} package will be
#' used to register Google fonts. Set to `FALSE` to disable this feature
#' entirely, which may result in errors during plotting if the fonts used are
#' not available locally.
#' @param ... Ignored #' @param ... Ignored
#' #'
#' @examples #' @examples
text_font_size = NULL, text_font_size = NULL,
title_font = NULL, title_font = NULL,
title_font_use_google = NULL, title_font_use_google = NULL,
title_font_size = NULL
title_font_size = NULL,
use_showtext = TRUE
) { ) {
text_color <- full_length_hex(text_color) text_color <- full_length_hex(text_color)
background_color <- full_length_hex(background_color) background_color <- full_length_hex(background_color)
title_font_size <- title_font_size %||% web_to_point(xaringanthemer_env$header_h3_font_size, scale = 0.8) %||% 14 title_font_size <- title_font_size %||% web_to_point(xaringanthemer_env$header_h3_font_size, scale = 0.8) %||% 14


text_font <- if (!is.null(text_font)) { text_font <- if (!is.null(text_font)) {
register_font(text_font, identical(text_font_use_google, TRUE))
register_font(text_font, identical(text_font_use_google, TRUE) && use_showtext)
} else { } else {
get_theme_font("text") get_theme_font("text")
} }
title_font <- if (!is.null(title_font)) { title_font <- if (!is.null(title_font)) {
register_font(title_font, identical(title_font_use_google, TRUE))
register_font(title_font, identical(title_font_use_google, TRUE) && use_showtext)
} else { } else {
get_theme_font("header") get_theme_font("header")
} }


# Fonts ------------------------------------------------------------------- # Fonts -------------------------------------------------------------------


get_theme_font <- function(element = c("text", "header", "code")) {
get_theme_font <- function(element = c("text", "header", "code"), use_showtext = TRUE) {
element <- match.arg(element) element <- match.arg(element)


element_family <- paste0(element, "_font_family") element_family <- paste0(element, "_font_family")
grepl("fonts.google", xaringanthemer_env[[element_url]], fixed = TRUE) grepl("fonts.google", xaringanthemer_env[[element_url]], fixed = TRUE)
} }


register_font(family, google = is_google_font, fn = sys.calls()[[max(1, sys.nframe() - 1)]][[1]])
register_font(
family,
google = is_google_font,
fn = sys.calls()[[max(1, sys.nframe() - 1)]][[1]],
use_showtext = use_showtext
)
} }


register_font <- function( register_font <- function(
family, family,
google = TRUE, google = TRUE,
fn = sys.calls()[[max(1, sys.nframe() - 1)]][[1]], fn = sys.calls()[[max(1, sys.nframe() - 1)]][[1]],
...
...,
use_showtext = TRUE
) { ) {
if (is.null(family)) {
if (is.null(family) || !use_showtext) {
return(NULL) return(NULL)
} }
family <- gsub("['\"]", "", family) family <- gsub("['\"]", "", family)

+ 4
- 0
man/theme_xaringan.Rd Wyświetl plik

\item{\code{title_font_use_google}}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{\code{title_font_use_google}}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}
\item{\code{title_font_size}}{Base text font size, inherits from \code{title_font_size}, \item{\code{title_font_size}}{Base text font size, inherits from \code{title_font_size},
or defaults to 14.} or defaults to 14.}
\item{\code{use_showtext}}{If \code{TRUE} (default) the \pkg{showtext} package will be
used to register Google fonts. Set to \code{FALSE} to disable this feature
entirely, which may result in errors during plotting if the fonts used are
not available locally.}
}} }}
} }
\value{ \value{

+ 7
- 1
man/theme_xaringan_base.Rd Wyświetl plik

text_font_size = NULL, text_font_size = NULL,
title_font = NULL, title_font = NULL,
title_font_use_google = NULL, title_font_use_google = NULL,
title_font_size = NULL
title_font_size = NULL,
use_showtext = TRUE
) )
} }
\arguments{ \arguments{


\item{title_font_size}{Base text font size, inherits from \code{title_font_size}, \item{title_font_size}{Base text font size, inherits from \code{title_font_size},
or defaults to 14.} or defaults to 14.}

\item{use_showtext}{If \code{TRUE} (default) the \pkg{showtext} package will be
used to register Google fonts. Set to \code{FALSE} to disable this feature
entirely, which may result in errors during plotting if the fonts used are
not available locally.}
} }
\value{ \value{
A ggplot2 theme A ggplot2 theme

+ 4
- 0
man/theme_xaringan_inverse.Rd Wyświetl plik

\item{\code{title_font_use_google}}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{\code{title_font_use_google}}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}
\item{\code{title_font_size}}{Base text font size, inherits from \code{title_font_size}, \item{\code{title_font_size}}{Base text font size, inherits from \code{title_font_size},
or defaults to 14.} or defaults to 14.}
\item{\code{use_showtext}}{If \code{TRUE} (default) the \pkg{showtext} package will be
used to register Google fonts. Set to \code{FALSE} to disable this feature
entirely, which may result in errors during plotting if the fonts used are
not available locally.}
}} }}
} }
\value{ \value{

Ładowanie…
Anuluj
Zapisz