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

Skip to content

Commit 4ca39f7

Browse files
committed
Merge pull request #5766 from ksemb/master
Deterministic LaTeX text in SVG images
1 parent 07999b1 commit 4ca39f7

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@ def test_bold_font_output_with_none_fonttype():
119119
ax.set_title('bold-title', fontweight='bold')
120120

121121

122-
def _test_determinism(filename):
122+
def _test_determinism_save(filename, usetex):
123123
# This function is mostly copy&paste from "def test_visibility"
124124
# To require no GUI, we use Figure and FigureCanvasSVG
125125
# instead of plt.figure and fig.savefig
126126
from matplotlib.figure import Figure
127127
from matplotlib.backends.backend_svg import FigureCanvasSVG
128128
from matplotlib import rc
129129
rc('svg', hashsalt='asdf')
130+
rc('text', usetex=usetex)
130131

131132
fig = Figure()
132133
ax = fig.add_subplot(111)
@@ -138,12 +139,14 @@ def _test_determinism(filename):
138139
a, b, c = ax.errorbar(x, y, yerr=yerr, fmt='ko')
139140
for artist in b:
140141
artist.set_visible(False)
142+
ax.set_title('A string $1+2+\sigma$')
143+
ax.set_xlabel('A string $1+2+\sigma$')
144+
ax.set_ylabel('A string $1+2+\sigma$')
141145

142146
FigureCanvasSVG(fig).print_svg(filename)
143147

144148

145-
@cleanup
146-
def test_determinism():
149+
def _test_determinism(filename, usetex):
147150
import os
148151
import sys
149152
from subprocess import check_call
@@ -154,15 +157,27 @@ def test_determinism():
154157
'import matplotlib; '
155158
'matplotlib.use("svg"); '
156159
'from matplotlib.tests.test_backend_svg '
157-
'import _test_determinism;'
158-
'_test_determinism("determinism.svg")'])
159-
with open('determinism.svg', 'rb') as fd:
160+
'import _test_determinism_save;'
161+
'_test_determinism_save(%r, %r)' % (filename, usetex)])
162+
with open(filename, 'rb') as fd:
160163
plots.append(fd.read())
161-
os.unlink('determinism.svg')
164+
os.unlink(filename)
162165
for p in plots[1:]:
163166
assert_equal(p, plots[0])
164167

165168

169+
@cleanup
170+
def test_determinism_notex():
171+
# unique filename to allow for parallel testing
172+
_test_determinism('determinism_notex.svg', usetex=False)
173+
174+
175+
@cleanup
176+
def test_determinism_tex():
177+
# unique filename to allow for parallel testing
178+
_test_determinism('determinism_tex.svg', usetex=True)
179+
180+
166181
if __name__ == '__main__':
167182
import nose
168183
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/textpath.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
182182
glyph_ids = []
183183

184184
if glyph_map is None:
185-
glyph_map = dict()
185+
glyph_map = OrderedDict()
186186

187187
if return_new_glyphs_only:
188188
glyph_map_new = OrderedDict()
@@ -241,10 +241,10 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None,
241241
s, self.DPI, prop)
242242

243243
if not glyph_map:
244-
glyph_map = dict()
244+
glyph_map = OrderedDict()
245245

246246
if return_new_glyphs_only:
247-
glyph_map_new = dict()
247+
glyph_map_new = OrderedDict()
248248
else:
249249
glyph_map_new = glyph_map
250250

@@ -320,10 +320,10 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
320320
dvi.close()
321321

322322
if glyph_map is None:
323-
glyph_map = dict()
323+
glyph_map = OrderedDict()
324324

325325
if return_new_glyphs_only:
326-
glyph_map_new = dict()
326+
glyph_map_new = OrderedDict()
327327
else:
328328
glyph_map_new = glyph_map
329329

0 commit comments

Comments
 (0)