R/font_import.R

Defines functions font_import font_import2 font_pokemon

Documented in font_import font_pokemon

##' @rdname font-import
##' @export
font_pokemon <- function() {
    font_import2('pokemon')
}

font_import2 <- function(font_dir) {
    path <- system.file("fonts", font_dir, package="meme")
    font_import(path)
}

##' load fonts
##'
##'
##' @title font_pokemon
##' @rdname font-import
##' @param path folder of fonts
##' @return NULL
##' @importFrom sysfonts font_add
##' @importFrom showtext showtext_auto
##' @export
##' @author Guangchuang Yu
font_import <- function(path='.') {
    wd <- getwd()
    setwd(path)
    fonts <- list.files(path, pattern="ttf")
    font_names <- sub("\\..*", "", fonts)
    for (i in seq_along(fonts)) {
        font_add(font_names[i], fonts[i])
    }
    showtext_auto()
    setwd(wd)
    message("font ", paste(font_names, collapse=", "), " loaded...")
}

Try the meme package in your browser

Any scripts or data that you put into this service are public.

meme documentation built on April 23, 2021, 5:07 p.m.