
    Ng\                         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dS )z7
Common functionality between the PDF and PS backends.
    )BytesION)subset   )font_managerft2font)AFM)RendererBase2   c                 t    t          | d          5 }t          |          cd d d            S # 1 swxY w Y   d S )Nrb)openr   )fnamefhs     _/var/www/html/ai-engine/env/lib/python3.11/site-packages/matplotlib/backends/_backend_pdf_ps.py_cached_get_afm_from_fnamer      s|    	eT		 b2ww                 s   -11c                    t          j        dd          }|xj        g dz  c_        |                     d          rd|_        t          j        | |          5 }t          j        |          }|                    |           |                     |           t                      }|	                    |d	           |cd
d
d
           S # 1 swxY w Y   d
S )aF  
    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
    ----------
    fontfile : str
        Path to the font file
    characters : str
        Continuous set of characters to include in subset
    T)glyph_namesrecommended_glyphs)FFTMPfEdBDFmetaz.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(      s1    n$GGGG          		(G	,	, $W555	
+++YY		"E	***                 s   A'CCCc                   $    e Zd ZdZd Zd Zd ZdS )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 | _         d S N)usedselfs    r   __init__zCharacterTracker.__init__D   s    			    c                     |                     |          }|                                D ]Q\  }}| j                            |j        t                                                    t          |                     RdS )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.trackG   ss    ((++"((** 	? 	?FBI  3551155c"gg>>>>	? 	?r1   c                     | j                             |j        t                                                    |           dS )zARecord that codepoint *glyph* is being typeset using font *font*.N)r-   r5   r   r6   r7   )r/   r&   glyphs      r   track_glyphzCharacterTracker.track_glyphM   s4    	TZ//33E:::::r1   N)__name__
__module____qualname____doc__r0   r=   r@    r1   r   r*   r*   <   sK           ? ? ?; ; ; ; ;r1   r*   c                   L     e Zd Z fdZd Zd Zd Zd Z fdZd Z	d Z
 xZS )	RendererPDFPSBasec                 d    t                                                       || _        || _        d S r,   )superr0   widthheight)r/   rJ   rK   	__class__s      r   r0   zRendererPDFPSBase.__init__W   s+    
r1   c                     dS )NFrE   r.   s    r   flipyzRendererPDFPSBase.flipy\   s    ur1   c                     dS )NTrE   r.   s    r   option_scale_imagez$RendererPDFPSBase.option_scale_image`   s    tr1   c                 (    t           j        d          S )Nzimage.composite_image)mplrcParamsr.   s    r   option_image_nocompositez*RendererPDFPSBase.option_image_nocomposited   s     < 7888r1   c                 *    | j         dz  | j        dz  fS )Ng      R@)rJ   rK   r.   s    r   get_canvas_width_heightz)RendererPDFPSBase.get_canvas_width_heighti   s    zD $+"444r1   c                    |dk    r#t                                          |||          S |r5| j        j                            |d|          }|j        |j        |j        fS t          j	        | j
                 r[|                     |          }|                    |          \  }}}}	}
|                                dz  }||z  }|	|z  }	|
|z  }
||	|
fS |                     |          }|                    |dt           j                   |                                \  }}	|                                }
d}||z  }|	|z  }	|
|z  }
||	|
fS )NTeXH   i  g        )flagsg      ?)rI   get_text_width_height_descent
_text2pathmathtext_parserparserJ   rK   depthrR   rS   _use_afm_rc_name_get_font_afmget_str_bbox_and_descentget_size_in_points_get_font_ttfset_textr   LOAD_NO_HINTINGget_width_heightget_descent)r/   r9   propismathr^   r&   lbwhdscalerL   s               r   r[   z/RendererPDFPSBase.get_text_width_height_descentm   s\   U??7788D&III 	O399!RFFE;ek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7Nr1   c                 X    t          j        |d| j                  }t          |          S )Nafm)fontext	directory)r   findfont_afm_font_dirr   )r/   ri   r   s      r   ra   zRendererPDFPSBase._get_font_afm   s1    %%4+=? ? ?)%000r1   c                     t           j                            |          }t          j        |          }|                                 |                    |                                d           |S )NrY   )r   fontManager_find_fonts_by_propsget_fontclearset_sizerc   )r/   ri   fnamesr&   s       r   rd   zRendererPDFPSBase._get_font_ttf   sZ    )>>tDD$V,,

d--//444r1   )rA   rB   rC   r0   rN   rP   rT   rV   r[   ra   rd   __classcell__)rL   s   @r   rG   rG   R   s        
    
    9 9 9
5 5 5    41 1 1
      r1   rG   )rD   ior   	functools	fontToolsr   
matplotlibrR    r   r   _afmr   backend_basesr	   	lru_cacher   r(   r*   rG   rE   r1   r   <module>r      s                        $ $ $ $ $ $ $ $       ( ( ( ( ( ( R  
# # #L; ; ; ; ; ; ; ;,? ? ? ? ? ? ? ? ? ?r1   