ó
È4ec           @   s¹  d  d l  Z  d  d l Z d  d l Z d  d l Z d d l m Z m Z d d l m Z	 d Z
 e j d ƒ Z e j d ƒ Z d Z e j j d ƒ rd  d l Z e e d	 ƒ r¹ e j Z n d  d l Z e j j Z x3 d D]" Z e e ƒ d k	 rØ e Z PqØ qØ We Z n  d „  Z d d „ Z d e f d „  ƒ  YZ d „  Z d e j f d „  ƒ  YZ  d d „ Z! e j" e  j# e  e ƒ e j$ e  j# e! ƒ e j% e  j# d d g ƒ e j& e  j# d ƒ d S(   iÿÿÿÿNi   (   t   Imaget	   ImageFile(   t   i32les   0.5s   ^%%([^:]*):[ \t]*(.*)[ \t]*$s   ^%[%!\w]([^:]*)[ \t]*$t   wint   whicht   gswin32ct   gswin64ct   gsc          C   s   t  r
 t St j j d ƒ s{ d d  l }  y< t t j d ƒ   } |  j	 d d g d | ƒWd  QXt SWq{ t
 k
 rw q{ Xn  t S(   NR   iÿÿÿÿt   wbR   s	   --versiont   stdout(   t   gs_windows_binaryt   Truet   syst   platformt
   startswitht
   subprocesst   opent   ost   devnullt
   check_callt   OSErrort   False(   R   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   has_ghostscript<   s    c         C   sü  |  d \ } }  } } | \ } } t  | ƒ p1 d } | d | | d | f } t d | d | d | d ƒ t d | d | d | d ƒ f }	 d d l }
 d d l } | j ƒ  \ } } t j | ƒ d } t | d ƒ rt j	 j
 | j ƒ r| j } nÁ | j ƒ  \ } } t j | ƒ | } t | d	 ƒ ‹ } | j d t j ƒ | j ƒ  } | j d ƒ | } xO | d k r¿| j t | d ƒ ƒ } | sŸPn  | t | ƒ 8} | j | ƒ qqWWd QXd d d | d |	 d d d d d | d d | d | d f d | d d g } t d k	 rGt s:t d ƒ ‚ n  t | d <n  zi d } t j j d ƒ rƒ|
 j ƒ  } | j |
 j O_ n  |
 j | d | ƒt j | ƒ } | j ƒ  Wd y' t j  | ƒ | rÙt j  | ƒ n  Wn t! k
 rín XX| j" j# ƒ  S(   s!   Render an image using Ghostscripti    i   g      R@i   i   iÿÿÿÿNt   nameR   id   i   R   s   -qs   -g%dx%ds   -r%fx%fs   -dBATCHs	   -dNOPAUSEs   -dSAFERs   -sDEVICE=ppmraws   -sOutputFile=%ss   -cs   %d %d translates   -ft   showpages%   Unable to locate Ghostscript on pathsR   t   startupinfoi  ($   t   intt   floatR   t   tempfilet   mkstempR   t   closet   Nonet   hasattrt   patht   existsR   R   t   seekt   iot   SEEK_ENDt   tellt   readt   mint   lent   writeR
   t   WindowsErrorR   R   R   t   STARTUPINFOt   dwFlagst   STARTF_USESHOWWINDOWR   R    t   loadt   unlinkR   t   imt   copy(   t   tilet   sizet   fpt   scalet   decodert   offsett   datat   lengtht   bboxt   resR   R   t   out_fdt   outfilet   infile_tempt   infilet   in_fdt   ft   fsizet
   lengthfilet   st   commandR   R1   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   GhostscriptL   sz    !'$	t   PSFilec           B   s/   e  Z d  Z d „  Z e j d „ Z d „  Z RS(   sP   
    Wrapper for bytesio object that treats either CR or LF as end of line.
    c         C   s   | |  _  d  |  _ d  S(   N(   R5   R   t   char(   t   selfR5   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   __init__±   s    	c         C   s    d  |  _ |  j j | | ƒ d  S(   N(   R   RI   R5   R#   (   RJ   R8   t   whence(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyR#   µ   s    	c         C   s–   |  j  p d } d  |  _  |  j j d ƒ } x, | d k rX | | } |  j j d ƒ } q- W|  j j d ƒ |  _  |  j  d k r‰ d  |  _  n  | j d ƒ S(   Nt    i   s   
s   latin-1(   RI   R   R5   R'   t   decode(   RJ   RE   t   c(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   readline¹   s    	
(   t   __name__t
   __module__t   __doc__RK   R$   t   SEEK_SETR#   RP   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRH   ¬   s   	c         C   s2   |  d  d k p1 t  |  ƒ d k o1 t |  ƒ d k S(   Ni   s   %!PSIÅÐÓÆ    (   R)   t   i32(   t   prefix(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   _acceptÊ   s    t   EpsImageFilec           B   sc   e  Z d  Z d Z d Z i d d 6d d 6d d 6d	 d
 6Z d „  Z d „  Z d d „ Z d „  Z	 RS(   s.   EPS File Parser for the Python Imaging Libraryt   EPSs   Encapsulated Postscriptt   Li   t   LABi   t   RGBi   t   CMYKi   c         C   sj  |  j  |  j ƒ \ } } t |  j ƒ } | j | ƒ d  } d |  _ d |  _ | j ƒ  } | j d ƒ } xö| r_| r't	 | ƒ d k r— t
 d ƒ ‚ n  y t j | ƒ } Wn  t j k
 rÌ t
 d ƒ ‚ n X| r™| j d d ƒ \ } }	 |	 |  j | <| d k r$y{ g  |	 j ƒ  D] }
 t t |
 ƒ ƒ ^ q} | d | d | d	 | d f |  _ d
 d |  j | | | f f g |  _ Wq–t k
 r’q–Xq$q't j | ƒ } | r| j d ƒ } | d k rÍPn  | d  d k rõ| d |  j | d  <q$d |  j | <q'| d d k rq't d ƒ ‚ n  | j ƒ  } | j d ƒ } | rj | d  d k rj Pqj qj Wxî | d  d k rPt	 | ƒ d k r”t
 d ƒ ‚ n  | d  d k r.| d j d  d ƒ d  \ } } } } t | ƒ d k ràPn  y |  j t | ƒ |  _ Wn t k
 rPn Xt | ƒ t | ƒ f |  _ d  S| j ƒ  j d ƒ } | scPqcqcW| sft d ƒ ‚ n  d  S(   NR\   i   s   
iÿ   s   not an EPS filei   t   BoundingBoxi    i   t   epst   EndCommentsi   s   PS-Adobei	   RM   t   %s   bad EPS headeri   s   %ImageData:i   i   s!   cannot determine EPS bounding box(   i   i   (   i    i    (   t   _find_offsetR5   RH   R#   R   t   modet   _sizeRP   t   stripR)   t   SyntaxErrort   splitt   matcht   ret   errort   groupt   infoR   R   R4   R3   t	   Exceptiont   fieldt   IOErrort   mode_mapt
   ValueError(   RJ   R:   R8   R5   t   boxt   s_rawRE   t   mt   kt   vt   it   xt   yt   bit   mo(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   _openÛ   sv    			+')
&c         C   sŸ   | j  d ƒ } | d  d k rG | j d t j ƒ | j ƒ  } d } nN t | d d !ƒ d k r‰ t | d d !ƒ } t | d d !ƒ } n t d ƒ ‚ | | f S(	   Ni    i   s   %!PSi    IÅÐÓÆ    i   i   s   not an EPS file(   R'   R#   R$   R%   R&   RU   Rf   (   RJ   R5   RE   R:   R8   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRb   ?  s    	c         C   sY   |  j  s d  St |  j  |  j |  j | ƒ |  _ |  j j |  _ |  j j |  _ g  |  _  d  S(   N(   R3   RG   R4   R5   R1   Rc   Rd   (   RJ   R6   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyR/   U  s    	!c         O   s   d  S(   N(    (   RJ   t   argst   kwargs(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt	   load_seek^  s    (
   RQ   RR   RS   t   formatt   format_descriptionRp   R|   Rb   R/   R   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRX   Ó   s   "	d		c         C   s|  |  j  ƒ  |  j d k r" d% } n< |  j d k r: d& } n$ |  j d k rR d' } n t d ƒ ‚ | } t } | t j k r¬ t j j d k r¬ t j	 | d d ƒ} t
 } q¬ n  zµ| r2| j d ƒ | j d ƒ | j d |  j ƒ | j d ƒ | j d ƒ | j d ƒ | j d |  j ƒ | j d | ƒ n  | j d ƒ | j d ƒ | j d |  j d | d ƒ | j d |  j ƒ | j d |  j ƒ | j d |  j d |  j d |  j d f ƒ | j d ƒ | j | d d ƒ t | d  ƒ r| j ƒ  n  t j |  | d! d( |  j d d$ f g ƒ | j d" ƒ | j d# ƒ t | d  ƒ r`| j ƒ  n  Wd$ | rw| j ƒ  n  Xd$ S()   s*   EPS Writer for the Python Imaging Library.RZ   i   i   t   imageR\   i   s   false 3 colorimageR]   i   s   false 4 colorimages   image mode is not supportedi   t   encodings   latin-1s   %!PS-Adobe-3.0 EPSF-3.0
s   %%Creator: PIL 0.1 EpsEncode
s   %%%%BoundingBox: 0 0 %d %d
s   %%Pages: 1
s   %%EndComments
s   %%Page: 1 1
s   %%ImageData: %d %d s   %d %d 0 1 1 "%s"
s   gsave
s   10 dict begin
s   /buf %d string def
i    s   %d %d scale
s   %d %d 8
s   [%d 0 0 -%d 0 %d]
s+   { currentfile buf readhexstring pop } bind
s   
t   flushR_   s   
%%%%EndBinary
s   grestore end
N(   i   i   R‚   (   i   i   s   false 3 colorimage(   i   i   s   false 4 colorimage(   i    i    (   R/   Rc   Rq   R   R   R	   t   version_infot   majorR$   t   TextIOWrapperR   R*   R4   R    R„   R   t   _saveR   t   detach(   R1   R5   t   filenameR_   t   operatort   base_fpt
   wrapped_fp(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRˆ   h  sR    
			 /)s   .pss   .epss   application/postscript(   R   R   R   ('   R$   R   Ri   R   RM   R    R   t   _binaryR   RU   t   __version__t   compileRg   Rn   R   R
   R   R   t   shutilR    R   t   distutils.spawnt	   distutilst   spawnt   find_executablet   binaryR   R   RG   t   objectRH   RW   RX   Rˆ   t   register_openR€   t   register_savet   register_extensionst   register_mime(    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   <module>   s<   		`		•C