a
    ¨º”h  ã                   @  sN   d dl mZ d dlZd dlmZ ddlmZ dZG dd„ dƒZd	Z	d
Z
dZdS )é    )ÚannotationsN)ÚIOé   )ÚEpsImagePluginFc                   @  s®   e Zd ZdZd&dddœdd„Zd'ddd	œd
d„Zddœdd„Zddddœdd„Zddddœdd„Zdddœdd„Z	ddddœdd„Z
er”dd lmZ d(dd!d"dd#œd$d%„ZdS ))ÚPSDrawzi
    Sets up printing to the given file. If ``fp`` is omitted,
    ``sys.stdout.buffer`` is assumed.
    NzIO[bytes] | NoneÚNone)ÚfpÚreturnc                 C  s   |st jj}|| _d S )N)ÚsysÚstdoutÚbufferr   )Úselfr   © r   ú8/var/www/auris/lib/python3.9/site-packages/PIL/PSDraw.pyÚ__init__%   s    zPSDraw.__init__z
str | None)Úidr	   c                 C  s:   | j  d¡ | j  t¡ | j  t¡ | j  d¡ i | _dS )z=Set up printing of a document. (Write PostScript DSC header.)sD   %!PS-Adobe-3.0
save
/showpage { } def
%%EndComments
%%BeginDocument
s   %%EndProlog
N)r   ÚwriteÚ	EDROFF_PSÚVDI_PSÚisofont)r   r   r   r   r   Úbegin_document*   s    ÿzPSDraw.begin_document)r	   c                 C  s&   | j  d¡ t| j dƒr"| j  ¡  dS )z-Ends printing. (Write PostScript DSC footer.)s%   %%EndDocument
restore showpage
%%End
ÚflushN)r   r   Úhasattrr   )r   r   r   r   Úend_document:   s    zPSDraw.end_documentÚstrÚint)ÚfontÚsizer	   c                 C  sJ   t |dƒ}|| jvr2| j d||f ¡ d| j|< | j d||f ¡ dS )z~
        Selects which font to use.

        :param font: A PostScript font name
        :param size: Size in points.
        úUTF-8s#   /PSDraw-%s ISOLatin1Encoding /%s E
r   s   /F0 %d /PSDraw-%s F
N)Úbytesr   r   r   )r   r   r   Z
font_bytesr   r   r   Úsetfont@   s    


ÿ
zPSDraw.setfontztuple[int, int])Úxy0Úxy1r	   c                 C  s   | j  dg |¢|¢R  ¡ 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).
        s   %d %d %d %d Vl
N©r   r   )r   r!   r"   r   r   r   ÚlineQ   s    zPSDraw.lineztuple[int, int, int, int])Úboxr	   c                 C  s   | j  d| ¡ dS )z‰
        Draws a rectangle.

        :param box: A tuple of four integers, specifying left, bottom, width and
           height.
        s   %d %d M 0 %d %d Vr
Nr#   )r   r%   r   r   r   Ú	rectangleY   s    zPSDraw.rectangle)ÚxyÚtextr	   c                 C  sD   t |dƒ}d | d¡¡}d | d¡¡}| j d||f  ¡ dS )zŠ
        Draws text at the given position. You must use
        :py:meth:`~PIL.PSDraw.PSDraw.setfont` before calling this method.
        r   s   \(ó   (s   \)ó   )s   %d %d M (%s) S
N)r   ÚjoinÚsplitr   r   )r   r'   r(   Z
text_bytesr   r   r   r(   b   s    
zPSDraw.textr   )ÚImagezImage.Imagez
int | None)r%   ÚimÚdpir	   c                 C  s2  |s|j dkrd}nd}|jd d | }|jd d | }t|d |d  ƒ}t|d |d  ƒ}||kr||| | }|}||kr”|| | }|}|| d |d  }|| d |d  }	| j d	||	f ¡ ||f|jkr||jd  }
||jd  }| j d
|
|f ¡ t || jdd¡ | j d¡ dS )z,Draw a PIL image, centered in the given box.Ú1éÈ   éd   r   éH   r   é   é   s   gsave
%f %f translate
s   %f %f scale
Ú s
   
grestore
N)Úmoder   Úfloatr   r   r   Z_save)r   r%   r.   r/   ÚxÚyZxmaxZymaxZdxZdyZsxZsyr   r   r   Úimageo   s.    
zPSDraw.image)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r$   r&   r(   ÚTYPE_CHECKINGr6   r-   r;   r   r   r   r   r      s   	
 ÿr   s×  /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
sß  /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 0 exch rlineto
        exch neg 0 rlineto
        0 exch neg rlineto
        setgray fill } 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
sã  /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
)Ú
__future__r   r
   Útypingr   r6   r   r@   r   r   r   ZERROR_PSr   r   r   r   Ú<module>   s   