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

HACK: For speed, write out font styles only once. #124

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Dec 10, 2019

  1. HACK: For speed, write out font styles only once. To elaborate:

    **Background:** I had a few DVI files what were over 1000 pages long,
    on which dvisvgm would take hours to run.
    (Specifically, these files were the literate-programming listings of
    TeX/eTeX/pdfTeX/XeTeX programs, as typeset by WEAVE, except with each
    section on a separate page... but this situation may also be familiar
    to those trying to run dvisvgm on the TikZ manual, as in #x / #y .)
    
    With this change, the time to run dvisvgm went from hours to seconds.
    
    **What it does:** When invoked with certain options, for every page
    of the DVI file, dvisvgm writes out `@font-face` and text style CSS
    rules, like:
    
        @font-face{font-family:cmr10;src:url(data:application/x-font-ttf;base64,AAEAAAAN...
    
    and
    
        text.f12 {font-family:cmr10;font-size:9.96264px}
    
    All that this change does, in a hacky way, is accumulate these across
    pages, and write each of them only once. Then, the separate SVGs for
    each page can all just use the common style.
    
    **Caveats:**
    This is a giant hack, with MANY caveats:
    
    1. assuming there are enough pages (SVGs) for all this to be worth it,
    
    2. assuming only 7-bit fonts (having glyphs in positions 0 to 127),
    
    3. assuming font has no license problems (so doesn't have to be subset),
    
    4. assuming the user can do some postprocessing, namely generating CSS
       files by wrapping the `font-faces.txt` and `font-styles.txt` files
       within `<style>` tags.
    
    5. assuming SVG files don't have to be self-contained, i.e.
    
       - when used from a HTML page, will be inserted directly into the DOM and
         inherit its styles, rather than being wrapped in `img`/`object` tags
    
       - alternatively, postprocessing can put in the SVG file something like
    
                <style>@import 'common.css';</style>
    
         at the right place, where `common.css` is produced by (4) above.
    
    6. assming dvisvgm is being invoked something like this:
    
            dvisvgm --page=1- --font-format=woff2,autohint
    
    then, it *may* help to just do the expensive font-writing once, as here.
    shreevatsa committed Dec 10, 2019
    Configuration menu
    Copy the full SHA
    a1b16cd View commit details
    Browse the repository at this point in the history