
    
g3&                        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e          Z G d	 d
e          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    )TYPE_CHECKINGList)Image	ImageDraw)QRModuleDrawer)StyledPilImage)ActiveWithNeighbors   c                       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__     W/var/www/api/venv/lib/python3.11/site-packages/qrcode/image/styles/moduledrawers/pil.pyr   r      s*           
r   r   c                   .     e Zd ZdZ fdZdefdZ xZS )SquareModuleDrawerz-
    Draws the modules as simple squares
    c                      t                      j        |i | t          j        | j        j                  | _        d S N)super
initializer   Drawr   _imgimgDrawselfargskwargs	__class__s      r   r   zSquareModuleDrawer.initialize    s8    D+F+++ ~dhm44r   	is_activec                 Z    |r(| j                             || j        j                   d S d S )Nfill)r   	rectangler   paint_colorr    boxr$   s      r   drawrectzSquareModuleDrawer.drawrect$   s=     	CL""3TX-A"BBBBB	C 	Cr   )r   r   r   r   r   boolr,   __classcell__r#   s   @r   r   r      sf         5 5 5 5 5Ct C C C C C C C Cr   r   c                   6     e Zd ZdZddZ fdZdefdZ x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                     || _         d S r   )
size_ratio)r    r4   s     r   __init__z!GappedSquareModuleDrawer.__init__1   s    $r   c                      t                      j        |i | t          j        | j        j                  | _        d| j        z
  | j        j        z  dz  | _	        d S )N      )
r   r   r   r   r   r   r   r4   box_sizedeltar   s      r   r   z#GappedSquareModuleDrawer.initialize4   sU    D+F+++ ~dhm44$/)TX->>B


r   r$   c                    |r~|d         d         | j         z   |d         d         | j         z   |d         d         | j         z
  |d         d         | j         z
  f}| j                            || j        j                   d S d S )Nr   r7   r&   )r:   r   r(   r   r)   )r    r+   r$   smaller_boxs       r   r,   z!GappedSquareModuleDrawer.drawrect9   s     	KAq	DJ&Aq	DJ&Aq	DJ&Aq	DJ&	K L"";TX5I"JJJJJ	K 	Kr   r2   )	r   r   r   r   r5   r   r-   r,   r.   r/   s   @r   r1   r1   )   s         % % % %C C C C C
Kt K K K K K K K Kr   r1   c                   2     e Zd ZdZdZ fdZdefdZ xZS )CircleModuleDrawerz&
    Draws the modules as circles
    Nc                     t                      j        |i | | j        j        }|t          z  }t          j        | j        j        ||f| j        j        j	                  | _
        t          j        | j
                                      dd||f| j        j                   | j
                            ||ft
          j        j                  | _
        d S )Nr   r&   )r   r   r   r9   ANTIALIASING_FACTORr   newmode
color_mask
back_colorcircler   r   ellipser)   resize
ResamplingLANCZOS)r    r!   r"   r9   	fake_sizer#   s        r   r   zCircleModuleDrawer.initializeK   s    D+F+++8$22	iHM	"H*
 

 	t{##++9i(tx/C 	, 	
 	
 	
 k(((H)=u?O?WXXr   r$   c                     |rA| j         j                            | j        |d         d         |d         d         f           d S d S Nr   r7   )r   r   pasterF   r*   s      r   r,   zCircleModuleDrawer.drawrectY   sN     	EHMc!fQiQ-CDDDDD	E 	Er   )	r   r   r   r   rF   r   r-   r,   r.   r/   s   @r   r?   r?   D   sr          FY Y Y Y YEt E E E E E E E Er   r?   c                   \     e Zd ZdZdZddZ fdZd Zdeee	                  dd	fd
Z
 x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).
    Tr7   c                     || _         d S r   )radius_ratio)r    rR   s     r   r5   zRoundedModuleDrawer.__init__j   s    (r   c                      t                      j        |i | t          | j        j        dz            | _        |                                  d S )Nr8   )r   r   intr   r9   corner_widthsetup_cornersr   s      r   r   zRoundedModuleDrawer.initializem   sQ    D+F+++ 1A 566r   c                 \   | j         j        }| j         j        j        }| j         j        }t          j        || j        | j        f|          | _        | j        t          z  }| j
        |z  }|dz  }t          j        |||f|          }t          j        |          }|                    dd||f|           |                    |d||f|           |                    d|||f|           |                    | j        | j        ft
          j        j                  | _        | j                            t
          j        j                  | _        | j                            t
          j        j                  | _        | j                            t
          j        j                  | _        d S Nr8   r   r&   )r   rC   rD   rE   r)   r   rB   rU   SQUARErA   rR   r   r   rG   r(   rH   rI   rJ   NW_ROUND	transpose	TransposeFLIP_TOP_BOTTOMSW_ROUND
ROTATE_180SE_ROUNDFLIP_LEFT_RIGHTNE_ROUND)	r    rC   rE   front_color
fake_widthradiusdiameterbase	base_draws	            r   rV   z!RoundedModuleDrawer.setup_cornersr   s   x}X(3
h*i4$d&78+
 
 &)<<
"Z/A:y:z*J
 
 N4((	1a84;GGGVQ
J?kRRRQ
J?kRRR 12E4D4L
 
 //0OPP//0JKK//0OPPr   r+   r$   r	   c                    |sd S |j          o|j         }|j         o|j         }|j         o|j         }|j         o|j          }|r| j        n| j        }|r| j        n| j        }|r| j        n| j        }	|r| j        n| j        }
| j	        j
                            ||d         d         |d         d         f           | j	        j
                            ||d         d         | j        z   |d         d         f           | j	        j
                            |	|d         d         | j        z   |d         d         | j        z   f           | j	        j
                            |
|d         d         |d         d         | j        z   f           d S rM   )WNESrZ   rY   rb   r`   r^   r   r   rN   rU   )r    r+   r$   
nw_rounded
ne_rounded
se_rounded
sw_roundednwnesesws              r   r,   zRoundedModuleDrawer.drawrect   s    	F"_8Y[
"_8Y[
"_8Y[
"_8Y[
(9T]]dk(9T]]dk(9T]]dk(9T]]dkBQCF1I 6777BQT->!>Aq	 JKKKQT..Aq	D<M0MN	
 	
 	
 	BQCF1I8I,I JKKKKKr   )r7   )r   r   r   r   needs_neighborsr5   r   rV   r   rT   r,   r.   r/   s   @r   rP   rP   ^   s          O) ) ) )    
Q Q Q2LDcO L8M L L L L L L L Lr   rP   c                   <     e Zd ZdZdZd
dZ fdZd Zdd	Z x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).
    Tr2   c                     || _         d S r   )horizontal_shrink)r    rz   s     r   r5   zVerticalBarsDrawer.__init__   s    !2r   c                      t                      j        |i | t          | j        j        dz            | _        t          d| j        z
  | j        z            | _        |                                  d S Nr8   r7   )	r   r   rT   r   r9   half_heightrz   r:   setup_edgesr   s      r   r   zVerticalBarsDrawer.initialize   sp    D+F+++tx01455!d448HHII
r   c                 H   | j         j        }| j         j        j        }| j         j        }| j        }|dz  }t          || j        z            }t          j	        |||f|          | _
        |t          z  }|t          z  }t          j	        |||f|          }	t          j        |	          }
|
                    dd||dz  f|           |	                    ||ft          j        j                  | _        | j                            t          j        j                  | _        d S rX   )r   rC   rD   rE   r)   r}   rT   rz   r   rB   rY   rA   r   r   rG   rH   rI   rJ   	ROUND_TOPr[   r\   r]   ROUND_BOTTOM)r    rC   rE   rc   heightwidthshrunken_widthrd   fake_heightrg   rh   s              r   r~   zVerticalBarsDrawer.setup_edges   s   x}X(3
h*!
UT%;;<<i~v&>LL00
22y:{+Z
 
 N4((	1a[1_=KPPPnf%=u?O?WXX N44U_5TUUr   r$   r	   c                    |r|j          }|j         }|r| j        n| j        }|r| j        n| j        }| j        j                            ||d         d         | j        z   |d         d         f           | j        j                            ||d         d         | j        z   |d         d         | j	        z   f           d S d S rM   )
rk   rm   r   rY   r   r   r   rN   r:   r}   )r    r+   r$   top_roundedbottom_roundedtopbottoms          r   r,   zVerticalBarsDrawer.drawrect   s     
	'k/K!*_N$/@$..T[C*8IT&&dkFHMc!fQi$*&<c!fQi%HIIIHMQTZ/QT=M1MN    
	 
	r   r=   r$   r	   
r   r   r   r   rv   r5   r   r~   r,   r.   r/   s   @r   rx   rx      s          O3 3 3 3    V V V*       r   rx   c                   <     e Zd ZdZdZd
dZ fdZd Zdd	Z x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).
    Tr2   c                     || _         d S r   )vertical_shrink)r    r   s     r   r5   zHorizontalBarsDrawer.__init__   s    .r   c                      t                      j        |i | t          | j        j        dz            | _        t          d| j        z
  | j        z            | _        |                                  d S r|   )	r   r   rT   r   r9   
half_widthr   r:   r~   r   s      r   r   zHorizontalBarsDrawer.initialize   sn    D+F+++dh/!344!d22doEFF
r   c                 H   | j         j        }| j         j        j        }| j         j        }| j        }|dz  }t          || j        z            }t          j	        |||f|          | _
        |t          z  }|t          z  }t          j	        |||f|          }	t          j        |	          }
|
                    dd|dz  |f|           |	                    ||ft          j        j                  | _        | j                            t          j        j                  | _        d S rX   )r   rC   rD   rE   r)   r   rT   r   r   rB   rY   rA   r   r   rG   rH   rI   rJ   
ROUND_LEFTr[   r\   ra   ROUND_RIGHT)r    rC   rE   rc   r   r   shrunken_heightrd   r   rg   rh   s              r   r~   z HorizontalBarsDrawer.setup_edges   s   x}X(3
h*ft';;<<iuo&>LL00
22y:{+Z
 
 N4((	1aa=KPPP++O$e&6&>
 
  ?44U_5TUUr   r$   r	   c                    |r|j          }|j         }|r| j        n| j        }|r| j        n| j        }| j        j                            ||d         d         |d         d         | j        z   f           | j        j                            ||d         d         | j	        z   |d         d         | j        z   f           d S d S rM   )
rj   rl   r   rY   r   r   r   rN   r:   r   )r    r+   r$   left_roundedright_roundedleftrights          r   r,   zHorizontalBarsDrawer.drawrect   s     
	({?L )OM&2C4??D(5FD$$4;EHMs1vay#a&)dj2H&IJJJHMAq	DO3SVAY5KL    
	 
	r   r=   r   r   r/   s   @r   r   r      s          O/ / / /    V V V.       r   r   N)typingr   r   PILr   r   &qrcode.image.styles.moduledrawers.baser   qrcode.image.styledpilr   qrcode.mainr	   rA   r   r   r1   r?   rP   rx   r   r   r   r   <module>r      s   & & & & & & & &                 A A A A A A 0555555//////  	 	 	 	 	n 	 	 	C C C C C0 C C CK K K K K6 K K K6E E E E E0 E E E4?L ?L ?L ?L ?L1 ?L ?L ?LD2 2 2 2 20 2 2 2j4 4 4 4 42 4 4 4 4 4r   