Created
March 7, 2014 16:39
-
-
Save klmr/9414893 to your computer and use it in GitHub Desktop.
Convert TTF to AFM files, fix format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
typeface="$1" | |
if [ "$typeface" == "" ]; then | |
echo >&2 "Usage: $0 typeface" | |
exit 1 | |
fi | |
set -u | |
sourcepath="$HOME/Library/Fonts" | |
converter='ttf2afm' | |
rm -rf "$typeface" | |
mkdir "$typeface" | |
cd "$typeface" | |
sourcefiles=($sourcepath/$typeface*.ttf) | |
echo "Found ${#sourcefiles[@]} font files for typeface $typeface" | |
cp "${sourcefiles[@]}" . || | |
(echo >&2 "Typeface $typeface not found"; exit 1) | |
# The sed script is adapted from the description found at | |
# <http://r.789695.n4.nabble.com/How-to-enable-Arial-font-for-postcript-pdf-figure-on-Windows-td3017809.html> | |
# We assume fixed line numbers for the variables to replace -- otherwise this | |
# would be quite hard to realise: we'd have to guess at the right lines, and I | |
# am not familiar enough with the AFM format to do this, although I thing that | |
# it would probably be safe to search for exact strings. | |
fontfiles=(./*.ttf) | |
for f in "${fontfiles[@]}"; do | |
($converter "$f" | | |
sed -e '/^Copyright/ d' \ | |
-e '3 s/^/FontName /' \ | |
-e '4 s/^/FullName /' \ | |
-e '5 s/^/FamilyName /' \ | |
-e '6 s/^/Weight /' \ | |
> "${f%.ttf}.afm") & | |
done | |
wait | |
rm *.ttf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment