
    G8cN                         d Z ddlmZ ddlZddlmZ ddlZddlm	Z	m
Z
 ddlmZ ddlmZ  ej                  d	      d
        Zd Z G d d      Z G d de      Zy)z7
Common functionality between the PDF and PS backends.
    )BytesION)subset   )font_managerft2font)AFM)RendererBase2   c                 \    t        | d      5 }t        |      cd d d        S # 1 sw Y   y xY w)Nrb)openr   )fnamefhs     E/usr/lib/python3/dist-packages/matplotlib/backends/_backend_pdf_ps.py_cached_get_afm_from_fnamer      s*    	eT	 b2w  s   "+c                    t        j                  dd      }|xj                  g dz  c_        | j                  d      rd|_        t        j
                  | |      5 }t        j                  |      }|j                  |       |j                  |       t               }|j                  |d	       |cd
d
d
       S # 1 sw Y   y
xY w)aD  
    Subset a TTF font

    Reads the named fontfile and restricts the font to the characters.
    Returns a serialization of the subset font as file-like object.

    Parameters
    ----------
    symbol : str
        Path to the font file
    characters : str
        Continuous set of characters to include in subset
    T)glyph_namesrecommended_glyphs)FFTMPfEdBDFz.ttcr   )options)textF)reorderTablesN)
r   Optionsdrop_tablesendswithfont_number	load_font	Subsetterpopulater   save)fontfile
charactersr   font	subsetterr   s         r   get_glyphs_subsetr'      s     nn$GG 22  			(G	, $$W5	
+Y		"E	*  s   AB??Cc                   "    e Zd ZdZd Zd Zd Zy)CharacterTrackerz
    Helper for font subsetting by the pdf and ps backends.

    Maintains a mapping of font paths to the set of character codepoints that
    are being used from that font.
    c                     i | _         y N)usedselfs    r   __init__zCharacterTracker.__init__?   s	    	    c                     |j                  |      }|j                         D ]K  \  }}| j                  j                  |j                  t                     j                  t        |             M y)z:Record that string *s* is being typeset using font *font*.N)_get_fontmapitemsr,   
setdefaultr   setaddord)r.   r%   schar_to_font_c_fs         r   trackzCharacterTracker.trackB   sW    ((+"((* 	?FBII  35155c"g>	?r0   c                 ~    | j                   j                  |j                  t                     j	                  |       y)zARecord that codepoint *glyph* is being typeset using font *font*.N)r,   r4   r   r5   r6   )r.   r%   glyphs      r   track_glyphzCharacterTracker.track_glyphH   s'    		TZZ/33E:r0   N)__name__
__module____qualname____doc__r/   r<   r?    r0   r   r)   r)   7   s    ?;r0   r)   c                   H     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )	RendererPDFPSBasec                 >    t         |           || _        || _        y r+   )superr/   widthheight)r.   rI   rJ   	__class__s      r   r/   zRendererPDFPSBase.__init__R   s    
r0   c                      y)NFrD   r-   s    r   flipyzRendererPDFPSBase.flipyW   s    r0   c                      y)NTrD   r-   s    r   option_scale_imagez$RendererPDFPSBase.option_scale_image[   s    r0   c                 *    t         j                  d    S )Nzimage.composite_image)mplrcParamsr-   s    r   option_image_nocompositez*RendererPDFPSBase.option_image_nocomposite_   s     << 7888r0   c                 >    | j                   dz  | j                  dz  fS )Ng      R@)rI   rJ   r-   s    r   get_canvas_width_heightz)RendererPDFPSBase.get_canvas_width_heightd   s    zzD $++"444r0   c                    |dk(  r=| j                         }|j                         }|j                  |||       \  }}}|||fS |rJ| j                  j                  j                  |d|      }	|	j                  |	j                  |	j                  fS t        j                  | j                     rO| j                  |      }
|
j                  |      \  }}}}}|j                         dz  }||z  }||z  }||z  }|||fS | j                  |      }
|
j                  |dt         j"                         |
j%                         \  }}|
j'                         }d}||z  }||z  }||z  }|||fS )NTeX)rendererH   i  g        )flagsg      ?)get_texmanagerget_size_in_pointsget_text_width_height_descent
_text2pathmathtext_parserparserI   rJ   depthrQ   rR   _use_afm_rc_name_get_font_afmget_str_bbox_and_descent_get_font_ttfset_textr   LOAD_NO_HINTINGget_width_heightget_descent)r.   r8   propismath
texmanagerfontsizewhdr`   r%   lbscales                 r   r]   z/RendererPDFPSBase.get_text_width_height_descenth   st   U?,,.J..0H >>8d ? ,GAq!a7NOO3399!RFE;;ekk99\\$//0%%d+D 99!<MAq!Q++-4EJAJAJAa7N%%d+DMM!S(?(?M@((*DAq  "AEJAJAJAa7Nr0   c                 \    t        j                  |d| j                        }t        |      S )Nafm)fontext	directory)r   findfont_afm_font_dirr   )r.   rj   r   s      r   rc   zRendererPDFPSBase._get_font_afm   s*    %%%4+=+=?)%00r0   c                     t         j                  j                  |      }t        j                  |      }|j	                          |j                  |j                         d       |S )NrY   )r   fontManager_find_fonts_by_propsget_fontclearset_sizer\   )r.   rj   fnamesr%   s       r   re   zRendererPDFPSBase._get_font_ttf   sM    ))>>tD$$V,

d--/4r0   )r@   rA   rB   r/   rM   rO   rS   rU   r]   rc   re   __classcell__)rK   s   @r   rF   rF   M   s+    

9
5<1
r0   rF   )rC   ior   	functools	fontToolsr   
matplotlibrQ    r   r   _afmr   backend_basesr	   	lru_cacher   r'   r)   rF   rD   r0   r   <module>r      s`        $  ( R 
B; ;,C Cr0   