Skip to content

Commit

Permalink
Use ttx to edit font metadata. Slow, wastes 10 min, but works.
Browse files Browse the repository at this point in the history
  • Loading branch information
Satish B committed Dec 12, 2021
1 parent 838fecc commit c419eac
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,45 @@ There is no dependency other than [`nototools`](https://github.com/googlefonts/n
| | |


<!--
1891 glyphs -> GSUB LookupIndex 1293 fails
1575 glyphs -> GSUB LookupIndex 646 fails. Max Lookuptable size = 1651
(NoSubjoined) 168 code points, 688 glpyhs -> GSUB LookupCount 1680
../venv_fonty/bin/pyftsubset NotoSerifTibetan-Regular.ttf \
--unicodes=U+0F00-0F8C,U+0F90,U+0F94,U+0F95,U+0F97,U+0F9F,U+0FA1,U+0FA3,U+0FA4,\
U+0FA6,U+0FA9,U+0FAB,U+0FAD,U+0FAF,U+0FB1-0FB3,U+0FB06-0FB8,U+0FBE-0FDA
=> gives 181 codepoints, 1380 glyphs, 401KB size, GSUB LookupCount 915
In comparison, Devanagari has GSUB LookupCount = 120 just!
--unicodes=U+0F00-0F68,U+0F6B-0F87,U+0F90,U+0F94,U+0F95,U+0F97,U+0F
9F,U+0FA1,U+0FA3,U+0FA4,U+0FA6,U+0FA9,U+0FAB,U+0FAD,U+0FAF,U+0FB1-0FB3,U+0FB06-0FB8,U+0FBE-0FDA
=> gives 174 codepoints, 1322 glyphs, 385KB size, GSUB LookupCount 892
-ka, -ga, -ja, -ta, -da, -na, -pa, -ba, -ma, -ya, -ra, -la, -wa, -tsa, -ha
Bhutanese/Tibetan only:
--unicodes=U+0F00-0F8F,U+0F90,U+0F92,U+0F97,U+0F9F,u+0FA1,U+0FA3,U+0FA4,U+0FA6,U+0FA8,U+0FA9,U+0FAD,U+0FB1-0FB3,U+0FB7
155 codepoints, 1435 glyphs, 426 KB,
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F97,U+0F9F,u+0FA1,U+0FA3,U+0FA4,U+0FA6,U+0FA8,U+0FA9,U+0FAD,U+0FB1-0FB3,U+0FB8,U+0FBE-0FDA
180 codepoints, 1456 glyphs, 431KB, GSUB 988 lookup ==> Not working
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F94,U+0FF99,U+0FAD,U+0FB1-0FB3,U+0FBA-0FDA
175 codepoints, 1023 glyphs, 285KB, GSUB 646 lookup ==> WORKS WITH EastAsia.ttf and SouthAsia.ttf!
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F94,U+0F9F,U+0FF99,U+0FAD,U+0FB1-0FB3,U+0FBA-0FDA
(added TA) 176 codepoints, 1096 glyphs, 309KB, GSUB 703
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F94,U+0F99,U+0F9F,U+0FA4,U+0FAD,U+0FB1-0FB3,U+0FBA-0FDA
(added TA, PA) 178 codepoints, 1170 glyphs, 330KB, GSUB 749
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F94,U+0F99,U+0F9F,U+0FA4,U+0FA9,U+0FAD,U+0FB1-0FB3,U+0FBA-0FDA
(added TA, PA, TSA) 179 codepoints, 1204 glyphs, 343KB, GSUB 771 ==> WORKS!
-->
20 changes: 0 additions & 20 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,6 @@ def download_fonts(directory="./"):
print("Could not retrieve %s. Please check if it exists", ttf)
sleep(0.5)

def edit_font_info(fontname):
from fontTools import ttLib
import re
print("editing font info %s" % fontname)
name_without_spaces = fontname.split('.')[0]
name_with_spaces = ' '.join(re.split('(?=[A-Z])', name_without_spaces)).strip()
font = ttLib.TTFont(fontname)
names = font['name'].names
for i in range(len(names)):
print(i, names[i].toStr())

encoding = names[0].getEncoding()
names[0].string += "; Copyright 2021 Satish B.; SIL Open Font License v1.1".encode(encoding)
names[1].string = name_with_spaces.encode(encoding)
names[3].string = names[3].toStr().replace('NotoSans', name_without_spaces).encode(encoding)
names[4].string = (name_with_spaces + ' ' + names[2].toStr()).encode(encoding)
names[6].string = (name_without_spaces + '-' + names[2].toStr()).encode(encoding)
font.save(fontname)
font.close()

# append new entries from # https://docs.microsoft.com/en-gb/typography/opentype/spec/scripttags
merge_noto.SCRIPT_TO_OPENTYPE_SCRIPT_TAG['TaiLe'] = 'tale'
merge_noto.SCRIPT_TO_OPENTYPE_SCRIPT_TAG['Multani'] = 'mult'
Expand Down
17 changes: 16 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,27 @@ subset_tibetan() {
fi
echo "Creating a smaller subset of Tibetan glyphs..."
$VIRTUAL_ENV/bin/pyftsubset NotoSerifTibetan-Regular.ttf --output-file=NotoSerifTibetanSubset-Regular.ttf \
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F94,U+0FF99,U+0FAD,U+0FB1-0FB3,U+0FBA-0FDA
--unicodes=U+0F00-0F8C,U+0F90,U+0F92,U+0F94,U+0F99,U+0F9F,U+0FA4,U+0FA9,U+0FAD,U+0FB1-0FB3,U+0FBA-0FDA
fi
cd "$OLDPWD"
}

subset_tibetan

edit_font_info() {
local fontname="$1"
local without_spaces="${fontname%%.*}"
local with_spaces=$(echo "$without_spaces" | sed -E 's/([a-z])([A-Z])/\1 \2/g')
local xml_file="$without_spaces".ttx
echo "Editing font metadata for $fontname"
$VIRTUAL_ENV/bin/ttx -o "$xml_file" "$fontname" 2> /dev/null
[[ $? -ne 0 ]] && echo "ERROR: Could not dump $fontname to xml" && return 1
sed -i -e "s/Noto Sans/$with_spaces/g" -e "s/NotoSans/$without_spaces/g" "$xml_file"
$VIRTUAL_ENV/bin/ttx -o "$fontname" "$xml_file" 2> /dev/null
[[ $? -ne 0 ]] && echo "ERROR: Could not dump xml to $fontname" && return 2
rm -f "$xml_file"
}

declare -a fonts=(
GoNotoSouthAsia.ttf
GoNotoAsiaHistorical.ttf
Expand All @@ -53,4 +67,5 @@ for font in "${fonts[@]}"; do
printf "Generating font $font. Current time: $(date)\n"
mkdir -p cached_fonts
time PYTHONPATH="nototools/nototools" python3 generate.py -o "$font" -d cached_fonts
edit_font_info "$font"
done

0 comments on commit c419eac

Please sign in to comment.