
    
3jl                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJrJrJrJrJr  SSKJr  SSKrSSKrSSKrSSKJrJrJr  SSKJr  \R<                  " \5      r \RB                  " SS	5      r"\
" S
S5      r#\
" SS5      r$ " S S\
" SS5      5      r%\&" S S S S S S S S S9r'STS jr( " S S5      r) " S S5      r* " S S \)5      r+S! r,\RZ                  " S"S"S#9 " S$ S%5      5       r. " S& S'5      r/ " S( S)5      r0\
" S*S+5      r1 " S, S-5      r2S. r3 " S/ S05      r4\S1 5       r5\S2 5       r6\" \6\/S35      r7\" \6\+S45      r8\S5:X  Gax  SSK9r9SS6K:J;r;  \;" 5       r<\<R{                  S75        \<R{                  S8S9\>SS:9  \<R{                  S;S<S=S>9  \<R                  5       r@\@R                  (       a  \R                  " \R                  S?9  S@ rD\)" \@R                  \@R                  5       rG\G GH  rH\I" SA\HR                   SB\HR                   SC\HR                   SD35        \I" SE5        \9R                  " \HR                  SF 5       H  u  rOrP\R                  SG:X  a  \OR                  R                  SH5      O\R                  " \OR                  5      rU\V" \OR                  \/5      (       a  \I" SI\U SJ\OR                  5        35        O\I" SI\U 35        \I" SK\OR                  SL-   35        \D" SMSNSOSPSQ5        \P HE  rN\D" \NR                  \NR                  \NR                  \NR                  5       \NR                  5        MG     M     \HR                  (       d  GMn  \I" SR5        \D" SMSNSSSQ5        \HR                   H6  r_\D" \_R                  \_R                  \_R                  \_R                  5        M8     GM     SSS5        gg! , (       d  f       g= f)UaC  
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                   t    \ rS rSrSr\S 5       r\" S 5      r\" S 5      r\" S 5      r	\S 5       r
S rS	rg
)TextE   a  
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                 L    U R                   R                  U R                  5      $ )zI
The FreeType index of this glyph (that can be passed to FT_Load_Glyph).
)font_index_dvi_to_freetypeglyphselfs    L/home/wildlama/miniconda3/lib/python3.13/site-packages/matplotlib/dviread.pyindex
Text.indexS   s     yy//

;;    c                 6    U R                   R                  5       $ N)r   resolve_pathr   s    r   <lambda>Text.<lambda>[   s    dii&<&<&>r   c                 .    U R                   R                  $ r   )r   sizer   s    r   r!   r"   \   s    diinnr   c                 .    U R                   R                  $ r   )r   effectsr   s    r   r!   r"   ]   s    ):):r   c                     [        [        S5      5      U R                  R                     nUR                  b"  [        UR                  5      U R                     $ U R                  $ )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_indexText.glyph_name_or_index_   sT    : =67		8I8IJ>>- 5>>*4::6 	?37::	?r   c                 4   U R                   R                  (       a  [        S5      eU R                   R                  5       nUR                  R                  5       R                  S5      (       aP  [        U R                  5      R                  5       (       a  [        U R                  5       S3$ SU R                  S 3$ [        R                  " U5      nUR                  U R                  5      n[        R                  R!                  U5      nU=(       d    U$ )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_nameText._as_unicode_or_name   s    99%&OPPyy%%'99??%%d++ .1_-H-H-J-Js4::'q) ,D)*,$$T*((4
MM++J7	&J&r    N)__name__
__module____qualname____firstlineno____doc__propertyr   	font_path	font_sizefont_effectsr/   rD   __static_attributes__rF   r   r   r   r   E   sV     < < >?I45I:;L? ?@'r   r   zx y font glyph widthc                     U$ r   rF   dvideltas     r   r!   r!      s    5r   c                 "    U R                  SSS9$ N   Fsigned	_read_argrR   s     r   r!   r!          #--%-8r   c                 "    U R                  SSS9$ )N   FrX   rZ   rR   s     r   r!   r!      r\   r   c                 "    U R                  SSS9$ )Nr^   TrX   rZ   rR   s     r   r!   r!      s    #--$-7r   c                 4    U(       a  U R                  USS9$ S $ )NTrX   rZ   rR   s     r   r!   r!      s    CMM%M=PDPr   c                 (    U R                  US-   SS9$ )NrW   TrX   rZ   rR   s     r   r!   r!      s    S]]519T]Br   c                 (    U R                  US-   SS9$ rV   rZ   rR   s     r   r!   r!      s    S]]519U]Cr   c                 .    U R                  US-   US:H  S9$ )NrW      rX   rZ   rR   s     r   r!   r!      s    S]]519eqj]Jr   )rawu1u4s4slenslen1ulen1olen1c                 $   ^ ^^^^ UUUUU 4S jnU$ )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                    >^ ^ T Vs/ s H  n[         U   PM     snm[        T 5      UU UU4S j5       nTc  UT	T'   U$ [        TTS-   5       H  nT	U   b   eUT	U'   M     U$ s  snf )Nc                    > Tb  U R                   T:w  a  [        S5      eT" U /T Vs/ s H  o"" XT-
  5      PM     snQ76 $ s  snf )Nzstate precondition failed)state
ValueError)r   bytefget_argsmethodminrp   s      r   wrapper,_dispatch.<locals>.decorate.<locals>.wrapper   sK     TZZ5%8 !<==$GX!FX!Ds("3X!FGG!Fs   A
rW   )_arg_mappingr   range)
ru   xrw   irt   argsmaxrv   rp   tables
   `   @r   decorate_dispatch.<locals>.decorate   s    -12TLOT2	v	H 
	H ; E#J
  3A&Qx'''"a '  3s   A$rF   )r   rv   r~   rp   r}   r   s   ````` r   	_dispatchr      s    @  Or   c                   "   \ rS rSrSrS/S-  r\" \\5      rS rS r	S r
S rS	 rS
 rS rSgS jr\" SS\R"                  S9S 5       r\" SS\R"                  SS9S 5       r\" S\R"                  SS9S 5       r\" SS\R"                  SS9S 5       rS r\" S\R"                  SS9S 5       rS  r\" S!5      S" 5       r\" S#\R4                  S$S9S% 5       r\" S&\R"                  S'9S( 5       r\" S)\R"                  S'9S* 5       r\" S+\R"                  S'9S, 5       r\" S-S.\R"                  S/S9S0 5       r\" S1S2\R"                  S3S9S4 5       r \" S5S6\R"                  S3S9S7 5       r!\" S8S9\R"                  S/S9S: 5       r"\" S;S<\R"                  S3S9S= 5       r#\" S>S?\R"                  S3S9S@ 5       r$\" SASB\R"                  S9SC 5       r%\" SDSE\R"                  SS9SF 5       r&\" SGSHSISJ9SK 5       r'\" SLSMSNSJ9SO 5       r(SP r)\" SQ\RT                  SRS9SS 5       r+\" ST\R4                  S'9SU 5       r,\" SVSWSX9SY 5       r-\" SZSWSX9S[ 5       r.\" S\SWSX9S] 5       r/\" S^SWSX9S_ 5       r0\" S`SWSX9Sa 5       r1\" SbSWSX9Sc 5       r2\" Sd5      Se 5       r3Sfr4g)hDvi   a!  
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                     [         R                  SU5        [        US5      U l        X l        0 U l        [        R                  U l        SU l	        g)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prerp   _missing_font)r   filenamer   s      r   __init__Dvi.__init__   s?     	

9h'4(	
]]
!r   c                     U $ )z+Context manager enter method, does nothing.rF   r   s    r   	__enter__Dvi.__enter__   s    r   c                 $    U R                  5         g)zH
Context manager exit method, closes the underlying file if it is open.
N)close)r   etypeevalueetraces       r   __exit__Dvi.__exit__   s     	

r   c              #      #    U R                  5       (       a*  U R                  5       v   U R                  5       (       a  M)  gg7f)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__Dvi.__iter__  s+       jjll,,.  jjlls   =AAc                 p    U R                   R                  (       d  U R                   R                  5         gg)z(Close the underlying file if it is open.N)r   closedr   r   s    r   r   	Dvi.close  s"    yyIIOO  r   c                 $   [         R                  =p[         R                  * =p4[         R                  * nU R                  U R                  -    Hy  n[	        U[
        5      (       a  Uu  pxpSnOUu  pxpn
UR                  U5      u  p[        X5      n[        X(U	-
  5      n[        X7U
-   5      n[        XHU-   5      n[        XX5      nM{     U R                  b  U R                  nSU l	        U R                  (       d  U R                  (       d  [        / / SSSS9$ U R                  c'  [        U R                  U R                  X1-
  XR-
  XE-
  S9$ U R                  S-  nXE-
  U-  nU R                   VVVVV
s/ s H%  u  pxnp[        Xq-
  U-  XH-
  U-  U-
  UXU-  5      PM'     nnnnnn
U R                   VVV	V
s/ s H%  u  pxp[        Xq-
  U-  XH-
  U-  U-
  X-  X-  5      PM'     nn	nnn
[        UUX1-
  U-  XR-
  U-  US9$ s  sn
nnnnf s  sn
n	nnf )zS
Output the text and boxes belonging to the most recent page.
page = dvi._output()
r   NtextboxeswidthheightdescentgzGRA)npinfr   r   
isinstancer   _height_depth_ofrv   r~   _baseline_vr   r   r   )r   minxminymaxxmaxy	maxy_pureeltr{   yhwer   gdr   rs   r   r   s                      r   r   Dvi._output  s   
 ffvvgVVG	99tzz)C#s## 
a#& dq,,Q/t<DtU#DtU#DtU#DI)I * '((I#DyyRr1aHH88TYYdjj"i	 $0 0
 HH&#q( (,yy2'0OQ1a afaZ$&!g!5q!qSA'0 	 2 &*ZZ1%/\aA afaZ$&!g!5qsAC@%/ 	 1 U49a-%NA-w@ 	@21s   6,H9,H

c                    S/nSU l          U R                  R                  S5      S   nU R                  U   " X5        U R                  (       a  U R                  R                  5       eU R                  U   R                  nUS:X  a  UR                  US   5        O*US:X  a  UR                  5         OUS:X  a  US==   S-  ss'   U R                   c4  [        [        U S	/ 5      5      S
:X  a  US   S:  a  U R                  U l         US:X  a  gU R                  [        R                  L a  U R                  5         gGM5  )\
Read one page from the file. Return True if successful,
False if there were no more pages.
r   NTrW   _push_pop_downstackrd   r^      F)r   r   read_dtabler   to_exceptionrG   appendpoplengetattrvrp   r   	post_postr   )r   
down_stackrr   r6   s       r   r   	Dvi._readK  s   . S
99>>!$Q'DLLt*!!((5577<<%..Dw!!*R.1 2!#  (GD'2671<"2!+#'66 s{zzY000

) r   c                 ^    [         R                  U R                  R                  U5      SUS9$ )zg
Read and return a big-endian integer *nbytes* long.
Signedness is determined by the *signed* keyword.
bigrX   )int
from_bytesr   r   )r   nbytesrY   s      r   r[   Dvi._read_argz  s&    
 ~~diinnV4eF~KKr   r      )rv   r~   rp   c                 
   U R                  U5        [        U R                  U R                     [        R
                  5      (       a  g U =R                  U R                  U R                     R                  U5      -  sl        g r   _put_char_realr   r   rs   r   _ExceptionInfor   	_width_ofr   chars     r   _set_char_immediateDvi._set_char_immediate  Y    D!djj(%*>*>??$**TVV$..t44r         )rl   )rv   r~   rp   r}   c                 
   U R                  U5        [        U R                  U R                     [        R
                  5      (       a  g U =R                  U R                  U R                     R                  U5      -  sl        g r   r   r   s     r   	_set_charDvi._set_char  r   r      )rh   rh   )rp   r}   c                 P    U R                  X5        U =R                  U-  sl        g r   )_put_rule_realr   r   abs      r   	_set_ruleDvi._set_rule  s    A!!r         c                 &    U R                  U5        g r   )r   r   s     r   	_put_charDvi._put_char  s    D!r   c                    U R                   U R                     n[        U[        R                  5      (       a  X l        g UR                  cK  U R                  R                  [        U R                  U R                  X!UR                  U5      5      5        g UR                  nUR                  U   R                   H  u  pEpgn[        [        X6R                  5      UR                   UR"                  UR                  S9n	U R                  R                  [        U R                  [        XC5      -   U R                  [        XS5      -   XU	R                  U5      5      5        M     U R$                  R'                  UR                  U   R$                   VVV
Vs/ s HR  u  pEp[)        U R                  [        XC5      -   U R                  [        XS5      -   [        X5      [        X5      5      PMT     snn
nn5        g s  snn
nnf )Nscalemetricsr+   vf)r   rs   r   r   r   r   _vfr   r   r   r   r   r   _scaleDviFont_mul1220_metricsr+   r   extendr   )r   r   r   r   r{   r   rs   r   r   newfr   r   s               r   r   Dvi._put_char_real  s   zz$&&!dE0011!%XXIIT$&&$&&$"&.."68 9 KKE!%$!4!4aAXeXX%>'(zz199P		  dffx/A&A&*ffx/A&A&*t~~a/@"B C "5 JJ 26$1E1EG 2F:1  #466HQ,>#>#'66HQ,>#>#+A#5x7I K 2FG H Gs   AG>   c                 &    U R                  X5        g r   )r   r   s      r   	_put_ruleDvi._put_rule  s    A!r   c                     US:  aB  US:  a;  U R                   R                  [        U R                  U R                  X5      5        g g g Nr   )r   r   r   r   r   r   s      r   r   Dvi._put_rule_real  s9    q5QUJJc$&&$&&!78 5r      c                     g r   rF   r   _s     r   _nopDvi._nop  s    r      )rh   rh   rh   rh   rh   rh   rh   rh   rh   rh   rh   c                     [         R                  U l        S=U l        =U l        =U l        =U l        =U l        U l        / U l	        / U l
        / U l        g r  )r   inpagerp   r   r   r   r{   r   zr   r   r   )r   c0c1c2c3c4c5c6c7c8c9ps               r   _bopDvi._bop  sN    %%
>????$&?46?DFTV
	
r   r   )rp   c                 J    [         R                  U l        U ?U ?U ?U ?U ?U ?U ?	g r   )
r   outerrp   r   r   r   r{   r   r  r   r  s     r   _eopDvi._eop  s*    __
FDFDFDFDFDFDJr      c                     U R                   R                  U R                  U R                  U R                  U R
                  U R                  U R                  45        g r   )r   r   r   r   r   r{   r   r  r  s     r   r   	Dvi._push  s9    

466466466466466466JKr      c                     U R                   R                  5       u  U l        U l        U l        U l        U l        U l        g r   )r   r   r   r   r   r{   r   r  r  s     r   r   Dvi._pop  s+    9=9I6r         )rj   c                 .    U =R                   U-  sl         g r   )r   )r   r   s     r   _right
Dvi._right      !r         )ri   c                 T    Ub  Xl         U =R                  U R                   -  sl        g r   )r   r   )r   new_ws     r   _right_wDvi._right_w      F$&&r         c                 T    Ub  Xl         U =R                  U R                   -  sl        g r   )r{   r   )r   new_xs     r   _right_xDvi._right_x  r7  r         c                 .    U =R                   U-  sl         g r   )r   )r   r   s     r   r   	Dvi._down  r0  r         c                 T    Ub  Xl         U =R                  U R                   -  sl        g r   )r   r   )r   new_ys     r   _down_yDvi._down_y  r7  r         c                 T    Ub  Xl         U =R                  U R                   -  sl        g r   )r  r   )r   new_zs     r   _down_zDvi._down_z  r7  r         c                     Xl         g r   rs   )r   ks     r   _fnt_num_immediateDvi._fnt_num_immediate  s    r         c                     Xl         g r   rQ  )r   new_fs     r   _fnt_numDvi._fnt_num  s    r         )rk   )rv   r~   r}   c                     U R                   R                  U5      n[        R                  SSR	                  U Vs/ s H#  nSUs=::  a  S:  a  O  O[        U5      OSU-  PM%     sn5      5        g s  snf )Nz!Dvi._xxx: encountered special: %s     r   z<%02x>)r   r   r   r   joinr9   )r   datalenspecialchs       r   _xxxDvi._xxx  sf    ))..)

/GG&(& !#b3SWHrMA&( )	*(s   *A1      )rl   rg   rg   rg   rf   rf   c                 *    U R                  XX4XV5        g r   )_fnt_def_real)r   rR  csr   r   ls          r   _fnt_defDvi._fnt_def  s    1q,r   c                    U R                   R                  XV-   5      nXv* S  nUR                  S5      (       a)  US:X  a#  [        R	                  X75      U R
                  U'   g UR                  S5      n [        U5      n	US:w  a-  U	R                  S:w  a  X)R                  :w  a  [        SU 35      e [!        U5      n[        X9X{S	9U R
                  U'   g ! [         ay  n
UR                  S5      (       a-  UR                  S5      (       a  US:X  a  U
R                  S5        [        R                  R                  U
5      U R
                  U'    S n
A
g S n
A
ff = f! [         a    S n Nf = f)
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FileNotFoundErrorr8   add_noter   r   from_exceptionchecksumrq   _vffile)r   rR  rj  rk  r   r   rl  nfontnametfmexcr   s               r   ri  Dvi._fnt_def_real  sK   IINN15!RS6t$$j $//5DJJqM??7+	8$C 6clla'A,=6qc:;;	"B  aaG

1% ! 	""3''H,=,=c,B,BqAvJK "00??DDJJqM	  ! 	B	s+   4C 3E 
E A/EEE+*E+   )rf   rg   rg   rg   rf   c                     U R                   R                  U5        US;  a  [        SU 35      eUS:w  d  US:w  a  [        S5      eUS:w  a  [        S5      e[        R                  U l        g )N)      zUnknown dvi format ii  ;zNonstandard units in dvi file  z%Nonstandard magnification in dvi file)r   r   rq   r   r"  rp   )r   r|   numdenmagrR  s         r   _preDvi._pre!  sh    		qF?21#677(?c\1<== $;DEE __
r      c                 .    [         R                  U l        g r   )r   r   rp   r  s     r   _post	Dvi._post3  s    ((
r      rF   r}   c                     [         er   r5   r   s    r   
_post_postDvi._post_post9      !!r      c                     [         er   r  r   s    r   _begin_reflectDvi._begin_reflect=  r  r      c                     [         er   r  r   s    r   _end_reflectDvi._end_reflectA  r  r      c                 Z   U R                  SSS9nU R                  SSS9nU R                  SSS9nU R                  SSS9nU R                  R                  U5      nU R                  SSS9n0 nUS-  (       a,  [        S5       Vs/ s H  oR                  SSS9PM     snUS'   US-  (       a  U R                  SS	S9S
-  US'   US-  (       a  U R                  SS	S9S
-  US'   US-  (       a  U R                  SS	S9S
-  US'   [        R                  X%Xg5      U R                  U'   g s  snf )Nr^   FrX   r  rW   i   rgbai   T   r   i    slanti @  embolden)r[   r   r   rz   r   
from_xetexr   )	r   rR  rk  flagsrl  r}  r|   r&   r  s	            r   _define_native_fontDvi._define_native_fontE  s*   NN1UN+NN1UN+q/NN1UN+IINN1NN1UN+6>HMaQ1~~a~>QGFO6> $q > FGH6>#~~a~=EGG6>"&..4."@5"HGJ**1<

1 Rs   D(   c                 F   U R                  SSS9nU R                  SSS9n[        SU-  5       Vs/ s H  o0R                  SSS9PM     nn[        U5       Vs/ s H  o0R                  SSS9PM     nnU R                  U R                     n[        U5       Hg  nU R                  R                  [        U R                  USU-     -   U R                  USU-  S-      -   XeU   UR                  XW   5      5      5        Mi     U =R                  U-  sl        g s  snf s  snf )Nr^   FrX   r  TrW   )
r[   rz   r   rs   r   r   r   r   r   r   )r   r   rR  r  xyr   r   r|   s           r   _set_glyphsDvi._set_glyphsX  s   NN1UN+NN1UN+6;AElClnnQtn,lC6;Ah?h^^Ae^,h?zz$&&!qAIIT$&&2a!e9"4dffr!a%!)}6L"&!dnnQT.BD E  	! D?s   DD   c                    U R                  SSS9nU R                  R                  SU-  5      nU R                  SSS9nU R                  SSS9n[        SU-  5       Vs/ s H  oPR                  SSS9PM     nn[        U5       Vs/ s H  oPR                  SSS9PM     nnU R                  U R
                     n[        U5       Hg  n	U R                  R                  [        U R                  USU	-     -   U R                  USU	-  S-      -   XU	   UR                  Xy   5      5      5        Mi     U =R                  U-  sl	        g s  snf s  snf )Nr  FrX   r^   TrW   )r[   r   r   rz   r   rs   r   r   r   r   r   r   )
r   rl  tr   rR  r  r  r   r   r|   s
             r   _set_text_and_glyphsDvi._set_text_and_glyphsd  s)   NN1UN+IINN1q5!NN1UN+NN1UN+6;AElClnnQtn,lC6;Ah?h^^Ae^,h?zz$&&!qAIIT$&&2a!e9"4dffr!a%!)}6L"&!dnnQT.BD E  	! D?s   EE   c                     [        S5      e)Nzunknown command: byte 255)rq   )r   re   s     r   
_malformedDvi._malformedr  s    455r   )r   r   r   r   rs   r   r   r   r   rp   r   r   r   r{   r   r  )F)5rG   rH   rI   rJ   rK   r   r   r   r   r   r   r   r   r   r   r[   r   r  r   r   r   r   r   r  r   r  r"  r  r#  r   r   r.  r5  r<  r   rF  rL  rS  rY  rd  rm  ri  r   r  r  r  r  r  r  r  r  r  rP   rF   r   r   r   r      s    fslG	7+I"!&
+@Z-^L 1#Y%5%565 75 3Cy'7'7jI5 J5 s)**> ? 3Cy'7'7jI" J"H( s)**>" ?"9 s^  s)//
; < s)**+G ,G s)**+L ,L s)**+J ,J 3Cy'7'7jI J 3Cy'7'7iH I
 3Cy'7'7iH I
 3Cy'7'7jI J 3Cy'7'7iH I
 3Cy'7'7iH I
 3Cy'7'78 9 3Cy'7'7jI J 3Cj1* 2* 3C&MN- O-H@ s)--.LM% N%" s)//*) +)
 s" " s" " s" " s= =$ s	 	 s  s^6 6r   r   c                       \ rS rSrSrS r\S 5       r\S 5       r\	" S 5      r
\R                  " S5      " \	" S 5      5      r\	S	 5       r\	S
 5       rS rS rS rS rS rS rS r\S 5       r\S 5       rS rSrg)r   iw  a1  
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                     [         R                  " [        US9  Xl        X l        X0l        X@l        S U l        S U l        g )N)r+   )	r
   check_isinstancebytesr   r   r+   r   _path	_encoding)r   r   r   r+   r   s        r   r   DviFont.__init__  s4    eW5
r   c                 x   USS  R                  S5      u  p4nUR                  S5      (       a  U(       a	  US S S;   d  [        SU 35      e[        R                  S:X  a  UR                  S5      O[        R                  " U5      nSn0 nUSS  (       av  USS  R                  S	5      R                  S
5       HO  n	U	R                  SS5      u  pU
S:X  a  UnM!  U
S;   a  [        U5      S-  X'   M9  [        R                  SU	5        MQ     [        U5      nU " XUS S9n[        U5      Ul        X}l        Xl        U$ )NrW      ]rp  )r      :zInvalid modern font name: ntutf8r   rq  rs  =r   )r  r  r   r  z#Ignoring invalid key-value pair: %rr   )
rpartitionrt  rq   osr6   rv  fsdecodesplitr   r   warning
TtfMetricsr	   r  r4   r&   )clsr   r+   path_bseprestr@   r4   r&   kvkeyvalr   r   s                 r   ru  DviFont.from_luatex  s$   #ABK2248T""4((ST"1X5L9'CDD(*4v}}V$R[[=P812hoog.44S988C+'>!G;;#&s8e#3GLLL!FK : T"57t4$Z
r   c                     [         R                  S:X  a  UR                  S5      O[         R                  " U5      n[	        U5      nU " XSU-   S-   S S9n[        U5      Ul        X7l        XGl        U$ )Nr  r  rp  r  r  )	r  r6   rv  r  r  r	   r  r4   r&   )r  r   r+   r4   r&   r@   r   r   s           r   r  DviFont.from_xetex  sb     *,Dw~~f%bkk'>RT"54'>D#8TB$Z
r   c                      U R                   S-  $ )Ng]e>)r   r   s    r   r!   DviFont.<lambda>  s    0F!Gr   3.11c                     [        [        U R                  R                  SS9S-   5       Vs/ s H/  nSU R                  R                  R	                  US5      -  S-	  PM1     sn$ s  snf )Nr   )defaultrW   r  r      )rz   r~   _tfmr   getr   s     r   r!   r    s]    #diioor:Q>?<A?D 
		##D!,	,3?<A <As   6A&c                 8    U R                   R                  S5      $ )zA fake filenamezlatin-1)r+   rv  r   s    r   fnameDviFont.fname  s     ||""9--r   c                     gr  rF   r   s    r   
face_indexDviFont.face_index      r   c                 2    U Vs0 s H  o"U _M     sn$ s  snf )zGet the mapping from characters to the font that includes them.

Each value maps to self; there is no fallback mechanism for DviFont.
rF   )r   stringr   s      r   _get_fontmapDviFont._get_fontmap  s    
 (..vtd
v...s   c                     [        U 5      [        U5      L =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r   )typer+   r$   r   others     r   __eq__DviFont.__eq__  sD    T
d5k) NLLEMM1N6:ii5::6M	Or   c                 .    U R                  U5      (       + $ r   )r  r  s     r   __ne__DviFont.__ne__  s    ;;u%%%r   c                 N    S[        U 5      R                   SU R                   S3$ )N<z: >)r  rG   r+   r   s    r   __repr__DviFont.__repr__  s&    4:&&'r$,,q99r   c                     U R                   R                  U5      nUc!  [        R                  SXR                  5        g[        UR                  U R                  5      $ )zWidth of char in dvi units.z No width for char %d in font %s.r   )r   get_metricsr   r   r+   r   	tex_widthr   )r   r   r   s      r   r   DviFont._width_of  sH    --++D1?JJ94N))4;;77r   c                 l   U R                   R                  U5      nUc$  [        R                  SXR                  5        SS/$ [        UR                  U R                  5      [        UR                  U R                  5      /n[        R                  " SU R                  5      (       a  US:X  a  SUS'   U$ )z&Height and depth of char in dvi units.z!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   DviFont._height_depth_of  s    --++D1?JJ:D,,Oq6MW''5W&&4
 88M4<<00TQYBrF	r   c                    U R                   c  [        [        S5      5      n XR                     nUR                  cM  [        SR                  UR                  R                  S5      UR                  R                  S5      5      5      e[        UR                  5      U l         U R                   $ U R                   $ ! [         a  n [        U R                  R                  S5       S35        [        [        U R                  R                  S5       S35      5      U l          S nAU R                   $ ! [         a    US ef = fS nAff = f)Nr(   zINo usable font file found for {} ({}); the font may lack a Type-1 versionrq  z.mfz.600pk)r  r)   r*   r+   r   rq   formatpsnamerv  r	   LookupErrorrx  )r   fontmappsfontr  s       r   r    DviFont.resolve_path  s0   :: |!<=G3 . ??*$ &J&,fV]]-A-A'-J-3^^-B-B7-K'MN N "&//2
zztzz  BB!T\\%8%8%A$B#"FG "&m<<..w78?'A "BDJJ zz ) (4'(Bs)   B= =
E
'D4/5E4EEE
c                     gr  rF   r   s    r   r4   DviFont.subfont  r  r   c                     U R                  5       R                  S5      (       a  0 $ [        [        S5      5      U R                     R
                  $ )Nz*.600pkr(   )r    r  r)   r*   r+   r&   r   s    r   r&   DviFont.effects  s@    $$Y//I-56t||DLLLr   c                    U R                   R                  S5      (       a  U$ U R                  c  [        R                  " U R                  5       5      n[        [        S5      5      U R                      nUR                  (       a;  [        UR                  5       Vs/ s H  nUR                  U5      PM     snU l        OUR                  5       U l        U R                  U   $ s  snf )z+Convert dvi glyph indices to FreeType ones.rp  r(   )r+   rt  r  r   r;   r    r)   r*   r,   r-   get_name_index_get_type1_encoding_vector)r   idxrA   r  r6   s        r   r   DviFont._index_dvi_to_freetype"  s     <<""4((J>>!(():):)<=Dl ;<T\\JF.8.I"K.Id #'"5"5d";.I"K "&!@!@!B~~c""	"Ks   C%)r  r   r  r   r   r+   N)rG   rH   rI   rJ   rK   r   classmethodru  r  rL   r$   r
   
deprecatedwidthsr  r  r  r  r  r  r   r   r    r   r4   r&   r   rP   rF   r   r   r   r   w  s     D  0   GHD__V$X /A &B CF . .  /O&:8&,   M M
#r   r   c                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
Vfi;  a  
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U ]  US5         S U l        0 U l        U R	                  5         U R                  5         g ! U R                  5         f = fr  )superr   _first_font_charsr   r   )r   r   	__class__s     r   r   Vf.__init__S  sB    1%	#DDKJJLJJLDJJLs   A Ac                      U R                   U   $ r   )r  )r   codes     r   __getitem__Vf.__getitem__\  s    {{4  r   c                 *   S=pS=p4 U R                   R                  S5      S   nU R                  [        R                  L a  U R                   R                  5       S-
  nXb:X  a  U R                  X5        S=n=pOFXb:  a  [        S5      eUS;   d  US:  a  [        SU S35      e[        R                  U   " X5        M  US	:  aL  UnU R                  S5      nU R                  S
5      nU R                  U5      n[        R                  U l        GO~US	:X  aF  U R                  S5      nU R                  S5      nU R                  S5      nU R                  U5        GO2SUs=::  a  S::  a  O  OU R                  US	-
  US:H  5      nU R                  S5      nU R                  S5      n	U R                  S5      n
U R                  S5      nU R                  S5      nU R                  XxXX5        U R                  c  Xpl        OUS:X  as  U R                  S5      nU R                  S5      nU R                   R                  U5      nU R                  S5      nU R                  S5      nU R                  XUU5        OUS:X  a  g[        SU 35      eGM  )r   NrW   r   z!Packet length mismatch in vf file)r  r   rf  zInappropriate opcode z in vf filer\  rd   r^   rg  r  r  zUnknown vf opcode )r   r   rp   r   r  tell_finalize_packetrq   r   r   r[   _init_packetri  r  r  )r   packet_charpacket_ends
packet_lenpacket_widthrr   byte_atrR  rj  rk  r   r   rl  r|   r{   csdss                    r   r   Vf._read_  s[   
 %)($((
99>>!$Q'DzzY---))..*1,)))+D>BBJB|*$%HIIz)TS[(+@k)RSSKK%d1 cz!
"nnQ/#~~a0"//5&--
!^^A.
"nnQ/#~~a0!!*-##NN4#:ts{;NN1%NN1%NN1%NN1%NN1%""1q4##+'($NN1%NN1%IINN1%^^A&^^A&		!B' #5dV!<==c r   c                 <   U R                   [        R                  :w  a  [        S5      eS=U l        =U l        =U l        =U l        =U l        U l	        / U l
        / U l        / U l        U R                  U l        S U l        U R                   R#                  5       U-   $ )NzMisplaced packet in vf filer   )rp   r   r"  rq   r   r   r   r{   r   r  r   r   r   r  rs   r   r   r!  )r   pls     r   r#  Vf._init_packet  s    ::(:;;>????$&?46?DFTV
	
!!!yy~~"$$r   c                     U R                   (       d.  [        U R                  U R                  US S S9U R                  U'   [
        R                  U l        g )Nr   )r   r   r   r   r  r   r"  rp   )r   r$  r'  s      r   r"  Vf._finalize_packet  s?    !!'+YYdjjT(+DKK$ __
r   c                     U R                   [        R                  La  [        S5      eUS:w  a  [        SU 35      e[	        U5      (       a  [
        R                  SU5        [        R                  U l         g )Nz pre command in middle of vf file   zUnknown vf format zvf file comment: %s)rp   r   r   rq   r   r   r   r"  )r   r|   r{   r)  r*  s        r   r  Vf._pre  s[    ::Y]]*?@@81!566q66JJ,a0__
r   )r  r  r   r   rs   r   r   rp   r   r   r   r{   r   r  )rG   rH   rI   rJ   rK   r   r  r   r#  r"  r  rP   __classcell__)r  s   @r   r  r  ;  s,    .!8>t	%%% %r   r  c                     X-  S-	  $ )z1Multiply two numbers in 12.20 fixed point format.r  rF   )num1num2s     r   r   r     s     I"r   T)frozenkw_onlyc                   8    \ rS rSr% Sr\\S'   \\S'   \\S'   Srg)
TexMetricsi  aq  
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  rF   N)rG   rH   rI   rJ   rK   r   __annotations__rP   rF   r   r   r;  r;    s     NONr   r;  c                       \ rS rSrSrS rS r\R                  " SSS9" \	" S 5      5      r
\R                  " SSS9" \	" S	 5      5      r\R                  " SSS9" \	" S
 5      5      rSrg)Tfmi  a  
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           
         [         R                  SU5        [        US5       nUR                  S5      n[        R
                  " SUSS 5      u  pEpgp[         R                  SXEXgX5        UR                  SU-  5      n
[        R
                  " S	U
S S
 5      u  U l        U l        UR                  SXe-
  S-   -  5      n[        R
                  " SU S3UR                  SU-  5      5      n[        R
                  " SU S3UR                  SU-  5      5      n[        R
                  " SU	 S3UR                  SU	-  5      5      nS S S 5        0 U l        [        [        WWS-   5      5       H@  u  nnWSU-     nUSU-  S-      n[        WU   WUS-	     WUS-     S9U R                  U'   MB     g ! , (       d  f       Nr= f)Nzopening tfm file %sr      z!6Hr     z(lh=%d, bc=%d, ec=%d, nw=%d, nh=%d, nd=%dr^   z!2I   rW   !r|      r  r  r  )r   r   r   r   structunpackr{  design_size_glyph_metrics	enumeraterz   r;  )r   r   r   header1lhbcecnwnhndheader2	char_infor  heightsdepthsr  r   byte0byte1s                      r   r   Tfm.__init__  s   

((3(D!TiimG%+]]5'!B-%H"BBBJJArr/ii"oG.4mmE72A;.O+DM4+		!RU1W+.I]]Qrd!9dii"o>Fmmat1Ityy2?G]]Qrd!9dii"o>F " !"5RT?3ICae$EaeAg&E(2 -"5A:. -)D% 4 "!s   D#F22
G c                 8    U R                   R                  U5      $ )z4Return a glyph's TexMetrics, or None if unavailable.)rI  r  )r   r  s     r   r  Tfm.get_metrics  s    ""&&s++r   r  r  )alternativec                 d    U R                    VVs0 s H  u  pXR                  _M     snn$ s  snnf r   )rI  r  r   rj  ms      r   r!   Tfm.<lambda>  &    $:M:MN:M$!q++~:MNN   ,c                 d    U R                    VVs0 s H  u  pXR                  _M     snn$ s  snnf r   )rI  r  r]  s      r   r!   r_    s&    4;N;NO;N41q,,;NOOra  c                 d    U R                    VVs0 s H  u  pXR                  _M     snn$ s  snnf r   )rI  r  r]  s      r   r!   r_     r`  ra  )rI  r{  rH  N)rG   rH   rI   rJ   rK   r   r  r
   r  rL   r   r   depthrP   rF   r   r   r>  r>    sp    $0, OOF>NOQE__V?OPRFOOF>NOQEr   r>  c                        \ rS rSrS rS rSrg)r  i  c                 :    [         R                  " U5      U l        g r   )r   r;   _face)r   r   s     r   r   TtfMetrics.__init__  s    !**84
r   c                 H   U R                   R                  nU R                   R                  U[        R                  5      n[        [        UR                  U-  S-  5      [        UR                  U-  S-  5      [        UR                  UR                  -
  U-  S-  5      S9$ )N   rE  )
rg  units_per_EM
load_glyphr   NO_SCALEr;  roundhoriAdvancehoriBearingYr   )r   r  upemr   s       r   r  TtfMetrics.get_metrics  s     zz&&JJ!!#y'9'9:AMMD0589Q^^d2U:;QXX6$>FG
 	
r   )rg  N)rG   rH   rI   rJ   r   r  rP   rF   r   r   r  r    s    5
r   r  PsFontz(texname psname effects encoding filenamec                   8    \ rS rSrSrSr\S 5       rS rS r	Sr
g)	r)   i  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                 `   [         R                  U 5      n[        R                  " U5      Ul        [        US5       n0 Ul        U HC  nUR                  SS5      S   nUR                  R                  U/ 5      R                  U5        ME     S S S 5        0 Ul
        U$ ! , (       d  f       N= f)Nr       rW   r   )object__new__r  r  ru  r   rv  r  
setdefaultr   rw  )r  r   r   r   linetfmnames         r   r{  PsfontsMap.__new__L  s    ~~c"X.
 (D!TDN**T1-a0))'26==dC  "
  "!s   AB
B-c           	      Z   [        U[        5      (       d   eXR                  ;   a:  U R                  R                  U5       H  nU R	                  U5      (       d  M    O    U R
                  U   $ ! [         a/    [        SU R                  < SUR                  S5      < S35      S ef = f)NzThe font map z5 is missing a PostScript font associated to TeX font rq  zo; this problem can often be solved by installing a suitable PostScript font package in your TeX package manager)
r   r  rv  r   _parse_and_cache_linerw  KeyErrorr  ru  rv  )r   r+   r}  s      r   r  PsfontsMap.__getitem__\  s    '5))))nn$**73--d33 4	7<<(( 	71 2**1..*A)D E+,- 37	7	7s   "A1 19B*c           	         U(       a  UR                  S5      (       a  gS=n=n=n=pVS=n=p[        R                  " SU5      n
U
 H  nUR                  5       u  pU(       a  UR                  S5      (       a  USS nM9  UR                  S5      (       a  USS nMV  UR                  S5      (       aX  US	S =(       d,    [	        [        S[	        U
5      R                  5       5      5      nUR                  S
5      (       a  UnM  UnSnM  Uc  UnM  Uc  UnM  M  U(       d  M  UnM     0 nU(       a`  [        UR                  5       5      nU HA  nUS:X  a  [        [	        U5      5      US'   M"  US:X  d  M*  [        [	        U5      5      US'   MC     Ub2  UR                  S5      (       a  Sn	OUR                  S5      (       d  SnOUb  SnU	(       a  U(       a  Uc  gU(       d  SU;   d  SU;   a  g[        UR                  SS5      5      S	:  a  g[        UR                  SS5      5      S:  a  gUc  UnUb  [        U5      nUb  [        U5      n[        X#UXVS9U R                  U'   g)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.
)ry     %   *   ;   #NFs   "([^"]*)(?:"|$)|(\S+)s   <<r  s   <[   <rW   s   .encTs	   SlantFontr  s
   ExtendFontr   )s   .ttfs   .ttcs   .otfr   )r+   r  r&   r,   r   )rt  r  finditergroupsnextfilterr8   reversedr  floatabsr  r*   rs  rw  )r   r}  r~  basenamerb  encodingfilefontfileis_subsettedis_t1is_truetypematchesr  quotedunquotedwordr&   wordss                    r   r   PsfontsMap._parse_and_cache_linek  se   8 t'EFFAEEE(EWE|-222u++7>E$||~F&&u--'|H((//#+AB<L((.. ! FtT']-A-A-C DE	 
 }}W--'+#''+_&G%'H & / 0 W]]_-E<'',T%['9GG$]*(-d5k(:GH%	    !344"&&w//!E<L,@'W,G0Cw{{7A&'!+w{{8Q'(1,H#(6L$X.H &g!!6W r   )ru  rw  rv  N)rG   rH   rI   rJ   rK   	__slots__r   r{  r  r  rP   rF   r   r   r)   r)     s.    *V 6I
  7]r   r)   c                    [         R                  " SS[        U 5      R                  SS95      n[         R                  " SU5      R                  S5      nUR                  5        Vs/ s H  o3(       d  M  UPM     nn[        S U 5       5      (       a  U Vs/ s H  o3SS PM	     sn$ [        S	U  S
35      es  snf s  snf )a  
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^  rq  )r,   z(?s)\[(.*)\]rW   c              3   B   #    U  H  oR                  S 5      v   M     g7f)/N)rt  ).0r}  s     r   	<genexpr>_parse_enc.<locals>.<genexpr>  s     
2ED??3Es   NzFailed to parse z as Postscript encoding)	r  subr	   	read_textsearchgroupr  allrq   )r@   no_commentsarrayr}  liness        r   r-   r-     s     &&DJ$8$8'$8$JKKIIo{399!<E#kkm4mdtTmE4

2E
222%*+UTQRU+++D61HIJJ	 5+s   '
B85B8B=c                   0    \ rS rSr\S 5       rS rS rSrg)_LuatexKpsewhichi  c                 Z    [         R                  U 5      nUR                  5       Ul        U$ r   )rz  r{  	_new_proc_proc)r  r   s     r   r{  _LuatexKpsewhich.__new__  s#    ~~c"^^%
r   c                 6   [         R                  " SS[        [        R                  " S5      5      /[         R
                  [         R
                  [         R                  S[        [        [        R                  " 5       S5      5      0[        R                  ES9$ )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  _LuatexKpsewhich._new_proc  so    {C(<(<_(M$NO//*//*BTBT!3tC,<,<,>'N#O ::  	 r   c                    U R                   R                  5       b  U R                  5       U l         U R                   R                  R	                  [
        R                  " U5      S-   5        U R                   R                  R                  5         U R                   R                  R                  5       R                  5       nUS:X  a  S $ [
        R                  " U5      $ )N   
s   nil)r  pollr  r  writer  fsencodeflushr  readlinerstripr  )r   r   outs      r   r  _LuatexKpsewhich.search  s    ::??()DJ

r{{84u<=

 jj((*113f}t:"++c*::r   )r  N)	rG   rH   rI   rJ   r   r{  r  r  rP   rF   r   r   r  r    s    
 
 ;r   r  c                    [        U [        5      (       a  U R                  SSS9n  [        5       nU(       a  UR                  U 5      nO[        R                  S:X  a  0 [        R                  ESS0ESS.nO)0 [        R                  E[        R                  " 5       SS	.nUS
   R                  [        [        [        R                   " 5       S5      5      S9   ["        R$                  " SSU /[&        40 UD6R)                  S5      nU(       a  U$ [	        SU < S35      e! [        [
        4 a    Sn GNf = f! [        [
        [*        4 a    Sn NKf = f)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  rv  r  rx  OSErrorr  sysplatformr  r  getfilesystemencodingupdater  r	   r  r  r   _check_and_log_subprocessr   r  RuntimeError)r   lkr@   kwargss       r   r*   r*     s[   . (E""??79?= 
yy"<<7" N

M,CWM")+F ,

^"%";";"= 13F 	utC$4$4$6FG 	 	I	22k84d>DfTl  HlDFG 	G; w' . "7L9 	D	s#   
D! .D: !D76D7:EEc                 (    U " [        X!-   5      5      $ r   )r*   )r  suffixr+   s      r   	_fontfiler  :  s    }W-.//r   z.tfmz.vf__main__)ArgumentParserr   r   r3   )nargsr  r  z-dz--debug
store_true)action)levelc                  `    [        SR                  [        SR                  U 5      5      5        g )N z{:>11})printr`  mapr  r  s    r   _print_fieldsr  P  s    chhs8??D123r   z=== NEW PAGE === (w: z, h: z, d: )z--- GLYPHS ---c                     U R                   $ r   )r   )r   s    r   r!   r!   X  s    r   r  r  zfont: z at zscale: rj  r{   r   r   r9   r   z--- BOXES ---r   )NN)re   )`rK   dataclassesenumloggingr  r  rF  r  r  collectionsr   	functoolsr   r   r   r   r   pathlibr	   fontTools.aglr=   numpyr   
matplotlibr  r
   r   r   matplotlib.ft2fontr   	getLoggerrG   r   Enumr   r   r   r   dictry   r   r   r   r  r   	dataclassr;  r>  r  rs  r)   r-   r  r*   r  rw  r|  	itertoolsargparser  parseradd_argumentr  
parse_argsr}   r   basicConfigDEBUGr  r   r   rS   pager  r   r   r   groupbyr   r   r  r6   r+   rv  r  	font_namer   r   r    r   r{   r   r   rD   r   boxrF   r   r   <module>r     s  &    	 	   
 " G G     0 0 (", IIj"EF	 &;<*+G':f45 G'^  887	P
B
C K#*/dY6 Y6xA# A#Hw% w%v dD1  24Q 4Qn
 
* 
HH	Im m`K0; ;2 :G :Gz 0 0 9c6*
)R
' z'F

#
SudC
i=Dzz'--04 
T]]DHH	%D E$++eDLL>L M"#(00<RSe<>GGtOT\\008"$++dll"; dmmS11F9+T$2C2C2E1FGHF9+./g 5678c3<!D!$&&$&&$**"&":":"<djjJ "  T zzzo&c3S1::C!#%%

CIIF &'  
&	%!   
&	%s   ;E,O,AO
O"