
    l0jl                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZmZmZmZ ddlmZ ddlZddlZddlZddlmZmZmZ ddlmZ  ej        e          Z  ej!        dd	          Z" e
d
d          Z# e
dd          Z$ G d d e
dd                    Z% e&d d d d d d d d           Z'dUdZ( G d d          Z) G d d          Z* G d  d!e)          Z+d" Z, ej-        d#d#$           G d% d&                      Z. G d' d(          Z/ G d) d*          Z0 e
d+d,          Z1 G d- d.          Z2d/ Z3 G d0 d1          Z4ed2             Z5ed3             Z6 ee6e/d4          Z7 ee6e+d5          Z8ed6k    r;ddl9Z9dd7l:m;Z;  e;            Z<e<=                    d8           e<=                    d9d:e>d;           e<=                    d<d=d>?           e<?                                Z@e@jA        r ejB        ejC        @           dA ZD e)e@jE        e@jF                  5 ZGeGD ]wZH eIdBeHjJ         dCeHjK         dDeHjL         dE            eIdF            e9jM        eHjN        dG           D ]\  ZOZPejQ        dHk    reOjR        S                    dI          n ejT        eOjR                  ZU eVeOjW        e/          r$ eIdJeU dKeOX                                            n eIdJeU             eIdLeOjY        dMz               eDdNdOdPdQdR           ePD ]7ZN eDeNjZ        eNj[        eNj\        eN]                                eNjJ                   8eHj^        rE eIdS            eDdNdOdTdR           eHj^        D ]$Z_ eDe_jZ        e_j[        e_jK        e_jJ                   %y	 ddd           dS # 1 swxY w Y   dS dS )VaC  
A module for reading dvi files output by TeX. Several limitations make
this not (currently) useful as a general-purpose dvi preprocessor, but
it is currently used by the pdf backend for processing usetex text.

Interface::

  with Dvi(filename, 72) as dvi:
      # iterate over pages:
      for page in dvi:
          w, h, d = page.width, page.height, page.descent
          for x, y, font, glyph, width in page.text:
              fontname = font.texname
              pointsize = font.size
              ...
          for x, y, height, width in page.boxes:
              ...
    N)
namedtuple)cachecached_property	lru_cachepartialwraps)Path)_apicbookfont_manager)	LoadFlagsDviStatez!pre outer inpage post_post finalePageztext boxes height width descentBoxzx y height widthc                       e Zd ZdZed             Z ed           Z ed           Z ed           Zed             Z	d Z
dS )	Texta  
    A glyph in the dvi file.

    In order to render the glyph, load the glyph at index ``text.index``
    from the font at ``text.font.resolve_path()`` with size ``text.font.size``,
    warped with ``text.font.effects``, then draw it at position
    ``(text.x, text.y)``.

    ``text.glyph`` is the glyph number actually stored in the dvi file (whose
    interpretation depends on the font).  ``text.width`` is the glyph width in
    dvi units.
    c                 @    | j                             | j                  S )zY
        The FreeType index of this glyph (that can be passed to FT_Load_Glyph).
        )font_index_dvi_to_freetypeglyphselfs    U/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/matplotlib/dviread.pyindexz
Text.indexS   s     y//
;;;    c                 4    | j                                         S N)r   resolve_pathr   s    r   <lambda>zText.<lambda>[   s    di&<&<&>&> r   c                     | j         j        S r   )r   sizer   s    r   r   zText.<lambda>\   s
    din r   c                     | j         j        S r   )r   effectsr   s    r   r   zText.<lambda>]   s    ): r   c                     t          t          d                    | j        j                 }|j        t          |j                  | j                 n| j        S )a  
        The glyph name, the native charmap glyph index, or the raw glyph index.

        If the font is a TrueType file (which can currently only happen for
        DVI files generated by xetex or luatex), then this number is the raw
        index of the glyph, which can be passed to FT_Load_Glyph/load_glyph.

        Otherwise, the font is a PostScript font.  For such fonts, if
        :file:`pdftex.map` specifies an encoding for this glyph's font,
        that is a mapping of glyph indices to Adobe glyph names; which
        is used by this property to convert dvi numbers to glyph names.
        Callers can then convert glyph names to glyph indices (with
        FT_Get_Name_Index/get_name_index), and load the glyph using
        FT_Load_Glyph/load_glyph.

        If :file:`pdftex.map` specifies no encoding for a PostScript font,
        this number is an index to the font's "native" charmap; glyphs should
        directly load using FT_Load_Char/load_char after selecting the native
        charmap.
        
pdftex.map)
PsfontsMapfind_tex_filer   texnameencoding
_parse_encr   )r   entrys     r   glyph_name_or_indexzText.glyph_name_or_index_   sN    : =6677	8IJ>- 5>**4:6637:	?r   c                    | j         j        rt          d          | j                                         }|j                                                            d          rHt          | j                  	                                rt          | j                   dn
d| j        dS t          j        |          }|                    | j                  }t          j                            |          }|p|S )Nz'Indexing TTC fonts is not supported yetpk?z#02x)r   subfontNotImplementedErrorr   namelowerendswithchrr   isprintabler   get_fontget_glyph_namer   	fontToolsagl	toUnicode)r   pathface
glyph_name	glyph_strs        r   _as_unicode_or_namezText._as_unicode_or_name   s    9 	Q%&OPPPy%%''9??%%d++ 	, .1__-H-H-J-J +s4:))))****,$T**((44
M++J77	&J&r   N)__name__
__module____qualname____doc__propertyr   	font_path	font_sizefont_effectsr,   r@    r   r   r   r   E   s          < < X< >>??I4455I8::;;L? ? X?@' ' ' ' 'r   r   zx y font glyph widthc                     |S r   rI   dvideltas     r   r   r      s    5 r   c                 0    |                      dd          S N   Fsigned	_read_argrK   s     r   r   r          #--%-88 r   c                 0    |                      dd          S )N   FrQ   rS   rK   s     r   r   r      rU   r   c                 0    |                      dd          S )NrW   TrQ   rS   rK   s     r   r   r      s    #--$-77 r   c                 8    |r|                      |d          nd S )NTrQ   rS   rK   s     r   r   r      s     PCMM%M===D r   c                 6    |                      |dz   d          S )NrP   TrQ   rS   rK   s     r   r   r      s    S]]519T]BB r   c                 6    |                      |dz   d          S rO   rS   rK   s     r   r   r      s    S]]519U]CC r   c                 >    |                      |dz   |dk              S )NrP      rQ   rS   rK   s     r   r   r      s    S]]519eqj]JJ r   )rawu1u4s4slenslen1ulen1olen1r^   c                 "      fd}|S )a  
    Decorator for dispatch by opcode. Sets the values in *table*
    from *min* to *max* to this method, adds a check that the Dvi state
    matches *state* if not None, reads arguments from the file according
    to *args*.

    Parameters
    ----------
    table : dict[int, callable]
        The dispatch table to be filled in.

    min, max : int
        Range of opcodes that calls the registered function; *max* defaults to
        *min*.

    state : _dvistate, optional
        State of the Dvi object in which these opcodes are allowed.

    args : list[str], default: ['raw']
        Sequence of argument specifications:

        - 'raw': opcode minus minimum
        - 'u1': read one unsigned byte
        - 'u4': read four bytes, treat as an unsigned number
        - 's4': read four bytes, treat as a signed number
        - 'slen': read (opcode - minimum) bytes, treat as signed
        - 'slen1': read (opcode - minimum + 1) bytes, treat as signed
        - 'ulen1': read (opcode - minimum + 1) bytes, treat as unsigned
        - 'olen1': read (opcode - minimum + 1) bytes, treat as unsigned
          if under four bytes, signed if four bytes
    c                      d D             t                      fd            }|<   n%t          dz             D ]}|         J ||<   |S )Nc                 (    g | ]}t           |         S rI   )_arg_mapping).0xs     r   
<listcomp>z/_dispatch.<locals>.decorate.<locals>.<listcomp>   s    222LO222r   c                 n      j         k    rt          d            g fdD             R  S )Nzstate precondition failedc                 .    g | ]} |z
            S rI   rI   )rk   fbyteminr   s     r   rm   z@_dispatch.<locals>.decorate.<locals>.wrapper.<locals>.<listcomp>   s)    !F!F!F!!D$s("3"3!F!F!Fr   )state
ValueError)r   rq   get_argsmethodrr   rs   s   ``r   wrapperz,_dispatch.<locals>.decorate.<locals>.wrapper   sY     TZ5%8%8 !<===6$G!F!F!F!F!F!FX!F!F!FGGGGr   rP   )r   range)	rv   rw   iru   argsmaxrr   rs   tables	   `  @r   decoratez_dispatch.<locals>.decorate   s    22T222	v	H 	H 	H 	H 	H 	H 	H 
	H ; E#JJ3A&& # #Qx'''"ar   rI   )r|   rr   r{   rs   rz   r}   s   ````` r   	_dispatchr~      s<    @         Or   c                   `   e Zd ZdZdgdz  Z eee          Zd Zd Zd Z	d Z
d Zd	 Zd
 ZdfdZ eddej                  d             Z eddej        d          d             Z edej        d          d             Z eddej        d          d             Zd Z edej        d          d             Zd  Z ed!          d"             Z ed#ej        d$          d%             Z ed&ej        '          d(             Z ed)ej        '          d*             Z ed+ej        '          d,             Z ed-d.ej        d/          d0             Z ed1d2ej        d3          d4             Z ed5d6ej        d3          d7             Z  ed8d9ej        d/          d:             Z! ed;d<ej        d3          d=             Z" ed>d?ej        d3          d@             Z# edAdBej                  dC             Z$ edDdEej        d          dF             Z% edGdHdIJ          dK             Z& edLdMdNJ          dO             Z'dP Z( edQej)        dR          dS             Z* edTej        '          dU             Z+ edVdWX          dY             Z, edZdWX          d[             Z- ed\dWX          d]             Z. ed^dWX          d_             Z/ ed`dWX          da             Z0 edbdWX          dc             Z1 edd          de             Z2dS )gDviaI  
    A reader for a dvi ("device-independent") file, as produced by TeX.

    The current implementation can only iterate through pages in order,
    and does not even attempt to verify the postamble.

    This class can be used as a context manager to close the underlying
    file upon exit. Pages can be read via iteration. Here is an overly
    simple way to extract text without trying to detect whitespace::

        >>> with matplotlib.dviread.Dvi('input.dvi', 72) as dvi:
        ...     for page in dvi:
        ...         print(''.join(chr(t.glyph) for t in page.text))
    N   c                     t                               d|           t          |d          | _        || _        i | _        t          j        | _        d| _	        dS )z
        Read the data from the file named *filename* and convert
        TeX's internal units to units of *dpi* per inch.
        *dpi* only sets the units and does not limit the resolution.
        Use None to return TeX's internal units.
        zDvi: %srbN)
_logdebugopenfiledpifonts	_dvistateprers   _missing_font)r   filenamer   s      r   __init__zDvi.__init__   sN     	

9h'''4((	
]
!r   c                     | S )z+Context manager enter method, does nothing.rI   r   s    r   	__enter__zDvi.__enter__   s    r   c                 .    |                                   dS )zX
        Context manager exit method, closes the underlying file if it is open.
        N)close)r   etypeevalueetraces       r   __exit__zDvi.__exit__   s     	

r   c              #      K   |                                  r,|                                 V  |                                  *dS dS )a\  
        Iterate through the pages of the file.

        Yields
        ------
        Page
            Details of all the text and box objects on the page.
            The Page tuple contains lists of Text and Box tuples and
            the page dimensions, and the Text and Box tuples contain
            coordinates transformed into a standard Cartesian
            coordinate system at the dpi value given when initializing.
            The coordinates are floating point numbers, but otherwise
            precision is not lost and coordinate values are not clipped to
            integers.
        N)_read_outputr   s    r   __iter__zDvi.__iter__  sR        jjll 	!,,..    jjll 	! 	! 	! 	! 	!r   c                 T    | j         j        s| j                                          dS dS )z(Close the underlying file if it is open.N)r   closedr   r   s    r   r   z	Dvi.close  s1    y 	IOO	 	r   c                 8   t           j        x}t           j         x}t           j         }| j        | j        z   D ]}t	          |t
                    r
|\  }}}}d}	n |\  }}}
}}|
                    |          \  }}	t          |          t          |||z
            }t          |||z             }t          ||	z             t          ||          }| j	        | j	        }d| _	        | j        s| j        st          g g ddd          S | j        't          | j        | j        |z
  ||z
  |z
            S | j        dz  |z
  z  fd| j        D             }fd| j        D             }t          |||z
  z  ||z
  z            S )zk
        Output the text and boxes belonging to the most recent page.
        page = dvi._output()
        r   NtextboxeswidthheightdescentgzGRAc           
      f    g | ]-\  }}}}}t          |	z
  z  |z
  z  z
  |||z            .S rI   )r   )
rk   rl   yrp   gwdr   maxyminxs
         r   rm   zDvi._output.<locals>.<listcomp>C  s\     2 2 2#Q1a afaZ$q&!g!5q!QqSAA 2 2 2r   c           	      h    g | ].\  }}}}t          |z
  z  |z
  z  z
  |z  |z            /S rI   )r   )	rk   rl   r   hr   r   r   r   r   s	        r   rm   zDvi._output.<locals>.<listcomp>E  s\     1 1 1!aAq afaZ$q&!g!5qsAaC@@ 1 1 1r   )npinfr   r   
isinstancer   _height_depth_ofrr   r{   _baseline_vr   r   )r   minymaxx	maxy_pureeltrl   r   r   r   er   r   r   r   r   r   r   r   s                 @@@@r   r   zDvi._output  s1   
 ftvgtVG	9tz) 	* 	*C#s## 0 
1a#& 1dAq,,Q//1tQ<<DtQU##DtQU##DtQU##DIq))II'(I#Dy 	I 	IRr1aHHHH8TYdj"4i	$ $Y0 0 0 0
 H&)#q(2 2 2 2 2 2 2'+y2 2 21 1 1 1 1 1 1%)Z1 1 1 U49a-%dNA-w@ @ @ 	@r   c                 x   dg}d| _         	 | j                            d          d         } | j        |         | |           | j        r| j                                        | j        |         j        }|dk    r|                    |d                    n1|dk    r|                                 n|dk    r|dxx         dz  cc<   | j         :t          t          | d	g                     d
k    r|d         dk    r| j        | _         |dk    rdS | j        t          j        u r|                                  dS 0)t
        Read one page from the file. Return True if successful,
        False if there were no more pages.
        r   NTrP   _push_pop_downstackr]   rW      F)r   r   read_dtabler   to_exceptionrA   appendpoplengetattrvrs   r   	post_postr   )r   
down_stackrq   r2   s       r   r   z	Dvi._readK  sM   . S
	9>>!$$Q'DDLtT***! 8(55777<%.Dw!!*R.1111    2!# (GD'266771<<"2!++#'6 s{{tzY000

u)	r   Fc                 l    t                               | j                            |          d|          S )z
        Read and return a big-endian integer *nbytes* long.
        Signedness is determined by the *signed* keyword.
        bigrQ   )int
from_bytesr   r   )r   nbytesrR   s      r   rT   zDvi._read_argz  s*    
 ~~dinnV44eF~KKKr   r      )rr   r{   rs   c                     |                      |           t          | j        | j                 t          j                  rd S | xj        | j        | j                                     |          z  c_        d S r   _put_char_realr   r   rp   r   _ExceptionInfor   	_width_ofr   chars     r   _set_char_immediatezDvi._set_char_immediate  d    D!!!dj(%*>?? 	F$*TV$..t444r         )re   )rr   r{   rs   rz   c                     |                      |           t          | j        | j                 t          j                  rd S | xj        | j        | j                                     |          z  c_        d S r   r   r   s     r   	_set_charzDvi._set_char  r   r      )ra   ra   )rs   rz   c                 R    |                      ||           | xj        |z  c_        d S r   )_put_rule_realr   r   abs      r   	_set_rulezDvi._set_rule  s+    Aq!!!!r         c                 0    |                      |           d S r   )r   r   s     r   	_put_charzDvi._put_char  s    D!!!!!r   c                    	  j          j                 }t          |t          j                  r	| _        d S |j        J j                            t           j
         j        |||                    |                               d S |j        	|j        |         j        D ]\  }}}}}t          t          	|j                  |j        |j        |j                  } j                            t           j
        t          |	          z    j        t          |	          z   |||                    |                                j                            	 fd|j        |         j        D                        d S )Nscalemetricsr(   vfc                     g | ]a\  }}}}t          j        t          |          z   j        t          |          z   t          |          t          |                    bS rI   )r   r   _mul1220r   )rk   rl   r   r   r   r   r   s        r   rm   z&Dvi._put_char_real.<locals>.<listcomp>  s     G G G $.1aA  #46HQ,>,>#>#'6HQ,>,>#>#+Au#5#5x57I7I K  K G G Gr   )r   rp   r   r   r   r   _vfr   r   r   r   r   r   _scaleDviFontr   _metricsr(   r   extend)
r   r   r   rl   r   rp   r   r   newfr   s
   `        @r   r   zDvi._put_char_real  s   z$&!dE011 	H!%DXIT$&$&$"&.."6"68 8 9 9 9 9 9 KE!%$!4 C C1aAXeQX%>%>'(z19P P P	  dfx5/A/A&A&*fx5/A/A&A&*At~~a/@/@"B "B C C C C J G G G G G 26$1EG G G H H H H Hr      c                 2    |                      ||           d S r   )r   r   s      r   	_put_rulezDvi._put_rule  s    Aq!!!!!r   c                     |dk    r<|dk    r8| j                             t          | j        | j        ||                     d S d S d S Nr   )r   r   r   r   r   r   s      r   r   zDvi._put_rule_real  sL    q55QUUJc$&$&!Q7788888 5UUr      c                     d S r   rI   r   _s     r   _nopzDvi._nop  s    r      )ra   ra   ra   ra   ra   ra   ra   ra   ra   ra   ra   c                     t           j        | _        dx| _        x| _        x| _        x| _        x| _        | _        g | _	        g | _
        g | _        d S r   )r   inpagers   r   r   r   rl   r   zr   r   r   )r   c0c1c2c3c4c5c6c7c8c9ps               r   _bopzDvi._bop  sO    %
>????$&?46?DFTV
	


r   r   )rs   c                 D    t           j        | _        | `| `| `| `| `| `| `	d S r   )
r   outerrs   r   r   r   rl   r   r  r   r   s     r   _eopzDvi._eop  s,    _
FDFDFDFDFDFDJJJr      c                     | j                             | j        | j        | j        | j        | j        | j        f           d S r   )r   r   r   r   r   rl   r   r  r   s     r   r   z	Dvi._push  s7    
464646464646JKKKKKr      c                     | j                                         \  | _        | _        | _        | _        | _        | _        d S r   )r   r   r   r   r   rl   r   r  r   s     r   r   zDvi._pop  s0    9=9I9I6r         )rc   c                 &    | xj         |z  c_         d S r   )r   )r   r   s     r   _rightz
Dvi._right      !r         )rb   c                 B    ||| _         | xj        | j         z  c_        d S r   )r   r   )r   new_ws     r   _right_wzDvi._right_w  %    DF$&r         c                 B    ||| _         | xj        | j         z  c_        d S r   )rl   r   )r   new_xs     r   _right_xzDvi._right_x  r  r         c                 &    | xj         |z  c_         d S r   )r   )r   r   s     r   r   z	Dvi._down  r  r         c                 B    ||| _         | xj        | j         z  c_        d S r   )r   r   )r   new_ys     r   _down_yzDvi._down_y  r  r         c                 B    ||| _         | xj        | j         z  c_        d S r   )r  r   )r   new_zs     r   _down_zzDvi._down_z  r  r         c                     || _         d S r   rp   )r   ks     r   _fnt_num_immediatezDvi._fnt_num_immediate  s    r         c                     || _         d S r   r5  )r   new_fs     r   _fnt_numzDvi._fnt_num  s    r         )rd   )rr   r{   rz   c                     | j                             |          }t                              dd                    d |D                                  d S )Nz!Dvi._xxx: encountered special: %s c                 V    g | ]&}d |cxk    rdk     rn nt          |          nd|z  'S )    r   z<%02x>)r5   )rk   chs     r   rm   zDvi._xxx.<locals>.<listcomp>  sN     ( ( ( !#b3SWWWHrM ( ( (r   )r   r   r   r   join)r   datalenspecials      r   _xxxzDvi._xxx  se    )..))

/GG ( (&( ( ( ) )	* 	* 	* 	* 	*r         )re   r`   r`   r`   r_   r_   c                 :    |                      ||||||           d S r   )_fnt_def_real)r   r6  csr   r   ls          r   _fnt_defzDvi._fnt_def  s&    1aAq!,,,,,r   c                    | j                             ||z             }|| d          }|                    d          r+|dk    r%t                              ||          | j        |<   d S |                    d          }	 t          |          }	n# t          $ rw}
|                    d          r0|	                    d          r|dk    r|

                    d           t          j                            |
          | j        |<   Y d }
~
d S d }
~
ww xY w|dk    r(|	j        dk    r||	j        k    rt          d|           	 t!          |          }n# t          $ r d }Y nw xY wt          ||	||	          | j        |<   d S )
N   [iFauLascii[;r   zeThis dvi file was likely generated with a too-old version of luaotfload; luaotfload 3.23 is required.ztfm checksum mismatch: r   )r   r   
startswithr   from_luatexr   decode_tfmfileFileNotFoundErrorr4   add_noter   r   from_exceptionchecksumrt   _vffile)r   r6  rL  rM  r   r   rN  nfontnametfmexcr   s               r   rK  zDvi._fnt_def_real  s   INN1q5!!aRSS6t$$ 	j $//155DJqMF??7++	8$$CC  	 	 	""3'' KH,=,=c,B,B KqAvvJK K K "0??DDDJqMFFFFF	 66cla''A,=,=:q::;;;	""BB  	 	 	BBB	aaBGGG
1s+   ?B 
DA,DDE E! E!   )r_   r`   r`   r`   r_   c                     | j                             |           |dvrt          d|           |dk    s|dk    rt          d          |dk    rt          d          t          j        | _        d S )N)      zUnknown dvi format ii  ;zNonstandard units in dvi file  z%Nonstandard magnification in dvi file)r   r   rt   r   r  rs   )r   ry   numdenmagr6  s         r   _prezDvi._pre!  s    	qF??6166777(??c\11<=== $;;DEEE _


r      c                 (    t           j        | _        d S r   )r   r   rs   r   s     r   _postz	Dvi._post3  s    (


r      rI   rz   c                     t           r   r1   r   s    r   
_post_postzDvi._post_post9      !!r      c                     t           r   rq  r   s    r   _begin_reflectzDvi._begin_reflect=  rs  r      c                     t           r   rq  r   s    r   _end_reflectzDvi._end_reflectA  rs  r      c                                           dd          }                      dd          }                      dd          }                      dd          } j                            |          }                      dd          }i }|dz  r fdt          d          D             |d<   |d	z  r                      dd
          dz  |d<   |dz  r                      dd
          dz  |d<   |dz  r                      dd
          dz  |d<   t                              ||||           j        |<   d S )NrW   FrQ   rd  rP   i   c                 >    g | ]}                     d d          S )rP   FrQ   rS   rk   r   r   s     r   rm   z+Dvi._define_native_font.<locals>.<listcomp>O  s)    QQQ1t~~a~>>QQQr   rgbai   T   r   i    slanti @  embolden)rT   r   r   rx   r   
from_xetexr   )r   r6  rM  flagsrN  r^  ry   r#   s   `       r   _define_native_fontzDvi._define_native_fontE  s[   NN1UN++NN1UN++q//NN1UN++INN1NN1UN++6> 	RQQQQaQQQGFO6> 	G $q > > FGH6> 	F#~~a~==EGG6> 	I"&..4."@"@5"HGJ**1aG<<
1r      c                                           dd          }                      dd          } fdt          d|z            D             } fdt          |          D             } j         j                 }t          |          D ]q} j                            t           j        |d|z           z    j        |d|z  dz            z   |||         |	                    ||                                        r xj        |z  c_        d S )NrW   FrQ   rd  c                 >    g | ]}                     d d          S rW   TrQ   rS   r}  s     r   rm   z#Dvi._set_glyphs.<locals>.<listcomp>\  )    CCCdnnQtn,,CCCr   c                 >    g | ]}                     d d          S rd  FrQ   rS   r}  s     r   rm   z#Dvi._set_glyphs.<locals>.<listcomp>]  )    ???T^^Ae^,,???r   rP   )
rT   rx   r   rp   r   r   r   r   r   r   )r   r   r6  xyr   r   ry   s   `      r   _set_glyphszDvi._set_glyphsX  s   NN1UN++NN1UN++CCCCeAEllCCC????eAhh???z$&!q 	E 	EAIT$&2a!e9"4dfr!a%!)}6L"&!dnnQqT.B.BD D E E E E!r      c                                           dd          } j                            d|z            }                      dd          }                      dd          } fdt          d|z            D             } fdt          |          D             } j         j                 }t          |          D ]q} j                            t           j	        |d|z           z    j
        |d|z  dz            z   |||         |                    ||                                        r xj	        |z  c_	        d S )Nrd  FrQ   rW   c                 >    g | ]}                     d d          S r  rS   r}  s     r   rm   z,Dvi._set_text_and_glyphs.<locals>.<listcomp>j  r  r   c                 >    g | ]}                     d d          S r  rS   r}  s     r   rm   z,Dvi._set_text_and_glyphs.<locals>.<listcomp>k  r  r   rP   )rT   r   r   rx   r   rp   r   r   r   r   r   r   )	r   rN  tr   r6  r  r   r   ry   s	   `        r   _set_text_and_glyphszDvi._set_text_and_glyphsd  sE   NN1UN++INN1q5!!NN1UN++NN1UN++CCCCeAEllCCC????eAhh???z$&!q 	E 	EAIT$&2a!e9"4dfr!a%!)}6L"&!dnnQqT.B.BD D E E E E!r      c                      t          d          )Nzunknown command: byte 255)rt   )r   r^   s     r   
_malformedzDvi._malformedr  s    4555r   )F)3rA   rB   rC   rD   r   r   r~   r   r   r   r   r   r   r   rT   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r   r  r  r$  r   r,  r1  r7  r<  rG  rO  rK  r   rj  rm  rr  rv  ry  r  r  r  r  rI   r   r   r   r      sE         fslG	7++I" " "    ! ! !&  
+@ +@ +@Z- - -^L L L L Y1#Y%56665 5 765 Y3Cy'7jIII5 5 JI5 Ys)*>>>  ?> Y3Cy'7jIII" " JI"H H H( Ys)*>>>" " ?>"9 9 9 Ys^^  ^ Ys)/
;;;  <; Ys)*+++G G ,+G Ys)*+++L L ,+L Ys)*+++J J ,+J Y3Cy'7jIII  JI Y3Cy'7iHHH  IH
 Y3Cy'7iHHH  IH
 Y3Cy'7jIII  JI Y3Cy'7iHHH  IH
 Y3Cy'7iHHH  IH
 Y3Cy'7888  98 Y3Cy'7jIII  JI Y3Cj111* * 21* Y3C&MNNN- - ON-H H H@ Ys)-.LMMM% % NM%" Ys)/***) ) +*)
 Ys" " " Ys" " " Ys" " " Ys= = =$ Ys	 	 	 Ys   Ys^^6 6 ^6 6 6r   r   c                   *   e Zd ZdZd Zed             Zed             Z ed           Z	  e
j        d           ed                     Zed             Zed	             Zd
 Zd Zd Zd Zd Zd Zd Zed             Zed             Zd ZdS )r   a  
    Encapsulation of a font that a DVI file can refer to.

    This class holds a font's texname and size, supports comparison,
    and knows the widths of glyphs in the same units as the AFM file.
    There are also internal attributes (for use by dviread.py) that
    are *not* used for comparison.

    The size is in Adobe points (converted from TeX points).

    Parameters
    ----------
    scale : float
        Factor by which the font is scaled from its natural size.
    metrics : Tfm | TtfMetrics
        TeX font metrics for this font
    texname : bytes
       Name of the font as used internally in the DVI file, as an ASCII
       bytestring.  This is usually very different from any external font
       names; `PsfontsMap` can be used to find the external name of the font.
    vf : Vf
       A TeX "virtual font" file, or None if this font is not virtual.

    Attributes
    ----------
    texname : bytes
    fname : str
       Compatibility shim so that DviFont can be used with
       ``_backend_pdf_ps.CharacterTracker``; not a real filename.
    size : float
       Size of the font in Adobe points, converted from the slightly
       smaller TeX points.
    c                     t          j        t          |           || _        || _        || _        || _        d | _        d | _        d S )N)r(   )	r
   check_isinstancebytesr   r   r(   r   _path	_encoding)r   r   r   r(   r   s        r   r   zDviFont.__init__  sF    eW5555
r   c                    |dd                               d          \  }}}|                    d          r|r|d d         dv st          d|           t          j        dk    r|                    d          nt          j        |          }d}i }|dd          r|dd                              d	                              d
          D ]Y}	|	                    dd          \  }
}|
dk    r|}$|
dv rt          |          dz  ||
<   >t          
                    d|	           Zt          |          } | |||d           }t          |          |_        ||_        ||_        |S )NrP      ]rQ  )r      :zInvalid modern font name: ntutf8r   rR  rT  =r   )r  r  r   r  z#Ignoring invalid key-value pair: %rr   )
rpartitionrU  rt   osr2   rW  fsdecodesplitr   r   warning
TtfMetricsr	   r  r0   r#   )clsr   r(   path_bseprestr<   r0   r#   kvkeyvalr   r   s                 r   rV  zDviFont.from_luatex  s   #ABBK22488T""4(( 	ES 	ET"1"X5L5LC'CCDDD(*4v}}V$$$R[=P=P8 	L122hoog..44S99 L L88C++S'>>!GG;;;#&s88e#3GCLLLL!FKKKKT""s5'7t444$ZZ
r   c                    t           j        dk    r|                    d          nt          j        |          }t	          |          } | ||d|z   dz   d           }t          |          |_        ||_        ||_        |S )Nr  r  rQ  r  r  )	r  r2   rW  r  r  r	   r  r0   r#   )r  r   r(   r0   r#   r<   r   r   s           r   r  zDviFont.from_xetex  s|     *,Dw~~f%%%bk'>R>RT""s5'4'>D#8TBBB$ZZ
r   c                     | j         dz  S )Ng]e>)r   r   s    r   r   zDviFont.<lambda>  s    0F!G r   3.11c                 r      fdt          t           j        j        d          dz             D             S )Nc                 \    g | ](}d j         j                            |d          z  dz	  )S )rf  r      )_tfmr   getrk   r   r   s     r   rm   z$DviFont.<lambda>.<locals>.<listcomp>  sM     <A <A <A 
	##D!,,	,3<A <A <Ar   r   )defaultrP   )rx   r{   r  r   r   s   `r   r   zDviFont.<lambda>  sP     <A <A <A <A#dior:::Q>??<A <A <A r   c                 6    | j                             d          S )zA fake filenamezlatin-1)r(   rW  r   s    r   fnamezDviFont.fname  s     |""9---r   c                     dS r   rI   r   s    r   
face_indexzDviFont.face_index      qr   c                        fd|D             S )zGet the mapping from characters to the font that includes them.

        Each value maps to self; there is no fallback mechanism for DviFont.
        c                     i | ]}|S rI   rI   r  s     r   
<dictcomp>z(DviFont._get_fontmap.<locals>.<dictcomp>  s    ...td...r   rI   )r   strings   ` r   _get_fontmapzDviFont._get_fontmap  s    
 /...v....r   c                 ~    t          |           t          |          u o| j        |j        k    o| j        |j        k    S r   )typer(   r!   r   others     r   __eq__zDviFont.__eq__  s@    T

d5kk) NLEM1N6:i5:6M	Or   c                 .    |                      |           S r   )r  r  s     r   __ne__zDviFont.__ne__  s    ;;u%%%%r   c                 B    dt          |           j         d| j         dS )N<z: >)r  rA   r(   r   s    r   __repr__zDviFont.__repr__  s&    94::&99$,9999r   c                     | j                             |          }|#t                              d|| j                   dS t          |j        | j                  S )zWidth of char in dvi units.Nz No width for char %d in font %s.r   )r   get_metricsr   r   r(   r   	tex_widthr   )r   r   r   s      r   r   zDviFont._width_of  sO    -++D11?JJ94NNN1)4;777r   c                 :   | j                             |          }|%t                              d|| j                   ddgS t          |j        | j                  t          |j        | j                  g}t          j
        d| j                  r|dk    rd|d<   |S )z&Height and depth of char in dvi units.Nz!No metrics for char %d in font %sr   s	   ^cmsy\d+$r   )r   r  r   r   r(   r   
tex_heightr   	tex_depthrematch)r   r   r   hds       r   r   zDviFont._height_depth_of  s    -++D11?JJ:D$,OOOq6MW'55W&44
 8M4<00 	TQYYBrF	r   c                 |   | j         .t          t          d                    }	 || j                 }|j        St          d                    |j                            d          |j                            d                              t          |j                  | _         n# t          $ r}	 t          | j                            d           d           t          t          | j                            d           d                    | _         n# t          $ r |d w xY wY d }~nd }~ww xY w| j         S )Nr%   zINo usable font file found for {} ({}); the font may lack a Type-1 versionrR  z.mfz.600pk)r  r&   r'   r(   r   rt   formatpsnamerW  r	   LookupErrorrY  )r   fontmappsfontra  s       r   r   zDviFont.resolve_path  so   : |!<!<==G3 . ?*$ &J&,fV]-A-A'-J-J-3^-B-B7-K-K'M 'MN N N "&/22

  B B BB!T\%8%8%A%A"F"F"FGGG "&m<..w77???'A 'A "B "BDJJ ) ( ( (4'( JJJJB zs)   B' '
D42*D=D/D''D//D4c                     dS r   rI   r   s    r   r0   zDviFont.subfont  r  r   c                     |                                                      d          ri S t          t          d                    | j                 j        S )Nz*.600pkr%   )r   r  r&   r'   r(   r#   r   s    r   r#   zDviFont.effects  sI    $$Y// 	I-5566t|DLLr   c                    | j                             d          r|S | j        t          j        |                                           t          t          d                    | j                  }|j        r&fdt          |j                  D             | _        n
                                | _        | j        |         S )z+Convert dvi glyph indices to FreeType ones.rQ  Nr%   c                 :    g | ]}                     |          S rI   )get_name_index)rk   r2   r=   s     r   rm   z2DviFont._index_dvi_to_freetype.<locals>.<listcomp>4  s=     "K "K "K&* #'"5"5d";"; "K "K "Kr   )r(   rU  r  r   r7   r   r&   r'   r)   r*   _get_type1_encoding_vector)r   idxr  r=   s      @r   r   zDviFont._index_dvi_to_freetype"  s     <""4(( 	J>!():):)<)<==Dl ; ;<<T\JF C"K "K "K "K.8.I.I"K "K "K "&!@!@!B!B~c""r   N)rA   rB   rC   rD   r   classmethodrV  r  rE   r!   r
   
deprecatedwidthsr  r  r  r  r  r  r   r   r   r   r0   r#   r   rI   r   r   r   r   w  s          D     [0   [ 8GGHHD$_T_V$$XX /A /A &B &B C CF . . X.   X/ / /O O O& & &: : :8 8 8  &  ,   _ M M _M
# # # # #r   r   c                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )Vfa  
    A virtual font (\*.vf file) containing subroutines for dvi files.

    Parameters
    ----------
    filename : str or path-like

    Notes
    -----
    The virtual font format is a derivative of dvi:
    http://mirrors.ctan.org/info/knuth/virtual-fonts
    This class reuses some of the machinery of `Dvi`
    but replaces the `!_read` loop and dispatch mechanism.

    Examples
    --------
    ::

        vf = Vf(filename)
        glyph = vf[code]
        glyph.text, glyph.boxes, glyph.width
    c                     t                                          |d           	 d | _        i | _        |                                  |                                  d S # |                                  w xY wr   )superr   _first_font_charsr   r   )r   r   	__class__s     r   r   zVf.__init__S  sa    1%%%	#DDKJJLLLJJLLLLLDJJLLLLs   "A A3c                     | j         |         S r   )r  )r   codes     r   __getitem__zVf.__getitem__\  s    {4  r   c                    dx}}dx}}	 | j                             d          d         }| j        t          j        u r| j                                         dz
  }||k    r|                     ||           dx}x}}nN||k    rt          d          |dv s|dk    rt          d| d	          t          j	        |         | |           |d
k     rT|}| 
                    d          }| 
                    d          }|                     |          }t          j        | _        n|d
k    rV| 
                    d          }| 
                    d          }| 
                    d          }|                     |           nfd|cxk    rdk    rn n| 
                    |d
z
  |dk              }| 
                    d          }| 
                    d          }	| 
                    d          }
| 
                    d          }| 
                    d          }|                     |||	|
||           | j        || _        n|dk    r| 
                    d          }| 
                    d          }| j                             |          }| 
                    d          }| 
                    d          }|                     ||||           n|dk    rdS t          d|           )r   NTrP   r   z!Packet length mismatch in vf file)r   r   rH  zInappropriate opcode z in vf filer>  r]   rW   rI  rb  rk  zUnknown vf opcode )r   r   rs   r   r   tell_finalize_packetrt   r   r   rT   _init_packetrK  r  rj  )r   packet_charpacket_ends
packet_lenpacket_widthrq   byte_atr6  rL  rM  r   r   rN  ry   rl   csdss                    r   r   zVf._read_  s   
 %)(k$((
\1	>9>>!$$Q'DzY---)..**1,k))))+|DDD>BBJB||{**$%HIIIz))TS[[()R)R)R)RSSSK%dD111 czz!
"nnQ//#~~a00"//55&-

!^^A..
"nnQ//#~~a00!!*----#########NN4#:ts{;;NN1%%NN1%%NN1%%NN1%%NN1%%""1aAq!444#+'(D$NN1%%NN1%%INN1%%^^A&&^^A&&		!QB'''' !<d!<!<===c1	>r   c                 &   | j         t          j        k    rt          d          dx| _        x| _        x| _        x| _        x| _        | _	        g | _
        g | _        g | _        | j        | _        d | _        | j                                        |z   S )NzMisplaced packet in vf filer   )rs   r   r  rt   r   r   r   rl   r   r  r   r   r   r  rp   r   r   r  )r   pls     r   r  zVf._init_packet  s    :((:;;;>????$&?46?DFTV
	
!!y~~"$$r   c                     | j         s&t          | j        | j        |d d           | j        |<   t
          j        | _        d S )Nr   )r   r   r   r   r  r   r  rs   )r   r  r  s      r   r  zVf._finalize_packet  sG    ! 	+'+YdjT(+ (+ (+DK$ _


r   c                     | j         t          j        urt          d          |dk    rt          d|           t	          |          rt
                              d|           t          j        | _         d S )Nz pre command in middle of vf file   zUnknown vf format zvf file comment: %s)rs   r   r   rt   r   r   r   r  )r   ry   rl   r  r  s        r   rj  zVf._pre  sp    :Y]**?@@@885!55666q66 	1JJ,a000_


r   )rA   rB   rC   rD   r   r  r   r  r  rj  __classcell__)r  s   @r   r  r  ;  s         .    ! ! !8> 8> 8>t	% 	% 	%% % %% % % % % % %r   r  c                     | |z  dz	  S )z1Multiply two numbers in 12.20 fixed point format.r  rI   )num1num2s     r   r   r     s     I"r   T)frozenkw_onlyc                   2    e Zd ZU dZeed<   eed<   eed<   dS )
TexMetricsa  
    Metrics of a glyph, with TeX semantics.

    TeX metrics have different semantics from FreeType metrics: tex_width
    corresponds to FreeType's ``advance`` (i.e., including whitespace padding);
    tex_height to ``bearingY`` (how much the glyph extends over the baseline);
    tex_depth to ``height - bearingY`` (how much the glyph extends under the
    baseline, as a positive number).
    r  r  r  N)rA   rB   rC   rD   r   __annotations__rI   r   r   r  r    s7           NNNOOONNNNNr   r  c                       e Zd ZdZd Zd Z  ej        dd           ed                     Z	  ej        dd           ed                     Z
  ej        dd           ed	                     Zd
S )Tfma  
    A TeX Font Metric file.

    This implementation covers only the bare minimum needed by the Dvi class.

    Parameters
    ----------
    filename : str or path-like

    Attributes
    ----------
    checksum : int
       Used for verifying against the dvi file.
    design_size : int
       Design size of the font (in 12.20 TeX points); unused because it is
       overridden by the scale factor specified in the dvi file.
    c           
         t                               d|           t          |d          5 }|                    d          }t	          j        d|dd                   \  }}}}}}	t                               d||||||	           |                    d|z            }
t	          j        d	|
d d
                   \  | _        | _        |                    d||z
  dz   z            }t	          j        d| d|                    d|z                      }t	          j        d| d|                    d|z                      }t	          j        d|	 d|                    d|	z                      }d d d            n# 1 swxY w Y   i | _        t          t          ||dz                       D ]P\  }}|d|z           }|d|z  dz            }t          ||         ||dz	           ||dz                     | j        |<   Qd S )Nzopening tfm file %sr      z!6Hrd     z(lh=%d, bc=%d, ec=%d, nw=%d, nh=%d, nd=%drW   z!2I   rP   !ry      r  r  r  )r   r   r   r   structunpackr\  design_size_glyph_metrics	enumeraterx   r  )r   r   r   header1lhbcecnwnhndheader2	char_infor  heightsdepthsr  r   byte0byte1s                      r   r   zTfm.__init__  s5   

((333(D!! 	?TiimmG%+]5'!B$-%H%H"BBBJJA2r2r2/ / /ii"ooG.4mE72A2;.O.O+DM4+		!RU1W+..I]9r999dii"oo>>FmIIIItyy2??G]9r999dii"oo>>F	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? !"5RT??33 	 	ICae$EaeAg&E(2 -"5A:. -) ) )D%%	 	s   EE??FFc                 6    | j                             |          S )z4Return a glyph's TexMetrics, or None if unavailable.)r  r  )r   r  s     r   r  zTfm.get_metrics  s    "&&s+++r   r  r  )alternativec                 $    d | j         D             S )Nc                 $    i | ]\  }}||j         S rI   )r  rk   rL  ms      r   r  z Tfm.<lambda>.<locals>.<dictcomp>       NNN$!Qq!+NNNr   r  r   s    r   r   zTfm.<lambda>      NN$:MNNN r   c                 $    d | j         D             S )Nc                 $    i | ]\  }}||j         S rI   )r  r,  s      r   r  z Tfm.<lambda>.<locals>.<dictcomp>  s     OOO41aq!,OOOr   r/  r   s    r   r   zTfm.<lambda>  s    OO4;NOOO r   c                 $    d | j         D             S )Nc                 $    i | ]\  }}||j         S rI   )r  r,  s      r   r  z Tfm.<lambda>.<locals>.<dictcomp>   r.  r   r/  r   s    r   r   zTfm.<lambda>   r0  r   N)rA   rB   rC   rD   r   r  r
   r  rE   r   r   depthrI   r   r   r  r    s         $  0, , , ?ODOF>>>NNOOQ QE?_T_V???OOPPR RF>ODOF>>>NNOOQ QEEEr   r  c                       e Zd Zd Zd ZdS )r  c                 8    t          j        |          | _        d S r   )r   r7   _face)r   r   s     r   r   zTtfMetrics.__init__  s    !*844


r   c                 (   | j         j        }| j                             |t          j                  }t          t          |j        |z  dz            t          |j        |z  dz            t          |j	        |j        z
  |z  dz                      S )N   r  )
r8  units_per_EM
load_glyphr   NO_SCALEr  roundhoriAdvancehoriBearingYr   )r   r  upemr   s       r   r  zTtfMetrics.get_metrics  s     z&J!!#y'9::AMD05899Q^d2U:;;QX6$>FGG
 
 
 	
r   N)rA   rB   rC   r   r  rI   r   r   r  r    s2        5 5 5
 
 
 
 
r   r  PsFontz(texname psname effects encoding filenamec                   8    e Zd ZdZdZed             Zd Zd ZdS )r&   a}  
    A psfonts.map formatted file, mapping TeX fonts to PS fonts.

    Parameters
    ----------
    filename : str or path-like

    Notes
    -----
    For historical reasons, TeX knows many Type-1 fonts by different
    names than the outside world. (For one thing, the names have to
    fit in eight characters.) Also, TeX's native fonts are not Type-1
    but Metafont, which is nontrivial to convert to PostScript except
    as a bitmap. While high-quality conversions to Type-1 format exist
    and are shipped with modern TeX distributions, we need to know
    which Type-1 fonts are the counterparts of which native fonts. For
    these reasons a mapping is needed from internal font names to font
    file names.

    A texmf tree typically includes mapping files called e.g.
    :file:`psfonts.map`, :file:`pdftex.map`, or :file:`dvipdfm.map`.
    The file :file:`psfonts.map` is used by :program:`dvips`,
    :file:`pdftex.map` by :program:`pdfTeX`, and :file:`dvipdfm.map`
    by :program:`dvipdfm`. :file:`psfonts.map` might avoid embedding
    the 35 PostScript fonts (i.e., have no filename for them, as in
    the Times-Bold example above), while the pdf-related files perhaps
    only avoid the "Base 14" pdf fonts. But the user may have
    configured these files differently.

    Examples
    --------
    >>> map = PsfontsMap(find_tex_file('pdftex.map'))
    >>> entry = map[b'ptmbo8r']
    >>> entry.texname
    b'ptmbo8r'
    >>> entry.psname
    b'Times-Bold'
    >>> entry.encoding
    '/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'
    >>> entry.effects
    {'slant': 0.16700000000000001}
    >>> entry.filename
    )	_filename	_unparsed_parsedc                 x   t                               |           }t          j        |          |_        t          |d          5 }i |_        |D ]L}|                    dd          d         }|j                            |g           	                    |           M	 d d d            n# 1 swxY w Y   i |_
        |S )Nr       rP   r   )object__new__r  r  rD  r   rE  r  
setdefaultr   rF  )r  r   r   r   linetfmnames         r   rJ  zPsfontsMap.__new__L  s   ~~c""X..
 (D!! 	DTDN D D**T1--a0))'266==dCCCCD	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D
 s   AB((B,/B,c           	      @   t          |t                    sJ || j        v r4| j                            |          D ]}|                     |          r n	 | j        |         S # t          $ r0 t          d| j        d|	                    d          d          d w xY w)NzThe font map z5 is missing a PostScript font associated to TeX font rR  zo; this problem can often be solved by installing a suitable PostScript font package in your TeX package manager)
r   r  rE  r   _parse_and_cache_linerF  KeyErrorr  rD  rW  )r   r(   rL  s      r   r  zPsfontsMap.__getitem__\  s    '5)))))dn$$**733  --d33 E	7<(( 	7 	7 	7, , ,*1..*A*A, , ,- - 37	7	7s   A# #:Bc           	         |r|                     d          rdS dx}x}x}x}}dx}x}}	t          j        d|          }
|
D ]}|                                \  }}|r|                     d          r|dd         };|                     d          r|dd         }[|                     d          rc|d	d         p;t	          t          dt	          |
                                                              }|                    d
          r|}|}d}||}||}|r|}i }|rqt          |                                          }|D ]M}|dk    r t          t	          |                    |d<   (|dk    rt          t	          |                    |d<   N|0|                    d          rd}	n|                    d          sd}n|d}|	r|r|dS |s
d|v sd|v rdS t          |                    dd                    d	k    rdS t          |                    dd                    dk    rdS ||}|t          |          }|t          |          }t          |||||          | j        |<   dS )a%  
        Parse a line in the font mapping file.

        The format is (partially) documented at
        http://mirrors.ctan.org/systems/doc/pdftex/manual/pdftex-a.pdf
        https://tug.org/texinfohtml/dvips.html#psfonts_002emap
        Each line can have the following fields:

        - tfmname (first, only required field),
        - psname (defaults to tfmname, must come immediately after tfmname if
          present),
        - fontflags (integer, must come immediately after psname if present,
          ignored by us),
        - special (SlantFont and ExtendFont, only field that is double-quoted),
        - fontfile, encodingfile (optional, prefixed by <, <<, or <[; << always
          precedes a font, <[ always precedes an encoding, < can precede either
          but then an encoding file must have extension .enc; < and << also
          request different font subsetting behaviors but we ignore that; < can
          be separated from the filename by whitespace).

        special, fontfile, and encodingfile can appear in any order.
        )rH     %   *   ;   #NFs   "([^"]*)(?:"|$)|(\S+)s   <<rd  s   <[   <rP   s   .encTs	   SlantFontr  s
   ExtendFontr   )s   .ttfs   .ttcs   .otfr   )r(   r  r#   r)   r   )rU  r  finditergroupsnextfilterr4   reversedr  floatabsr  r'   rB  rF  )r   rL  rM  basenamerF  encodingfilefontfileis_subsettedis_t1is_truetypematchesr  quotedunquotedwordr#   wordss                    r   rO  z PsfontsMap._parse_and_cache_linek  s#   8  	t'EFF 	FAEEE(EWE|h-222u{+7>> 	! 	!E$||~~FH !&&u-- ('|HH((// (#+ABB<LL((.. ( ! FtT']]-A-A-C-C D DEE	 
 }}W-- ,'+#''+_&GG%'H !  	;W]]__--E ; ;<''',T%[['9'9GG$$]**(-d5kk(:(:GH%   !344 "&&w// !E 	< 	L,@F 	'W,,G0C0CFw{{7A&&''!++Fw{{8Q''((1,,FH#(66L$X..H &Hg!H!6 !6 !6W tr   N)	rA   rB   rC   rD   	__slots__r   rJ  r  rO  rI   r   r   r&   r&     sd        * *V 6I
   Y7 7 7] ] ] ] ]r   r&   c                 l   t          j        ddt          |                               d                    }t          j        d|                              d          }d |                                D             }t          d |D                       rd	 |D             S t          d
|  d          )a5  
    Parse a \*.enc file referenced from a psfonts.map style file.

    The format supported by this function is a tiny subset of PostScript.

    Parameters
    ----------
    path : `os.PathLike`

    Returns
    -------
    list
        The nth list item is the PostScript glyph name of the nth glyph.
    z%.*r@  rR  )r)   z(?s)\[(.*)\]rP   c                     g | ]}||S rI   rI   rk   rL  s     r   rm   z_parse_enc.<locals>.<listcomp>  s    444dt4T444r   c              3   @   K   | ]}|                     d           V  dS )/N)rU  rl  s     r   	<genexpr>z_parse_enc.<locals>.<genexpr>  s.      
2
2D4??3
2
2
2
2
2
2r   c                 "    g | ]}|d d         S )rP   NrI   rl  s     r   rm   z_parse_enc.<locals>.<listcomp>  s     +++TQRR+++r   zFailed to parse z as Postscript encoding)	r  subr	   	read_textsearchgroupr  allrt   )r<   no_commentsarrayliness       r   r*   r*     s     &DJJ$8$8'$8$J$JKKKIo{3399!<<E44ekkmm444E

2
2E
2
2
222 K++U++++IDIIIJJJr   c                   0    e Zd Zed             Zd Zd ZdS )_LuatexKpsewhichc                 l    t                               |           }|                                |_        |S r   )rI  rJ  	_new_proc_proc)r  r   s     r   rJ  z_LuatexKpsewhich.__new__  s)    ~~c""^^%%
r   c                 (   t          j        ddt          t          j        d                    gt           j        t           j        t           j        dt          t          t          j	                    d                    it          j                  S )Nluatexz	--luaonlyzkpsewhich.luaMT_VARTEXFONTSvartexfonts)stdinstdoutstderrenv)
subprocessPopenstrr   _get_data_pathPIPEDEVNULLr	   mplget_cachedirr  environr   s    r   r|  z_LuatexKpsewhich._new_proc  sv    {C(<_(M(M$N$NO/*/*BT!3tC,<,>,>'N'N#O#O :      	 r   c                    | j                                         |                                 | _         | j         j                            t          j        |          dz              | j         j                                         | j         j        	                                
                                }|dk    rd nt          j        |          S )N   
s   nil)r}  pollr|  r  writer  fsencodeflushr  readlinerstripr  )r   r   outs      r   rs  z_LuatexKpsewhich.search  s    :??())DJ
r{844u<===
   j((**1133f}}tt"+c*:*::r   N)rA   rB   rC   r   rJ  r|  rs  rI   r   r   rz  rz    sK        
  U
     ; ; ; ; ;r   rz  c                    t          | t                    r|                     dd          } 	 t                      }n# t          t
          f$ r d}Y nw xY w|r|                    |           }nt          j        dk    ri t          j
        ddidd}n#i t          j
        t          j                    dd	}|d
                             t          t          t          j                    d                               	 t#          j        dd| gt&          fi |                    d          }n# t          t
          t*          f$ r d}Y nw xY w|r|S t	          d| d          )a  
    Find a file in the texmf tree using kpathsea_.

    The kpathsea library, provided by most existing TeX distributions, both
    on Unix-like systems and on Windows (MikTeX), is invoked via a long-lived
    luatex process if luatex is installed, or via kpsewhich otherwise.

    .. _kpathsea: https://www.tug.org/kpathsea/

    Parameters
    ----------
    filename : str or path-like

    Raises
    ------
    FileNotFoundError
        If the file is not found.
    zutf-8replace)errorsNwin32command_line_encoding)r  r)   surrogateescape)r  r)   r  r  r  )r  	kpsewhichz	-mktex=pk
z:Matplotlib's TeX implementation searched for a file named z* in your texmf tree, but could not find it)r   r  rW  rz  rY  OSErrorrs  sysplatformr  r  getfilesystemencodingupdater  r	   r  r  r   _check_and_log_subprocessr   r  RuntimeError)r   lkr<   kwargss       r   r'   r'     s   . (E"" >??79?==w'    
 yy""<7"" N
M,CWMM")+ +FF ,
^"%";"="= 13 3F 	utC$4$6$6FFGG 	 	I 	I 	I	2k84d >D fTll D "7L9 	 	 	DDD	  GFF F FG G 	Gs!   = AA .D/ /E
Ec                 8     | t          ||z                       S r   )r'   )r  suffixr(   s      r   	_fontfiler  :  s    3}Wv-..///r   z.tfmz.vf__main__)ArgumentParserr   r   r/   )nargsr  r  z-dz--debug
store_true)action)levelc                  p    t          d                    t          dj        |                                d S )N z{:>11})printrD  mapr  ro  s    r   _print_fieldsr  P  s.    chhs8?D112233333r   z=== NEW PAGE === (w: z, h: z, d: )z--- GLYPHS ---c                     | j         S r   )r   )r   s    r   r   r   X  s     r   r  r  zfont: z at zscale: r:  rl   r   r   r5   r   z--- BOXES ---r   )NNrf   )`rD   dataclassesenumloggingr  r  r  r  r  collectionsr   	functoolsr   r   r   r   r   pathlibr	   fontTools.aglr9   numpyr   
matplotlibr  r
   r   r   matplotlib.ft2fontr   	getLoggerrA   r   Enumr   r   r   r   dictrj   r~   r   r   r  r   	dataclassr  r  r  rB  r&   r*   rz  r'   r  rX  r]  	itertoolsargparser  parseradd_argumentr\  
parse_argsrz   r   basicConfigDEBUGr  r   r   rL   pager  r   r   r   groupbyr   r   rt  r2   r(   rW  r  	font_namer   r   r   r   rl   r   r   r@   r   boxrI   r   r   <module>r     s   &       				 				      



 " " " " " " G G G G G G G G G G G G G G                   0 0 0 0 0 0 0 0 0 0 ( ( ( ( ( (w"", DIj"EFF	 z&;<<j*++G' G' G' G' G'::f455 G' G' G'^ t  888877	P	P
B
B
C
C K
J#  */ / / /dY6 Y6 Y6 Y6 Y6 Y6 Y6 Y6xA# A# A# A# A# A# A# A#Hw% w% w% w% w% w% w% w%v   dD111       214Q 4Q 4Q 4Q 4Q 4Q 4Q 4Qn
 
 
 
 
 
 
 
* 
HH	I	Im m m m m m m m`K K K0; ; ; ; ; ; ; ;2 :G :G :Gz 0 0 0 79c6**
')R
'
' z''''''^F

###
SudCCC
i===Dz 1'-00004 4 4 
T]DH	%	% G 	G 	GDE LL L*.+L L<@LL L L M M ME"###0y0<R<RSS J Je<>GtOOT\00888"-"+dl";"; :dmS11 0EG9GG$2C2C2E2EGGHHHHE.9..///7g 577888c3<<<! J JD!M$&$&$*"&":":"<"<djJ J J JJ z Go&&&c3S111: G GC!M#%
CIFFFF)	GG G G G G G G G G G G G G G G G G G! s   7E<OOO