U
    ڲg                     @  s   d Z ddl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 G dd dZG d	d
 d
ZG dd dZG dd dZdS )z]
(Experimental) WCK-style drawing interface operations

.. seealso:: :py:mod:`PIL.ImageDraw`
    )annotations)BinaryIO   )Image
ImageColor	ImageDraw	ImageFont	ImagePath)StrOrBytesPathc                   @  s&   e Zd ZdZdddddddd	Zd
S )Penz"Stores an outline color and width.r      strintNone)colorwidthopacityreturnc                 C  s   t || _|| _d S N)r   getrgbr   r   )selfr   r   r    r   2/tmp/pip-unpacked-wheel-xela2va7/PIL/ImageDraw2.py__init__$   s    zPen.__init__N)r   r   __name__
__module____qualname____doc__r   r   r   r   r   r   !   s   r   c                   @  s$   e Zd ZdZd
ddddddZd	S )BrushzStores a fill colorr   r   r   r   )r   r   r   c                 C  s   t || _d S r   )r   r   r   )r   r   r   r   r   r   r   ,   s    zBrush.__init__N)r   r   r   r   r   r   r   )   s   r   c                   @  s&   e Zd ZdZdddddddd	Zd
S )Fontz Stores a TrueType font and color   r   zStrOrBytesPath | BinaryIOfloatr   )r   filesizer   c                 C  s   t || _t||| _d S r   )r   r   r   r   Ztruetypefont)r   r   r#   r$   r   r   r   r   3   s    zFont.__init__N)r!   r   r   r   r   r   r    0   s    r    c                   @  s   e Zd ZdZd&ddddddd	Zd
dddZd'ddZdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% ZdS )(Drawz4
    (Experimental) WCK-style drawing interface
    NzImage.Image | strz"tuple[int, int] | list[int] | Nonez&float | tuple[float, ...] | str | Noner   )imager$   r   r   c                 C  sH   t |tr,|d krd}t|t|||}t|| _|| _d | _	d S )Nz>If image argument is mode string, size must be a list or tuple)

isinstancer   
ValueErrorr   newr   r&   drawr'   	transform)r   r'   r$   r   msgr   r   r   r   @   s    
zDraw.__init__zImage.Image)r   c                 C  s   | j S r   )r'   )r   r   r   r   flushO   s    z
Draw.flushc                 C  s   d  }}d}t |tr$|j}|j}nt |tr:|j}|j}t |trL|j}nt |tr\|j}| jrxt|}|| j |dkr| jj	|||d nt
| j||||d d S )Nr   line)fillr   )r0   outline)r(   r   r   r   r   r,   r	   Pathr+   r/   getattr)r   opxyZpenZbrushr1   r0   r   r   r   r   renderR   s$    




zDraw.renderc                 C  s   |\}}dd|dd|f| _ dS )zSets a transformation offset.r   r   N)r,   )r   offsetZxoffsetZyoffsetr   r   r   settransformj   s    zDraw.settransformc                 G  s   | j d|||f|  dS )z
        Draws an arc (a portion of a circle outline) between the start and end
        angles, inside the given bounding box.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.arc`
        arcNr6   r   r5   startendoptionsr   r   r   r9   o   s    zDraw.arcc                 G  s   | j d|||f|  dS )z
        Same as :py:meth:`~PIL.ImageDraw2.Draw.arc`, but connects the end points
        with a straight line.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.chord`
        chordNr:   r;   r   r   r   r?   x   s    z
Draw.chordc                 G  s   | j d|f|  dS )z
        Draws an ellipse inside the given bounding box.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.ellipse`
        ellipseNr:   r   r5   r>   r   r   r   r@      s    zDraw.ellipsec                 G  s   | j d|f|  dS )z
        Draws a line between the coordinates in the ``xy`` list.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.line`
        r/   Nr:   rA   r   r   r   r/      s    z	Draw.linec                 G  s   | j d|||f|  dS )z
        Same as arc, but also draws straight lines between the end points and the
        center of the bounding box.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.pieslice`
        piesliceNr:   r;   r   r   r   rB      s    zDraw.pieslicec                 G  s   | j d|f|  dS )a  
        Draws a polygon.

        The polygon outline consists of straight lines between the given
        coordinates, plus a straight line between the last and the first
        coordinate.


        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.polygon`
        polygonNr:   rA   r   r   r   rC      s    zDraw.polygonc                 G  s   | j d|f|  dS )zg
        Draws a rectangle.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.rectangle`
        	rectangleNr:   rA   r   r   r   rD      s    zDraw.rectanglec                 C  s8   | j rt|}| | j  | jj|||j|jd dS )zw
        Draws the string at the given position.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.text`
        )r%   r0   N)r,   r	   r2   r+   textr%   r   r   r5   rE   r%   r   r   r   rE      s    
z	Draw.textc                 C  s0   | j rt|}| | j  | jj|||jdS )z
        Returns bounding box (in pixels) of given text.

        :return: ``(left, top, right, bottom)`` bounding box

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.textbbox`
        r%   )r,   r	   r2   r+   textbboxr%   rF   r   r   r   rH      s    
zDraw.textbboxc                 C  s   | j j||jdS )z
        Returns length (in pixels) of given text.
        This is the amount by which following text should be offset.

        .. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.textlength`
        rG   )r+   
textlengthr%   )r   rE   r%   r   r   r   rI      s    zDraw.textlength)NN)N)r   r   r   r   r   r.   r6   r8   r9   r?   r@   r/   rB   rC   rD   rE   rH   rI   r   r   r   r   r&   ;   s"     
			r&   N)r   
__future__r   typingr    r   r   r   r   r	   _typingr
   r   r   r    r&   r   r   r   r   <module>   s   