Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fritschy/b191e24ac3ded744ca941352283f9189 to your computer and use it in GitHub Desktop.
Save fritschy/b191e24ac3ded744ca941352283f9189 to your computer and use it in GitHub Desktop.
#!/bin/bash
# XXX not my work, just keeping it here for everyone to see, -fritschy
# Based in part on https://wincent.com/wiki/Fixing_the_baseline_on_the_Consolas_font_on_OS_X
function fail()
{
local error=${1:-Unknown error}
echo "Failed! $error"
exit 1
}
# Check for ttx and xmlstarlet
# Get ttx: sudo apt install fonttools
# Get xmlstarlet: sudo apt install xmlstarlet
[[ -z "`which ttx`" || -z "`which xmlstarlet`" ]] && fail "\"$tool\" was not found in your PATH"
# Loop over Consolas fonts
for font in 'Consolas Regular' 'Consolas Italic' 'Consolas Bold' 'Consolas Bold Italic'; do
if [ -f "$font.ttf" ]; then
# Dump font tables into .ttx XML file
ttx "$font.ttf"
[ $? -ne 0 ] && fail "ttx returned non-zero while processing $font"
# Validate the .ttx XML file
xmlstarlet val "$font.ttx"
[ $? -ne 0 ] && fail "$font.ttx is not valid XML"
# Update the ascent, descent, and lineGap values in the Horizontal Header (hhea) table
xmlstarlet ed -L -u "/ttFont/hhea/ascent/@value" -v "1884" "$font.ttx"
xmlstarlet ed -L -u "/ttFont/hhea/descent/@value" -v "-514" "$font.ttx"
xmlstarlet ed -L -u "/ttFont/hhea/lineGap/@value" -v "0" "$font.ttx"
# Delete the digital signature (DSIG) table, since the
# modified font will no longer match the original signature
xmlstarlet ed -L -d "/ttFont/DSIG" "$font.ttx"
# Rewrite the font from the .ttx file
ttx "$font.ttx"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment