Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26c0c63

Browse files
committed
Add test and expand comment
A test comparing images is difficult because the metrics are taken from the tex (which is correctly selected) so that even when the incorrect png is selected, it will be shifted so an image comparison will always fail.
1 parent df6b560 commit 26c0c63

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import matplotlib.pyplot as plt
5+
6+
from matplotlib.texmanager import TexManager
7+
8+
def test_fontconfig_preamble():
9+
"""
10+
Test that the preamble is included in _fontconfig
11+
"""
12+
plt.rcParams['text.usetex'] = True
13+
14+
tm1 = TexManager()
15+
font_config1 = tm1.get_font_config()
16+
17+
plt.rcParams['text.latex.preamble'] = [r'\usepackage{txfonts}']
18+
tm2 = TexManager()
19+
font_config2 = tm2.get_font_config()
20+
21+
assert font_config1 != font_config2

lib/matplotlib/texmanager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def __init__(self):
203203
'default.' % ff, 'helpful')
204204
setattr(self, font_family_attr, self.font_info[font_family])
205205
fontconfig.append(getattr(self, font_family_attr)[0])
206-
# Add a hash of the latex preamble to fontconfig
206+
# Add a hash of the latex preamble to self._fontconfig so that the
207+
# correct png is selected for strings rendered with same font and dpi
208+
# even if the latex preamble changes within the session
207209
preamble_bytes = six.text_type(self.get_custom_preamble()).encode('utf-8')
208210
fontconfig.append(md5(preamble_bytes).hexdigest())
209211
self._fontconfig = ''.join(fontconfig)

0 commit comments

Comments
 (0)