Browse Source

theme_xaringan() and friends accept google_fonts()s for font arguments

tags/v0.3.0
Garrick Aden-Buie 6 years ago
parent
commit
55fe9084c5
6 changed files with 27 additions and 9 deletions
  1. +12
    -2
      R/ggplot2.R
  2. +2
    -0
      R/utils.R
  3. +4
    -2
      man/theme_xaringan.Rd
  4. +4
    -2
      man/theme_xaringan_base.Rd
  5. +4
    -2
      man/theme_xaringan_inverse.Rd
  6. +1
    -1
      man/theme_xaringan_set_defaults.Rd

+ 12
- 2
R/ggplot2.R View File

#' defaults, see [theme_xaringan_restore_defaults()]. #' defaults, see [theme_xaringan_restore_defaults()].
#' @param text_font Font to use for text elements, passed to #' @param text_font Font to use for text elements, passed to
#' [sysfonts::font_add_google()], if available and `text_font_use_google` is #' [sysfonts::font_add_google()], if available and `text_font_use_google` is
#' `TRUE`. Inherits from `text_font_family`.
#' `TRUE`. Inherits from `text_font_family`. If manually specified, can be a
#' [google_font()].
#' @param text_font_use_google Is `text_font` available on [Google #' @param text_font_use_google Is `text_font` available on [Google
#' Fonts](https://fonts.google.com)? #' Fonts](https://fonts.google.com)?
#' @param text_font_size Base text font size, inherits from `text_font_size`, or #' @param text_font_size Base text font size, inherits from `text_font_size`, or
#' defaults to 11. #' defaults to 11.
#' @param title_font Font to use for title elements, passed to #' @param title_font Font to use for title elements, passed to
#' [sysfonts::font_add_google()], if available and `title_font_use_google` is #' [sysfonts::font_add_google()], if available and `title_font_use_google` is
#' `TRUE`. Inherits from `title_font_family`.
#' `TRUE`. Inherits from `title_font_family`. If manually specified, can be a
#' [google_font()].
#' @param title_font_use_google Is `title_font` available on [Google #' @param title_font_use_google Is `title_font` available on [Google
#' 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`,
text_font_size <- text_font_size %||% web_to_point(xaringanthemer_env$text_font_size, scale = 1.25) %||% 11 text_font_size <- text_font_size %||% web_to_point(xaringanthemer_env$text_font_size, scale = 1.25) %||% 11
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_use_google <- text_font_use_google %||% is_google_font(text_font)
title_font_use_google <- title_font_use_google %||% is_google_font(title_font)

text_font <- if (!is.null(text_font)) { text_font <- if (!is.null(text_font)) {
register_font(text_font, identical(text_font_use_google, TRUE) && use_showtext) register_font(text_font, identical(text_font_use_google, TRUE) && use_showtext)
} else { } else {
#' [theme_xaringan_inverse()]. #' [theme_xaringan_inverse()].
#' #'
#' @family xaringanthemer ggplot2 themes #' @family xaringanthemer ggplot2 themes
#' @param text_font Font to use for text elements, passed to
#' [sysfonts::font_add_google()], if available and `text_font_use_google` is
#' `TRUE`. Inherits from `text_font_family`. Must be a length-one character.
#' @inheritParams theme_xaringan #' @inheritParams theme_xaringan
#' @inheritParams theme_xaringan_base #' @inheritParams theme_xaringan_base
#' @return Invisibly returns a list of the current ggplot2 geom defaults #' @return Invisibly returns a list of the current ggplot2 geom defaults
text_font = NULL text_font = NULL
) { ) {
requires_package("ggplot2") requires_package("ggplot2")
text_font %||% stopifnot(is.character(text_font) && length(text_font) == 1)


blend <- color_blender(text_color, background_color) blend <- color_blender(text_color, background_color)


if (is.null(family) || !use_showtext) { if (is.null(family) || !use_showtext) {
return(NULL) return(NULL)
} }
if (is_google_font(family)) family <- family$family
family <- gsub("['\"]", "", family) family <- gsub("['\"]", "", family)


if (!identical(xaringanthemer_env$showtext_auto, TRUE)) { if (!identical(xaringanthemer_env$showtext_auto, TRUE)) {

+ 2
- 0
R/utils.R View File

) )
} }


is_google_font <- function(x) inherits(x, "google_font")

#' @title List Valid Google Language Codes #' @title List Valid Google Language Codes
#' @description Gives a list of valid Language Codes for Google Fonts, or #' @description Gives a list of valid Language Codes for Google Fonts, or
#' validates that the language codes given are valid. #' validates that the language codes given are valid.

+ 4
- 2
man/theme_xaringan.Rd View File



\item{text_font}{Font to use for text elements, passed to \item{text_font}{Font to use for text elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is
\code{TRUE}. Inherits from \code{text_font_family}.}
\code{TRUE}. Inherits from \code{text_font_family}. If manually specified, can be a
\code{\link[=google_font]{google_font()}}.}


\item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?}




\item{title_font}{Font to use for title elements, passed to \item{title_font}{Font to use for title elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is
\code{TRUE}. Inherits from \code{title_font_family}.}
\code{TRUE}. Inherits from \code{title_font_family}. If manually specified, can be a
\code{\link[=google_font]{google_font()}}.}


\item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}



+ 4
- 2
man/theme_xaringan_base.Rd View File



\item{text_font}{Font to use for text elements, passed to \item{text_font}{Font to use for text elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is
\code{TRUE}. Inherits from \code{text_font_family}.}
\code{TRUE}. Inherits from \code{text_font_family}. If manually specified, can be a
\code{\link[=google_font]{google_font()}}.}


\item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?}




\item{title_font}{Font to use for title elements, passed to \item{title_font}{Font to use for title elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is
\code{TRUE}. Inherits from \code{title_font_family}.}
\code{TRUE}. Inherits from \code{title_font_family}. If manually specified, can be a
\code{\link[=google_font]{google_font()}}.}


\item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}



+ 4
- 2
man/theme_xaringan_inverse.Rd View File



\item{text_font}{Font to use for text elements, passed to \item{text_font}{Font to use for text elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is
\code{TRUE}. Inherits from \code{text_font_family}.}
\code{TRUE}. Inherits from \code{text_font_family}. If manually specified, can be a
\code{\link[=google_font]{google_font()}}.}


\item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?}




\item{title_font}{Font to use for title elements, passed to \item{title_font}{Font to use for title elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is
\code{TRUE}. Inherits from \code{title_font_family}.}
\code{TRUE}. Inherits from \code{title_font_family}. If manually specified, can be a
\code{\link[=google_font]{google_font()}}.}


\item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?} \item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}



+ 1
- 1
man/theme_xaringan_set_defaults.Rd View File



\item{text_font}{Font to use for text elements, passed to \item{text_font}{Font to use for text elements, passed to
\code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is
\code{TRUE}. Inherits from \code{text_font_family}.}
\code{TRUE}. Inherits from \code{text_font_family}. Must be a length-one character.}
} }
\value{ \value{
Invisibly returns a list of the current ggplot2 geom defaults Invisibly returns a list of the current ggplot2 geom defaults

Loading…
Cancel
Save