31
31
import numpy as np
32
32
33
33
import matplotlib as mpl
34
- from matplotlib import cbook , dviread , rcParams
34
+ from matplotlib import _api , cbook , dviread , rcParams
35
35
36
36
_log = logging .getLogger (__name__ )
37
37
@@ -43,14 +43,12 @@ class TexManager:
43
43
Repeated calls to this constructor always return the same instance.
44
44
"""
45
45
46
- # Caches.
47
46
texcache = os .path .join (mpl .get_cachedir (), 'tex.cache' )
48
- grey_arrayd = {}
49
47
50
- font_family = 'serif'
51
- font_families = ( 'serif' , 'sans-serif' , 'cursive' , 'monospace' )
52
-
53
- font_info = {
48
+ _grey_arrayd = {}
49
+ _font_family = 'serif'
50
+ _font_families = ( 'serif' , 'sans-serif' , 'cursive' , 'monospace' )
51
+ _font_info = {
54
52
'new century schoolbook' : ('pnc' , r'\renewcommand{\rmdefault}{pnc}' ),
55
53
'bookman' : ('pbk' , r'\renewcommand{\rmdefault}{pbk}' ),
56
54
'times' : ('ptm' , r'\usepackage{mathptmx}' ),
@@ -71,36 +69,42 @@ class TexManager:
71
69
'computer modern sans serif' : ('cmss' , r'\usepackage{type1ec}' ),
72
70
'computer modern typewriter' : ('cmtt' , r'\usepackage{type1ec}' )}
73
71
72
+ grey_arrayd = _api .deprecate_privatize_attribute ("3.5" )
73
+ font_family = _api .deprecate_privatize_attribute ("3.5" )
74
+ font_families = _api .deprecate_privatize_attribute ("3.5" )
75
+ font_info = _api .deprecate_privatize_attribute ("3.5" )
76
+
74
77
@functools .lru_cache () # Always return the same instance.
75
78
def __new__ (cls ):
76
79
Path (cls .texcache ).mkdir (parents = True , exist_ok = True )
77
80
return object .__new__ (cls )
78
81
79
82
def get_font_config (self ):
80
83
ff = rcParams ['font.family' ]
81
- if len (ff ) == 1 and ff [0 ].lower () in self .font_families :
82
- self .font_family = ff [0 ].lower ()
84
+ if len (ff ) == 1 and ff [0 ].lower () in self ._font_families :
85
+ self ._font_family = ff [0 ].lower ()
83
86
else :
84
87
_log .info ('font.family must be one of (%s) when text.usetex is '
85
88
'True. serif will be used by default.' ,
86
- ', ' .join (self .font_families ))
87
- self .font_family = 'serif'
89
+ ', ' .join (self ._font_families ))
90
+ self ._font_family = 'serif'
88
91
89
- fontconfig = [self .font_family ]
92
+ fontconfig = [self ._font_family ]
90
93
fonts = {}
91
- for font_family in self .font_families :
94
+ for font_family in self ._font_families :
92
95
for font in rcParams ['font.' + font_family ]:
93
- if font .lower () in self .font_info :
94
- fonts [font_family ] = self .font_info [font .lower ()]
95
- _log .debug ('family: %s, font: %s, info: %s' ,
96
- font_family , font , self .font_info [font .lower ()])
96
+ if font .lower () in self ._font_info :
97
+ fonts [font_family ] = self ._font_info [font .lower ()]
98
+ _log .debug (
99
+ 'family: %s, font: %s, info: %s' ,
100
+ font_family , font , self ._font_info [font .lower ()])
97
101
break
98
102
else :
99
103
_log .debug ('%s font is not compatible with usetex.' , font )
100
104
else :
101
105
_log .info ('No LaTeX-compatible font found for the %s font '
102
106
'family in rcParams. Using default.' , font_family )
103
- fonts [font_family ] = self .font_info [font_family ]
107
+ fonts [font_family ] = self ._font_info [font_family ]
104
108
fontconfig .append (fonts [font_family ][0 ])
105
109
# Add a hash of the latex preamble to fontconfig so that the
106
110
# correct png is selected for strings rendered with same font and dpi
@@ -112,7 +116,7 @@ def get_font_config(self):
112
116
# file's preamble:
113
117
cmd = {fonts [family ][1 ]
114
118
for family in ['serif' , 'sans-serif' , 'monospace' ]}
115
- if self .font_family == 'cursive' :
119
+ if self ._font_family == 'cursive' :
116
120
cmd .add (fonts ['cursive' ][1 ])
117
121
cmd .add (r'\usepackage{type1cm}' )
118
122
self ._font_preamble = '\n ' .join (sorted (cmd ))
@@ -169,7 +173,7 @@ def make_tex(self, tex, fontsize):
169
173
basefile = self .get_basefile (tex , fontsize )
170
174
texfile = '%s.tex' % basefile
171
175
fontcmd = {'sans-serif' : r'{\sffamily %s}' ,
172
- 'monospace' : r'{\ttfamily %s}' }.get (self .font_family ,
176
+ 'monospace' : r'{\ttfamily %s}' }.get (self ._font_family ,
173
177
r'{\rmfamily %s}' )
174
178
175
179
Path (texfile ).write_text (
@@ -262,11 +266,11 @@ def get_grey(self, tex, fontsize=None, dpi=None):
262
266
if not dpi :
263
267
dpi = rcParams ['savefig.dpi' ]
264
268
key = tex , self .get_font_config (), fontsize , dpi
265
- alpha = self .grey_arrayd .get (key )
269
+ alpha = self ._grey_arrayd .get (key )
266
270
if alpha is None :
267
271
pngfile = self .make_png (tex , fontsize , dpi )
268
272
rgba = mpl .image .imread (os .path .join (self .texcache , pngfile ))
269
- self .grey_arrayd [key ] = alpha = rgba [:, :, - 1 ]
273
+ self ._grey_arrayd [key ] = alpha = rgba [:, :, - 1 ]
270
274
return alpha
271
275
272
276
def get_rgba (self , tex , fontsize = None , dpi = None , rgb = (0 , 0 , 0 )):
0 commit comments