This script is used to patch and subset the Source Code Pro font for use on my blog.
More details are available at velvetcache.org/2024/02/12/box-drawing-on-the-web
This script is used to patch and subset the Source Code Pro font for use on my blog.
More details are available at velvetcache.org/2024/02/12/box-drawing-on-the-web
| 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 |