ó
±éRc           @  s   d  Z  d d l m Z d d l Z d d l Z d d l j Z d d l m	 Z	 d d l m
 Z
 d d l Z d d l Z d d l Z d d l Z e j d d k r¬ d „  Z n  e j d	 d d
 d d d d d d d ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d „ Z i  Z i  Z  d  „  Z! d! „  Z" d" „  Z# e$ d# k rd d l Z e j% j& d$ ƒ e j' d Z( y e) e j' d ƒ Z* Wn e+ k
 re Z* n Xe e( e* ƒ Z, e e d% ƒ ƒ Z- xð e, D]è Z. e/ d& ƒ e Z0 x™ e. j1 D]Ž \ Z2 Z3 Z4 Z5 Z6 e4 e0 k r�e/ d' e4 j7 d( e4 j8 e9 d) d* ƒ ƒ e4 Z0 n  e/ e2 e3 e5 d+ e5 k oÀd, k  n oÎe: e5 ƒ pÔd- e6 ƒ qMWx3 e. j; D]( \ Z2 Z3 Z6 Z< e/ e2 e3 d. e6 e< ƒ qéWq-Wn  d S(/   sI  
An experimental 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::

  dvi = Dvi(filename, 72)
  # iterate over pages (but only one page is supported for now):
  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:
          ...

iÿÿÿÿ(   t   print_functionN(   t
   subprocess(   t   rcParamsi    i   c         C  s   |  S(   N(    (   t   x(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   ord"   s    t   pret   outeri   t   inpagei   t	   post_postt   finalei   t   Dvic           B  s  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  RS(   s°   
    A dvi ("device-independent") file, as produced by TeX.
    The current implementation only reads the first page and does not
    even attempt to verify the postamble.
    c         C  s]   t  j j d | d ƒ t | d ƒ |  _ | |  _ i  |  _ t j |  _	 |  j
 | ƒ |  _ d S(   s½   
        Initialize the object. This takes the filename as input and
        opens the file; actually reading the file happens when
        iterating through the pages of the file.
        s   Dvi: t   debugt   rbN(   t
   matplotlibt   verboset   reportt   opent   filet   dpit   fontst	   _dvistateR   t   statet   _get_baselinet   baseline(   t   selft   filenameR   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   __init__.   s    		c   
      C  sˆ   t  d r„ t j j | ƒ \ } } | d } t j j | ƒ r„ t | d ƒ � } | j ƒ  j ƒ  } Wd  QX| \ } } }	 t | ƒ Sn  d  S(   Ns   text.latex.previews	   .baselineR   (
   R   t   ost   patht   splitextt   existsR   t   readt   splitt   floatt   None(
   R   R   t   baset   extt   baseline_filenamet   fdt   lt   heightt   deptht   width(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR   ;   s    

c         c  s2   x+ t  r- |  j ƒ  } | r) |  j ƒ  Vq Pq Wd S(   s  
        Iterate through the pages of the file.

        Returns (text, boxes) pairs, where:
          text is a list of (x, y, fontnum, glyphnum, width) tuples
          boxes is a list of (x, y, height, width) tuples

        The coordinates are 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(   t   Truet   _readt   _output(   R   t	   have_page(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   __iter__F   s
    	c         C  s    |  j  j s |  j  j ƒ  n  d S(   s:   
        Close the underlying file if it is open.
        N(   R   t   closedt   close(   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR1   [   s    c         C  sX  t  j t  j t  j t  j f \ } } } } t  j } xÆ |  j |  j D]´ } t | ƒ d k rz | \ } } }	 }
 d } n* | \ } } } } }
 | j | ƒ \ }	 } t | | ƒ } t | | |	 ƒ } t | | |
 ƒ } t | | | ƒ } t | | ƒ } qG W|  j d k rDt
 j d |  j d |  j d | | d | | d | ƒ S|  j d d } |  j d k ru| | | } n	 |  j } g  |  j D]B \ } } } } }
 | | | | | | | | | |
 | f ^ qˆ} g  |  j D]@ \ } } }	 }
 | | | | | | | |	 | |
 | f ^ qÚ} t
 j d | d | d | | | d | | | d | ƒ S(   sk   
        Output the text and boxes belonging to the most recent page.
        page = dvi._output()
        i   i    t   textt   boxesR*   R(   t   descentgáz®GR@i   i   Ni   (   t   npt   infR2   R3   t   lent   _height_depth_oft   mint   maxR   R"   t	   mpl_cbookt   BunchR   (   R   t   minxt   minyt   maxxt   maxyt	   maxy_puret   eltR   t   yt   ht   wt   et   fontt   gR4   t   dt   fR2   R3   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR-   b   s8    ,
		OPc         C  sj   xc t  re t |  j j d ƒ d ƒ } |  j | ƒ | d k rB t  S|  j t j k r |  j ƒ  t	 Sq Wd S(   st   
        Read one page from the file. Return True if successful,
        False if there were no more pages.
        i   i    iŒ   N(
   R+   R   R   R   t	   _dispatchR   R   R   R1   t   False(   R   t   byte(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR,   ‹   s    	
c         C  sw   |  j  j | ƒ } t | d ƒ } | rA | d k rA | d } n  x/ t d | ƒ D] } d | t | | ƒ } qQ W| S(   s~   
        Read and return an integer argument *nbytes* long.
        Signedness is determined by the *signed* keyword.
        i    i€   i   i   (   R   R   R   t   range(   R   t   nbytest   signedt   strt   valuet   i(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   _argž   s    c         C  s	  d | k o d k n r, |  j  | ƒ n×| d k rQ |  j  |  j d ƒ ƒ n²| d k rv |  j  |  j d ƒ ƒ n�| d k r› |  j  |  j d ƒ ƒ nh| d	 k rÃ |  j  |  j d
 t ƒ ƒ n@| d k rú |  j |  j d
 t ƒ |  j d
 t ƒ ƒ n	| d k r|  j |  j d ƒ ƒ nä| d k rD|  j |  j d ƒ ƒ n¿| d k ri|  j |  j d ƒ ƒ nš| d k r‘|  j |  j d
 t ƒ ƒ nr| d k rÈ|  j |  j d
 t ƒ |  j d
 t ƒ ƒ n;| d k rá|  j ƒ  n"| d k r"|  j g  t d ƒ D] } |  j d
 t ƒ ^ q Œ  ná| d k r;|  j	 ƒ  nÈ| d k rT|  j
 ƒ  n¯| d k rm|  j ƒ  n–| d k r•|  j |  j d t ƒ ƒ nn| d k r½|  j |  j d t ƒ ƒ nF| d k rå|  j |  j d t ƒ ƒ n| d k r|  j |  j d
 t ƒ ƒ nö| d k r)|  j dA ƒ nÚ| d k rQ|  j |  j d t ƒ ƒ n²| d k ry|  j |  j d t ƒ ƒ nŠ| d k r¡|  j |  j d t ƒ ƒ nb| d k rÉ|  j |  j d
 t ƒ ƒ n:| d  k rå|  j dA ƒ n| d! k r|  j |  j d t ƒ ƒ nö| d" k r5|  j |  j d t ƒ ƒ nÎ| d# k r]|  j |  j d t ƒ ƒ n¦| d$ k r…|  j |  j d
 t ƒ ƒ n~| d% k r­|  j |  j d t ƒ ƒ nV| d& k rÕ|  j |  j d t ƒ ƒ n.| d' k rý|  j |  j d t ƒ ƒ n| d( k r%|  j |  j d
 t ƒ ƒ nÞ| d) k rA|  j dA ƒ nÂ| d* k ri|  j |  j d t ƒ ƒ nš| d+ k r‘|  j |  j d t ƒ ƒ nr| d, k r¹|  j |  j d t ƒ ƒ nJ| d- k rá|  j |  j d
 t ƒ ƒ n"| d. k rý|  j dA ƒ n| d/ k r%|  j |  j d t ƒ ƒ nÞ| d0 k rM|  j |  j d t ƒ ƒ n¶| d1 k ru|  j |  j d t ƒ ƒ nŽ| d2 k r�|  j |  j d
 t ƒ ƒ nfd3 | k o´d4 k n rÍ|  j | d3 ƒ n6| d5 k rò|  j |  j d ƒ ƒ n| d6 k r|  j |  j d ƒ ƒ nì| d7 k r<|  j |  j d ƒ ƒ nÇ| d8 k rd|  j |  j d
 t ƒ ƒ nŸd9 | k o{d: k n rµ|  j | d8 ƒ } |  j j | ƒ } |  j | ƒ nNd; | k oÌd< k n rV|  j | d: | d< k ƒ } g  dB D] } |  j | ƒ ^ qô\ } } }	 }
 } |  j j |
 | ƒ } |  j | | | |	 |
 | | ƒ n­ | d= k rÁg  dC D] } |  j | ƒ ^ qi\ } } } } } |  j j | ƒ } |  j | | | | | ƒ nB | d> k rÚ|  j ƒ  n) | d? k ró|  j ƒ  n t d@ | ƒ ‚ dA S(D   s¶   
        Based on the opcode *byte*, read the correct kinds of
        arguments from the dvi file and call the method implementing
        that opcode with those arguments.
        i    i   i€   i   i�   i   i‚   i   iƒ   i   i„   i…   i†   i‡   iˆ   i‰   iŠ   i‹   i   iŒ   i�   iŽ   i�   i�   i‘   i’   i“   i”   i•   i–   i—   i˜   i™   iš   i›   iœ   i�   iž   iŸ   i    i¡   i¢   i£   i¤   i¥   i¦   i§   i¨   i©   iª   i«   iê   ië   iì   ií   iî   iï   iò   ió   iö   i÷   iø   iù   s   unknown command: byte %dN(   i   i   i   i   i   (   i   i   i   i   i   (   t	   _set_charRT   R+   t	   _set_rulet	   _put_chart	   _put_rulet   _nopt   _bopRN   t   _eopt   _pusht   _popt   _rightt   _right_wR"   t   _right_xt   _downt   _down_yt   _down_zt   _fnt_numR   R   t   _xxxt   _fnt_deft   _pret   _postt
   _post_postt
   ValueError(   R   RM   RS   R7   t   specialt   kR   t   ct   sRI   t   aR'   t   nt   numt   dent   mag(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRK   «   sè          +     +  5                                    1"1  c         C  s–   |  j  t j k r! t d ƒ ‚ n  | d k r@ t d | ƒ ‚ n  | d k s\ | d d
 k rk t d ƒ ‚ n  | d k r† t d	 ƒ ‚ n  t j |  _  d  S(   Ns!   pre command in middle of dvi filei   s   Unknown dvi format %diÀ’ƒi;  i   s   nonstandard units in dvi fileiè  s%   nonstandard magnification in dvi filei   (   R   R   R   Rj   R   (   R   RS   Rq   Rr   Rs   t   comment(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRg   ô   s    c         C  sT   |  j  t j k r! t d ƒ ‚ n  |  j | ƒ |  j |  j |  j j | ƒ 7_ d  S(   Ns   misplaced set_char in dvi file(	   R   R   R   Rj   RW   RD   R   RJ   t	   _width_of(   R   t   char(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRU     s    c         C  sD   |  j  t j k r! t d ƒ ‚ n  |  j | | ƒ |  j | 7_ d  S(   Ns   misplaced set_rule in dvi file(   R   R   R   Rj   RX   RD   (   R   Ro   t   b(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRV     s    c      
   C  s�  |  j  t j k r! t d ƒ ‚ n  |  j |  j } | j d  k rq |  j j	 |  j
 |  j | | | j | ƒ f ƒ n(| j } x¥ | j | j D]“ \ } } } } } t d t | | j ƒ d | j d | j d | j ƒ }	 |  j j	 |  j
 t | | ƒ |  j t | | ƒ |	 | |	 j | ƒ f ƒ q‹ W|  j j g  | j | j D]V \ } } }
 } |  j
 t | | ƒ |  j t | | ƒ t |
 | ƒ t | | ƒ f ^ q<ƒ d  S(   Ns   misplaced put_char in dvi filet   scalet   tfmt   texnamet   vf(   R   R   R   Rj   R   RJ   t   _vfR"   R2   t   appendRD   t   vRu   t   _scalet   DviFontt   _mul2012t   _tfmRz   R3   t   extend(   R   Rv   RG   Rx   R   RC   RJ   RH   RE   t   newfRo   Rw   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRW     s    	&c         C  sb   |  j  t j k r! t d ƒ ‚ n  | d k r^ | d k r^ |  j j |  j |  j | | f ƒ n  d  S(   Ns   misplaced put_rule in dvi filei    (   R   R   R   Rj   R3   R}   RD   R~   (   R   Ro   Rw   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRX   )  s    c         C  s   d  S(   N(    (   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRY   2  s    c         C  s}   |  j  t j k r( t d |  j  ƒ ‚ n  t j |  _  d \ |  _ |  _ |  _ |  _ |  _	 |  _
 g  |  _ g  |  _ g  |  _ d  S(   Ns$   misplaced bop in dvi file (state %d)i    (   i    i    i    i    i    i    (   R   R   R   Rj   R   RD   R~   RE   R   RC   t   zt   stackR2   R3   (   R   t   c0t   c1t   c2t   c3t   c4t   c5t   c6t   c7t   c8t   c9t   p(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRZ   5  s    *		c         C  s[   |  j  t j k r! t d ƒ ‚ n  t j |  _  |  ` |  ` |  ` |  ` |  `	 |  `
 |  ` d  S(   Ns   misplaced eop in dvi file(   R   R   R   Rj   R   RD   R~   RE   R   RC   R…   R†   (   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR[   >  s    c         C  sY   |  j  t j k r! t d ƒ ‚ n  |  j j |  j |  j |  j |  j	 |  j
 |  j f ƒ d  S(   Ns   misplaced push in dvi file(   R   R   R   Rj   R†   R}   RD   R~   RE   R   RC   R…   (   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR\   D  s    c         C  sX   |  j  t j k r! t d ƒ ‚ n  |  j j ƒ  \ |  _ |  _ |  _ |  _	 |  _
 |  _ d  S(   Ns   misplaced pop in dvi file(   R   R   R   Rj   R†   t   popRD   R~   RE   R   RC   R…   (   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR]   I  s    c         C  s4   |  j  t j k r! t d ƒ ‚ n  |  j | 7_ d  S(   Ns   misplaced right in dvi file(   R   R   R   Rj   RD   (   R   Rw   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR^   N  s    c         C  sO   |  j  t j k r! t d ƒ ‚ n  | d  k	 r9 | |  _ n  |  j |  j 7_ d  S(   Ns   misplaced w in dvi file(   R   R   R   Rj   R"   RE   RD   (   R   t   new_w(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR_   S  s
    c         C  sO   |  j  t j k r! t d ƒ ‚ n  | d  k	 r9 | |  _ n  |  j |  j 7_ d  S(   Ns   misplaced x in dvi file(   R   R   R   Rj   R"   R   RD   (   R   t   new_x(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR`   Z  s
    c         C  s4   |  j  t j k r! t d ƒ ‚ n  |  j | 7_ d  S(   Ns   misplaced down in dvi file(   R   R   R   Rj   R~   (   R   Ro   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRa   a  s    c         C  sO   |  j  t j k r! t d ƒ ‚ n  | d  k	 r9 | |  _ n  |  j |  j 7_ d  S(   Ns   misplaced y in dvi file(   R   R   R   Rj   R"   RC   R~   (   R   t   new_y(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRb   f  s
    c         C  sO   |  j  t j k r! t d ƒ ‚ n  | d  k	 r9 | |  _ n  |  j |  j 7_ d  S(   Ns   misplaced z in dvi file(   R   R   R   Rj   R"   R…   R~   (   R   t   new_z(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRc   m  s
    c         C  s.   |  j  t j k r! t d ƒ ‚ n  | |  _ d  S(   Ns   misplaced fnt_num in dvi file(   R   R   R   Rj   RJ   (   R   Rl   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRd   t  s    c         C  sê   t  j d d k r� t j j d d j g  | D]D } d t | ƒ k oO d k  n r` t | ƒ pm d t | ƒ ^ q, ƒ d ƒ ne t j j d d j g  | D]> } d t | ƒ k o½ d k  n rÈ | pÕ d t | ƒ ^ qš ƒ d ƒ d  S(	   Ni    i   s!   Dvi._xxx: encountered special: %st    i    i   s   <%02x>R   (   t   syst   version_infoR   R   R   t   joinR   t   chr(   R   Rk   t   ch(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRe   y  s    		O
		Ic   
   	   C  s�   t  | | j d ƒ ƒ } | d k rW | j d k rW | | j k rW t d | ƒ ‚ n  t | | j d ƒ ƒ }	 t d | d | d | d |	 ƒ |  j | <d  S(   Nt   asciii    s   tfm checksum mismatch: %sRx   Ry   Rz   R{   (   t   _tfmfilet   decodet   checksumRj   t   _vffileR€   R   (
   R   Rl   Rm   Rn   RI   Ro   R'   Rp   Ry   R{   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRf   ‰  s
    *c         C  s1   |  j  t j k r! t d ƒ ‚ n  t j |  _  d  S(   Ns   misplaced post in dvi file(   R   R   R   Rj   R   (   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRh   –  s    c         C  s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRi   �  s    (!   t   __name__t
   __module__t   __doc__R   R   R/   R1   R-   R,   RL   RT   RK   Rg   RU   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rh   Ri   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR
   '   s<   					)		I																						R€   c           B  sA   e  Z d  Z d Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s*  
    Object that 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).

    .. attribute:: texname

       Name of the font as used internally by TeX and friends. This
       is usually very different from any external font names, and
       :class:`dviread.PsfontsMap` can be used to find the external
       name of the font.

    .. attribute:: size

       Size of the font in Adobe points, converted from the slightly
       smaller TeX points.

    .. attribute:: widths

       Widths of glyphs in glyph-space units, typically 1/1000ths of
       the point size.

    Rz   t   sizet   widthsR   R|   R‚   c         C  sç   t  j d d k r4 t | t ƒ r4 | j d ƒ } n  | | | | f \ |  _ |  _ |  _ |  _ | d d d |  _	 y t
 | j j ƒ  ƒ d } Wn t k
 r© d } n Xg  t | ƒ D]# } d	 | j j | d ƒ d
 ?^ q· |  _ d  S(   Ni    i   R�   g      R@gáz®GR@i   i   i   iè  i   i   (   R˜   R™   t
   isinstancet   bytesRŸ   R   R‚   Rz   R|   R¦   R:   R*   t   iterkeysRj   RN   t   getR§   (   R   Rx   Ry   Rz   R{   t   ncharsRv   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR   ½  s    "*
c         C  s4   |  j  | j  k o3 |  j | j k o3 |  j | j k S(   N(   t	   __class__Rz   R¦   (   R   t   other(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   __eq__Ê  s    c         C  s   |  j  | ƒ S(   N(   R¯   (   R   R®   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   __ne__Î  s    c         C  sX   |  j  j j | d ƒ } | d k	 r4 t | |  j ƒ St j j d | |  j	 f d ƒ d S(   sM   
        Width of char in dvi units. For internal use by dviread.py.
        s   No width for char %d in font %sR   i    N(
   R‚   R*   R«   R"   R�   R   R   R   R   Rz   (   R   Rv   R*   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRu   Ñ  s    	c         C  s©   g  } xœ |  j  j d f |  j  j d f f D]v \ } } | j | d ƒ } | d k rˆ t j j d | | |  j f d ƒ | j	 d ƒ q+ | j	 t
 | |  j ƒ ƒ q+ W| S(   sX   
        Height and depth of char in dvi units. For internal use by dviread.py.
        R(   R)   s   No %s for char %d in font %sR   i    N(   R‚   R(   R)   R«   R"   R   R   R   Rz   R}   R�   R   (   R   Rv   t   resultt   metrict   nameRR   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR8   ß  s    	(   s   texnames   sizes   widthss   _scales   _vfs   _tfm(	   R£   R¤   R¥   t	   __slots__R   R¯   R°   Ru   R8   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR€      s   				t   Vfc           B  sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s³   
    A virtual font (\*.vf file) containing subroutines for dvi files.

    Usage::

      vf = Vf(filename)
      glyph = vf[code]
      glyph.text, glyph.boxes, glyph.width
    c         C  sN   t  j |  | d ƒ z) d  |  _ i  |  _ d  |  _ |  j ƒ  Wd  |  j ƒ  Xd  S(   Ni    (   R
   R   R"   t   _first_fontt   _charst   _packet_endsR,   R1   (   R   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR   ü  s    			c         C  s   |  j  | S(   N(   R·   (   R   t   code(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   __getitem__  s    c         C  s  |  j  t j k r¡ |  j j ƒ  d } | |  j k rA |  j ƒ  q¡ | |  j k r_ t d ƒ ‚ q¡ | d k sw | d k rŠ t d | ƒ ‚ n  t j	 |  | ƒ d  Sn  | d k  râ |  j
 d ƒ |  j
 d ƒ } } |  j | | | ƒ n| d k r/g  d D] } |  j
 | ƒ ^ qõ \ } } } |  j | | | ƒ nÏ d | k oFd
 k n r^t j	 |  | ƒ n  | d k rÓ|  j
 d ƒ |  j
 d ƒ } } |  j j | ƒ } |  j
 d	 ƒ |  j
 d	 ƒ }	 }
 |  j | | |	 |
 ƒ n+ | d k rît j |  _  n t d | ƒ ‚ d  S(   Ni   s!   Packet length mismatch in vf filei‹   iŒ   ió   s"   Inappropriate opcode %d in vf fileiò   i   i   iö   i÷   iø   s   unknown vf opcode %d(   i‹   iŒ   (   i   i   i   (   R   R   R   R   t   tellR¸   t   _finalize_packetRj   R
   RK   RT   t   _init_packetR   Rg   R   (   R   RM   t   byte_att   ccRy   R   t   plRS   Rl   t   cst   ds(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRK   	  s4    +c         C  s¬   |  j  t j k r! t d ƒ ‚ n  t j |  _  |  j j ƒ  | |  _ | |  _ | |  _	 d \ |  _
 |  _ |  _ |  _ |  _ |  _ g  g  g  |  _ |  _ |  _ |  j |  _ d  S(   Ns   Misplaced packet in vf filei    (   i    i    i    i    i    i    (   R   R   R   Rj   R   R   R»   R¸   t   _packet_chart   _packet_widthRD   R~   RE   R   RC   R…   R†   R2   R3   R¶   RJ   (   R   RÀ   R¿   Ry   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR½   +  s    		*c         C  sA   t  j d |  j d |  j d |  j ƒ |  j |  j <t j |  _	 d  S(   NR2   R3   R*   (
   R;   R<   R2   R3   RÄ   R·   RÃ   R   R   R   (   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR¼   6  s    	(c         C  sv   |  j  t j k r! t d ƒ ‚ n  | d k r@ t d | ƒ ‚ n  t | ƒ rf t j j d | d ƒ n  t j |  _  d  S(   Ns    pre command in middle of vf fileiÊ   s   Unknown vf format %ds   vf file comment: R   (	   R   R   R   Rj   R7   R   R   R   R   (   R   RS   R   RÁ   RÂ   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRg   ;  s    c         G  s2   t  j |  | | Œ |  j d  k r. | |  _ n  d  S(   N(   R
   Rf   R¶   R"   (   R   Rl   t   args(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRf   E  s    (
   R£   R¤   R¥   R   Rº   RK   R½   R¼   Rg   Rf   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRµ   ñ  s   		
		"			
c         C  s<   d |  k o d k  n s" t  ‚ |  d @r4 |  d S|  Sd S(	   s4   
    Convert from two's complement to negative.
    i    i   i    i   Nl        l        l        (   t   AssertionError(   Rq   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt	   _fix2compJ  s    "
c         C  s   |  | d ?S(   s;   
    Multiply two numbers in 20.12 fixed point format.
    i   (    (   t   num1t   num2(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR�   T  s    t   Tfmc           B  s   e  Z d  Z d Z d „  Z RS(   sB  
    A TeX Font Metric file. This implementation covers only the bare
    minimum needed by the Dvi class.

    .. attribute:: checksum

       Used for verifying against the dvi file.

    .. attribute:: design_size

       Design size of the font (in what units?)

    .. attribute::  width

       Width of each character, needs to be scaled by the factor
       specified in the dvi file. This is a dict because indexing may
       not start from 0.

    .. attribute:: height

       Height of each character.

    .. attribute:: depth

       Depth of each character.
    R    t   design_sizeR*   R(   R)   c         C  s*  t  j j d | d ƒ t | d ƒ �ó } | j d ƒ } t j d | d d !ƒ \ } } } } } }	 t  j j d | | | | | |	 f d ƒ | j d	 | ƒ }
 t j d
 |
 d  ƒ \ |  _ |  _ | j d	 | | d ƒ } | j d	 | ƒ } | j d	 | ƒ } | j d	 |	 ƒ } Wd  QXi  i  i  |  _	 |  _
 |  _ g  | | | f D]& } t j d t | ƒ d	 | ƒ ^ qH\ } } } x¦ t t | | d ƒ ƒ D]‹ \ } } t | t | d	 | ƒ ƒ |  j	 | <t | t | d	 | d ƒ d	 ?ƒ |  j
 | <t | t | d	 | d ƒ d @ƒ |  j | <q—Wd  S(   Ns   opening tfm file R   R   i   s   !6Hi   i   s(   lh=%d, bc=%d, ec=%d, nw=%d, nh=%d, nd=%di   s   !2Ii   i   s   !%dIi   (   R   R   R   R   R   t   structt   unpackR    RË   R*   R(   R)   R7   t	   enumeratet   xrangeRÇ   R   (   R   R   R   t   header1t   lht   bct   ect   nwt   nht   ndt   header2t	   char_infoR§   t   heightst   depthsR   t   idxRv   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR   x  s(    +	"B&%-(   s   checksums   design_sizes   widths   heights   depth(   R£   R¤   R¥   R´   R   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRÊ   [  s   t
   PsfontsMapc           B  s8   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z RS(   s·  
    A psfonts.map formatted file, mapping TeX fonts to PS fonts.
    Usage::

     >>> map = PsfontsMap(find_tex_file('pdftex.map'))
     >>> entry = map['ptmbo8r']
     >>> entry.texname
     'ptmbo8r'
     >>> entry.psname
     'Times-Bold'
     >>> entry.encoding
     '/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'
     >>> entry.effects
     {'slant': 0.16700000000000001}
     >>> entry.filename

    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.
    psfonts.map, pdftex.map, dvipdfm.map. psfonts.map is used by
    dvips, pdftex.map by pdfTeX, and dvipdfm.map by dvipdfm.
    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.
    t   _fontc         C  s2   i  |  _  t | d ƒ � } |  j | ƒ Wd  QXd  S(   Nt   rt(   RÝ   R   t   _parse(   R   R   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR   ¸  s    	c         C  s±   y |  j  | } Wn' t k
 r: |  j  | j d ƒ } n X| j | j } } | d  k	 r| | j d ƒ r| t | ƒ | _ n  | d  k	 r­ | j d ƒ r­ t | j ƒ | _ n  | S(   NR�   t   /(   RÝ   t   KeyErrorRŸ   R   t   encodingR"   t
   startswitht   find_tex_file(   R   Rz   R±   t   fnt   enc(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRº   ½  s    c         C  s@  x9| D]1} | j  ƒ  } | d k s | j d ƒ r: q n  g  d } } xá | t | ƒ k  r*| | d k r© | d 7} | j d | ƒ } | j | | | !ƒ | d } nK | j d | d ƒ } | d k rÚ t | ƒ } n  | j | | | !ƒ | } x0 | t | ƒ k  r&| | d k r&| d 7} q÷ WqJ W|  j | ƒ q Wd S(	   s   Parse each line into words.R—   t   %i    t   "i   t    iÿÿÿÿN(   t   stripRã   R7   t   indexR}   t   findt	   _register(   R   R   t   linet   wordst   post   end(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRß   É  s&    
 %c   	      C  s›  | d  \ } } d \ } } } xÀ | d D]´ } | j d ƒ sH | } q* | j d ƒ } | j d ƒ su | j d ƒ rÆ | d k	 r¡ t j j d | | f d ƒ n  | j d ƒ r½ | d } qÞ | } q* | d k sØ t ‚ | } q* W| j ƒ  } i  } y% t	 | | j
 d	 ƒ d ƒ | d
 <Wn t k
 r,n Xy% t	 | | j
 d ƒ d ƒ | d <Wn t k
 ren Xt j d | d | d | d | d | ƒ |  j | <d S(   s>  Register a font described by "words".

        The format is, AFAIK: texname fontname [effects and filenames]
        Effects are PostScript snippets like ".177 SlantFont",
        filenames begin with one or two less-than signs. A filename
        ending in enc is an encoding file, other filenames are font
        files. This can be overridden with a left bracket: <[foobar
        indicates an encoding file named foobar.

        There is some difference between <foo.pfb and <<bar.pfb in
        subsetting, but I have no example of << in my TeX installation.
        i   R—   t   <t   [s   .encs   Multiple encodings for %s = %sR   i   t	   SlantFontt   slantt
   ExtendFontRƒ   Rz   t   psnamet   effectsRâ   R   N(   R—   NN(   R"   Rã   t   lstript   endswithR   R   R   RÆ   R    R!   Rë   Rj   R;   R<   RÝ   (	   R   Rï   Rz   R÷   Rø   Râ   R   t   wordt   eff(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRí   ß  s:    			
%%	(   s   _font(   R£   R¤   R¥   R´   R   Rº   Rß   Rí   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRÜ   “  s   "			t   Encodingc           B  s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   sû   
    Parses a \*.enc file referenced from a psfonts.map style file.
    The format this class understands is a very limited subset of
    PostScript.

    Usage (subject to change)::

      for name in Encoding(filename):
          whatever(name)
    Râ   c         C  se   t  | d ƒ �P } t j j d | d ƒ |  j | ƒ |  _ t j j d t |  j ƒ d ƒ Wd  QXd  S(   NRÞ   s   Parsing TeX encoding s   debug-annoyings   Result: (   R   R   R   R   Rß   Râ   t   repr(   R   R   R   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR   #  s    c         c  s   x |  j  D] } | Vq
 Wd  S(   N(   Râ   (   R   R³   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR/   )  s    c   	      C  s,  g  } d } x| D]} | j  d ƒ } | d k rA | |  } n  | j ƒ  } | d k rŽ d | k rŽ d } | | j d ƒ d j ƒ  } qŽ n  | d k r d | k rÂ | | j d ƒ  } d } n  | j ƒ  } xS | D]H } | j d ƒ r| j d ƒ } | j | d ƒ qÕ t d	 | ƒ ‚ qÕ Wq q W| S(
   Ni    Rç   iÿÿÿÿRó   i   t   ]i   Rà   s   Broken name in encoding file: (   Rì   Rê   Rë   R    Rã   Rƒ   Rj   (	   R   R   R±   R   Rî   t   comment_startRï   RE   t   subwords(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRß   -  s,    #	(   s   encoding(   R£   R¤   R¥   R´   R   R/   Rß   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRý     s
   
		c         C  s®   d g } | d
 k	 r) | d | g 7} n  | |  g 7} t j j d |  | f d ƒ t j | d t j d t j ƒ} | j ƒ  d j ƒ  } t j j d | d ƒ | j	 d	 ƒ S(   sé  
    Call :program:`kpsewhich` to find a file in the texmf tree. If
    *format* is not None, it is used as the value for the
    :option:`--format` option.

    Apparently most existing TeX distributions on Unix-like systems
    use kpathsea. I hear MikTeX (a popular distribution on Windows)
    doesn't use kpathsea, so what do we do? (TODO)

    .. seealso::

      `Kpathsea documentation <http://www.tug.org/kpathsea/>`_
        The library that :program:`kpsewhich` is part of.
    t	   kpsewhichs	   --format=s   find_tex_file(%s): %sR   t   stdoutt   stderri    s   find_tex_file result: %sR�   N(
   R"   R   R   R   R   t   Popent   PIPEt   communicatet   rstripRŸ   (   R   t   formatt   cmdt   pipeR±   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRä   L  s    	c         C  sY   y | |  SWn t  k
 r n Xt |  | ƒ } | rE | | ƒ } n d  } | | |  <| S(   N(   Rá   Rä   R"   (   Rz   t   class_t   suffixt   cacheR   R±   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt	   _fontfileu  s    
c         C  s   t  |  t d t ƒ S(   Ns   .tfm(   R  RÊ   t	   _tfmcache(   Rz   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyRž   „  s    c         C  s   t  |  t d t ƒ S(   Ns   .vf(   R  Rµ   t   _vfcache(   Rz   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyR¡   ‡  s    t   __main__s   debug-annoyings
   pdftex.maps   === new page ===RG   t   scaledg       @i   i    i€   t   .t   BOX(=   R¥   t
   __future__R    t   errnoR   t   matplotlib.cbookt   cbookR;   t   matplotlib.compatR   R   t   numpyR5   RÌ   R˜   R   R™   R   R<   R   t   objectR
   R€   Rµ   RÇ   R�   RÊ   RÜ   Rý   R"   Rä   R  R  R  Rž   R¡   R£   R   t	   set_levelt   argvt   fnameR!   R   t
   IndexErrort   dvit   fontmapt   paget   printt   fPrevR2   R   RC   RJ   Rm   RE   Rz   R   t   powR›   R3   RD   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/dviread.pyt   <module>   s`   *ÿ zQY	
	8ƒ6&			  

&	B