o
    ÓèFh|&  ã                   @   sÌ   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 er*d 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 )é    )Úabsolute_import)ÚTYPE_CHECKINGÚList)Ú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   ú^/var/www/html/loop/nvenv/lib/python3.10/site-packages/qrcode/image/styles/moduledrawers/pil.pyr      s   
 r   c                       s.   e Zd ZdZ‡ fdd„Zdef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 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def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   ó
   || _ d S r   )Ú
size_ratio)r   r.   r   r   r   Ú__init__4   ó   
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   7   s   z#GappedSquareModuleDrawer.initializer!   c                 C   sd   |r0|d d | j  |d d | j  |d d | j  |d d | j  f}| jj|| jjd� d S d S )Nr   r1   r"   )r4   r   r$   r   r%   )r   r'   r!   Úsmaller_boxr   r   r   r(   <   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def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   r3   ÚANTIALIASING_FACTORr   ÚnewÚmodeÚ
color_maskÚ
back_colorÚcircler   r   Úellipser%   ÚresizeÚ
ResamplingÚLANCZOS)r   r   r   r3   Ú	fake_sizer   r   r   r   N   s   ýÿzCircleModuleDrawer.initializer!   c                 C   s2   |r| j j | j|d d |d d f¡ d S d S ©Nr   r1   )r   r   Úpaster=   r&   r   r   r   r(   \   s   *ÿzCircleModuleDrawer.drawrect)	r   r   r   r   r=   r   r)   r(   r*   r   r   r   r   r7   G   s
    r7   c                       sP   e Zd ZdZdZddd„Z‡ fdd„Zdd	„ Zd
eee	  ddf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).
    Tr1   c                 C   r-   r   )Úradius_ratio)r   rF   r   r   r   r/   m   r0   zRoundedModuleDrawer.__init__c                    s0   t ƒ j|i |¤Ž t| jjd ƒ| _|  ¡  d S )Nr2   )r   r   Úintr   r3   Úcorner_widthÚsetup_cornersr   r   r   r   r   p   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 ©Nr2   r   r"   )r   r:   r;   r<   r%   r   r9   rH   ÚSQUAREr8   rF   r   r   r>   r$   r?   r@   rA   ÚNW_ROUNDÚ	transposeÚ	TransposeÚFLIP_TOP_BOTTOMÚSW_ROUNDÚ
ROTATE_180ÚSE_ROUNDÚFLIP_LEFT_RIGHTÚNE_ROUND)	r   r:   r<   Úfront_colorÚ
fake_widthÚradiusÚdiameterÚbaseÚ	base_drawr   r   r   rI   u   s,   
ÿ


ÿ
ÿz!RoundedModuleDrawer.setup_cornersr'   r!   r	   c                 C   s4  |sd S |j  o|j }|j o|j }|j o|j }|j o#|j  }|r)| jn| j}|r1| jn| j}|r9| jn| j}	|rA| 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 rC   )ÚWÚNÚEÚSrL   rK   rT   rR   rP   r   r   rD   rH   )r   r'   r!   Ú
nw_roundedÚ
ne_roundedÚ
se_roundedÚ
sw_roundedÚnwÚneÚseÚswr   r   r   r(   Ž   s    $*$ÿ.zRoundedModuleDrawer.drawrect)r1   )r   r   r   r   Úneeds_neighborsr/   r   rI   r   rG   r(   r*   r   r   r   r   rE   a   s    	
"rE   c                       ó@   e Zd ZdZdZddd„Z‡ fdd„Zdd	„ Z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   r-   r   )Úhorizontal_shrink)r   rj   r   r   r   r/   ¬   r0   zVerticalBarsDrawer.__init__c                    óF   t ƒ j|i |¤Ž t| jjd ƒ| _td| j | j ƒ| _|  ¡  d S ©Nr2   r1   )	r   r   rG   r   r3   Úhalf_heightrj   r4   Úsetup_edgesr   r   r   r   r   ¯   ó   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 rJ   )r   r:   r;   r<   r%   rm   rG   rj   r   r9   rK   r8   r   r   r>   r?   r@   rA   Ú	ROUND_TOPrM   rN   rO   ÚROUND_BOTTOM)r   r:   r<   rU   ÚheightÚwidthÚshrunken_widthrV   Úfake_heightrY   rZ   r   r   r   rn   µ   ó    

ÿ
zVerticalBarsDrawer.setup_edgesr!   r	   c                 C   s–   |rI|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 d S rC   )
r\   r^   rp   rK   rq   r   r   rD   r4   rm   )r   r'   r!   Útop_roundedÚbottom_roundedÚtopÚbottomr   r   r   r(   Ê   ó   *$ÿøzVerticalBarsDrawer.drawrectr6   ©r!   r	   ©
r   r   r   r   rg   r/   r   rn   r(   r*   r   r   r   r   ri   £   ó    
ri   c                       rh   )Ú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   r-   r   )Úvertical_shrink)r   r€   r   r   r   r/   á   r0   zHorizontalBarsDrawer.__init__c                    rk   rl   )	r   r   rG   r   r3   Ú
half_widthr€   r4   rn   r   r   r   r   r   ä   ro   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 rJ   )r   r:   r;   r<   r%   r�   rG   r€   r   r9   rK   r8   r   r   r>   r?   r@   rA   Ú
ROUND_LEFTrM   rN   rS   ÚROUND_RIGHT)r   r:   r<   rU   rs   rr   Úshrunken_heightrV   ru   rY   rZ   r   r   r   rn   ê   rv   z HorizontalBarsDrawer.setup_edgesr!   r	   c                 C   s–   |rI|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 d S rC   )
r[   r]   r‚   rK   rƒ   r   r   rD   r4   r�   )r   r'   r!   Úleft_roundedÚright_roundedÚleftÚrightr   r   r   r(   ÿ   r{   zHorizontalBarsDrawer.drawrectr6   r|   r}   r   r   r   r   r   Ø   r~   r   N)Ú
__future__r   Útypingr   r   Úqrcode.compat.pilr   r   Ú&qrcode.image.styles.moduledrawers.baser   Úqrcode.image.styledpilr   Úqrcode.mainr	   r8   r   r   r+   r7   rE   ri   r   r   r   r   r   Ú<module>   s   B5