o
    Ûäh-&  ã                   @   s¼   d dl 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 )é    )Ú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   úX/var/www/html/venv/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__1   ó   
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   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   r/   r    )r2   r   r"   r
   r#   )r   r%   r   Ú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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
   r1   ÚANTIALIASING_FACTORr   ÚnewÚmodeÚ
color_maskÚ
back_colorÚcircler   r   Úellipser#   ÚresizeÚ
ResamplingÚLANCZOS)r   r   r   r1   Ú	fake_sizer   r   r   r   K   s   ýÿzCircleModuleDrawer.initializer   c                 C   s2   |r| j j | j|d d |d d f¡ d S d S ©Nr   r/   )r
   r   Úpaster;   r$   r   r   r   r&   Y   s   *ÿzCircleModuleDrawer.drawrect)	r   r   r   r   r;   r   r'   r&   r(   r   r   r   r   r5   D   s
    r5   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).
    Tr/   c                 C   r+   r   )Úradius_ratio)r   rD   r   r   r   r-   j   r.   zRoundedModuleDrawer.__init__c                    s0   t ƒ j|i |¤Ž t| jjd ƒ| _|  ¡  d S )Nr0   )r   r   Úintr
   r1   Ú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 ©Nr0   r   r    )r
   r8   r9   r:   r#   r   r7   rF   ÚSQUAREr6   rD   r   r   r<   r"   r=   r>   r?   ÚNW_ROUNDÚ	transposeÚ	TransposeÚFLIP_TOP_BOTTOMÚSW_ROUNDÚ
ROTATE_180ÚSE_ROUNDÚFLIP_LEFT_RIGHTÚNE_ROUND)	r   r8   r:   Úfront_colorÚ
fake_widthÚradiusÚdiameterÚbaseÚ	base_drawr   r   r   rG   r   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 rA   )ÚWÚNÚEÚSrJ   rI   rR   rP   rN   r
   r   rB   rF   )r   r%   r   Ú
nw_roundedÚ
ne_roundedÚ
se_roundedÚ
sw_roundedÚnwÚneÚseÚswr   r   r   r&   ‹   s    $*$ÿ.zRoundedModuleDrawer.drawrect)r/   )r   r   r   r   Úneeds_neighborsr-   r   rG   ÚlistrE   r&   r(   r   r   r   r   rC   ^   s    	
"rC   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   ri   r   r   r   r-   ©   r.   zVerticalBarsDrawer.__init__c                    óF   t ƒ j|i |¤Ž t| jjd ƒ| _td| j | j ƒ| _|  ¡  d S ©Nr0   r/   )	r   r   rE   r
   r1   Úhalf_heightri   r2   Ú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 rH   )r
   r8   r9   r:   r#   rl   rE   ri   r   r7   rI   r6   r   r   r<   r=   r>   r?   Ú	ROUND_TOPrK   rL   rM   ÚROUND_BOTTOM)r   r8   r:   rS   ÚheightÚwidthÚshrunken_widthrT   Úfake_heightrW   rX   r   r   r   rm   ²   s    

ÿ
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 rA   )
rZ   r\   ro   rI   rp   r
   r   rB   r2   rl   )r   r%   r   Útop_roundedÚbottom_roundedÚtopÚbottomr   r   r   r&   Ç   ó   *$ÿøzVerticalBarsDrawer.drawrectr4   ©r   r   ©
r   r   r   r   re   r-   r   rm   r&   r(   r   r   r   r   rh       s    
rh   c                       rg   )Ú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-   Þ   r.   zHorizontalBarsDrawer.__init__c                    rj   rk   )	r   r   rE   r
   r1   Ú
half_widthr}   r2   rm   r   r   r   r   r   á   rn   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 rH   )r
   r8   r9   r:   r#   r~   rE   r}   r   r7   rI   r6   r   r   r<   r=   r>   r?   Ú
ROUND_LEFTrK   rL   rQ   ÚROUND_RIGHT)r   r8   r:   rS   rr   rq   Úshrunken_heightrT   rt   rW   rX   r   r   r   rm   ç   s$   

ÿ
ÿ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 rA   )
rY   r[   r   rI   r€   r
   r   rB   r2   r~   )r   r%   r   Úleft_roundedÚright_roundedÚleftÚrightr   r   r   r&   þ   ry   zHorizontalBarsDrawer.drawrectr4   rz   r{   r   r   r   r   r|   Õ   s    
r|   N)Útypingr   ÚPILr   r   Ú&qrcode.image.styles.moduledrawers.baser   Úqrcode.image.styledpilr   Úqrcode.mainr   r6   r	   r   r)   r5   rC   rh   r|   r   r   r   r   Ú<module>   s    B5