google-font-download
This is a small shell script that allows you to download Google's web fonts to your local file system. Additionally, a CSS file that uses your local copy of the fonts is generated. You may want to use this if you want to avoid requesting resources from 3rd party servers (for example for privacy reasons or because you do not have a connection to the public internet).
Requirements
To run this script, you will need:
- Bash (>= 4.x)
- curl
- getopt, preferrably a version that preserves quoted whitespace and long options
- tput
- fmt
- sed, in a version that has extended regex support using either
-E
(BSD) or-r
(GNU) - awk
- tr
- grep
License
The script is released under the 2-clause BSD license. The SPDX identifier of
this license is BSD-2-Clause. See the LICENSE
file for
the terms.
Usage
Synopsis
google-font-download [OPTION...] [FONT...]
Options
-f FORMAT
,--format=FORMAT
- Download the specified set of webfont formats from Google's servers.
FORMAT
is a comma-separated list of identifiers for webfont formats. Supported identifiers areeof
,woff
,svg
, andttf
. Additionally, the special valueall
expands to all supported formats. The default isall
. Note that you may not really need all formats. In most cases, WOFF is enough. See http://caniuse.com/#search=woff for a current status. -h
,--help
- Display this message and exit.
-l LANGSPEC
,--languages=LANGSPEC
- Download the specified subset of languages from Google's webfonts.
LANGSPEC
is a comma-separated list of idenfitiers for font subsets. Common identifiers arelatin
,latin-ext
,cyrillic
,cyrillic-ext
,greek
,greek-ext
, etc. The default islatin
. -o OUTPUT
,--output=OUTPUT
- Write the generated CSS into
OUTPUT
. The file will be overwritten and will be created if it doesn't exist. The default isfont.css
.
Positional Arguments
This script accepts an arbitrary number of font specs. A font spec is any string that Google's servers will accept as famility URL parameter. Note that your font spec should not be URL-encoded and only one font weight is supported per font specification. If you want to download multiple font weights or styles, provide multiple font specs.
For example, to download Open Sans in
- light (300),
- normal (400),
- normal italic (400italic),
- bold (700), and
- bold italic (700italic), run:
google-font-download \
"Open Sans:300" "Open Sans:400" "Open Sans:400italic" \
"Open Sans:700" "Open Sans:700italic"