Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deterministic SVGs with --font-format other than svg #120

Open
shreevatsa opened this issue Nov 22, 2019 · 2 comments
Open

Deterministic SVGs with --font-format other than svg #120

shreevatsa opened this issue Nov 22, 2019 · 2 comments
Assignees

Comments

@shreevatsa
Copy link

When I run dvisvgm multiple times on the same DVI file, with --font-format set to anything other than svg, the resulting SVG files are different (not always, but at least about 10% of the time). This makes it inconvenient to have the SVG files checked into version control, or to run regression tests on the steps leading up to their creation.

The command is something like:

dvisvgm --page=1- --font-format=$format foo.dvi

where $format is one of ttf, woff, or woff2. The diffs are all in the @font-face lines, i.e. the actual base-64 encoding of the font.

Is it known where this non-determinism/randomness come from? Is there a way to avoid it (set a random seed or something)? It possibly has something to do with the time, as using faketime helps a bit.

@mgieseki
Copy link
Owner

I have to look more closely into the sources, but I guess you're right. It's probably the fontforge library that writes the current date/time into the TTF header which also affects WOFF and WOFF2 as they are basically compressed TTF files.

@mgieseki mgieseki self-assigned this Nov 22, 2019
@shreevatsa
Copy link
Author

Thanks, that is probably it. Meanwhile, after reading the libfaketime documentation further, I discovered a way to use it that seems to help:

  1. The first time, run with FAKETIME_SAVE_FILE set and an arbitrary starting timestamp, e.g.

    FAKETIME_SAVE_FILE='./saved-fake-times' faketime '2008-12-24 08:15:42' dvisvgm --page=1- --font-format=woff2 foo.dvi
    
  2. On subsequent runs, use this same file, with FAKETIME_LOAD_FILE:

    FAKETIME_LOAD_FILE='./saved-fake-times' faketime '2008-12-24 08:15:42' dvisvgm --page=1- --font-format=woff2 foo.dvi
    

This seems to result in the same SVG files across runs, though I'm yet to try it with a larger file. The same font still varies across the SVGs corresponding to different pages, but across runs it seems to be consistent. Anyway, this is probably not the ideal solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants