
    P/PhP                         d Z ddlmZ ddl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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     c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/matplotlib/backends/_backend_pdf_ps.py_cached_get_afm_from_fnamer      s|    	eT		 b2ww                 s   -11c                 8   t          j        dd          }|xj        g dz  c_        |                     d          rd|_        t          j        | |          }t          j        |          }|                    |           |                     |           |S )a  
    Subset a TTF font

    Reads the named fontfile and restricts the font to the characters.

    Parameters
    ----------
    fontfile : str
        Path to the font file
    characters : str
        Continuous set of characters to include in subset

    Returns
    -------
    fontTools.ttLib.ttFont.TTFont
        An open font object representing the subset, which needs to
        be closed by the caller.
    T)glyph_namesrecommended_glyphs)FFTMPfEdBDFmetaMERGTSIVZapfbdatbloccidgfdscfeatfmtxfondjustkerxltagmorxtrakxrefz.ttcr   )options)text)r   Optionsdrop_tablesendswithfont_number	load_font	Subsetterpopulate)fontfile
charactersr)   font	subsetters        r   get_glyphs_subsetr6      s    ( n$GGGG     .     Hg..D 111IJ'''TK    c                 P    t                      }|                     |d           |S )z
    Convert a TTFont object into a file-like object.

    Parameters
    ----------
    font : fontTools.ttLib.ttFont.TTFont
        A font object

    Returns
    -------
    BytesIO
        A file object with the font saved into it
    F)reorderTables)r   save)r4   r   s     r   font_as_filer;   O   s(     
BIIbI&&&Ir7   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__j   s    			r7   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)rB   r4   schar_to_font_c_fs         r   trackzCharacterTracker.trackm   ss    ((++"((** 	? 	?FBI  3551155c"gg>>>>	? 	?r7   c                     | j                             |j        t                                                    |           dS )zARecord that codepoint *glyph* is being typeset using font *font*.N)r@   rG   r   rH   rI   )rB   r4   glyphs      r   track_glyphzCharacterTracker.track_glyphs   s4    	TZ//33E:::::r7   N)__name__
__module____qualname____doc__rC   rO   rR    r7   r   r=   r=   b   sK           ? ? ?; ; ; ; ;r7   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?   )superrC   widthheight)rB   r\   r]   	__class__s      r   rC   zRendererPDFPSBase.__init__}   s+    
r7   c                     dS )NFrW   rA   s    r   flipyzRendererPDFPSBase.flipy   s    ur7   c                     dS )NTrW   rA   s    r   option_scale_imagez$RendererPDFPSBase.option_scale_image   s    tr7   c                 (    t           j        d          S )Nzimage.composite_image)mplrcParamsrA   s    r   option_image_nocompositez*RendererPDFPSBase.option_image_nocomposite   s     < 7888r7   c                 *    | j         dz  | j        dz  fS )Ng      R@)r\   r]   rA   s    r   get_canvas_width_heightz)RendererPDFPSBase.get_canvas_width_height   s    zD $+"444r7   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        j                   |                                \  }}	|                                }
d}||z  }|	|z  }	|
|z  }
||	|
fS )NTeXH   i  g        )flagsg      ?)r[   get_text_width_height_descent
_text2pathmathtext_parserparser\   r]   depthrd   re   _use_afm_rc_name_get_font_afmget_str_bbox_and_descentget_size_in_points_get_font_ttfset_textr   	LoadFlags
NO_HINTINGget_width_heightget_descent)rB   rK   propismathrp   r4   lbwhdscaler^   s               r   rm   z/RendererPDFPSBase.get_text_width_height_descent   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(9(DMEEE((**DAq  ""AEJAJAJAa7Nr7   c                 X    t          j        |d| j                  }t          |          S )Nafm)fontext	directory)r   findfont_afm_font_dirr   )rB   r|   r   s      r   rs   zRendererPDFPSBase._get_font_afm   s1    %%4+=? ? ?)%000r7   c                 ^   t           j                            |          }	 t          j        |          }|                                 |                    |                                d           |S # t          $ r/ t          j	        t                                        d|            w xY w)Nrk   zMThe PostScript/PDF backend does not currently support the selected font (%s).)r   fontManager_find_fonts_by_propsget_fontclearset_sizeru   RuntimeErrorlogging	getLoggerrS   warning)rB   r|   fnamesr4   s       r   rv   zRendererPDFPSBase._get_font_ttf   s    )>>tDD		(00DJJLLLMM$1133R888K 	 	 	h''//239; ; ; 		s   AA3 39B,)rS   rT   rU   rC   r`   rb   rf   rh   rm   rs   rv   __classcell__)r^   s   @r   rY   rY   x   s        
    
    9 9 9
5 5 5    41 1 1
      r7   rY   )rV   ior   	functoolsr   	fontToolsr   
matplotlibrd    r   r   _afmr   backend_basesr	   	lru_cacher   r6   r;   r=   rY   rW   r7   r   <module>r      s@                         $ $ $ $ $ $ $ $       ( ( ( ( ( ( R  
5 5 5p  &; ; ; ; ; ; ; ;,E E E E E E E E E Er7   