î
úÙ XÇ  ã               @   sH   d  d l  m Z d  d l Z Gd d „  d e ƒ Z d Z d Z d Z d S)é    )ÚEpsImagePluginNc               @   s‹   e  Z d  Z d Z d d d „ Z d d „  Z d d d „ Z d	 d
 „  Z d d „  Z d d „  Z	 d d „  Z
 d d „  Z d d d „ Z d S)ÚPSDrawzk
    Sets up printing to the given file. If **file** is omitted,
    :py:attr:`sys.stdout` is assumed.
    Nc             C   s   | s t  j } n  | |  _ d  S)N)ÚsysÚstdoutÚfp)Úselfr   © r   úG/home/ubuntu/projects/ifolica/lib/python3.4/site-packages/PIL/PSDraw.pyÚ__init__   s    zPSDraw.__init__c             C   sN   t  t k s |  j t j k r1 |  j j | ƒ n |  j j t  | d ƒ ƒ d  S)NzUTF-8)ÚbytesÚstrr   r   r   Úwrite)r   Zto_writer   r   r	   Ú	_fp_write$   s    zPSDraw._fp_writec             C   sA   |  j  d ƒ |  j  t ƒ |  j  t ƒ |  j  d ƒ i  |  _ d S)z=Set up printing of a document. (Write Postscript DSC header.)zD%!PS-Adobe-3.0
save
/showpage { } def
%%EndComments
%%BeginDocument
z%%EndProlog
N)r   Ú	EDROFF_PSÚVDI_PSÚisofont)r   Úidr   r   r	   Úbegin_document*   s
    zPSDraw.begin_documentc             C   s3   |  j  d ƒ t |  j d ƒ r/ |  j j ƒ  n  d S)z-Ends printing. (Write Postscript DSC footer.)z%%%EndDocument
restore showpage
%%End
ÚflushN)r   Úhasattrr   r   )r   r   r   r	   Úend_document8   s    zPSDraw.end_documentc             C   sQ   | |  j  k r6 |  j d | | f ƒ d |  j  | <n  |  j d | | f ƒ d S)z~
        Selects which font to use.

        :param font: A Postscript font name
        :param size: Size in points.
        z#/PSDraw-%s ISOLatin1Encoding /%s E
é   z/F0 %d /PSDraw-%s F
N)r   r   )r   ZfontÚsizer   r   r	   Úsetfont@   s
    	zPSDraw.setfontc             C   s   | | } |  j  d | ƒ d S)z¿
        Draws a line between the two points. Coordinates are given in
        Postscript point coordinates (72 points per inch, (0, 0) is the lower
        left corner of the page).
        z%d %d %d %d Vl
N)r   )r   Zxy0Zxy1Úxyr   r   r	   ÚlineO   s    
zPSDraw.linec             C   s   |  j  d | ƒ d S)a8  
        Draws a rectangle.

        :param box: A 4-tuple of integers whose order and function is currently
                    undocumented.

                    Hint: the tuple is passed into this format string:

                    .. code-block:: python

                        %d %d M %d %d 0 Vr

        z%d %d M %d %d 0 Vr
N)r   )r   Úboxr   r   r	   Ú	rectangleX   s    zPSDraw.rectanglec             C   sR   d j  | j d ƒ ƒ } d j  | j d ƒ ƒ } | | f } |  j d | ƒ d S)zŠ
        Draws text at the given position. You must use
        :py:meth:`~PIL.PSDraw.PSDraw.setfont` before calling this method.
        z\(ú(z\)ú)z%d %d M (%s) S
N)ÚjoinÚsplitr   )r   r   Útextr   r   r	   r"   g   s    zPSDraw.textc             C   s‘  | s' | j  d k r d } q' d } n  t | j d d ƒ | } t | j d d ƒ | } t | d | d ƒ } t | d | d ƒ } | | k r° | | | } | } n  | | k rÓ | | | } | } n  | | d | d } | | d | d }	 |  j d	 | |	 f ƒ | | f | j k rg| | j d }
 | | j d } |  j d
 |
 | f ƒ n  t j | |  j d d ƒ |  j d ƒ d S)z,Draw a PIL image, centered in the given box.Ú1éÈ   éd   r   éH   r   é   é   zgsave
%f %f translate
z%f %f scale
Nz

grestore
)ÚmodeÚfloatr   r   r   Z_saver   )r   r   ZimZdpiÚxÚyZxmaxZymaxZdxZdyZsxZsyr   r   r	   Úimageq   s.    				zPSDraw.image)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r   r"   r-   r   r   r   r	   r      s   	
r   a×  /S { show } bind def
/P { moveto show } bind def
/M { moveto } bind def
/X { 0 rmoveto } bind def
/Y { 0 exch rmoveto } bind def
/E {    findfont
        dup maxlength dict begin
        {
                1 index /FID ne { def } { pop pop } ifelse
        } forall
        /Encoding exch def
        dup /FontName exch def
        currentdict end definefont pop
} bind def
/F {    findfont exch scalefont dup setfont
        [ exch /setfont cvx ] cvx bind def
} bind def
añ  /Vm { moveto } bind def
/Va { newpath arcn stroke } bind def
/Vl { moveto lineto stroke } bind def
/Vc { newpath 0 360 arc closepath } bind def
/Vr {   exch dup 0 rlineto
        exch dup neg 0 exch rlineto
        exch neg 0 rlineto
        0 exch rlineto
        100 div setgray fill 0 setgray } bind def
/Tm matrix def
/Ve {   Tm currentmatrix pop
        translate scale newpath 0 0 .5 0 360 arc closepath
        Tm setmatrix
} bind def
/Vf { currentgray exch setgray fill setgray } bind def
aã  /landscape false def
/errorBUF 200 string def
/errorNL { currentpoint 10 sub exch pop 72 exch moveto } def
errordict begin /handleerror {
    initmatrix /Courier findfont 10 scalefont setfont
    newpath 72 720 moveto $error begin /newerror false def
    (PostScript Error) show errorNL errorNL
    (Error: ) show
        /errorname load errorBUF cvs show errorNL errorNL
    (Command: ) show
        /command load dup type /stringtype ne { errorBUF cvs } if show
        errorNL errorNL
    (VMstatus: ) show
        vmstatus errorBUF cvs show ( bytes available, ) show
        errorBUF cvs show ( bytes used at level ) show
        errorBUF cvs show errorNL errorNL
    (Operand stargck: ) show errorNL /ostargck load {
        dup type /stringtype ne { errorBUF cvs } if 72 0 rmoveto show errorNL
    } forall errorNL
    (Execution stargck: ) show errorNL /estargck load {
        dup type /stringtype ne { errorBUF cvs } if 72 0 rmoveto show errorNL
    } forall
    end showpage
} def end
)ZPILr   r   Úobjectr   r   r   ZERROR_PSr   r   r   r	   Ú<module>   s
   •"