| 1 |
|
| 2 |
\chapter{Junicode on the Web}\hypertarget{OnTheWeb}{} |
| 3 |
%\fancyhead[CE]{\scshape\color{myRed} {\addfontfeatures{Numbers=OldStyle}\thepage}\hspace{10pt}on the web} |
| 4 |
|
| 5 |
If you are using Junicode on a web page, you should prefer the variable fonts |
| 6 |
(those with “VF” in the family name and filename) to the static fonts. One |
| 7 |
variable font file can do the work of many traditional font files. For example, |
| 8 |
the \href{https://psb1558.github.io/Junicode-font/Junicode-2-feature-test.html}% |
| 9 |
{Test of High-Level CSS Properties} web page displays Junicode in regular, |
| 10 |
bold and semicondensed styles. It used |
| 11 |
to be that your user would have to download three font files, one for each |
| 12 |
style, but one variable font will display all three. |
| 13 |
|
| 14 |
But you may be thinking, \textit{That font is big}! It's true: even the |
| 15 |
compressed webfont (.woff2) is nearly a megabyte in size—enough to seriously |
| 16 |
slow down the loading of a web page. |
| 17 |
|
| 18 |
To solve this problem, you'll need to subset the font—that is, produce a copy |
| 19 |
that contains only what you need. The subsetted font that downloads |
| 20 |
with the property test web page |
| 21 |
is approximately 275k in size—almost thirty percent of the |
| 22 |
size of the full webfont. It's still a pretty big download, but that's because the page |
| 23 |
displays a lot of the font's features. If I were displaying, say, a diplomatic |
| 24 |
transcript of a Latin text, the font would be much smaller. |
| 25 |
|
| 26 |
So the first section of this chapter will talk about how to subset the Junicode |
| 27 |
font. |
| 28 |
|
| 29 |
\section{Subsetting Junicode} |
| 30 |
|
| 31 |
First the legalities. It is perfectly all right to create a modified version |
| 32 |
of Junicode via subsetting, compress it into a webfont (almost certainly in |
| 33 |
woff2 format), and host it on your web server. This is because “Junicode” is |
| 34 |
not a “Reserved Font Name” (which complicates web use of |
| 35 |
many fonts licensed under the Open Font License). If you are nevertheless nervous about the |
| 36 |
legal requirements of the Open Font License, you can change the font name to |
| 37 |
something arbitrary with the \texttt{--obfuscate-names} option |
| 38 |
of the pyftsubset program, and you can embed the Open Font License, or a |
| 39 |
link to it, in your CSS. These steps should settle any ambiguity about whether |
| 40 |
you are in compliance with the license. |
| 41 |
|
| 42 |
Generating a subsetted version of Junicode should be one of the last tasks you |
| 43 |
perform before deploying your web page(s). Until then, it is recommended that |
| 44 |
you work with the unmodified font. After subsetting, review your |
| 45 |
pages thoroughly to make sure everything is displayed properly. If you have |
| 46 |
forgotten to include a glyph in your subsetted font, you will see little boxes |
| 47 |
where characters should be or, perhaps, the correct characters |
| 48 |
displayed in the wrong typeface. If you have omitted features, you will see |
| 49 |
default instead of transformed characters. |
| 50 |
|
| 51 |
There are many subsetting programs, some online and very easy to use. But for |
| 52 |
maximum control (and thus the smallest fonts), you should choose pyftsubset, a |
| 53 |
part of the \href{https://github.com/fonttools/fonttools}{fontTools} library, |
| 54 |
which runs under Python 3.7 or higher. This is a command-line tool which |
| 55 |
takes a long list of arguments; you should create a shell script to run it. |
| 56 |
|
| 57 |
Here is the script used to create the subsetted font for the property test |
| 58 |
web page mentioned above: |
| 59 |
|
| 60 |
\small\begin{verbatim} |
| 61 |
#!/bin/zsh |
| 62 |
pyftsubset JunicodeVF-Roman.ttf \ |
| 63 |
--flavor=woff2 --output-file=JunicodeVFsubset.woff2 \ |
| 64 |
--recommended-glyphs \ |
| 65 |
--text="jq" --text-file=Junicode-2-feature-test.html \ |
| 66 |
--layout-features+=liga,ss01,ss02,ss03,ss04,ss05,ss06,ss07,ss08,\ |
| 67 |
ss10,ss12,ss13,ss14,ss15,ss16,ss17,ss18,ss19,ss20,cv01,cv02,cv05,\ |
| 68 |
cv06,cv07,cv08,cv09,cv10,dlig,hlig,onum,pnum,pcap,smcp,c2sc,subs,\ |
| 69 |
sups,zero \ |
| 70 |
--layout-features-=rlig |
| 71 |
\end{verbatim} |
| 72 |
|
| 73 |
\normalsize\noindent For those unfamiliar with shell scripts, the first line specifies the shell |
| 74 |
the script is to run under (in this case the default shell for Mac OS, but |
| 75 |
\texttt{bash} is another possible choice), and the backslashes mean |
| 76 |
that the command continues on the next line. The rest of the file is a list |
| 77 |
of arguments passed to pyftsubset. Let's walk through them. |
| 78 |
|
| 79 |
First after the program name comes the name of the unsubsetted, uncompressed |
| 80 |
font file. After that, |
| 81 |
the \texttt{--flavor} argument tells the program that you want a webfont in |
| 82 |
woff2 format, and \texttt{--output} is the name of the font file you want the |
| 83 |
program to save. |
| 84 |
|
| 85 |
Having taken care of this preliminary business, we tell pyftsubset what we |
| 86 |
want the font to contain. |
| 87 |
|
| 88 |
\texttt{--recommended-glyphs} includes a few characters that |
| 89 |
every font should have, according to the OpenType specification---though in |
| 90 |
fact modern browsers don't care. It's best, however, to conform to the specification, |
| 91 |
since it's impossible to say with absolute certainty that no program will |
| 92 |
ever reject the font |
| 93 |
because of the absence of these few characters. |
| 94 |
|
| 95 |
\texttt{--text-file} is the name of a file to treat as a list of characters |
| 96 |
that \textit{must} be included in the font. In this case I have simply used |
| 97 |
the html file for the web page for this purpose. If your site contains |
| 98 |
multiple web pages, your job will be more complicated. You must make sure the |
| 99 |
text file contains all the characters used on the site---either that or |
| 100 |
supplement the text file with a \texttt{--text} argument (which here adds |
| 101 |
two lowercase letters that don't appear in the web page---just in case). |
| 102 |
The text file will |
| 103 |
contain only encoded characters—you don't have to worry here about unencoded |
| 104 |
characters produced by OpenType features. |
| 105 |
|
| 106 |
\texttt{--layout-features+} tells the program which OpenType features you |
| 107 |
want to retain in the font. All others, except for the |
| 108 |
\hyperlink{req}{Required Features}, are discarded. All of the characters |
| 109 |
referenced in these features will also be included in the output file, as long |
| 110 |
as those characters are variants of characters in your text file. For example, |
| 111 |
the \textSourceText{smcp}\index{smcp} (Small Caps) feature has many more small caps than there are letters |
| 112 |
of the alphabet, but most of them are not included in the subsetted font. The |
| 113 |
program's parsimony with characters keeps the font file as small as possible. |
| 114 |
Note that some features are included automatically: \textSourceText{ccmp}\index{ccmp}, |
| 115 |
\textSourceText{locl}\index{locl}, \textSourceText{calt}\index{calt}, |
| 116 |
\textSourceText{liga}\index{liga}, \textSourceText{rlig}\index{rlig}, |
| 117 |
\textSourceText{kern}\index{kern}, \textSourceText{mark}\index{mark}, |
| 118 |
and \textSourceText{mkmk}\index{mkmk}. |
| 119 |
|
| 120 |
|
| 121 |
\texttt{--layout-features-} tells the program which OpenType features to omit. |
| 122 |
Normally, \textSourceText{rlig} (Required Ligtures) is automatically |
| 123 |
included in fonts by pyftsubset, but as it has no relevance to this web page, |
| 124 |
it can be omitted. |
| 125 |
|
| 126 |
These are the most useful arguments, but there are many more. Type |
| 127 |
\texttt{pyftsubset --help} for a complete list. Once you have written your |
| 128 |
script, run it (in Mac OS or Linux you need to make the file executable |
| 129 |
by typing \texttt{chmod +x mysubsetscript} on the command line). |
| 130 |
|
| 131 |
Before you put your subsetted font to work, check it carefully in a program |
| 132 |
like \href{https://github.com/justvanrossum/fontgoggles}{FontGoggles}, |
| 133 |
which lets you preview the font and test all its OpenType features. If you |
| 134 |
find errors, revise your script and run it again. |
| 135 |
|
| 136 |
\section{Junicode and CSS/HTML} |
| 137 |
|
| 138 |
This section assumes a basic knowledge of HTML (Hypertext Markup Language, used |
| 139 |
to construct web pages) and CSS (Cascading Style Sheets, used to format them). |
| 140 |
If you want to learn about these subjects, the number of good books and online |
| 141 |
tutorials is so great that it makes no sense to try to list them. Just make sure |
| 142 |
that the instructional materials you choose are of recent vintage, because the |
| 143 |
relevant standards are always changing. |
| 144 |
|
| 145 |
In the CSS for your web page, the \texttt{@font-face} at-rule for a variable |
| 146 |
font is a little different |
| 147 |
from the one for a static font in that the range of possible values for each |
| 148 |
axis can be declared: |
| 149 |
|
| 150 |
\small\begin{verbatim} |
| 151 |
@font-face { |
| 152 |
font-family: "Junicode VF"; |
| 153 |
src: url("./webfiles/JunicodeVFsubset.woff2"); |
| 154 |
font-weight: 300 700; |
| 155 |
font-stretch: 75% 125%; |
| 156 |
font-style: normal; |
| 157 |
} |
| 158 |
\end{verbatim} |
| 159 |
|
| 160 |
\normalsize\noindent These ranges are not strictly necessary, but they will prevent your |
| 161 |
supplying invalid values for \texttt{font-weight} and \texttt{font-stretch} |
| 162 |
(that is, \texttt{width}) in other CSS rules. |
| 163 |
|
| 164 |
Once you have declared the font, you can invoke it in setting up classes. |
| 165 |
For example: |
| 166 |
|
| 167 |
\small\begin{verbatim} |
| 168 |
body { |
| 169 |
font-family: "Junicode VF"; |
| 170 |
font-size: 28px; |
| 171 |
font-weight: normal; /* that is, 400 */ |
| 172 |
font-stretch: 112.5%; /* that is, semiexpanded */ |
| 173 |
} |
| 174 |
h1 { |
| 175 |
font-family: "Junicode VF"; |
| 176 |
font-size: 125%; |
| 177 |
font-weight: 600; /* that is, semibold */ |
| 178 |
font-stretch: 112.5%; /* that is, semiexpanded */ |
| 179 |
} |
| 180 |
.annotation { |
| 181 |
font-size: 90%; |
| 182 |
font-weight: 300; /* that is, light */ |
| 183 |
font-stretch: 87.5%; /* that is, semicondensed */ |
| 184 |
} |
| 185 |
\end{verbatim} |
| 186 |
|
| 187 |
\normalsize\noindent These classes should be tested in all browsers. If any fail to |
| 188 |
display text properly, you can use \texttt{font-variation-settings} |
| 189 |
instead of the high-level \texttt{font-weight} and \texttt{font-stretch}: |
| 190 |
|
| 191 |
\small\begin{verbatim} |
| 192 |
body { |
| 193 |
font-family: "Junicode VF"; |
| 194 |
font-size: 28px; |
| 195 |
font-variation-settings: "wght" 400, "wdth" 112.5; |
| 196 |
} |
| 197 |
h1 { |
| 198 |
font-family: "Junicode VF"; |
| 199 |
font-size: 125%; |
| 200 |
font-variation-settings: "wght" 600, "wdth" 112.5; |
| 201 |
} |
| 202 |
.annotation { |
| 203 |
font-size: 90%; |
| 204 |
font-variation-settings: "wght" 300, "wdth" 87.5; |
| 205 |
} |
| 206 |
\end{verbatim} |
| 207 |
|
| 208 |
\normalsize\noindent To accommodate older browsers, you should make a selection of |
| 209 |
Junicode static fonts, subset them, and include them in your CSS. For example, |
| 210 |
if you need normal and bold weights of Junicode roman, your |
| 211 |
\texttt{@font-face} at-rule may look like this: |
| 212 |
|
| 213 |
\small\begin{verbatim} |
| 214 |
@font-face { |
| 215 |
font-family: "Junicode VF"; |
| 216 |
src: url("./webfiles/JunicodeVFsubset.woff2"); |
| 217 |
font-weight: 300 700; |
| 218 |
font-stretch: 75% 125%; |
| 219 |
font-style: normal; |
| 220 |
} |
| 221 |
@font-face { |
| 222 |
font-family: "Junicode"; |
| 223 |
src: url("./webfiles/Junicode-Regular.woff2"); |
| 224 |
font-weight: 400; |
| 225 |
font-style: normal; |
| 226 |
} |
| 227 |
@font-face { |
| 228 |
font-family: "Junicode"; |
| 229 |
src: url("./webfiles/Junicode-Bold.woff2"); |
| 230 |
font-weight: 700; |
| 231 |
font-style: normal; |
| 232 |
} |
| 233 |
\end{verbatim} |
| 234 |
|
| 235 |
\normalsize\noindent Now use \texttt{@supports} in your CSS rules to determine which |
| 236 |
font gets downloaded: |
| 237 |
|
| 238 |
\small\begin{verbatim} |
| 239 |
body { |
| 240 |
font-family: "Junicode", serif; |
| 241 |
} |
| 242 |
@supports (font-variation-settings: normal) { |
| 243 |
body { |
| 244 |
font-family: "Junicode VF", serif; |
| 245 |
} |
| 246 |
} |
| 247 |
b { |
| 248 |
font-weight: 700; |
| 249 |
} |
| 250 |
@supports (font-variation-settings: "wght" 700) { |
| 251 |
b { |
| 252 |
font-variation-settings: "wght" 700; |
| 253 |
} |
| 254 |
} |
| 255 |
\end{verbatim} |
| 256 |
|
| 257 |
\normalsize\noindent The variable version of Junicode will be downloaded only if |
| 258 |
the browser supports it, and the static version will be downloaded only if |
| 259 |
needed. |