-
Notifications
You must be signed in to change notification settings - Fork 24
Improve fonts generation: use fonttools to generate (reproducible) fonts #54
Conversation
* set created/modified timestamp * remove fontforge timestamp(FFTM) and GDEF table * set font version * fix metrics * generate WOFF, WOFF2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm super excited about this change. I think it's going to unlock a lot of doors for us. Requesting a way to avoid updating font files with no changes to the glyphs themselves.
@@ -72,10 +73,11 @@ if [[ $(docker images "$IMAGE" | wc -l) -lt 2 ]]; then | |||
fi | |||
|
|||
CMDS="set -ex | |||
export SOURCE_DATE_EPOCH=${LAST_COMMIT_DATE} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this still result in all files being modified (albeit only on commit) whenever someone makes any change? It would be nice if we only updated font files where we changed something. I think there might be some way to do that while also bumping the timestamp in those files, but it might be easier to just set SOURCE_DATE_EPOCH
to be a constant.
version = json.load(f)['version'] | ||
|
||
font['name'].setName(unicode('Version ' + version), 5, 3, 1, 1033) | ||
font['name'].setName(unicode('Version ' + version), 5, 1, 0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's 5, 3, 1, 1033
and 5, 1, 0, 0
about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbarabash They are name ID, platform ID, encoding ID, and language ID of NAME table, respectively. We have two tables, (3, 1, 1033) and (1, 0, 0), which are Unicode variants. (See Space.ttx)
font_file = sys.argv[1] | ||
font_name = os.path.splitext(os.path.basename(font_file))[0] | ||
|
||
font = TTFont(font_file, recalcBBoxes=False, recalcTimestamp=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for figuring out all of these TTFont
options to produce a reproducible build.
mkdir -p ttf | ||
rm -f ttf/* | ||
.PHONY: fonts | ||
fonts: ff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could rewrite this rule to be a per .ff rule since makeFF
outputs multiple files to ff/KaTeX_$font.ff
. This would allow us to only update those .ttf, .woff, and .woff2 files that have meaningful changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd have to check in the .ff
files themselves which isn't the worst. Long term we might look at splitting up makeFF
. Another short term approach we might look at is setting the default timestamp to be whatever it was in the file from the last commit... write the file, if there are changes, update the timestamp to be the current timestamp and update the file with that timestamp.
|
||
# save WOFF2 | ||
font.flavor = 'woff2' | ||
font.save(os.path.join('woff2', font_name + '.woff2'), reorderTables=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad that FontTools
makes it easy to save all these different formats.
@kevinbarabash I was thinking of moving |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ylemkimon I'd like to move things to JS as well. Since this is an intermediary step we can leave deciding whether or not to update individual font files to a future PR.
We should probably merge #50 first. |
@kevinbarabash |
Yay! |
This PR is part of #12.
SOURCE_DATE_EPOCH
, which is set to the last commit date ofsrc/fonts
inbuildFonts.sh
FFTM
) table, Please do not put timestamps in saved (SFD) files fontforge/fontforge#2711package.json
fonttools
, removefix_os2_metrics.rb
and RubyOS/2
andhhea
metrics usingfonttools
, removemodify_ascent_descent.py
fonttools
, removewoff-tools
andwoff2_compress
, combine targets into phonyfonts
targetI compared the output using
ttx
and differences other than above weremaxInstructionDefs
inhead
, which probably was a bug in previousfontforge
and few metrics, resulting in (sub)pixel changes but nothing visible.