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

Skip to content

Commit 2fa695f

Browse files
committed
Globally cache a single TexManager instance.
This allows sharing its caches across renderer instances. (If it was up to me this class would be replaced by module-level functions and a module-level cache, but heh.)
1 parent de38ef2 commit 2fa695f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/matplotlib/texmanager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"""
3030

3131
import copy
32+
import functools
3233
import glob
3334
import hashlib
3435
import logging
@@ -48,6 +49,8 @@
4849
class TexManager(object):
4950
"""
5051
Convert strings to dvi files using TeX, caching the results to a directory.
52+
53+
Repeated calls to this constructor always return the same instance.
5154
"""
5255

5356
cachedir = mpl.get_cachedir()
@@ -95,6 +98,10 @@ class TexManager(object):
9598
('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview',
9699
'font.family') + tuple('font.' + n for n in font_families))
97100

101+
@functools.lru_cache() # Always return the same instance.
102+
def __new__(cls):
103+
return object.__new__(cls)
104+
98105
def __init__(self):
99106

100107
if self.texcache is None:

lib/matplotlib/textpath.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def _get_adobe_standard_encoding():
2424

2525

2626
class TextToPath(object):
27-
"""
28-
A class that convert a given text to a path using ttf fonts.
29-
"""
27+
"""A class that converts strings to paths."""
3028

3129
FONT_SCALE = 100.
3230
DPI = 72

0 commit comments

Comments
 (0)