Skip to content

Commit 62e44ee

Browse files
committed
fix a few more typos
1 parent 532e98b commit 62e44ee

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

content/blog/fonts-in-r/index.Rmd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ library(ggplot2)
6868

6969
(An updated version of this blog post will be available at [the systemfonts webpage](https://systemfonts.r-lib.org))
7070

71-
The purpose of this document is to give you the a thorough overview of fonts in R. However, for this to be possible, you'll first need a basic understanding of fonts in general. If you already have a thorough understanding of digital typography you can skip to [the next section](#font-handling-in-r).
71+
The purpose of this document is to give you a thorough overview of fonts in R. However, for this to be possible, you'll first need a basic understanding of fonts in general. If you already have a thorough understanding of digital typography you can skip to [the next section](#font-handling-in-r).
7272

7373
## Digital typography
7474

@@ -80,7 +80,7 @@ There is a good chance that you, like 99% of world, use "font" as the term descr
8080

8181
When most people use the word "font" or "font family", what they are actually describing is a typeface. A **typeface** is a style of lettering that forms a cohesive whole. As an example, consider the well-known "Helvetica" typeface. This name embraces many different weights (bold, normal, light) as well as slanted (italic) and upright. However, all of these variations are all as much Helvetica as the others - they are all part of the same typeface.
8282

83-
A **font** is a subset of a typeface, describing a particular variation of the typeface, i.e. the combination of typeface, weight, width, and slant that comes together to describe the specific subset of a typeface that is used. We typically give a specific combination of these features a name, like "bold" or "medium" or "italic", which we call the **font style**[^1]. In other words, a font is a particularly style within a typeface.
83+
A **font** is a subset of a typeface, describing a particular variation of the typeface, i.e. the combination of weight, width, and slant that comes together to describe the specific subset of a typeface that is used. We typically give a specific combination of these features a name, like "bold" or "medium" or "italic", which we call the **font style**[^1]. In other words, a font is a particularly style within a typeface.
8484

8585
[^1]: Be aware that the style name is at the discretion of the developer of the typeface. It is very common to see discrepancies between the style name and e.g. the weight reported by the font (e.g. Avenir Next Ultra Light is a *thin* weight font).
8686

@@ -112,13 +112,13 @@ In the rest of this document we will use the terms typeface and font with the me
112112
Next, we need to talk about how typefaces are represented for use by computers. Font files record information on how to draw the individual glyphs (characters), but also instructions about how to draw sequences of glyphs like distance adjustments (kerning) and substitution rules (ligatures). Font files typically encode a single font but can encode a full typeface:
113113

114114
```{r}
115-
typefaces <- systemfonts::system_fonts()
115+
typefaces <- systemfonts::system_fonts()[, c("path", "index", "family", "style")]
116116
117117
# Full typeface in one file
118-
typefaces[typefaces$family == "Helvetica", c("path", "index", "family", "style")]
118+
typefaces[typefaces$family == "Helvetica", ]
119119
120120
# One font per font file
121-
typefaces[typefaces$family == "Arial", c("path", "index", "family", "style")]
121+
typefaces[typefaces$family == "Arial", ]
122122
```
123123

124124
Here, each row is a font, with **family** giving the name of the typeface, and **style** the font style.
@@ -137,7 +137,7 @@ While we have mainly talked about font files as containers for the shape of glyp
137137
dplyr::glimpse(systemfonts::font_info(family = "Helvetica"))
138138
```
139139

140-
As well as a bunch of information about individual glyphs, Further, for each glyph there is a range of information in addition to its shape:
140+
Further, for each glyph there is a range of information in addition to its shape:
141141

142142
```{r}
143143
systemfonts::glyph_info("j", family = "Helvetica", size = 30)
@@ -154,9 +154,9 @@ The `x_advance` in particular is important when rendering text because it tells
154154

155155
### Text shaping {#text-shaping}
156156

157-
The next important concept to understand is **text shaping**, which, in the simplest of terms, is to convert a succession of characters into sequence of glyphs along with their locations. Important here is the distinction between **characters**, the things you think of as letters, and **glyphs**, which is what the font will draw. For example, think of the character "f", which is often tricky to draw because the "hook" of the f can interfere with other characters. To solve this problem, many typefaces include **ligatures**, like "fi", which are used for specific pairs of characaters. Ligatures are extremely important for languages like Arabic.
157+
The next important concept to understand is **text shaping**, which, in the simplest of terms, is to convert a succession of characters into a sequence of glyphs along with their locations. Important here is the distinction between **characters**, the things you think of as letters, and **glyphs**, which is what the font will draw. For example, think of the character "f", which is often tricky to draw because the "hook" of the f can interfere with other characters. To solve this problem, many typefaces include **ligatures**, like "fi", which are used for specific pairs of characaters. Ligatures are extremely important for languages like Arabic.
158158

159-
Just a few of the challenges of text shaping include kerning, bidirectional text, and font substitution. **Kerning**, which controls the distance between specific pairs of characters. For example, you can put "VM" a little closer together but "OO" needs to be a little further apart. Kerning is an integral part of all modern text rendering and you will almost solemnly notice it when it is absent (or worse, [wrongly applied](https://www.fastcompany.com/91324550/kerning-on-pope-francis-tomb-is-a-travesty)).
159+
A few of the challenges of text shaping include kerning, bidirectional text, and font substitution. **Kerning** is the adjustment of distance between specific pairs of characters. For example, you can put "VM" a little closer together but "OO" needs to be a little further apart. Kerning is an integral part of all modern text rendering and you will almost solemnly notice it when it is absent (or worse, [wrongly applied](https://www.fastcompany.com/91324550/kerning-on-pope-francis-tomb-is-a-travesty)).
160160

161161
Not every language writes text in the same direction, but regardless of your native script, you are likely to use arabic numerals which are always written left-to-right. This gives rise to the challenge of **bidirectional** (or bidi) text, which mixes text flowing in different directions. This imposes a whole new range of challenges!
162162

@@ -212,9 +212,9 @@ This means that it is up to the graphics device to find the approprate font file
212212

213213
There have been a number of efforts to resolve these problems over the years:
214214

215-
- **extrafont**: Developed by Winston Chang, [extrafont](https://github.com/wch/extrafont) sought to mainly improve the situation for the `pdf()` device which generally only had access to the postscript fonts that comes with R. The package allows the `pdf()` device to get access to TrueType fonts installed on the computer, as well as provide means for embedding the font into the PDF so that it can be opened on systems where the font is not installed. (It also provides the capabilities to to the Windows `png()` device).
215+
- **extrafont**: Developed by Winston Chang, [extrafont](https://github.com/wch/extrafont) sought to mainly improve the situation for the `pdf()` device which generally only had access to the postscript fonts that comes with R. The package allows the `pdf()` device to get access to TrueType fonts installed on the computer, as well as provide means for embedding the font into the PDF so that it can be opened on systems where the font is not installed. (It also provides the capabilities to the Windows `png()` device).
216216

217-
- **sysfonts** and **showtext**. These packages are developed by Yixuan Qiu and provide support for system fonts to all graphics devices, by hijacking the `text()` method of the graphics device to text text as polygons or raster images. This guarantees your plots will look the same on every device, but it doesn't do advanced text shaping, so there's no support for ligatures or font substituion. Additionally, it produces large files with inaccessible text when used to produce pdf and svg outputs.
217+
- **sysfonts** and **showtext**. These packages are developed by Yixuan Qiu and provide support for system fonts to all graphics devices, by hijacking the `text()` method of the graphics device to treat text as polygons or raster images. This guarantees your plots will look the same on every device, but it doesn't do advanced text shaping, so there's no support for ligatures or font substitution. Additionally, it produces large files with inaccessible text when used to produce pdf and svg outputs.
218218

219219
- **systemfonts** and **textshaping**. These packages are developed by me to provide a soup-to-nuts solution to text rendering for graphics devices. [systemfonts](https://systemfonts.r-lib.org) provides access to fonts installed on the system along with font fallback mechanisms, registration of non-system fonts, reading of font files etc. [textshaping](https://github.com/r-lib/textshaping) builds on top of systemfonts and provides a fully modern engine for shaping text. The functionality is exposed both at the R level and at the C level, so that graphics devices can directly access to font lookup and shaping.
220220

@@ -339,7 +339,7 @@ grid::grid.text(
339339

340340
### Fonts from other places
341341

342-
Historically, systemfonts primary role was to access the font installed on your computer, the **system fonts**. But what if you're using a computer where you don't have the rights to install new fonts, or you don't want the hassle of installing a font just to use it for a single plot? That's the problem solved by `systemfonts::add_font()` which makes it easy to use a font based on a path. But in many cases you don't even need that as systemfont now scans `./fonts` and `~/fonts`. This means that you can put personal fonts in a fonts folder in your home directory, and project fonts in a fonts directory at the root of the project. This is a great way to ensure that specific fonts are available when you deploy some code to a server.
342+
Historically, systemfonts primary role was to access the font installed on your computer, the **system fonts**. But what if you're using a computer where you don't have the rights to install new fonts, or you don't want the hassle of installing a font just to use it for a single plot? That's the problem solved by `systemfonts::add_font()` which makes it easy to use a font based on a path. But in many cases you don't even need that as systemfont now scans `./fonts` and `~/fonts` and adds any font files it find. This means that you can put personal fonts in a fonts folder in your home directory, and project fonts in a fonts directory at the root of the project. This is a great way to ensure that specific fonts are available when you deploy some code to a server.
343343

344344
And you don't even need to leave R to populate these folders. `systemfonts::get_from_google_fonts()` will download and install a google font in `~/fonts`:
345345

@@ -369,7 +369,7 @@ By default, `require_font()` places new fonts in a temporary folder so it doesn'
369369

370370
### Font embedding in SVG
371371

372-
Fonts work a little differently in vector formats like SVG. These formats include the raw text and only render the font when you open the file. This makes for small, accessible files with crisp text at every every level of zoom. But it comes with a price: since the text is rendered when it's opened, it relies on the font in use being available on the viewer's computer. This obviously puts you at the mercy of their font selection, so if you want consistent outputs you'll need to **embed** the font.
372+
Fonts work a little differently in vector formats like SVG. These formats include the raw text and only render the font when you open the file. This makes for small, accessible files with crisp text at every level of zoom. But it comes with a price: since the text is rendered when it's opened, it relies on the font in use being available on the viewer's computer. This obviously puts you at the mercy of their font selection, so if you want consistent outputs you'll need to **embed** the font.
373373

374374
In SVG, you can embed fonts using an `@import` statement in the stylesheet, and can point to a web resource so the SVG doesn't need to contain the entire font. systemfonts provides facilities to generate URLs for import statements and can provide them in a variety of formats:
375375

0 commit comments

Comments
 (0)