Skip to content

Commit

Permalink
Add ET Book fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrnold committed Jun 5, 2018
1 parent 632603f commit 9d678c5
Show file tree
Hide file tree
Showing 22 changed files with 293 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Expand Up @@ -4,3 +4,5 @@
^examples$
^\.travis\.yml$
^codecov\.yml$
^.*\.Rproj$
^\.Rproj\.user$
21 changes: 14 additions & 7 deletions DESCRIPTION
Expand Up @@ -5,6 +5,8 @@ Version: 0.0.1
Description: Geoms, a theme, and utilities inspired by Tufte's work.
This package includes a minimal-ink theme, Tufte's boxplot variant,
and axis lines with ranges determined by the data.
A copy of the 'ET Book' font <https://github.com/edwardtufte/et-book>
is also included.
URL: http://github.com/jrnold/ggtufte
BugReports: https://github.com/jrnold/ggtufte
License: MIT + file LICENSE
Expand All @@ -13,21 +15,26 @@ LazyData: true
Depends:
R (>= 3.2.0)
Imports:
ggplot2 (>= 2.2.1),
extrafont
ggplot2 (>= 2.2.1),
extrafont
Suggests:
spelling,
tufte,
tufte,
knitr,
rmarkdown,
testthat,
covr
Authors@R: c(person("Jeffrey", "Arnold", role = c("aut", "cre"), email = "jeffrey.arnold@gmail.com",
comment = c(ORCID = "0000-0001-9953-3904")),
person("Hadley", "Wickham", role = c("ctb"),
comment = "Code from the ggplot2 package."),
person("Justin", "Talbot", role = "ctb",
comment = "Code from the labeling package"))
person("Hadley", "Wickham", role = c("ctb"),
comment = "Code from the ggplot2 package."),
person("Justin", "Talbot", role = "ctb",
comment = "Code from the labeling package"),
person("Dimitry", "Krasny", comment = "ET Book Font", role = c("cph")),
person("Bonnie", "Scranton", comment = "ET Book Font", role = c("cph")),
person("Edward", "Tufte", comment = "ET Book Font", role = c("cph")),
person("Bob", "Rudis", role = "ctb",
comment = "Code from hrbrthemes package."))
RoxygenNote: 6.0.1
VignetteBuilder: knitr
Language: en-US
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -5,12 +5,15 @@ export(GeomTufteboxplot)
export(StatFivenumber)
export(extended_range_breaks)
export(extended_range_breaks_)
export(font_et)
export(geom_rangeframe)
export(geom_tufteboxplot)
export(import_et_book)
export(smart_digits)
export(smart_digits_format)
export(stat_fivenumber)
export(theme_tufte)
export(tufte_theme_fonts)
importFrom(ggplot2,Geom)
importFrom(ggplot2,GeomPoint)
importFrom(ggplot2,GeomSegment)
Expand Down
56 changes: 56 additions & 0 deletions R/et-book.R
@@ -0,0 +1,56 @@
#' Import ET Book font for use in plots
#'
#' There is an option `ggtufte.loadfonts` which -- if set to `TRUE` -- will
#' call `extrafont::loadfonts()` to register non-core fonts with R PDF & PostScript
#' devices. If you are running under Windows, the package calls the same function
#' to register non-core fonts with the Windows graphics device.
#'
#'

#' @md
#' @note This will take care of ensuring PDF/PostScript usage. The location of the
#' font directory is displayed after the base import is complete. It is highly
#' recommended that you install them on your system the same way you would any
#' other font you wish to use in other programs.
#' @references <https://edwardtufte.github.io/et-book/>
#' @source <https://github.com/edwardtufte/et-book>
#' @export
import_et_book <- function() {
# function adapted from hbrthemes::import_roboto_condensed
font_dir <- system.file("fonts", package = "ggtufte")

suppressWarnings(suppressMessages(extrafont::font_import(font_dir,
prompt = FALSE)))
message(
sprintf(
paste0("You will likely need to install these fonts on your ",
"system as well.",
"\n\nYou can find them in [%s]"),
font_dir)
)

}

#' ET Book fonts
#'
#' ET Book (ETBembo font-family) comprises five fonts:
#'
#' - `"ETBembo RomanLF"`: Roman (lining figures)
#' - `"ETBembo RomanOSF"`: Roman (oldstyle figures)
#' - `"ETBembo SemiBoldOSF"`: Semi-bold (oldstyle figures)
#' - `"ETBembo BoldLF"`: Bold (lining figures)
#' - `"ETBembo DisplayItalic"`: Display Italic (oldstyle figures)
#'
#' @md
#' @title ET Book fonts R variable aliases
#' @format length 5 character vector. Values are the
#' font names, and names are the description of the font.
#' @rdname ETBembo
#' @export
#' @examples
#' font_et
font_et <- c("Roman (line figures)" = "ETBembo RomanLF",
"Roman (old-style figures)" = "ETBembo RomanOSF",
"Bold (line figures)" = "ETBembo BoldLF",
"Semi-bold (old-style figures)" = "ETBembo SemiBoldOSF",
"Display italic" = "ETBembo DisplayItalic")
23 changes: 21 additions & 2 deletions R/tufte.R
Expand Up @@ -24,8 +24,9 @@
#' @example examples/ex-theme_tufte.R
#' @export
#' @importFrom ggplot2 theme element_blank theme_bw
theme_tufte <- function(base_size = 11, base_family = "serif", ticks = TRUE) {
## TODO: start with theme_minimal
theme_tufte <- function(base_size = 11,
base_family = extrafont::choose_font(ggtufte::tufte_theme_fonts),
ticks = TRUE) {
ret <- theme_bw(base_family = base_family, base_size = base_size) +
theme(legend.background = element_blank(),
legend.key = element_blank(),
Expand All @@ -40,3 +41,21 @@ theme_tufte <- function(base_size = 11, base_family = "serif", ticks = TRUE) {
}
ret
}

#' Font options to use with the Tufte Theme
#'
#' List of font or font-families to use with \code{theme_tufte}.
#' It starts with the preferred ETBembo font used in Tufte's book along with
#' fallback options.
#'
#' This list is derived from the list of fonts used in
#' [https://github.com/edwardtufte/tufte-css](tufte-css)
#'
#' @md
#' @format A character vector.
#' @export
#' @examples
#' tufte_theme_fonts
tufte_theme_fonts <-
c("ETBembo RomanLF", "Palatino", "Palatino Linotype", "Palatino LT STD",
"Book Antiqua", "Georgia", "serif")
25 changes: 25 additions & 0 deletions R/zzz.R
@@ -0,0 +1,25 @@
# adapted from hrbrthemes zzz.R
.onAttach <- function(libname, pkgname) {
# nocov start
if (.Platform$OS.type == "windows") { # nocov start
if (interactive()) {
packageStartupMessage("Registering Windows fonts with R")
}
extrafont::loadfonts("win", quiet = TRUE)
}

if (getOption("ggtufte.loadfonts", default = FALSE)) {
if (interactive()) {
packageStartupMessage("Registering PDF & PostScript fonts with R")
}
extrafont::loadfonts("pdf", quiet = TRUE)
extrafont::loadfonts("postscript", quiet = TRUE)
}

fnt <- extrafont::fonttable()
if (!any(grepl("ETBembo", fnt$FamilyName))) {
packageStartupMessage("NOTE: The ET Book fonts are required to use this theme.")
packageStartupMessage(" Please use ggtufte::import_et_book() to install the ET Book fonts.")
} # nocov end

}
2 changes: 2 additions & 0 deletions examples/ex-geom_rangeframe.R
@@ -1,4 +1,6 @@
library("ggplot2")
library("extrafont")
extrafont::loadfonts()

ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
Expand Down
2 changes: 2 additions & 0 deletions examples/ex-geom_tufteboxplot.R
@@ -1,4 +1,6 @@
library("ggplot2")
library("extrafont")
extrafont::loadfonts()

p <- ggplot(mtcars, aes(factor(cyl), mpg))
# with a point for the median and lines for whiskers
Expand Down
2 changes: 2 additions & 0 deletions examples/ex-theme_tufte.R
@@ -1,4 +1,6 @@
library("ggplot2")
library("extrafont")
extrafont::loadfonts()

p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
Expand Down
4 changes: 4 additions & 0 deletions ggtufte.Rproj
Expand Up @@ -13,3 +13,7 @@ RnwWeave: Sweave
LaTeX: pdfLaTeX

StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
13 changes: 13 additions & 0 deletions inst/COPYRIGHTS
@@ -0,0 +1,13 @@
All R source code files are released under the MIT license.

-----------------------------

ET Book font has the following license/copyright:

Copyright (c) 2015 Dmitry Krasny, Bonnie Scranton, Edward Tufte.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 changes: 14 additions & 0 deletions inst/WORDLIST
Expand Up @@ -17,3 +17,17 @@ quartile
tufte
Tufte
Tufte's
ETBembo
VignetteEncoding
VignetteEngine
VignetteIndexEntry
css
edwardtufte
github
https
knitr
natbib
rmarkdown
sidenotes
xelatex
oldstyle
Binary file not shown.
Binary file added inst/fonts/et-book-roman-old-style-figures.ttf
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions man/ETBembo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/geom_rangeframe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/geom_tufteboxplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/import_et_book.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/theme_tufte.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions man/tufte_theme_fonts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d678c5

Please sign in to comment.