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