Skip to content

Commit

Permalink
Add a script to download and use local fonts
Browse files Browse the repository at this point in the history
By downloading the fonts, we can use more recent versions of the fonts,
and fonts that are not currently packaged.
  • Loading branch information
pnorman committed Jul 16, 2022
1 parent 828c41a commit 02c5b24
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.thumb.png
layers/
data/
fonts/
tmp/
*.xml
*.osm.pbf
Expand Down
135 changes: 135 additions & 0 deletions scripts/get-fonts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/sh
set -e

FONTDIR="./fonts"

mkdir -p "${FONTDIR}"

# download filename url
download() {
## Download if newer, and if curl fails, clean up and exit
curl --fail -A "get-fonts.sh/osm-carto" -o "$1" -z "$1" -sL "$2" || echo "Failed to download $1 $2" && rm -f "$1" && exit 1
}

# TTF Hinted Noto Fonts

# Fonts available in regular, bold, and italic
REGULAR_BOLD_ITALIC="NotoSans"

# Fonts available in regular and bold
REGULAR_BOLD="NotoSansAdlam
NotoSansAdlamUnjoined
NotoSansArabicUI
NotoNaskhArabicUI
NotoSansArmenian
NotoSansBalinese
NotoSansBamum
NotoSansBengaliUI
NotoSansCanadianAboriginal
NotoSansCham
NotoSansCherokee
NotoSansDevanagariUI
NotoSansEthiopic
NotoSansGeorgian
NotoSansGujaratiUI
NotoSansGurmukhiUI
NotoSansHebrew
NotoSansJavanese
NotoSansKannadaUI
NotoSansKayahLi
NotoSansKhmerUI
NotoSansLaoUI
NotoSansLisu
NotoSansMalayalamUI
NotoSansMyanmarUI
NotoSansOlChiki
NotoSansOriyaUI
NotoSansSinhalaUI
NotoSansSundanese
NotoSansSymbols
NotoSansTaiTham
NotoSansTamilUI
NotoSansTeluguUI
NotoSansThaana
NotoSansThaiUI
NotoSerifTibetan"

# Fonts with regular and black, but no bold
REGULAR_BLACK="NotoSansSyriac"

# Fonts only available in regular
REGULAR="NotoSansBatak
NotoSansBuginese
NotoSansBuhid
NotoSansChakma
NotoSansCoptic
NotoSansHanunoo
NotoSansLepcha
NotoSansLimbu
NotoSansMandaic
NotoSansMongolian
NotoSansNewTaiLue
NotoSansNKo
NotoSansOsage
NotoSansOsmanya
NotoSansSamaritan
NotoSansSaurashtra
NotoSansShavian
NotoSansSymbols2
NotoSansTagalog
NotoSansTagbanwa
NotoSansTaiLe
NotoSansTaiViet
NotoSansTifinagh
NotoSansVai
NotoSansYi"

# Download the fonts in the lists above

for font in $REGULAR_BOLD_ITALIC; do
regular="$font-Regular.ttf"
bold="$font-Bold.ttf"
italic="$font-Italic.ttf"
download "${FONTDIR}/${regular}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${regular}"
download "${FONTDIR}/${bold}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${bold}"
download "${FONTDIR}/${italic}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${italic}"
done

for font in $REGULAR_BOLD; do
regular="$font-Regular.ttf"
bold="$font-Bold.ttf"
download "${FONTDIR}/${regular}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${regular}"
download "${FONTDIR}/${bold}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${bold}"
done

for font in $REGULAR_BLACK; do
regular="$font-Regular.ttf"
black="$font-Black.ttf"
download "${FONTDIR}/${regular}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${regular}"
download "${FONTDIR}/${black}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${black}"
done

for font in $REGULAR; do
regular="$font-Regular.ttf"
download "${FONTDIR}/${regular}" "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/${font}/${regular}"
done

# Other noto fonts which don't follow the URL pattern above
download "${FONTDIR}/NotoSansCJKjp-Regular.otf" "https://github.com/googlefonts/noto-cjk/raw/main/Sans/OTF/Japanese/NotoSansCJKjp-Regular.otf"
download "${FONTDIR}/NotoSansCJKjp-Bold.otf" "https://github.com/googlefonts/noto-cjk/raw/main/Sans/OTF/Japanese/NotoSansCJKjp-Bold.otf"

# Fonts in zipfiles need a temporary directory
TMPDIR=$(mktemp -d -t get-fonts.XXXXXXXXX)

trap "rm -rf ${TMPDIR} ${FONTDIR}/static" EXIT

# Noto Emoji B&W isn't available as a separate download, so we need to download the package and unzip it
curl --fail -A "get-fonts.sh/osm-carto" -o "${TMPDIR}/Noto_Emoji.zip" -sL 'https://fonts.google.com/download?family=Noto%20Emoji'

unzip -oqq "${TMPDIR}/Noto_Emoji.zip" static/NotoEmoji-Regular.ttf static/NotoEmoji-Bold.ttf -d "${FONTDIR}"
mv "${FONTDIR}/static/NotoEmoji-Regular.ttf" "${FONTDIR}"
mv "${FONTDIR}/static/NotoEmoji-Bold.ttf" "${FONTDIR}"

curl --fail -A "get-fonts.sh/osm-carto" -o "${TMPDIR}/hanazono.zip" -sL 'https://osdn.net/frs/redir.php?f=hanazono-font%2F68253%2Fhanazono-20170904.zip'

unzip -oqq "${TMPDIR}/hanazono.zip" HanaMinA.ttf HanaMinB.ttf -d "${FONTDIR}"
67 changes: 27 additions & 40 deletions style/fonts.mss
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
About fonts:
Noto is a font family that wants to cover most of Unicode with a harmonic
design across various scripts. We use Noto for most text, with some support
for backward-compatibility and some fallback fonts.
design across various scripts. We use Noto for most text and some fallback fonts.
By order:
1. Noto Sans is available for most scripts and it is used as a first choice.
Where available the UI version of the fonts – which provides tighter vertical
metrics – is used (except for the base font, where the UI version is deprecated
since Noto Phase III, and Sinhala where both versions are used for backwards
compatibility with Ubuntu 16.04). We intent to have all scripts of Noto in
metrics – is used. We intent to have all scripts of Noto in
our list except dead (historic) scripts of whom we assume that they are not
used in “name” tags in OSM. Most of the list is in alphabetical order,
but there are some exceptions.
Expand All @@ -26,12 +23,6 @@ but there are some exceptions.
two variants SC/TC, it won’t be a uniform rendering anyway. So we default
to Japanese. However, this choice stays somewhat arbitrary and subjective.
See also https://github.com/gravitystorm/openstreetmap-carto/issues/2208
- For the Syriac script, there exist Noto Sans Syriac Eastern,
Noto Sans Syriac Western Regular and Noto Sans Syriac Estrangela Regular.
As for CJK fonts, we have no knowledge about what language the “names” tag
contains. We choose Syriac Eastern because it seems to be the most
widespreaded script variant (Syriac Western is less common, and Syriac
Estrangela mostly of historic interest.)
2. Noto provides various variants of Arabic: Noto Kufi Arabic, Noto Naskh
Arabic, Noto Nastaliq Urdu and Noto Sans Arabic. Kufi and Urdu styles are not
Expand All @@ -46,32 +37,20 @@ without Noto Sans Arabic UI.
3. Noto Serif is used for scripts that are not supported by Noto Sans. Currently
this is only Tibetan: The old Noto Sans Tibetan has been renamed to Noto Serif
Tibetan in 2015, since then only Noto Serif Tibetan gets updated. We still
include the old one for compatibility on systems without Noto Serif Tibetan.
See also https://github.com/googlefonts/noto-fonts/issues/1540
Tibetan in 2015, since then only Noto Serif Tibetan gets updated.
4. Noto provides two variants of Emoji: Noto Color Emoji and Noto Emoji. The
colour variant is a SVG flavoured OpenType font that contains coloured emojis.
This is not useful in cartography, so we use the “normal” monochromatic
Noto Emoji.
5. The list still includes DejaVu for compatibility on systems without Noto.
6. Fallback fonts. Hanazono covers almost all CJK characters, even in Unicode
Plane 2. Unifont is a fallback of last resort with full coverage in Plane 0
(Unifont Medium), some coverage in Plane 1 (Unifont Upper Medium) and no
coverage in Plane 2. Unifont has different font names on different Linux
distributions (and sometimes even in different versions of the same Linux
distribution), see #429 and #2924 for details. We have therefore both,
“Unifont Medium” and “unifont Medium” in our list, so on almost all
distributions we catch the font if installed – and you will always get an error
message for the other missing font name. We prefer having an error message than
requiring our users to customize the font list depending on their Linux
distribution. Unifont Medium Sample would cover the BMP PUA with
replacement characters, but cannot be used because Mapnik does not
support SBIT TTF.
5. Fallback fonts. Hanazono covers almost all CJK characters, even in Unicode
Plane 2.
*/

/* Use vendored fonts. This allows for more recent versions and better coverage */
font-directory: url('fonts');

/*
A regular style.
*/
Expand Down Expand Up @@ -119,11 +98,11 @@ A regular style.
"Noto Sans Samaritan Regular",
"Noto Sans Saurashtra Regular",
"Noto Sans Shavian Regular",
"Noto Sans Sinhala UI Regular", "Noto Sans Sinhala Regular",
"Noto Sans Sinhala UI Regular",
"Noto Sans Sundanese Regular",
"Noto Sans Symbols Regular",
"Noto Sans Symbols2 Regular",
"Noto Sans Syriac Eastern Regular",
"Noto Sans Syriac Regular",
"Noto Sans Tagalog Regular",
"Noto Sans Tagbanwa Regular",
"Noto Sans Tai Le Regular",
Expand All @@ -139,23 +118,25 @@ A regular style.

"Noto Sans Arabic UI Regular", "Noto Naskh Arabic UI Regular",

"Noto Serif Tibetan Regular", "Noto Sans Tibetan Regular",
"Noto Serif Tibetan Regular",

"Noto Emoji Regular",

"DejaVu Sans Book",

"HanaMinA Regular", "HanaMinB Regular",
"Unifont Medium", "unifont Medium", "Unifont Upper Medium";
"HanaMinA Regular", "HanaMinB Regular";

/*
A bold style is available for almost all scripts. Bold text is heavier than
regular text and can be used for emphasis. Fallback is a regular style.
*/
@bold-fonts: "Noto Sans Bold",
"Noto Sans CJK JP Bold",
"Noto Sans Adlam Bold",
"Noto Sans Adlam Unjoined Bold",
"Noto Sans Armenian Bold",
"Noto Sans Balinese Bold",
"Noto Sans Bamum Bold",
"Noto Sans Bengali UI Bold",
"Noto Sans Canadian Aboriginal Bold",
"Noto Sans Cham Bold",
"Noto Sans Cherokee Bold",
"Noto Sans Devanagari UI Bold",
Expand All @@ -164,24 +145,30 @@ regular text and can be used for emphasis. Fallback is a regular style.
"Noto Sans Gujarati UI Bold",
"Noto Sans Gurmukhi UI Bold",
"Noto Sans Hebrew Bold",
"Noto Sans Javanese Bold",
"Noto Sans Kannada UI Bold",
"Noto Sans Kayah Li Bold",
"Noto Sans Khmer UI Bold",
"Noto Sans Lao UI Bold",
"Noto Sans Lisu Bold",
"Noto Sans Malayalam UI Bold",
"Noto Sans Myanmar UI Bold",
"Noto Sans Ol Chiki Bold",
"Noto Sans Oriya UI Bold",
"Noto Sans Sinhala UI Bold", "Noto Sans Sinhala Bold",
"Noto Sans Sinhala UI Bold",
"Noto Sans Sundanese Bold",
"Noto Sans Symbols Bold",
"Noto Sans Syriac Black",
"Noto Sans Tai Tham Bold",
"Noto Sans Tamil UI Bold",
"Noto Sans Telugu UI Bold",
"Noto Sans Thaana Bold",
"Noto Sans Thai UI Bold",

"Noto Sans Arabic UI Bold", "Noto Naskh Arabic UI Bold",

"Noto Serif Tibetan Bold", "Noto Sans Tibetan Bold",

"DejaVu Sans Bold",
"Noto Serif Tibetan Bold",
"Noto Emoji Bold",

@book-fonts;

Expand Down

0 comments on commit 02c5b24

Please sign in to comment.