Skip to content

Instantly share code, notes, and snippets.

@jmhobbs
Last active February 12, 2024 23:08
Show Gist options
  • Save jmhobbs/b15516c7586d1d14fe08c925783fd9d6 to your computer and use it in GitHub Desktop.
Save jmhobbs/b15516c7586d1d14fe08c925783fd9d6 to your computer and use it in GitHub Desktop.
Font Subsetting for Velvetcache.org
UNICODES=(
"U+0020-007E" # ASCII Printables
"U+00A1-00BF" # Latin-1 symbols
"U+00D7" # Multiplication sign
"U+00F7" # Division sign
"U+2000-206F" # General Punctuation
"U+2190-21FF" # Arrows
"U+2200-22FF" # Mathematical Operators
"U+2500-257F" # Box Drawing
)
unicodes_string="${UNICODES[*]}"
echo "Patching"
python patch-font.py
echo "Subsetting"
rm -f SourceCodePro-Regular-subset*.woff2
rm -f source-code-pro-*.css
pyftsubset SourceCodePro-Regular-patched.ttf \
--output-file="SourceCodePro-Regular-subset.woff2" \
--flavor=woff2 \
--no-hinting \
--desubroutinize \
--layout-features="ccmp" \
--unicodes="${unicodes_string//${IFS:0:1}/,}"
SHA=$(sha256sum SourceCodePro-Regular-subset.woff2 | head -c 7)
mv SourceCodePro-Regular-subset.woff2 "SourceCodePro-Regular-subset-$SHA.woff2"
cat > "source-code-pro-$SHA.css" <<EOF
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url('SourceCodePro-Regular-subset-$SHA.woff2') format('woff2');
}
EOF
echo "-> SourceCodePro-Regular-subset-$SHA.woff2"
echo "-> source-code-pro-$SHA.css"
from fontTools import ttLib
tt = ttLib.TTFont("SourceCodePro-Regular.ttf")
for table in tt["cmap"].tables:
if table.platformID == 0:
if table.cmap[0x25CA] == "lozenge":
print("Patching table", table.platformID, table.platEncID)
table.cmap[0x22C4] = "lozenge"
tt.save("SourceCodePro-Regular-patched.ttf")
Brotli==1.1.0
fonttools==4.48.1
zopfli==0.2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment