Skip to content

Instantly share code, notes, and snippets.

@thundernixon
Last active June 22, 2023 07:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thundernixon/583dbfaf018bde2c118352e162103375 to your computer and use it in GitHub Desktop.
Save thundernixon/583dbfaf018bde2c118352e162103375 to your computer and use it in GitHub Desktop.
A shell script to update 'isFixedPitch' attribute 'value' from 0 to 1 on OpenType POST table. Also updates the font version.
# requires XMLstarlet: https://brewformulas.org/Xmlstarlet
# requires gftools: pip install git+https://github.com/googlefonts/gftools
# updates isFixedPitch attribute 'value' from 0 to 1 on OpenType POST table
#
# USAGE:
# TTX a file in the family to see its current version number in nameID 5
# $ ttx -t name <font_path>
# then, on the command line, run:
# $ chmod +x <relative_path>/set-is_fixed_pitch.sh
# $ ./set-is_fixed_pitch.sh <font_directory_path> <old_version> <new_version>
set -e
directory=$1
oldVersion=$2
newVersion=$3
cd $directory
# clean up any existing ttx files
for file in ./*; do
if [[ $file == *".ttx" ]]; then
rm $file
fi
done
# TTX; set isFixedPitch to 1; update HEAD
ttfs=$(ls ./*.ttf)
for ttf in $ttfs; do
ttx $ttf
rm $ttf
ttxPath=${ttf/".ttf"/".ttx"}
# this edits, in the same file, the isFixedPitch attribute 'value' to 1
xml ed --inplace -u "/*/post/isFixedPitch[@value=0]/@value" -v 1 $ttxPath
# this edits, in the same file, the head version value to newVersion
xml ed --inplace -u "/*/head/fontRevision[@value=$oldVersion]/@value" -v $newVersion $ttxPath
ttx $ttxPath
rm $ttxPath
done
# # use gftools to bump version number of fonts
gftools update-version $ttfs $oldVersion $newVersion
# if there are fixed files, remove old ttfs and move fixed into their place
for file in ./*; do
if [[ $file == *".fix" ]]; then
rm ${file/".ttf.fix"/".ttf"}
cp $file ${file/"ttf.fix"/"ttf"}
rm $file
fi
done
# TTX new files and print updates to terminal to confirm results
ttfs=$(ls ./*.ttf)
for ttf in $ttfs; do
echo =================================================
echo $(basename $file)
ttx -t name -t head -t post -q $ttf
ttxPath=${ttf/".ttf"/".ttx"}
# print font nameID 5 (version)
echo NAME nameID 5:
versionName=$(xml sel --noblanks --indent --text -t -v "*/name/namerecord[@nameID=5]" $ttxPath)
echo → ${versionName/"\n"/""}
# print head fontRevision value
echo HEAD fontRevision:
fontRevision=$(xml sel --noblanks --indent --text -t -v "*/head/fontRevision[@value]/@value" $ttxPath)
echo → ${fontRevision/"\n"/""}
# print post table isFixedPitch
echo POST isFixedPitch:
isFixedPitch=$(xml sel --noblanks --indent --text -t -v "*/post/isFixedPitch[@value]/@value" $ttxPath)
echo → ${isFixedPitch/"\n"/""}
rm $ttxPath
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment