@@ -437,22 +437,29 @@ def _get_layout(self, renderer):
437437 dpi = self .get_figure (root = True ).dpi
438438 # Determine full vertical extent of font, including ascenders and descenders:
439439 if not self .get_usetex ():
440- font = get_font (fontManager ._find_fonts_by_props (self ._fontproperties ))
441- possible_metrics = [
442- ('OS/2' , 'sTypoLineGap' , 'sTypoAscender' , 'sTypoDescender' ),
443- ('hhea' , 'lineGap' , 'ascent' , 'descent' )
444- ]
445- for table_name , linegap_key , ascent_key , descent_key in possible_metrics :
446- table = font .get_sfnt_table (table_name )
447- if table is None :
448- continue
449- # Rescale to font size/DPI if the metrics were available.
450- fontsize = self ._fontproperties .get_size_in_points ()
451- units_per_em = font .get_sfnt_table ('head' )['unitsPerEm' ]
452- line_gap = table [linegap_key ] / units_per_em * fontsize * dpi / 72
453- min_ascent = table [ascent_key ] / units_per_em * fontsize * dpi / 72
454- min_descent = - table [descent_key ] / units_per_em * fontsize * dpi / 72
455- break
440+ if hasattr (renderer , '_get_font_height_metrics' ):
441+ # TODO: This is a temporary internal method call (for _backend_pdf_ps to
442+ # support AFM files) until we design a proper API for the backends.
443+ min_ascent , min_descent , line_gap = renderer ._get_font_height_metrics (
444+ self ._fontproperties )
445+ if min_ascent is None :
446+ font = get_font (fontManager ._find_fonts_by_props (self ._fontproperties ))
447+ possible = [
448+ ('OS/2' , 'sTypoLineGap' , 'sTypoAscender' , 'sTypoDescender' ),
449+ ('hhea' , 'lineGap' , 'ascent' , 'descent' )
450+ ]
451+ for table_name , linegap_key , ascent_key , descent_key in possible :
452+ table = font .get_sfnt_table (table_name )
453+ if table is None :
454+ continue
455+ # Rescale to font size/DPI if the metrics were available.
456+ fontsize = self ._fontproperties .get_size_in_points ()
457+ units_per_em = font .get_sfnt_table ('head' )['unitsPerEm' ]
458+ scale = 1 / units_per_em * fontsize * dpi / 72
459+ line_gap = table [linegap_key ] * scale
460+ min_ascent = table [ascent_key ] * scale
461+ min_descent = - table [descent_key ] * scale
462+ break
456463 if None in (min_ascent , min_descent ):
457464 # Fallback to font measurement.
458465 _ , h , min_descent = _get_text_metrics_with_cache (
0 commit comments