1717
1818import numpy as np
1919
20- from matplotlib import cbook , __version__ , rcParams , checkdep_ghostscript
21- from matplotlib . afm import AFM
20+ from matplotlib import (
21+ cbook , _path , __version__ , rcParams , checkdep_ghostscript )
2222from matplotlib .backend_bases import (
2323 _Backend , FigureCanvasBase , FigureManagerBase , GraphicsContextBase ,
2424 RendererBase )
2525from matplotlib .cbook import (get_realpath_and_stat , is_writable_file_like ,
26- maxdict , file_requires_unicode )
27- from matplotlib .font_manager import findfont , is_opentype_cff_font , get_font
26+ file_requires_unicode )
27+ from matplotlib .font_manager import is_opentype_cff_font , get_font
2828from matplotlib .ft2font import KERNING_DEFAULT , LOAD_NO_HINTING
2929from matplotlib .ttconv import convert_ttf_to_ps
3030from matplotlib .mathtext import MathTextParser
3131from matplotlib ._mathtext_data import uni2type1
3232from matplotlib .path import Path
33- from matplotlib import _path
3433from matplotlib .transforms import Affine2D
3534from matplotlib .backends .backend_mixed import MixedModeRenderer
35+ from . import _backend_pdf_ps
3636
3737_log = logging .getLogger (__name__ )
3838
@@ -180,13 +180,19 @@ def _move_path_to_path_or_stream(src, dst):
180180 shutil .move (src , dst , copy_function = shutil .copyfile )
181181
182182
183- class RendererPS (RendererBase ):
183+ class RendererPS (_backend_pdf_ps . RendererPDFPSBase ):
184184 """
185185 The renderer handles all the drawing primitives using a graphics
186186 context instance that controls the colors/styles.
187187 """
188188
189- afmfontd = maxdict (50 )
189+ @property
190+ @cbook .deprecated ("3.1" )
191+ def afmfontd (self , _cache = cbook .maxdict (50 )):
192+ return _cache
193+
194+ _afm_font_dir = pathlib .Path (rcParams ["datapath" ], "fonts" , "afm" )
195+ _use_afm_rc_name = "ps.useafm"
190196
191197 def __init__ (self , width , height , pswriter , imagedpi = 72 ):
192198 # Although postscript itself is dpi independent, we need to imform the
@@ -217,9 +223,6 @@ def __init__(self, width, height, pswriter, imagedpi=72):
217223 self .used_characters = {}
218224 self .mathtext_parser = MathTextParser ("PS" )
219225
220- self ._afm_font_dir = os .path .join (
221- rcParams ['datapath' ], 'fonts' , 'afm' )
222-
223226 def track_characters (self , font , s ):
224227 """Keeps track of which characters are required from each font."""
225228 realpath , stat_key = get_realpath_and_stat (font .fname )
@@ -323,75 +326,6 @@ def create_hatch(self, hatch):
323326 self ._hatches [hatch ] = name
324327 return name
325328
326- def get_canvas_width_height (self ):
327- # docstring inherited
328- return self .width * 72.0 , self .height * 72.0
329-
330- def get_text_width_height_descent (self , s , prop , ismath ):
331- # docstring inherited
332-
333- if rcParams ['text.usetex' ]:
334- texmanager = self .get_texmanager ()
335- fontsize = prop .get_size_in_points ()
336- w , h , d = texmanager .get_text_width_height_descent (s , fontsize ,
337- renderer = self )
338- return w , h , d
339-
340- if ismath :
341- width , height , descent , pswriter , used_characters = \
342- self .mathtext_parser .parse (s , 72 , prop )
343- return width , height , descent
344-
345- if rcParams ['ps.useafm' ]:
346- if ismath :
347- s = s [1 :- 1 ]
348- font = self ._get_font_afm (prop )
349- l , b , w , h , d = font .get_str_bbox_and_descent (s )
350-
351- fontsize = prop .get_size_in_points ()
352- scale = 0.001 * fontsize
353- w *= scale
354- h *= scale
355- d *= scale
356- return w , h , d
357-
358- font = self ._get_font_ttf (prop )
359- font .set_text (s , 0.0 , flags = LOAD_NO_HINTING )
360- w , h = font .get_width_height ()
361- w /= 64 # convert from subpixels
362- h /= 64
363- d = font .get_descent ()
364- d /= 64
365- return w , h , d
366-
367- def flipy (self ):
368- # docstring inherited
369- return False
370-
371- def _get_font_afm (self , prop ):
372- key = hash (prop )
373- font = self .afmfontd .get (key )
374- if font is None :
375- fname = findfont (prop , fontext = 'afm' , directory = self ._afm_font_dir )
376- if fname is None :
377- fname = findfont (
378- "Helvetica" , fontext = 'afm' , directory = self ._afm_font_dir )
379- font = self .afmfontd .get (fname )
380- if font is None :
381- with open (fname , 'rb' ) as fh :
382- font = AFM (fh )
383- self .afmfontd [fname ] = font
384- self .afmfontd [key ] = font
385- return font
386-
387- def _get_font_ttf (self , prop ):
388- fname = findfont (prop )
389- font = get_font (fname )
390- font .clear ()
391- size = prop .get_size_in_points ()
392- font .set_size (size , 72.0 )
393- return font
394-
395329 def get_image_magnification (self ):
396330 """
397331 Get the factor by which to magnify images passed to draw_image.
@@ -400,14 +334,6 @@ def get_image_magnification(self):
400334 """
401335 return self .image_magnification
402336
403- def option_scale_image (self ):
404- # docstring inherited
405- return True
406-
407- def option_image_nocomposite (self ):
408- # docstring inherited
409- return not rcParams ['image.composite_image' ]
410-
411337 def draw_image (self , gc , x , y , im , transform = None ):
412338 # docstring inherited
413339
0 commit comments