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

mathtext: Use DejaVu display symbols when available #5612

Merged
merged 3 commits into from Dec 8, 2015

Conversation

zblz
Copy link
Member

@zblz zblz commented Dec 3, 2015

With the new DejaVu font default many of the symbols (most notably the integral, product, and summation symbol) are very small, as they are designed for inline math. The DejaVu fonts include display-sized variants for some of the math symbols outside of the unicode range. According to @mdboom, it is currently non-trivial to access these variants in a consistent manner from matplotlib, so here I did a bit of hack so we can always access them:

  • I modified the subset.py script from google web fonts so that it can create a font with a subset of all the glyphs with names ending in .display and move them to the unicode index corresponding to the regular glyph. I created two ttf files with this: DejaVuSansDisplay.ttf and DejaVuSerifDisplay.ttf. The family names have an additional Display at the end to differentiate them from the regular fonts. These are pretty small, as they only have a dozen characters.
  • I have saved this modified subset.py with the fonts in lib/matplotlib/mpl-data/fonts/ttf. I think it's good to keep it so this modification can be done in the future if we update the version of DejaVu fonts, but I am not sure this is the right place. A better location might be tools. Ideas? It has an Apache license, so AFAICT it's ok to distribute it.
  • The DejaVu font classes in mathtext.py will now look first for a glyph in the display version of the fonts (I have added them as fontname ex, following the cmex example), and if not found will use the regular version.

The baseline images definitely look better, specially the ones that include fractions and integrals.

@mdboom mdboom added this to the next major release (2.0) milestone Dec 3, 2015
@mdboom
Copy link
Member

mdboom commented Dec 3, 2015

Wow. This is super helpful. Very cool.

I created two ttf files with this: DejaVuSansDisplay.ttf and DejaVuSerifDisplay.ttf.

That's a good idea. Linux packagers will probably want to remove our DejaVu and substitute their own package. Providing our own custom fonts for just these extra characters is going to be much better received than modifying DejaVu directly.

A better location might be tools. Ideas?

I think tools is probably better. Can you also add a script that calls subset.py and does exactly the right thing to go from a new DejaVu to the Display subsets? (Otherwise exactly how to do this will be lost in time).

The baseline images definitely look better, specially the ones that include fractions and integrals.

I agree. They look much much better.

@zblz
Copy link
Member Author

zblz commented Dec 3, 2015

I added a small usage string for subset.py when called without arguments or with -h, as an additional scripts seems too much for the little use it will get.

@mdboom
Copy link
Member

mdboom commented Dec 3, 2015

Maybe also add a note that fontforge must be installed...

@zblz
Copy link
Member Author

zblz commented Dec 3, 2015

In the end I added a small script that makes the two calls to subset.py and checks before that fontforge is importable.

mdboom added a commit that referenced this pull request Dec 8, 2015
mathtext: Use DejaVu display symbols when available
@mdboom mdboom merged commit 08cb2c0 into matplotlib:master Dec 8, 2015
@zblz zblz deleted the dejavu-display-symbols branch December 8, 2015 16:47
@mdboom
Copy link
Member

mdboom commented Dec 8, 2015

Backported to 2.0.x as a77bb83

mdboom added a commit that referenced this pull request Dec 8, 2015
mathtext: Use DejaVu display symbols when available
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

Successfully merging this pull request may close these issues.

None yet

3 participants