the typefaces
This has moved around a bit. I’m content that it deserves its own document, but I’m not 100% sure about its name. But the little bit that doesn’t have to do with typefaces, is rather out of scope. But right now there’s no other section for typography/typesetting.
A lot of this site is about putting words in front of people. Here we give typography some special consideration as it relates to the web platform.
1 text
Here we set a standard reading width and provide a couple of other mixins for controlling the presentation of text.
$readingRems = 50rem
clip-text()
white-space nowrap
overflow hidden
text-overflow ellipsis
compact-spacing()
letter-spacing -.04em
2 fonts
font (n.2)
"complete set of characters of a particular face and size of type,” 1680s (also fount), earlier “a casting” (1570s), from Middle French fonte “a casting,” noun use of fem. past participle of fondre “to melt” (see found (v.2)). So called because all the letters in a given set were cast at the same time.
2.1 level 1 : font families
Most of what willshake has to offer is text. What we add to that—structure and guidance—also comes in the form of words. We can use typefaces in a significant way to communicate a difference between these different types of text. Here we describe how we use font “families” to distinguish essentially “architectural” lettering from printed work.
The concept of font families has its roots in the art of typography, which in turn took its first cues from calligraphy. What we now call “serif” fonts (those whose characters feature “finishing strokes, flared or tapering ends"1), trace their origin to the earliest typefaces, which naturally maintained continuity with the traditional style of hand-writing. Only much later—and originating in the realm of architecture, not print—could letterforms be abstracted from their manual origins, leading to the more geometric and minimalist typefaces that we now call sans serif. “These ‘sanserif’ letters,” writes James Mosley,
appeared in the drawings of English architects like John Soane, they began to be used by some sculptors too, and then they were taken up by signwriters.
We will use “sans” type according with this history, using it for our signs and messages, while “serif” fonts will be used for the work of other authors, whether in extracts or long form.
2.1.1 technique
So, how do we do it?
In 1996, the web got its first official specification for font selection, as
part of “CSS Level 1"2. Bert Bos, who co-authored the proposal for
the World Wide Web Consortium, describes the rationale in his talk “The history
of a model for fonts on the Web” [Bos]. Because networks at the time would take
too long to download entire typefaces—and because there was no common format
anyway—the group settled on a set of font families as a way for authors to
specify their general intent. It was up to the browser to choose an available
font that best matched the family indicated, which was done by using the
font-family
property (essentially unchanged in CSS levels 2 and 3).
What should we call the “paper” font?
The term “body” font makes no sense. It’s a vestige of old thinking. Maybe it should be “space” font? Something more consistent with the way that we talk about it here.
“Book” font is less bad but I’m still taking suggestions.
$bodyFontFamily = "'Lato', 'Open Sans', Verdana, Helvetica, Arial, sans-serif"
$bookFontFamily = "'TeX Gyre Schola', Georgia, serif"
$paperFontFamily = "'IM Fell DW Pica'," + $bookFontFamily
body-font()
font-family s($bodyFontFamily)
book-font()
font-family s($bookFontFamily)
paper-font()
font-family s($paperFontFamily)
For these to take effect, they have to be referenced. We’ll set the default to our font:
@import fonts
body
body-font()
2.2 level 2 : web fonts
In the “old days” of CSS level 1, the web still didn’t have much to offer in the
way of typefaces. Browsers could use whatever fonts were available on the
system, and authors could select from these by name or family; but other fonts
could not be provided for use by the site. It was not until CSS Level 2
introduced the @font-face
rule, along with a few standard font formats, that
authors had a way to provide typefaces themselves along with their
content3. (Although @font-face
became an official
recommendation in 1998, it was at least ten years before the web fonts were
widely adopted.)
Talk about this code and the fonts, where they came from, etc.
We have to ship the fonts:
: foreach $(ROOT)/assets/fonts/* \
|> !link_from \
|> $(SITE_STYLE)/fonts/%b
This symlinks the files to the site folder in the expected place. A symlink is sufficient in this case because these files are not going to change.
Note that two of the license files thus copied were renamed so that they would not include spaces, which Tup doesn’t allow.
$loadAllWeights = false
font-weight(w)
font-weight: w
if w == 400
font-weight: normal
if w == 700
font-weight: bold
font(family, file, weight = 400, style = normal)
$base = "fonts/" + file
@font-face
font-family family
src url($base + '.eot')
src: url($base + '.eot?#iefix') format('embedded-opentype'),
url($base + '.svg#' + file) format('svg'),
url($base + '.woff') format('woff'),
url($base + '.ttf') format('truetype');
font-weight weight
font-style style
// Part of the attempt to deal with bad web font rendering on Windows Chrome
@media screen and (-webkit-min-device-pixel-ratio:0)
@font-face
font-family family
src url($base + '.svg#' + file) format('svg')
font-weight weight
font-style style
font('IM Fell DW Pica', 'IMFellDWPicaBasic-Regular')
font('IM Fell DW Pica', 'IMFellDWPicaBasic-Italic', style: italic)
font('TeX Gyre Schola', 'TexGyreSchola-Regular')
font('TeX Gyre Schola', 'TexGyreSchola-Bold', bold)
font('TeX Gyre Schola', 'TexGyreSchola-Italic', style: italic)
font('TeX Gyre Schola', 'TexGyreSchola-BoldItalic', bold, italic)
lato(variant, weight)
$regular = (variant == 'Bold') ? '' : '-Regular'
$prefix = 'LatoLatin' + (variant == '' ? '' : '-') + variant
font('Lato', $prefix + $regular, weight: weight)
font('Lato', $prefix + '-Italic', weight: weight, style: italic)
lato('Hair' , 100) if $loadAllWeights
// Right... so why not specify 300 for light instead of 200? I think 300 is
// what you mean. Fira 200 is also light, and that's in fact what you get on FF
// Mobile if you don't load web fonts.
//
// While you're at it, make a light-weight construct with Stylus so you can
// change this in one place.
lato('Light', 200) // "Thin" is the Lato 200, but it's too thin
lato('Light', 300) if $loadAllWeights
lato('' , 400)
lato('Med' , 500) if $loadAllWeights
lato('SemBd', 600) if $loadAllWeights
lato('Bold' , 700)
lato('ExtBd', 800) if $loadAllWeights
lato('Black', 900) if $loadAllWeights
This is written to its own stylesheet bundle (font-face-rules
), allowing it to
be used independently by SVG graphics wishing to use these fonts, simply by
referencing it.
This is needed for the program graph, as long as I’m not bundling the
stylesheets. See also document-graph-rules.css
: $(CSS)/font-face-rules.css \
|> !copy_to |> $(SITE_STYLE)/%b
3 issues
3.1 on loading speed
Last I checked, the fonts were by far the largest share of a cold start (byte-wise). I’ve already subsetted Lato, but somewhat cursorily.
http://www.sitepoint.com/improving-font-performance-subsetting-local-storage/
3.2 TODO consider falling back to native fonts on mobile
I’m pretty attached to Lato. But the fonts are currently by far the largest part of a cold download. And mobile devices (especially lower-resolution (i.e. non-retina)) tend to ship with an optimized font set built in.
4 colophon
This scrap is from an old test page for typeface weights. At some point I’ll do a proper “colophon” that talks about the choice of Lato, Tex Gyre Schola, and IM Fell, whilst illustrating their beauty.
.ps {
background: white;
border-radius: 2px;
padding: 1em;
display: inline-block;
font-size: 200%;
max-width: 10.5em;
margin-right: 2em;
margin-bottom: 2em;
--border-left: 1px solid blue;
--border-right: 1px solid blue;
}
.p {
margin: 0;
text-align: justify;
/* -moz-text-align-last: justify; */ /* working around, see below */
/* -moz-text-justify: distribute; */ /* doesn't exist */
height: 1.2em;
overflow: hidden;
}
.t {
white-space: nowrap;
}
/* Simulate effect of text-align-last: justify */
.p:after {
content: '';
display: inline-block;
width: 40em;
}
.p1 { font-weight: 100; font-size: 200%; height: 1.1em; line-height: 1.1; }
.p2 { font-weight: 200; font-size: 110%; line-height: 1; height: 2.1em; padding-top: .15em; letter-spacing: .04em; }
.p3 { font-weight: 300; letter-spacing: .1em; }
.p4 { font-weight: 400; }
.p5 { font-weight: 500; height: 1em; line-height: 1; }
.p6 { font-weight: 600; font-size: 150%; }
.p7 { font-weight: 700; font-size: 150%; letter-spacing: .15em; }
.p8 { font-weight: 800; }
.p9 { font-weight: 900; font-size: 133%; }
<div class="ps">
<p class="p p4"><span class="t t1">“To be or not to be”</span></p>
<p class="p p8"><span class="t t1">“my second-best bed”</span></p>
<p class="p p2"><span class="t t1">Shall I compare thee</span> <span class="t t2">to a summer’s day?</span></p>
<p class="p p7"><span class="t t1">Dr. Johnson</span></p>
<p class="p p3"><span class="t t1">the balcony scene</span></p>
<p class="p p9"><span class="t t1">the Scottish play</span></p>
<p class="p p1"><span class="t t1">Shakespeare</span></p>
<p class="p p5"><span class="t t1">The Globe theater</span></p>
<p class="p p6"><span class="t t1">the First Folio</span></p>
</div>
<div class="ps">
<p class="p" style="font-weight: 100;">Weight 100</p>
<p class="p" style="font-weight: 200;">Weight 200</p>
<p class="p" style="font-weight: 300;">Weight 300</p>
<p class="p" style="font-weight: 400;">Weight 400</p>
<p class="p" style="font-weight: 500;">Weight 500</p>
<p class="p" style="font-weight: 600;">Weight 600</p>
<p class="p" style="font-weight: 700;">Weight 700</p>
<p class="p" style="font-weight: 800;">Weight 800</p>
<p class="p" style="font-weight: 900;">Weight 900</p>
</div>
5 Appendix : An old webkit hack to deal with Chrome’s web font rendering on Windows
The following “text stroke” hack was used to help with bad web font rendering in Chrome for Windows4. As of Chrome 37 (which uses “DirectWrite”), web font rendering is substantially improved, and this hack has the opposite effect, of making good text look bad. So currently, this would only help Chrome for Windows users who have turned off automatic updates (in which case they get what they asked for); as such, I am turning it off. This hack does still help the same issue with Opera for Windows (though note that, as it is limited to web fonts, it makes installed fonts look worse). But detecting that condition would have to be done in script.
body {
-webkit-text-stroke .5px
}
6 Bibliography
- Bos, Bert, “The history of a model for fonts on the Web.” SXSW conference. March 13, 2010. http://www.w3.org/Talks/2010/0313-Fonts-SXSW/
- Mosley, James, “The Nymph and the Grot, an update.” Typefoundry: documents for the history of type and letterforms. (blog). January 6, 2007. http://typefoundry.blogspot.com/2007/01/nymph-and-grot-update.html