o
    >e|&                     @   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   f/var/www/html/humari/django-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__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