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

Already on GitHub? Sign in to your account

Mixing Arial with mathtext on Windows 8 fails #1710

Merged
merged 2 commits into from Jan 29, 2013

Conversation

Projects
None yet
3 participants
Contributor

mdboom commented Jan 28, 2013

Along with quite a few other fonts as well, but I've not been able to identify exactly which ones; but Arial is the easiest one to test. Trying to use the Arial font with some mathtext in the string that you are trying to show leads to a lengthy stack trace (when I get the chance I'll regenerate it and post it).

Reference:
http://matplotlib.1069221.n5.nabble.com/mathtext-and-fonts-under-Windows-8-td40172.html

A related fix from some other software:
http://code.google.com/p/sumatrapdf/issues/detail?id=2056
http://code.google.com/p/sumatrapdf/source/diff?spec=svn6770&r=6770&format=side&path=/trunk/mupdf/pdf/pdf_font.c

According to a poster in that thread,

"It seems that at least some of the fonts in Windows 8 no longer contain a glyph names table. MuPDF has under some circumstances relied too much on such a table being present. I've adjusted the logic so that it no longer does. The next (pre)release version (2.2.6770 or later) should thus be able to display PDF documents without embedded fonts under Windows 8 as intended. Thanks again for all your help for debugging this issue."

Contributor

dhyams commented Jan 27, 2013

Sample code to reproduce:

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

t = np.arange(0.01, 1.0, 0.1)
s = np.exp(-t)
plt.plot(t, s)

fp = fm.FontProperties(family='Arial')

#plt.title('Arial font without mathtext',fontproperties=fp)
plt.title('Arial font + mathtext: $E=mc^2$',fontproperties=fp)

plt.show()

Traceback is as follows:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in call
return self.func(_args)
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 276, in resize
self.show()
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 348, in draw
FigureCanvasAgg.draw(self)
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 439, in draw
self.figure.draw(self.renderer)
File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, *_kwargs)
File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 999, in draw
func(_args)
File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, *_kwargs)
File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 2086, in draw
a.draw(renderer)
File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, _args, *_kwargs)
File "C:\Python26\lib\site-packages\matplotlib\text.py", line 531, in draw
bbox, info = self._get_layout(renderer)
File "C:\Python26\lib\site-packages\matplotlib\text.py", line 313, in _get_layout
ismath=ismath)
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 204, in get_text_width_height_descent
self.mathtext_parser.parse(s, self.dpi, prop)
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 3010, in parse
box = self._parser.parse(s, font_output, fontsize, dpi)
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 2338, in parse
result = self._expression.parseString(s)
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 1089, in parseString
loc, tokens = self._parse( instring, 0 )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 1020, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 962, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 2681, in parseImpl
return self.expr._parse( instring, loc, doActions, callPreParse=False )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 1020, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 962, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 2409, in parseImpl
loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 1020, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File "C:\Python26\lib\site-packages\matplotlib\pyparsing_py2.py", line 989, in _parseNoCache
tokens = fn( instring, tokensStart, retTokens )
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 2420, in non_math
symbols = [Char(c, self.get_state()) for c in s]
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 1305, in init
self._update_metrics()
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 1312, in _update_metrics
self.font, self.font_class, self.c, self.fontsize, self.dpi)
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 467, in get_metrics
info = self._get_info(font, font_class, sym, fontsize, dpi)
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 602, in _get_info
self._get_glyph(fontname, font_class, sym, fontsize)
File "C:\Python26\lib\site-packages\matplotlib\mathtext.py", line 716, in _get_glyph
cached_font.charmap[num])
RuntimeError: Face has no glyph names

Member

dmcdougall commented Jan 27, 2013

@dhyams Can you reproduce this on version 1.2?

Contributor

dhyams commented Jan 28, 2013

Yes, the stack trace above is from 1.2.

Contributor

dhyams commented Jan 28, 2013

The configuration of the computer tested on:

  • fresh Windows 8 installation
  • binary install of Python 2.6.6 (32 bit)
  • binary install of numpy superpack 1.6.2 from sourceforge site
  • binary install of matplotlib 1.2

All installs were fresh from the download, as well.

Member

dmcdougall commented Jan 28, 2013

Thanks @dhyams. I'm not able to reproduce this on my mac.

Contributor

dhyams commented Jan 28, 2013

Right; this is a Windows 8 only bug...on Windows 7 it works just fine.

Owner

mdboom commented Jan 28, 2013

Can you try the attached patch and verify it works on Window 8? It will require a recompile of C++ code. I was able to confirm it resolves the issue when using the arial.ttf file from Windows 8 on Linux, but I do not have Windows 8 to test on.

dhyams commented on d5710a4 Jan 28, 2013

Fixed! Amazing, thanks Michael!

arial_success

mdboom added a commit that referenced this pull request Jan 29, 2013

Merge pull request #1710 from mdboom/font_with_no_glyph_names
Mixing Arial with mathtext on Windows 8 fails

@mdboom mdboom merged commit 10bf587 into matplotlib:v1.2.x Jan 29, 2013

1 check passed

default The Travis build passed
Details

bgamari pushed a commit to bgamari/matplotlib that referenced this pull request Nov 5, 2013

matplotlib#1710
When a font doesn't have a glyph name, we should synthesize.  This fixes the
Arial font problems under Windows 8.

@mdboom mdboom deleted the mdboom:font_with_no_glyph_names branch Aug 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment