-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
121 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#' Check if Lato font is installed in the system | ||
#' | ||
#' Verify if you have Lato font installed in your system | ||
#' | ||
#' @importFrom systemfonts system_fonts | ||
#' | ||
#' @returns TRUE if Lato is installed in the system | ||
#' @export | ||
lato_installed <- function() { | ||
sys_fonts <- system_fonts() | ||
any(grepl("lato", sys_fonts$family, ignore.case = TRUE)) | ||
} | ||
|
||
#' Check if Lato font is registered through \code{extrafont} | ||
#' | ||
#' Verify if Lato is registered through \code{extrafont} | ||
#' | ||
#' @importFrom systemfonts system_fonts | ||
#' @importFrom extrafont fonts | ||
#' | ||
#' @returns TRUE if Lato is registered | ||
#' @export | ||
lato_registered <- function() { | ||
any(grepl("lato", fonts(), ignore.case = TRUE)) | ||
} | ||
|
||
#' Import Lato font | ||
#' | ||
#' Import Lato font for use in R graphic devices | ||
#' | ||
#' @importFrom systemfonts register_font | ||
#' @importFrom extrafont font_import | ||
#' | ||
#' @export | ||
import_lato <- function() { | ||
if (!lato_installed()) { | ||
font_dir <- system.file("fonts", "Lato", | ||
package = "unhcrthemes") | ||
register_font( | ||
name = "Lato", | ||
plain = file.path(font_dir, "Lato-Regular.ttf"), | ||
italic = file.path(font_dir, "Lato-Italic.ttf"), | ||
bold = file.path(font_dir, "Lato-Bold.ttf"), | ||
bolditalic = file.path(font_dir, | ||
"Lato-BoldItalic.ttf")) | ||
pattern <- "(?i)lato-(regular|bold|italic|bolditalic)" | ||
suppressMessages(extrafont::font_import(font_dir, | ||
pattern = pattern, | ||
prompt = FALSE)) | ||
suppressMessages(extrafont::loadfonts()) | ||
} else { | ||
font_dir <- systemfonts::system_fonts() | ||
b <- grepl("lato", font_dir$family, ignore.case = TRUE) | ||
font_dir <- font_dir[b, ] | ||
font_dir <- unique(dirname(font_dir$path)) | ||
pattern <- "(?i)lato-(regular|bold|italic|bolditalic)" | ||
suppressMessages(extrafont::font_import(font_dir, | ||
pattern = pattern, | ||
prompt = FALSE)) | ||
suppressMessages(extrafont::loadfonts()) | ||
} | ||
update_geom_font_defaults() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,9 @@ | ||
#' @noRd | ||
lato_exists <- function() { | ||
sys_fonts <- systemfonts::system_fonts() | ||
any(grepl("lato", sys_fonts$family, ignore.case = TRUE)) | ||
} | ||
|
||
.onLoad <- function(libname, pkgname) { | ||
font_dir <- system.file("fonts", "Lato", | ||
package = "unhcrthemes") | ||
|
||
if (!lato_exists()) { | ||
systemfonts::register_font( | ||
name = "Lato", | ||
plain = file.path(font_dir, "Lato-Regular.ttf"), | ||
italic = file.path(font_dir, "Lato-Italic.ttf"), | ||
bold = file.path(font_dir, "Lato-Bold.ttf"), | ||
bolditalic = file.path(font_dir, | ||
"Lato-BoldItalic.ttf")) | ||
pattern <- "(?i)lato-(regular|bold|italic|bolditalic)" | ||
suppressMessages(extrafont::font_import(font_dir, | ||
pattern = pattern, | ||
prompt = FALSE)) | ||
suppressMessages(extrafont::loadfonts()) | ||
} else { | ||
font_dir <- systemfonts::system_fonts() | ||
b <- grepl("lato", font_dir$family, ignore.case = TRUE) | ||
font_dir <- font_dir[b, ] | ||
font_dir <- unique(dirname(font_dir$path)) | ||
pattern <- "(?i)lato-(regular|bold|italic|bolditalic)" | ||
suppressMessages(extrafont::font_import(font_dir, | ||
pattern = pattern, | ||
prompt = FALSE)) | ||
suppressMessages(extrafont::loadfonts()) | ||
} | ||
update_geom_font_defaults() | ||
} | ||
|
||
.onAttach <- function(libname, pkgname) { | ||
if (!lato_exists()) { | ||
if (!lato_installed()) { | ||
packageStartupMessage("Lato font is missing, please install it!") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters