ipython / xkcd-font

The xkcd font
https://cdn.rawgit.com/ipython/xkcd-font/master/preview.html
Other
1.06k stars 48 forks source link

Make the TTF "xkcd Script" deterministic #19

Closed pelson closed 7 years ago

pelson commented 7 years ago

Currently, it seems the ttf depends on the day. I modified the (pretty well hidden) "UniqueID" field so that it doesn't include the date.

Incidentally, to diff a ttf/otf/woff/sfd or any other type of font that fontforge can read, you can simply use the sfddiff tool. Even better, it is included in the docker image I built, pelson/fontbuilder.

In this instance:

> git difftool --extcmd='docker run -i -t -v $(pwd):$(pwd) -w $(pwd) -e LC_ALL:en_US.UTF-8 pelson/fontbuilder sfddiff' --no-prompt HEAD~1.. -- xkcd-script/font/*.ttf

Copyright (c) 2000-2014 by George Williams. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Based on sources from 22:38 UTC 29-Apr-2017-D.
 Based on source from git with hash: b8e5ff8f24955f4d7d59ac73c903cc088b21bdb6
Names
 The copyright notice differs. In /Users/pelson/dev/jupyter/xkcd-font/.diff-tmp/js7Hac_xkcd-script.ttf it is (Copyright (c) 2017, Anonymous) while in /Users/pelson/dev/jupyter/xkcd-font/xkcd-script/font/xkcd-script.ttf it is (Copyright (c) ipython/xkcd-font contributors, Creative Commons Attribution-NonCommercial 3.0 License)
 The UniqueID English (US) differs. In /Users/pelson/dev/jupyter/xkcd-font/.diff-tmp/js7Hac_xkcd-script.ttf it is (FontForge 2.0 : xkcd-Script-Regular : 14-6-2017) while in /Users/pelson/dev/jupyter/xkcd-font/xkcd-script/font/xkcd-script.ttf it is (xkcd Script)

Note that in my instance, I needed to make the location of my temporary directory readable from within the docker container, so I set export TMPDIR=.diff-tmp; mkdir -p $TMPDIR.

pelson commented 7 years ago

Hmmm. This is still producing a diff at each re-build, but sfddiff doesn't see any difference. This is a slightly gnarly-er problem than I'd hoped...

pelson commented 7 years ago

Turns out my creation time and my xuid are both being modified each time the script is run. Apparently xuid is no longer necessary (NOTE: Adobe now says that both XUID and UniqueID are unnecessary.).

Unfortunately, I'm struggling to find a clear way to set the creationtime. I'm looking specifically at https://github.com/fontforge/fontforge/pull/2609.

pelson commented 7 years ago

Phew. I think I've got it, after tweaking the stat time of the sfd file. I've pushed the commit up, if travis pushes a second commit to my branch I've failed, otherwise, this should be good to go. (I'm signing out for a bit)

pelson commented 7 years ago

This is now good to go, though I'm reluctant to self-merge. Anybody?

pelson commented 7 years ago

Incidentally, (i.e. for my own record) I used the following to print out all attributes of a ttf (they weren't all being diffed by sdfdiff - namely xuid and creationtime):

import fontforge
import sys

font = fontforge.open(sys.argv[1])

seen = []
for k in dir(font):
    if k in seen:
        continue
    seen.append(k)
    v = getattr(font, k) 

    if not k.startswith('_') and not callable(v):
        print(k, v)