a
    ç´«j-&  ã                   @   s¼   d dl mZ d dlmZmZ d dlmZ erDd dlmZ d dl	m
Z
 dZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )ÚTYPE_CHECKING)ÚImageÚ	ImageDraw)ÚQRModuleDrawer)ÚStyledPilImage)ÚActiveWithNeighborsé   c                   @   s   e Zd ZU dZded< dS )ÚStyledPilQRModuleDrawerzù
    A base class for StyledPilImage module drawers.

    NOTE: the color that this draws in should be whatever is equivalent to
    black in the color space, and the specified QRColorMask will handle adding
    colors as necessary to the image
    r   ÚimgN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© r   r   úd/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/qrcode/image/styles/moduledrawers/pil.pyr	      s   
r	   c                       s.   e Zd ZdZ‡ fdd„Zedœdd„Z‡  ZS )ÚSquareModuleDrawerz-
    Draws the modules as simple squares
    c                    s&   t ƒ j|i |¤Ž t | jj¡| _d S ©N)ÚsuperÚ
initializer   ÚDrawr
   Ú_imgÚimgDraw©ÚselfÚargsÚkwargs©Ú	__class__r   r   r       s    zSquareModuleDrawer.initialize©Ú	is_activec                 C   s   |r| j j|| jjd� d S )N©Úfill)r   Ú	rectangler
   Úpaint_color©r   Úboxr    r   r   r   Údrawrect$   s    zSquareModuleDrawer.drawrect)r   r   r   r   r   Úboolr'   Ú__classcell__r   r   r   r   r      s   r   c                       s8   e Zd ZdZd
dd„Z‡ fdd„Zedœdd	„Z‡  ZS )ÚGappedSquareModuleDrawerz¹
    Draws the modules as simple squares that are not contiguous.

    The size_ratio determines how wide the squares are relative to the width of
    the space they are printed in
    çš™™™™™é?c                 C   s
   || _ d S r   )Ú
size_ratio)r   r,   r   r   r   Ú__init__1   s    z!GappedSquareModuleDrawer.__init__c                    s>   t ƒ j|i |¤Ž t | jj¡| _d| j | jj d | _	d S )Né   é   )
r   r   r   r   r
   r   r   r,   Úbox_sizeÚdeltar   r   r   r   r   4   s    z#GappedSquareModuleDrawer.initializer   c                 C   s`   |r\|d d | j  |d d | j  |d d | j  |d d | j  f}| jj|| jjd� d S )Nr   r.   r!   )r1   r   r#   r
   r$   )r   r&   r    Zsmaller_boxr   r   r   r'   9   s    üz!GappedSquareModuleDrawer.drawrect)r+   )	r   r   r   r   r-   r   r(   r'   r)   r   r   r   r   r*   )   s   
r*   c                       s2   e Zd ZdZdZ‡ fdd„Zedœdd„Z‡  ZS )ÚCircleModuleDrawerz&
    Draws the modules as circles
    Nc                    s~   t ƒ j|i |¤Ž | jj}|t }t | jj||f| jjj	¡| _
t | j
¡jdd||f| jjd� | j
 ||ftjj¡| _
d S )Nr   r!   )r   r   r
   r0   ÚANTIALIASING_FACTORr   ÚnewÚmodeÚ
color_maskÚ
back_colorÚcircler   r   Úellipser$   ÚresizeÚ
ResamplingÚLANCZOS)r   r   r   r0   Z	fake_sizer   r   r   r   K   s    ýÿzCircleModuleDrawer.initializer   c                 C   s.   |r*| j j | j|d d |d d f¡ d S ©Nr   r.   )r
   r   Úpaster8   r%   r   r   r   r'   Y   s    zCircleModuleDrawer.drawrect)	r   r   r   r   r8   r   r(   r'   r)   r   r   r   r   r2   D   s   r2   c                       sN   e Zd ZdZdZddd„Z‡ fdd„Zdd	„ Zeee	  d
dœdd„Z
‡  ZS )ÚRoundedModuleDraweraP  
    Draws the modules with all 90 degree corners replaced with rounded edges.

    radius_ratio determines the radius of the rounded edges - a value of 1
    means that an isolated module will be drawn as a circle, while a value of 0
    means that the radius of the rounded edge will be 0 (and thus back to 90
    degrees again).
    Tr.   c                 C   s
   || _ d S r   )Úradius_ratio)r   r@   r   r   r   r-   j   s    zRoundedModuleDrawer.__init__c                    s0   t ƒ j|i |¤Ž t| jjd ƒ| _|  ¡  d S )Nr/   )r   r   Úintr
   r0   Úcorner_widthÚsetup_cornersr   r   r   r   r   m   s    zRoundedModuleDrawer.initializec           	      C   s   | j j}| j jj}| j j}t || j| jf|¡| _| jt	 }| j
| }|d }t |||f|¡}t |¡}|jdd||f|d� |j|d||f|d� |jd|||f|d� | | j| jftjj¡| _| j tjj¡| _| j tjj¡| _| j tjj¡| _d S ©Nr/   r   r!   )r
   r5   r6   r7   r$   r   r4   rB   ÚSQUAREr3   r@   r   r   r9   r#   r:   r;   r<   ÚNW_ROUNDÚ	transposeÚ	TransposeÚFLIP_TOP_BOTTOMÚSW_ROUNDZ
ROTATE_180ÚSE_ROUNDÚFLIP_LEFT_RIGHTÚNE_ROUND)	r   r5   r7   Úfront_colorÚ
fake_widthZradiusZdiameterÚbaseÚ	base_drawr   r   r   rC   r   s,    
ÿ


ÿ
ÿz!RoundedModuleDrawer.setup_cornersr   )r&   r    c                 C   s4  |sd S |j  o|j }|j o&|j }|j o6|j }|j oF|j  }|rR| jn| j}|rb| jn| j}|rr| jn| j}	|r‚| jn| j}
| j	j
 ||d d |d d f¡ | j	j
 ||d d | j |d d f¡ | j	j
 |	|d d | j |d d | j f¡ | j	j
 |
|d d |d d | j f¡ d S r=   )ÚWÚNÚEÚSrF   rE   rM   rK   rJ   r
   r   r>   rB   )r   r&   r    Z
nw_roundedZ
ne_roundedZ
se_roundedZ
sw_roundedÚnwÚneÚseÚswr   r   r   r'   ‹   s     $*$ÿzRoundedModuleDrawer.drawrect)r.   )r   r   r   r   Úneeds_neighborsr-   r   rC   ÚlistrA   r'   r)   r   r   r   r   r?   ^   s   	
r?   c                       sD   e Zd ZdZdZddd„Z‡ fdd„Zdd	„ Zd
dœdd„Z‡  Z	S )ÚVerticalBarsDrawerzÌ
    Draws vertically contiguous groups of modules as long rounded rectangles,
    with gaps between neighboring bands (the size of these gaps is inversely
    proportional to the horizontal_shrink).
    Tr+   c                 C   s
   || _ d S r   )Úhorizontal_shrink)r   r]   r   r   r   r-   ©   s    zVerticalBarsDrawer.__init__c                    sF   t ƒ j|i |¤Ž t| jjd ƒ| _td| j | j ƒ| _|  ¡  d S ©Nr/   r.   )	r   r   rA   r
   r0   Úhalf_heightr]   r1   Úsetup_edgesr   r   r   r   r   ¬   s    zVerticalBarsDrawer.initializec                 C   s¼   | j j}| j jj}| j j}| j}|d }t|| j ƒ}t 	|||f|¡| _
|t }|t }t 	|||f|¡}	t |	¡}
|
jdd||d f|d� |	 ||ftjj¡| _| j tjj¡| _d S rD   )r
   r5   r6   r7   r$   r_   rA   r]   r   r4   rE   r3   r   r   r9   r:   r;   r<   Ú	ROUND_TOPrG   rH   rI   ÚROUND_BOTTOM)r   r5   r7   rN   ÚheightÚwidthZshrunken_widthrO   Úfake_heightrP   rQ   r   r   r   r`   ²   s     

ÿ
zVerticalBarsDrawer.setup_edgesr   r   c                 C   s’   |rŽ|j  }|j }|r| jn| j}|r.| jn| j}| jj ||d d | j |d d f¡ | jj ||d d | j |d d | j	 f¡ d S r=   )
rS   rU   ra   rE   rb   r
   r   r>   r1   r_   )r   r&   r    Ztop_roundedZbottom_roundedÚtopÚbottomr   r   r   r'   Ç   s    *$ÿzVerticalBarsDrawer.drawrect)r+   ©
r   r   r   r   rZ   r-   r   r`   r'   r)   r   r   r   r   r\       s   
r\   c                       sD   e Zd ZdZdZddd„Z‡ fdd„Zdd	„ Zd
dœdd„Z‡  Z	S )ÚHorizontalBarsDrawerzÌ
    Draws horizontally contiguous groups of modules as long rounded rectangles,
    with gaps between neighboring bands (the size of these gaps is inversely
    proportional to the vertical_shrink).
    Tr+   c                 C   s
   || _ d S r   )Úvertical_shrink)r   rj   r   r   r   r-   Þ   s    zHorizontalBarsDrawer.__init__c                    sF   t ƒ j|i |¤Ž t| jjd ƒ| _td| j | j ƒ| _|  ¡  d S r^   )	r   r   rA   r
   r0   Ú
half_widthrj   r1   r`   r   r   r   r   r   á   s    zHorizontalBarsDrawer.initializec                 C   s¼   | j j}| j jj}| j j}| j}|d }t|| j ƒ}t 	|||f|¡| _
|t }|t }t 	|||f|¡}	t |	¡}
|
jdd|d |f|d� |	 ||ftjj¡| _| j tjj¡| _d S rD   )r
   r5   r6   r7   r$   rk   rA   rj   r   r4   rE   r3   r   r   r9   r:   r;   r<   Ú
ROUND_LEFTrG   rH   rL   ÚROUND_RIGHT)r   r5   r7   rN   rd   rc   Zshrunken_heightrO   re   rP   rQ   r   r   r   r`   ç   s$    

ÿ
ÿz HorizontalBarsDrawer.setup_edgesr   r   c                 C   s’   |rŽ|j  }|j }|r| jn| j}|r.| jn| j}| jj ||d d |d d | j f¡ | jj ||d d | j	 |d d | j f¡ d S r=   )
rR   rT   rl   rE   rm   r
   r   r>   r1   rk   )r   r&   r    Zleft_roundedZright_roundedÚleftÚrightr   r   r   r'   þ   s    *$ÿzHorizontalBarsDrawer.drawrect)r+   rh   r   r   r   r   ri   Õ   s   
ri   N)Útypingr   ZPILr   r   Z&qrcode.image.styles.moduledrawers.baser   Zqrcode.image.styledpilr   Zqrcode.mainr   r3   r	   r   r*   r2   r?   r\   ri   r   r   r   r   Ú<module>   s   B5