
 m[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z m Z m Z m Z m Z d d	 l  m! Z! m" Z" m# Z# m$ Z$ d d
 l% m& Z& d d l' m( Z( m) Z) m* Z* d d l+ m, Z, m- Z- d d l. m/ Z/ d d l0 m1 Z1 d d l2 m3 Z3 d d l4 m5 Z5 d d l m6 Z6 d d l7 m8 Z8 d d l9 m: Z: d d l; Z< d d l= Z= d d l> Z> e j? e@  ZA d ZB d ZC d eD f d     YZE eE   ZF i d d f d 6d d f d 6d d f d 6d d f d  6d! d f d" 6d# d! f d$ 6d% d# f d& 6d' d% f d( 6d) d' f d* 6d+ d) f d, 6d- d+ f d. 6d/ d- f d0 6d1 d2 f d3 6d4 d1 f d5 6d6 d7 f d8 6d9 d6 f d: 6d; d9 f d< 6d= d; f d> 6d? d= f d@ 6dA d? f dB 6dC dA f dD 6dE dC f dF 6dG dE f dH 6dI dG f dJ 6dK dI f dL 6ZG dM   ZH dN   ZI dO   ZJ dP   ZK dQ   ZL dR e f dS     YZM dT e f dU     YZN dV e f dW     YZO dX   ZP eQ d eR eQ dY  ZS eQ d eR eQ dZ  ZT eQ d[  ZU d\   ZV eR eQ d]  ZW d^ e f d_     YZX d` da db dc dd de df g ZY e jZ dg e f dh     Y Z[ d S(i   uF   
A PostScript backend, which can produce both PostScript .ps and .eps
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   StringIO(   t   mkstemp(   t   cbookt   __version__t   rcParamst   checkdep_ghostscript(   t   AFM(   t   _Backendt   FigureCanvasBaset   FigureManagerBaset   GraphicsContextBaset   RendererBase(   t   get_realpath_and_statt   is_writable_file_liket   maxdictt   file_requires_unicode(   t
   subprocess(   t   findfontt   is_opentype_cff_fontt   get_font(   t   KERNING_DEFAULTt   LOAD_NO_HINTING(   t   convert_ttf_to_ps(   t   MathTextParser(   t	   uni2type1(   t   Path(   t   _path(   t   Affine2D(   t   MixedModeRendereru   Level IIt   PsBackendHelperc           B` s>   e  Z d    Z e d    Z e d    Z e d    Z RS(   c         C` s   i  |  _  d  S(   N(   t   _cached(   t   self(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   __init__3   s    c         C` sd   y |  j  d SWn t k
 r" n Xt   \ } } | d k rG d } n  t |  |  j  d <t |  S(   u1   
        executable name of ghostscript.
        u   gs_exeu   gsN(   R"   t   KeyErrorR	   t   Nonet   str(   R#   t   gs_exet
   gs_version(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR(   6   s    	c         C` s   y |  j  d SWn t k
 r" n Xd d l m } m } | |  j d g d | } | j   \ } } t j r | j	 d  } n | } y( t
 t t | j   j d    } Wn t k
 r d } n X| |  j  d <| S(	   u)   
        version of ghostscript.
        u
   gs_versioni    (   t   Popent   PIPEu	   --versiont   stdoutu   asciiu   .(   i    i    (   R"   R%   t   matplotlib.compat.subprocessR*   R+   R(   t   communicatet   sixt   PY3t   decodet   tuplet   mapt   intt   stript   splitt
   ValueError(   R#   R*   R+   t   st   pipet   stderrt   verR)   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR)   G   s     	(
c         C` s   |  j  d d k S(   uM   
        True if the installed ghostscript supports ps2write device.
        i    i	   (   R)   (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   supports_ps2write`   s    (   t   __name__t
   __module__R$   t   propertyR(   R)   R<   (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR!   1   s   	g      !@i   u   letteri   u   legali   u   ledgergGz@@gHzgG@u   a0gp=
c7@u   a1g
ףp=0@u   a2gzGa'@u   a3g
ףp= @u   a4gRQ@u   a5gQ@u   a6gHzG@u   a7g(\ @u   a8gZd;O?gffffff @u   a9gRQ?u   a10gfffffFD@g)\L@u   b0g)\<@u   b1gQE4@u   b2g)\,@u   b3gQ8$@u   b4gp=
ף@u   b5g)\(@u   b6gp=
ף@u   b7gGz@u   b8g)\(?u   b9g)\(?u   b10c         C` s   t  t j t   } | j   | j   xO | D]G } | j d  rK q0 n  t | \ } } |  | k  r0 | | k  r0 | Sq0 Wd S(   Nu   lu   a0(   t   listR/   t   iterkeyst	   papersizet   sortt   reverset
   startswith(   t   wt   ht   keyst   keyt   pwt   ph(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   _get_papertype   s    

  c         C` sd   t  |  t j  r |  St |   } |  | k r8 t |  Sd |  } | j d  } | j d  } | S(   Nu   %1.3fu   0u   .(   t
   isinstanceR/   t   string_typesR4   R'   t   rstrip(   t   valt   ivalR8   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   _num_to_str   s      

c          G` s   d j  t t |    S(   Nu    (   t   joinR3   RR   (   t   args(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   _nums_to_str   s    c         C` s   |  j  d d  }  |  j  d d  }  |  j  d d  }  |  j  d d  }  |  j  d	 d
  }  t j d d   |   }  |  j d  S(   uH   Quote dangerous characters of S for use in a PostScript string constant.s   \s   \\t   (s   \(t   )s   \)t   's   \251t   `s   \301s   [^ -~\n]c         S` s   d t  |  j    S(   Ns   \%03o(   t   ordt   group(   t   x(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   <lambda>   s    u   ascii(   t   replacet   ret   subR1   (   R8   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   quote_ps_string   s    c         C` s   t  |  rb t |  r0 t j |  d d d n t j |  d  } |  t j | |  Wd QXnE t | d  j   t j |  j	 } t j
 |  |  t j | |  d S(   u   Move the contents of file at *src* to path-or-filelike *dst*.

    If *dst* is a path, the metadata of *src* are *not* copied.
    u   rt   encodingu   latin-1u   rbNu   w(   R   R   t   iot   opent   shutilt   copyfileobjt   closet   ost   statt   st_modet   movet   chmod(   t   srct   dstt   fht   mode(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   _move_path_to_path_or_stream   s    $t
   RendererPSc           B` s  e  Z d  Z e d  Z d d  Z d   Z d   Z d d  Z d d  Z	 d d	  Z
 d d
  Z d d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z d( d  Z e d( d  Z d   Z d( d  Z d( d  Z  d   Z! d  d( d!  Z" e d( d"  Z# d#   Z$ d$   Z% d%   Z& d&   Z' e( e( d( d'  Z) RS()   u   
    The renderer handles all the drawing primitives using a graphics
    context instance that controls the colors/styles.
    i2   iH   c         C` s   t  j |   | |  _ | |  _ | |  _ t d rG d |  _ g  |  _ n  | |  _ d |  _
 d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ i  |  _ | d |  _ i  |  _ d |  _ i  |  _ t d  |  _ t j j t d d d  |  _ d S(	   u   
        Although postscript itself is dpi independent, we need to
        imform the image code about a requested dpi to generate high
        res images and them scale them before embeddin them
        u   text.usetexi    g      R@u   PSu   datapathu   fontsu   afmN(   R   R$   t   widtht   heightt	   _pswriterR   t   textcntt   psfragt   imagedpiR&   t   colort	   linewidtht   linejoint   linecapt   linedasht   fontnamet   fontsizet   _hatchest   image_magnificationt   _clip_pathst   _path_collection_idt   used_charactersR   t   mathtext_parserRh   t   pathRS   t   _afm_font_dir(   R#   Rs   Rt   t   pswriterRx   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR$      s.    			
														c         C` sa   t  | j  \ } } |  j j | | t   f  } | d j g  | D] } t |  ^ qD  d S(   uD   Keeps track of which characters are required from
        each font.i   N(   R   t   fnameR   t
   setdefaultt   sett   updateRZ   (   R#   t   fontR8   t   realpatht   stat_keyR   R\   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   track_characters   s    	c         C` sY   xR t  j |  D]A \ } \ } } |  j j | | t   f  } | d j |  q Wd  S(   Ni   (   R/   t	   iteritemsR   R   R   R   (   R#   t   otherR   R   t   charsetR   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   merge_used_characters   s    "	i   c         C` s   | | | f |  j  k r | | k rG | | k rG |  j j d |  n |  j j d | | | f  | r | | | f |  _  q n  d  S(   Nu   %1.3f setgray
u   %1.3f %1.3f %1.3f setrgbcolor
(   Ry   Ru   t   write(   R#   t   rt   gt   bt   store(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt	   set_color   s     c         C` sH   t  |  } | |  j k rD |  j j d |  | rD | |  _ qD n  d  S(   Nu   %1.3f setlinewidth
(   t   floatRz   Ru   R   (   R#   Rz   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   set_linewidth   s
     c         C` s<   | |  j  k r8 |  j j d |  | r8 | |  _  q8 n  d  S(   Nu   %d setlinejoin
(   R{   Ru   R   (   R#   R{   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   set_linejoin   s     c         C` s<   | |  j  k r8 |  j j d |  | r8 | |  _  q8 n  d  S(   Nu   %d setlinecap
(   R|   Ru   R   (   R#   R|   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   set_linecap  s     c         C` s   |  j  d  k	 rC |  j  \ } } t j | |  rC | | k rC d  Sn  | d  k	 r t |  r d t |   | f } |  j j |  n |  j j d  | r | | f |  _  n  d  S(   Nu   [%s] %d setdash
u   [] 0 setdash
(   R}   R&   t   npt   array_equalt   lenRU   Ru   R   (   R#   t   offsett   seqR   t   oldot   oldseqR8   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   set_linedash
  s    c         C` sw   t  d r d  S| | f |  j |  j f k rs d | | f } |  j j |  | r^ | |  _ n  | rs | |  _ qs n  d  S(   Nu	   ps.useafmu%   /%s findfont
%1.3f scalefont
setfont
(   R   R~   R   Ru   R   (   R#   R~   R   R   t   out(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   set_font  s    
   c         C` s   d } | |  j  k r  |  j  | Sd t |  j   } t d } |  j d } |  j j d t    |  j j |  j t j	 |  t
   j |  d t  |  j j d t    | |  j  | <| S(   NiH   u   H%du   hatch.linewidthu     << /PatternType 1
     /PaintType 2
     /TilingType 2
     /BBox[0 0 %(sidelen)d %(sidelen)d]
     /XStep %(sidelen)d
     /YStep %(sidelen)d

     /PaintProc {
        pop
        %(linewidth)f setlinewidth
t   simplifyu}           fill
        stroke
     } bind
   >>
   matrix
   0.0 %(pageheight)f translate
   makepattern
   /%(name)s exch def
(   R   R   R   Rt   Ru   R   t   localst   _convert_pathR   t   hatchR   t   scalet   False(   R#   R   t   sidelent   nameRz   t
   pageheight(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   create_hatch#  s    
		$
		c         C` s   |  j  d |  j d f S(   u4   return the canvas width and height in display coordsg      R@(   Rs   Rt   (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   get_canvas_width_heightF  s    c         C` s  t  d rP |  j   } | j   } | j | | d |  \ } } } | | | f S| r |  j j | d |  \ }	 }
 } } } |	 |
 | f St  d r| r | d d !} n  |  j |  } | j |  \ } } } } } | j   } d | } | | 9} | | 9} | | 9} | | | f S|  j |  } | j	 | d d	 t
 | j   \ } } | d
 } | d
 } | j   } | d
 } | | | f S(   um   
        get the width and height in display coords of the string s
        with FontPropertry prop

        u   text.usetext   rendereriH   u	   ps.useafmi   igMbP?g        t   flagsg      P@(   R   t   get_texmanagert   get_size_in_pointst   get_text_width_height_descentR   t   parset   _get_font_afmt   get_str_bbox_and_descentt   _get_font_ttft   set_textR   t   get_width_heightt   get_descent(   R#   R8   t   propt   ismatht
   texmanagerR   RF   RG   t   dRs   Rt   t   descentR   R   R   t   lR   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR   J  s8    
'
 






c         C` s   t  S(   u3   return true if small y numbers are top for renderer(   R   (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   flipyq  s    c         C` s   t  |  } |  j j |  } | d  k r t | d d d |  j } | d  k ro t d d d d |  j } n  |  j j |  } | d  k r t j | d   } t |  } Wd  QX| |  j | <n  | |  j | <n  | S(   Nt   fontextu   afmt	   directoryu	   Helveticau   rb(	   t   hasht   afmfontdt   getR&   R   R   Rc   Rd   R
   (   R#   R   RI   R   R   Ro   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR   u  s    c         C` sB   t  |  } t |  } | j   | j   } | j | d  | S(   Ng      R@(   R   R   t   clearR   t   set_size(   R#   R   R   R   t   size(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR     s    
c         C` sN   | j  d  \ } } | d  d  d  d  d   d  d  f } | | | j   f S(   Ni   ii   (   t   shapet   tostring(   R#   t   rgbaRG   RF   t   rgb(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   _rgb  s    (i   c         C` si   t  j |  } t |  } g  } xA t d | |  D]- } t | | |  } | j | | | ! q4 W| S(   Ni    (   t   binasciit   b2a_hexR   t   ranget   mint   append(   R#   R8   t   chars_per_linet   nhext   linest   it   limit(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt
   _hex_lines  s    c         C` s   |  j  S(   u   
        Get the factor by which to magnify images passed to draw_image.
        Allows a backend to have images at a different resolution to other
        artists.
        (   R   (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   get_image_magnification  s    c         C` s   t  S(   u@   
        ps backend support arbitrary scaling of image.
        (   t   True(   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   option_scale_image  s    c         C` s	   t  d S(   ul   
        return whether to generate a composite image from multiple images on
        a set of axes
        u   image.composite_image(   R   (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   option_image_nocomposite  s    c         C` s.   |  j  |  \ } } } d } | | | | f S(   Nu   false 3 colorimage(   R   (   R#   t   imRG   RF   t   bitst   imagecmd(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   _get_image_h_w_bits_command  s    c         C` sr  |  j  |  \ } } } }	 d j |  j |   j d  }
 | d k rk d } | |  j } | |  j } n0 d j t t | j   j	     } d } d } |  j
 d } | j   } | j   \ } } g  } | d k	 r| j \ } } } } | j d t | | | |   n  | d k	 rB|  j | |  } | j d |  n  d	 j |  } d
 t   } |  j j |  d S(   u   
        Draw the Image instance into the current axes; x is the
        distance in pixels from the left hand side of the canvas and y
        is the distance from bottom
        s   
u   asciiu   1 0 0 1 0 0u    g      ?iH   u
   %s clipboxu   %su   
u   gsave
%(clip)s
%(x)s %(y)s translate
[%(matrix)s] concat
%(xscale)s %(yscale)s scale
/DataString %(w)s string def
%(w)s %(h)s 8 [ %(w)s 0 0 -%(h)s 0 %(h)s ]
{
currentfile DataString readhexstring pop
} bind %(imagecmd)s
%(hexlines)s
grestore
N(   R   RS   R   R1   R&   R   R3   R'   t   frozent	   to_valuesRt   t   get_clip_rectanglet   get_clip_patht   boundsR   RU   t   _get_clip_pathR   Ru   R   (   R#   t   gcR\   t   yR   t	   transformRG   RF   R   R   t   hexlinest   matrixt   xscalet   yscalet   fight   bboxt   clippatht   clippath_transt   clipt   clipxt   clipyt   clipwt   clipht   idt   ps(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt
   draw_image  s,    !$#c         C` si   | r) d d |  j  d |  j d f } n d  } t j | | | | d  d d d d d d g t  j d	  S(
   Ng        g      R@i   t   mR   t    t   ct   clu   ascii(   Rs   Rt   R&   R   t   convert_to_stringR   R1   (   R#   R   R   R   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR     s    c         C` s   | t  |  f } |  j j |  } | d  k r d t |  j  } d | g } | j |  j | | d t  | j d d d g  |  j	 j
 d j |   | |  j | <n  | S(   Nu   c%xu   /%s {R   u   clipu   newpathu   } bind def
u   
(   R   R   R   R&   R   R   R   R   t   extendRu   R   RS   (   R#   R   t   clippath_transformRI   t   pidt   ps_cmd(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR     s    
c         C` sb   | d k o | j   d k } | j o* | } |  j | | d | d | } |  j | | |  d S(   uI   
        Draws a Path instance using the given affine transform.
        R   R   N(   R&   t   get_hatch_patht   should_simplifyR   t   _draw_ps(   R#   R   R   R   t   rgbFaceR   R   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt	   draw_path  s    c         C` s  t  r |  j j d  n  | r t |  d k rJ | d d k rJ d } q | d | d k om | d k n r d | d } q d | d  } n  d	 d
 d d g } | j   }	 | j   s t | j    d k r | j   n | j   d }
 |	 d k o|
 d k } | r^| j	 d |	  | j
   } | j	 d |  | j   } | j	 d |  n  | j	 |  j | | d t  | r| r| j	 d
  n  | r| j | d g  n  | r| j	 d  qn  | r| j	 d  n  | j d d g  xy | j | d d d |  j d |  j d f d t D]B \ } } t |  r-| d \ } } | j	 d | | f  q-q-Wd j |  } |  j | | | d t d t d S(   u   
        Draw the markers defined by path at each of the positions in x
        and y.  path coordinates are points, x and y coords will be
        transformed by the transform
        u   % draw_markers 
i   i   i    i   i   u   %1.3f setgrayu   %1.3f %1.3f %1.3f setrgbcoloru   /o {u   gsaveu   newpathu	   translateu   %.1f setlinewidthu   %d setlinejoinu   %d setlinecapR   u   fillu   grestoreu   strokeu
   } bind defR   iH   iu   %g %g ou   
t   fillt   strokeN(   t   debugPSRu   R   R   R&   t   get_linewidtht   get_forced_alphat   get_rgbt	   get_alphaR   t   get_joinstylet   get_capstyleR   R   R  t   iter_segmentsRs   Rt   RS   R  (   R#   R   t   marker_patht   marker_transR   t   transR  t   ps_colorR  t   lwt   alphaR  t   jintt   cintt   verticest   codeR\   R   R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   draw_markers  sP     "	(0
	 c         C` s  t  |  d k r% t  | d j  n d } |  j | | | | |  } | d | d | d | k  } | s t j |  | | | | | | | | |	 |
 | | |  S|  j j } g  } x t |  j | | |   D] \ } \ } } d |  j	 | f } d | d d g } | j
 |  j | | d t  | j d	 g  | d
 j |   | j
 |  q Wxp |  j | | | | | | | | |	 |
 | | |  D]; \ } } } } } d | | | f } |  j | | |  qW|  j	 d 7_	 d  S(   Ni    i   i   u   p%x_%xu   /%s {u   newpathu	   translateR   u   } bind def
u   
u   %g %g %si   (   R   R   t   _iter_collection_uses_per_pathR   t   draw_path_collectionRu   R   t	   enumeratet   _iter_collection_raw_pathsR   R   R   R   R  RS   t   _iter_collectionR  (   R#   R   t   master_transformt   pathst   all_transformst   offsetst   offsetTranst
   facecolorst
   edgecolorst
   linewidthst
   linestylest   antialiasedst   urlst   offset_positiont   len_patht   uses_per_patht   should_do_optimizationR   t
   path_codesR   R   R   R   R  t   xot   yot   path_idt   gc0R  R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR$  A  s8    	+ "	"u   TeX!c	         C` sH  |  j  | | |  \ }	 }
 } | j   } d |  j } d | j   d  } i d d 6d d 6j t d d	 d
  } | | } d | | f } d	 } t d r t | | |  } |  j j d | | | | d | f  n> t | | | |  } |  j j d | | | | d | f  d t	   } |  j
 j |  |  j d 7_ d S(   u&   
        draw a Text instance
        u
   psmarker%du   %1.3f,%1.3f,%1.3fi   u   {\sffamily %s}u
   sans-serifu   {\ttfamily %s}u	   monospaceu   font.familyi    u   {\rmfamily %s}u   \color[rgb]{%s} %su   text.latex.previewu/   \psfrag{%s}[Bl][Bl][1][%f]{\fontsize{%f}{%f}%s}g      ?u/   \psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}u5   gsave
%(pos)s moveto
(%(thetext)s)
show
grestore
    i   N(   R   R   Rv   R  R   R   RU   Rw   R   R   Ru   R   (   R#   R   R\   R   R8   R   t   angleR   t   mtextRF   RG   t   blR   t   thetextRy   t   fontcmdt   text   corrt   posR   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   draw_texl  s$    



*'c	         C` s  |  j  j }	 t r |	 d  n  t | j    d k rQ | j   d d k rQ d S| d k ry |  j | | | | | |  S| r |  j | | | | | |  St d r	|  j | j     |  j	 |  }
 |
 j
   } | j   } d | } d } |
 j |  d | } d } g  } x | D] } t j t |  d	  } y |
 j |  } Wn& t k
 rrd	 } |
 j d
  } n X| d k	 r|
 j | |  } n d } | } | | | 7} | j d | | | f  | | | 7} qWd j |  } d t   } |  j  j |  n|  j |  }
 |
 j | d d t |  j |
 |  |  j | j     |
 j   } y | d j d  } Wn$ t k
 r| d j d  } n X| j d d  j d  } |  j | | j    d } g  } d } d } x | D] } t |  } |
 j  |  } | d k r3t d
  } d } d } n |
 j! |  } |
 j" | d t } | d k	 r{|
 j# | | t$  } n d } | } | | d 7} | j d | | | f  | | j% d 7} qWd j |  } d t   } |  j  j |  d S(   u'   
        Draw a Text instance.
        u   % text
i   i   i    Nu   TeXu	   ps.useafmgMbP?u   questionu   ?u   %f %f m /%s glyphshowu   
u|   gsave
/%(fontname)s findfont
%(fontsize)s scalefont
setfont
%(x)f %(y)f translate
%(angle)f rotate
%(thetext)s
grestore
    R   i   i   u	   mac_romani	  u   utf-16beu   asciiu   replaceu   .notdefg      P@g      @uB   gsave
%(x)f %(y)f translate
%(angle)f rotate
%(thetext)s
grestore
(   i   i    i    i   (   i   i   i	  i   (&   Ru   R   R  R   R  RD  t   draw_mathtextR   R   R   t   get_fontnameR   R   R&   R   R   RZ   t   get_width_from_char_nameR%   t   get_width_chart   get_kern_dist_from_nameR   RS   R   R   R   R   R   t   get_sfntR1   t   encodeR   t   get_char_indext   get_glyph_namet	   load_chart   get_kerningR   t   linearHoriAdvance(   R#   R   R\   R   R8   R   R<  R   R=  R   R   R~   R   R   t   thisxt   thisyt	   last_nameR   R  R   Rs   t   kernR?  R   t   sfntt   ps_namet   lastgindt   ccodet   gindt   glyph(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt	   draw_text  s    .


	c         C` s   t    S(   N(   t   GraphicsContextPS(   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   new_gc  s    c         C` s   t  r |  j j d  n  |  j j | d |  \ } } }	 }
 } |  j |  |  j | j     |
 j   } d t	   } |  j j |  d S(   u>   
        Draw the math text using matplotlib.mathtext
        u   % mathtext
iH   uB   gsave
%(x)f %(y)f translate
%(angle)f rotate
%(thetext)s
grestore
N(
   R  Ru   R   R   R   R   R   R  t   getvalueR   (   R#   R   R\   R   R8   R   R<  Rs   Rt   R   R   R   R?  R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyRE     s    'c         C` s,   |  j  | | j d  | j d  |  d  S(   Ni   i   i   i   (   i   i   i   (   i   i   i   (   t   draw_gouraud_trianglest   reshape(   R#   R   t   pointst   colorsR  (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   draw_gouraud_triangle  s    c         C` s  t  |  t  |  k s t  | j d k s3 t  | j d d k sL t  | j d d k se t  | j d k sz t  | j d d k s t  | j d d k s t  | j } | j | d | d d f  } | j |  } | j | d | d d f  } t j | d d d } t j | d d d }	 t j	 d |	 |  }
 | \ } } |	 \ } } t j
 | d | d f d	 d d d d f d d d f g } d | d
 <| | |
 | d <| d  d   d  d  f d | d <t | j    } |  j j d t    d  S(   Ni   i   i   i   i    t   axisi   i    t   dtypeu   flagsu   u1u   pointsu   >u4u   colorsg     o@u   
gsave
<< /ShadingType 4
   /ColorSpace [/DeviceRGB]
   /BitsPerCoordinate 32
   /BitsPerComponent 8
   /BitsPerFlag 8
   /AntiAlias true
   /Decode [ %(xmin)f %(xmax)f %(ymin)f %(ymax)f 0 1 0 1 0 1 ]
   /DataSource (%(stream)s)
>>
shfill
grestore
i   i   I       I    (   u   flagsu   u1(   i   (   i   (   R   t   AssertionErrort   ndimR   R`  R   R   R   t   maxt   ceilt   emptyRa   R   Ru   R   R   (   R#   R   Ra  Rb  R  R   t   flat_pointst   flat_colorst
   points_mint
   points_maxt   factort   xmint   ymint   xmaxt   ymaxt	   streamarrt   stream(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR_    s6    	!!
$	c         C` se  |  j  j } t r- | r- | d | d  n  | j   } | oB | } | ov | d k	 ov t |  d k pv | d d k } | j   }	 | r |  j | j    | j	   }
 |  j
 |
  | j   } |  j |  |  j | j     |  j | j   d    n  | d  | j   } | rK| j \ } } } } | d | | | | f  n  | j   \ } } | r|  j | |  } | d |  n  | | j    | d  | r| s|	 r| d  n  |  j d d	 | d   | d
  | s|	 r| d  qn  |	 rD|  j |	  } | d  | d | j   d   | d |  n  | rW| d  n  | d  d S(   uv  
        Emit the PostScript sniplet 'ps' with all the attributes from 'gc'
        applied.  'ps' must consist of PostScript commands to construct a path.

        The fill and/or stroke kwargs can be set to False if the
        'ps' string already includes filling and/or stroking, in
        which case _draw_ps is just supplying properties and
        clipping.
        u   % u   
i   g        u   gsave
u    %1.4g %1.4g %1.4g %1.4g clipbox
u   %s
R   i    u   fill
u	   grestore
u	   %f %f %f u   %s setpattern fill grestore
u   stroke
N(   Ru   R   R  t   shouldstrokeR&   R   t	   get_hatchR   R  R  R   R  R   R   t
   get_dashesR   R  R   R   R   R   R5   R   t   get_hatch_color(   R#   R   R   R  R  R  t   commandR   t   mightstrokeR   R  R  t   cliprectR\   R   RF   RG   R   R   R   t
   hatch_name(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR  G  sT    "



N(*   R=   R>   t   __doc__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   R   R  R"  R$  RD  R[  R]  RE  Rc  R_  R   R  (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyRr      sH   "			#		'									0
	
:	+#n				.R\  c           B` s#   e  Z d    Z d   Z d   Z RS(   c         C` s&   i d d 6d d 6d d 6t  j |   S(   Ni    u   butti   u   roundi   u
   projecting(   R   R  (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s    
c         C` s&   i d d 6d d 6d d 6t  j |   S(   Ni    u   miteri   u   roundi   u   bevel(   R   R  (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s    
c         C` s>   |  j    d k o= t |  j    d k p= |  j   d d k S(   Ng        i   (   R  R   R  (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyRv    s    (   R=   R>   R  R  Rv  (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR\    s   		t   FigureCanvasPSc           B` s   e  Z e Z d  Z d   Z i d d 6d d 6Z d   Z d   Z d   Z	 d	   Z
 d  d
 d
 d e d d d  Z d d  Z RS(   iH   c         C` s   d  S(   N(    (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   draw  s    u
   Postscriptu   psu   Encapsulated Postscriptu   epsc         C` s   d S(   Nu   ps(    (   R#   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   get_default_filetype  s    c         O` s   |  j  | d | |  S(   Nu   ps(   t	   _print_ps(   R#   t   outfileRT   t   kwargs(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   print_ps  s    c         O` s   |  j  | d | |  S(   Nu   eps(   R  (   R#   R  RT   R  (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt	   print_eps  s    c      
   O` sN  | j  d t d  } | j   } | d k r1 n. | t k r_ t d | d j t  f   n  | j  d d  j   } | d k r t } n! | d k r t } n t d	   |  j j	 d
  | j  d d
  } | j  d d  }	 | j  d d  }
 t d r%|  j
 | | | |	 |
 | | | |  n% |  j | | | |	 |
 | | | |  d  S(   Nu	   papertypeu   ps.papersizeu   autou*   %s is not a valid papertype. Use one of %su   , u   orientationu   portraitu	   landscapeu-   Orientation must be "portrait" or "landscape"iH   u   dpiu	   facecoloru   wu	   edgecoloru   text.usetex(   t   popR   t   lowerRB   t   RuntimeErrorRS   R   R   t   figuret   set_dpit   _print_figure_text   _print_figure(   R#   R  t   formatRT   R  t	   papertypet   orientationt   isLandscapeRx   t	   facecolort	   edgecolor(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s0     	 	
	
	u   wu   portraitc
   "      ` s  | d k  t  | t j t t d d  f  rX t t d d    |  } 	 t } n' t |  rs d 	 t } n t	 d    j
 j   \ 
   d k r | r t  
   q t 
    n  | r t  \ } } n t  \ } } t d ro d k ro
 | k s" | k ro| rJt  
   t  \ } } qlt 
    t  \ } } qon  d  | 
  d! |    j
 j j \ } } } }  }  } | | } | | } d
  | r| | | | f \ } } } } d |     d  n  | | | | f    j
 j   }  j
 j   }  j
 j |   j
 j |  |
 j d t  } | rd t f d     Y} |    _ n t j    _ |
 j d d  }  j 
   j d |  t  j
 
  |  d | }  j
 j |  | rd S j
 j |   j
 j |  |	 d k	 rZd |	 k rZ|	 d  n d t d            	 
   f d   } t d rqt   \ } } z t j  | d d d  } | |  Wd QXt d d k rt! |  d  d   n, t d d k r:t" |  d  d   n  t# | |  Wd t j$ j% |  rmt j& |  n  Xn | rt' |  }  |  rt j( st  | t  rt j) | d d } d   }! |! | _* n | } | |  n+ t j  | d d d  } | |  Wd QXd S("   u  
        Render the figure to hardcopy.  Set the figure patch face and
        edge colors.  This is useful because some of the GUIs have a
        gray figure face color background and you'll probably want to
        override this on hardcopy

        If outfile is a string, it is interpreted as a file name.
        If the extension matches .ep* write encapsulated postscript,
        otherwise write a stand-alone PostScript file.

        If outfile is a file object, a stand-alone PostScript file is
        written into this file object.

        metadata must be a dictionary. Currently, only the value for
        the key 'Creator' is used.
        u   epsu   PathLikeu   fspathc         S` s   |  S(   N(    (   t   obj(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR]     s    u,   outfile must be a path or a file-like objectu   autou   ps.usedistilleriH   g      ?i    iZ   u   dryrunt
   NullWriterc           B` s   e  Z d    Z RS(   c         _` s   d  S(   N(    (   R#   t   klR  (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR     s    (   R=   R>   R   (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s   u   bbox_inches_restoreRx   t   bbox_inches_restoreNu   Creatoru   matplotlib version u   , http://matplotlib.org/c         ` s   r t  d d |  n t  d d |  	 rF t  d 	 d |  n  t  d  d |  t j d  } | r t j j t |   j d  } n t j   } t  d | d |  t  d	  d |   s t  d
  d |  n  t  d   d |   st  d d |  n  t  d d |  t	 t
  } t  d d |  t d s]| t	  j  7} n  t  d | d |  t  d d |  xJ t
 D]B } | j   } x- | j d  D] } t  | j   d |  qWqWt d sx t j  j  D] \ } } t	 |  rt |  } g  }	 x* | D]" }
 | j |
  } |	 j |  qWt d } t	 |	  d k rgd } n  t |  rt d   q|  j   t | j t j    |  | |	  qqWn  t  d d |  t  d d |   st  d d |  n  t  d d |  t  d t    d |   r;t  d  d |  n  t  d t 
 d  d d d  d |   j j   } t | t j  s| j  d  } n  t  | d |  t  d d |  t  d  d |   st  d! d |  n  |  j   d  S("   Nu   %!PS-Adobe-3.0 EPSF-3.0t   fileu   %!PS-Adobe-3.0u	   %%Title: u   %%Creator: u   SOURCE_DATE_EPOCHu   %a %b %d %H:%M:%S %Yu   %%CreationDate: u   %%Orientation: u   %%DocumentPaperSizes: u   %%%%BoundingBox: %d %d %d %du
   %%Pages: 1u   %%EndCommentsu   %%BeginPrologu	   ps.useafmu   /mpldict %d dict defu   mpldict beginu   
u   ps.fonttypei   i*   ux   OpenType CFF fonts can not be saved using the internal Postscript backend at this time; consider using the Cairo backendu   endu   %%EndPrologu   %%Page: 1 1u   %s translateu	   %d rotateu
   %s clipboxiH   i    u   asciiu   showpageu   %%EOF(!   t   printRh   t   getenvt   datetimet   utcfromtimestampR4   t   strftimet   timet   ctimeR   t   psDefsR   R   R5   R6   R/   t
   itervaluesR   RL  R   R   R  t   flushR   RK  t   syst   getfilesystemencodingRU   Ru   R^  RM   t	   text_typeR1   (   Ro   t   source_date_epocht   source_datet   NdictR   R   t   font_filenamet   charsR   t	   glyph_idsR  RY  t   fonttypet   content(   R   t   creator_strRt   t   isEPSFR  R  t   ps_renderert   rotationR#   t   titleRs   R8  R9  (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   print_figure_impl1  s    	

	
	
$u   wRb   u   latin-1u   ghostscriptt   ptypeR   u   xpdfc           S` s   d  S(   N(    (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt
   do_nothing  s    (    g      B@g      B@(+   RM   R/   RN   t   getattrRh   R   R   R&   R   R7   R  t   get_size_inchesRL   RB   R   R   R   t   get_facecolort   get_edgecolort   set_facecolort   set_edgecolorR   t   objectRu   Rc   R   R  t   _renderer_classR    R  R   R   Rd   t
   gs_distillt   xpdf_distillRq   R   t   isfilet   unlinkR   R0   t   TextIOWrapperRg   ("   R#   R  R  t   dpiR  R  R  R  R  t   metadataR  t   passed_in_file_objectt   paperHeightt
   paperWidthR   R   RF   RG   t   llxt   llyt   urxt   uryt   origfacecolort   origedgecolort   dryrunR  t   _bbox_inches_restoreR   R  t   fdt   tmpfileRo   t   requires_unicodeR  (    (   R   R  Rt   R  R  R  R  R  R#   R  Rs   R8  R9  s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s    		  

				3^
	c
   0      K` s  | d k } t  | t j  r' | } n! t |  r< d } n t d   d |  j _ |  j j   \ } } d } d } |  j j	 j
 \ } } } } | } | } | | } | | } | | | | f } |  j j   } |  j j   } |  j j |  |  j j |  |
 j d t  } | r=d t f d     Y} |   |  _ n t j   |  _ |
 j d d  } |  j | | |  j d	 | } t |  j | | | | d
 | }  |  j j |   | rd S|  j j |  |  j j |  |	 d k	 rd |	 k r|	 d }! n d t d }! t   \ }" }# zt j |" d d d }$ t d d |$ | rdt d | d |$ n  t d |! d |$ t j d  }% |% rt j j  t! |%   j" d  }& n t# j$   }& t d |& d |$ t d | d |$ t d d |$ t% t&  }' t d d |$ t d |' d |$ t d d |$ xJ t& D]B }( |( j'   }( x- |( j( d  D] } t | j'   d |$ q^Wq<Wt d d |$ t d  d |$ t d d |$ t d! t) | |  d |$ t d" t) | d | d d d  d |$ t |  j j*   d |$ t d d |$ t d# d |$ |$ j+   Wd QX| rqt, } | | } } | | | | f } n  | r|  j j   \ }) }* | r-|* |) }) }* q-n t- | |  }+ | d$ k r|+ } t. |+ \ }) }* nT t. | \ }) }* | |) k s| |* k r-| r-t. |+ \ }) }* t/ j0 d% | |+  n  | j1   }, |, j2   }- |, j3   }. t4 |# | j5 |- |. |) |* |  }/ t6 d& d' k st6 d( rt7 |# | d) | d* | d+ |/ n2 t6 d& d, k rt8 |# | d) | d* | d+ |/ n  t9 |# |  Wd t j: j; |#  rt j< |#  n  Xd S(-   uS  
        If text.usetex is True in rc, a temporary pair of tex/eps files
        are created to allow tex to manage the text layout via the PSFrags
        package. These files are processed to yield the final ps or eps file.

        metadata must be a dictionary. Currently, only the value for
        the key 'Creator' is used.
        u   epsu,   outfile must be a path or a file-like objectiH   i    u   dryrunR  c           B` s   e  Z d    Z RS(   c         _` s   d  S(   N(    (   R#   R  R  (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR     s    (   R=   R>   R   (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s   u   bbox_inches_restoreRx   R  Nu   Creatoru   matplotlib version u   , http://matplotlib.org/u   wRb   u   latin-1u   %!PS-Adobe-3.0 EPSF-3.0R  u	   %%Title: u   %%Creator: u   SOURCE_DATE_EPOCHu   %a %b %d %H:%M:%S %Yu   %%CreationDate: u   %%%%BoundingBox: %d %d %d %du   %%EndCommentsu   %%BeginPrologu   /mpldict %d dict defu   mpldict beginu   
u   endu   %%EndPrologu   %s translateu
   %s clipboxu   showpageu   autouU   Your figure is too big to fit on %s paper. %s paper will be used to prevent clipping.u   ps.usedistilleru   ghostscriptu   text.usetexR  R   t   rotatedu   xpdf(=   RM   R/   RN   R   R&   R7   R  R  R  R   R   R  R  R  R  R   R   R  Ru   Rc   R   R  R  R    R  R   R   Rd   R  Rh   R  R  R  R4   R  R  R  R   R  R5   R6   RU   R^  R  R   RL   RB   t   _logt   infoR   t   get_font_preamblet   get_custom_preamblet   convert_psfragsRw   R   R  R  Rq   R   R  R  (0   R#   R  R  R  R  R  R  R  R  R  R  R  R  Rs   Rt   R8  R9  R   R   RF   RG   R  R  R  R  R   R  R  R  R  R  R  R   R  R  R  Ro   R  R  R  R   R  R  t   temp_papertypeR   t   font_preamblet   custom_preamblet   psfrag_rotated(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s    		

			$		


N(   R=   R>   Rr   R  t	   fixed_dpiR  t	   filetypesR  R  R  R  R   R&   R  R  (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s   	

						c         C` s4  t  j j |   d } |  d } t j |  |  |  d }	 |  d }
 |  d } | d k rc d } n d } t d r| d	 } n d
 } d | | | | | | | d j |  | t  j j |  d f
 } t j |	 d  h } t d r | j	 | j
 d   n> y | j	 | j
 d   Wn! t k
 r8t j d    n XWd QX|	 j d d  }	 |	 j d d  }	 t d  d d |	 g } t j d |  y" t j | d | d t j } Wn8 t j k
 r} t d |	 | j j d  f   n Xt j |  t d  d  d! d" t  j j |  t  j j |
  g } t j |  y" t j | d | d t j } Wn8 t j k
 r} t d# |
 | j j d  f   n Xt j |  t  j |  t j | |   t j |   + } d$ | j d%  k rt } n t } Wd QXt s0x+ t j |  d&  D] } t  j |  qWn  | S('   uj  
    When we want to use the LaTeX backend with postscript, we write PSFrag tags
    to a temporary postscript file, each one marking a position for LaTeX to
    render some text. convert_psfrags generates a LaTeX document containing the
    commands to convert those tags to text. LaTeX/dvips produces the postscript
    file that includes the actual text.
    i    u   .epsu   .texu   .dviu   .psu	   landscapeiZ   u   text.latex.unicodeu-   \usepackage{ucs}
\usepackage[utf8x]{inputenc}u    uE  \documentclass{article}
%s
%s
%s
\usepackage[dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0in,0in}]{geometry}
\usepackage{psfrag}
\usepackage[dvips]{graphicx}
\usepackage{color}
\pagestyle{empty}
\begin{document}
\begin{figure}
\centering
\leavevmode
%s
\includegraphics*[angle=%s]{%s}
\end{figure}
\end{document}
u   
iu   wbu   utf8u   asciiub   You are using unicode and latex, but have not enabled the matplotlib 'text.latex.unicode' rcParam.Nu   \u   /u   ~u   \string~u   latexu   -interaction=nonstopmodeu   "%s"u   %st   cwdR:   ug   LaTeX was not able to process the following file:
%s

Here is the full report generated by LaTeX:
%s 

u   utf-8u   dvipsu   -qu   -R0u   -oug   dvips was not able to process the following file:
%s

Here is the full report generated by dvips:
%s 

u	   Landscapei  u   .*(   Rh   R   R6   Re   Rk   R   RS   Rc   Rd   R   RK  t   UnicodeEncodeErrorR  R  R^   R'   t   debugR   t   check_outputt   STDOUTt   CalledProcessErrorR  t   outputR1   t   basenamet   removet   readR   R   R  t   glob(   R  t   psfragsR  R  R  R  R  t   tmpdirt   epsfilet	   latexfilet   dvifilet   psfileR<  t   unicode_preambleR8   t   latexhRz  t   reportt   excRo   R  R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR  \  sv    	



	
	)
!		c         C` s<  | r d } n
 d | } |  d } t  d } t j } t j rH d }	 n d }	 t |  d d d	 | d
 |	 | d | |  g }
 t j |
  y t j |
 d t j	 } Wn2 t j
 k
 r } t d | j j d    n Xt j |  t j |   t j | |   | r8t j r+t |  | d | q8t |   n  d S(   u   
    Use ghostscript's pswrite or epswrite device to distill a file.
    This yields smaller files without illegal encapsulated postscript
    operators. The output is low-level, converting text to outlines.
    u	   -dEPSCropu   -sPAPERSIZE=%su   .psu   ps.distiller.resu   ps2writeu   pswriteu   -dBATCHu	   -dNOPAUSEu   -r%du   -sDEVICE=%su   -sOutputFile=%sR:   ug   ghostscript was not able to process your image.
Here is the full report generated by ghostscript:
%s 

u   utf-8R  N(   R   t   ps_backend_helperR(   R<   R'   R  R  R   R  R  R  R  R  R1   Rh   R  Re   Rk   t   pstoeps(   R  t   epsR  R   R  t   paper_optionR  R  R(   t   device_nameRz  R  R  (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s4    	


			
	c      	   C` s  |  d } |  d } t  d  d d d d d | r8 d	 n d
 | |  | g	 } t j |  y t j | d t j } Wn2 t j k
 r }	 t d |	 j j	 d    n Xt j |  t  d  d d d | | g } t j |  y t j | d t j } Wn2 t j k
 r1}	 t d |	 j j	 d    n Xt j |  t
 j |   t j | |   | rot |   n  x( t j |  d  D] }
 t
 j |
  qWd S(   u
  
    Use ghostscript's ps2pdf and xpdf's/poppler's pdftops to distill a file.
    This yields smaller files without illegal encapsulated postscript
    operators. This distiller is preferred, generating high-level postscript
    output that treats text as text.
    u   .pdfu   .psu   ps2pdfu   -dAutoFilterColorImages#falseu   -dAutoFilterGrayImages#falseu   -dAutoRotatePages#falseu   -sGrayImageFilter#FlateEncodeu   -sColorImageFilter#FlateEncodeu	   -dEPSCropu   -sPAPERSIZE#%sR:   u]   ps2pdf was not able to process your image.
Here is the full report generated by ps2pdf:
%s 

u   utf-8u   pdftopsu   -paperu   matchu   -level2u_   pdftops was not able to process your image.
Here is the full report generated by pdftops:
%s 

u   .*N(   R'   R  R  R   R  R  R  R  R  R1   Rh   R  Re   Rk   R  R  (   R  R  R  R   R  t   pdffileR  Rz  R  R  R   (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    sB    

	c   	      C` s   |  \ } } } } | r/ d | | d f } n d } d | | t  j |  t  j |  f } d | | | | f } d j | | g  | f S(   uw   
    return a postscript header stringfor the given bbox lbrt=(l, b, r, t).
    Optionally, return rotate command.
    u   %.2f %.2f  translate
90 rotatei    u    u   %%%%BoundingBox: %d %d %d %du)   %%%%HiResBoundingBox: %.6f %.6f %.6f %.6fu   
(   R   Ri  RS   (	   t   lbrtR  R   R   R   t   tt   rotatet	   bbox_infot   hires_bbox_info(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   get_bbox_header7  s    (c      
   C` s  t  j } | d d d d |  g } t j |  t j | d t j d t j d t j d t } | j | j	 } } t j | j
    | j
   } t j |  t j d	 |  } | r | j   } n t d
 |   g  | j   d D] }	 t |	  ^ q \ }
 } } } | d k rG|
 d | d | d | d f \ }
 } } } nv |
 | d } | | d } | d | d d } | d | d d } | | | | | | | | f \ }
 } } } d |
 | t j |  t j |  f } d |
 | | | f } d j | | g  S(   u   
    Use ghostscript's bbox device to find the center of the bounding box.
    Return an appropriately sized bbox centered around that point. A bit of a
    hack.
    u   -dBATCHu	   -dNOPAUSEu   -sDEVICE=bboxu   %st   stdinR,   R:   t	   close_fdsu   %%HiResBoundingBox: .*uV   Ghostscript was not able to extract a bounding box.Here is the Ghostscript output:

%sii   i   i    i   u   %%%%BoundingBox: %d %d %d %du)   %%%%HiResBoundingBox: %.6f %.6f %.6f %.6fu   
N(   R  R(   R  R  R   R*   R+   R   R,   R:   R  R  R_   t   searchR[   R  R6   R   R&   R   Ri  RS   (   R  R   R(   Rz  t   pR,   R:   R  t
   bbox_foundR   R   R   R   R  R\   R   t   dxt   dyR  (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   get_bboxJ  s4    		51.(c   
      C` s  | r! t  | d | \ } } n d \ } } |  d } t j | d  *} t j |  d  } | j } x | D] }	 |	 j d  r | d  | r| | j d  d  qqq |	 j d	  r | |	  | d
  | r | | j d  d  n  Pqq | r|	 j d  rqq | |	  qq WxF | D]> }	 |	 j d  rI| d  q'|	 j d  r[q'| |	  q'WWd QXWd QXt j |   t	 j
 | |   d S(   u   
    Convert the postscript to encapsulated postscript.  The bbox of
    the eps file will be replaced with the given *bbox* argument. If
    None, original bbox will be used.
    R  u   .epsu   wbu   rbs   %!PSs   %!PS-Adobe-3.0 EPSF-3.0
u   asciis   
s   %%EndCommentssp   %%BeginProlog
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1
s   %%Bounds   %%HiResBounds   %%DocumentMedias   %%Pagess   %%EOFsJ   cleartomark
countdictstack
exch sub { end } repeat
restore
showpage
%%EOF
s   %%PageBoundingBoxN(   NN(   s   %%Bounds   %%HiResBounds   %%DocumentMedias   %%Pages(   R  R&   Rc   Rd   R   RE   RK  Rh   R  Re   Rk   (
   R  R   R  R  R  R  t   epsht   tmphR   t   line(    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR  v  s<    
 	


		t   FigureManagerPSc           B` s   e  Z RS(    (   R=   R>   (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s   u   /m { moveto } bind defu   /l { lineto } bind defu   /r { rlineto } bind defu   /c { curveto } bind defu   /cl { closepath } bind defuU   /box {
      m
      1 index 0 r
      0 exch r
      neg 0 r
      cl
    } bind defu<   /clipbox {
      box
      clip
      newpath
    } bind deft
   _BackendPSc           B` s   e  Z e Z e Z RS(    (   R=   R>   R  t   FigureCanvasR  t   FigureManager(    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyR    s   (\   R~  t
   __future__R    R   R   R   R/   t	   six.movesR   R  Rh   Re   R  R  R  Rc   t   loggingt   tempfileR   t
   matplotlibR   R   R   R	   t   matplotlib.afmR
   t   matplotlib.backend_basesR   R   R   R   R   t   matplotlib.cbookR   R   R   R   R-   R   t   matplotlib.font_managerR   R   R   t   matplotlib.ft2fontR   R   t   matplotlib.ttconvR   t   matplotlib.mathtextR   t   matplotlib._mathtext_dataR   t   matplotlib.pathR   R   t   matplotlib.transformsR   t!   matplotlib.backends.backend_mixedR    t   numpyR   R   R_   t	   getLoggerR=   R  t   backend_versionR  R  R!   R  RB   RL   RR   RU   Ra   Rq   Rr   R\  R  R  R   R&   R  R  R  R  R  R  R  t   exportR  (    (    (    s=   lib/python2.7/site-packages/matplotlib/backends/backend_ps.pyt   <module>   s   "H"("6		
				   	t43	,=		