
    @wg3&                         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y)    )TYPE_CHECKINGList)Image	ImageDraw)QRModuleDrawer)StyledPilImage)ActiveWithNeighbors   c                       e Zd ZU dZded<   y)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__     \/var/www/horilla/myenv/lib/python3.12/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        |   |i | t        j                  | j                  j
                        | _        y N)super
initializer   Drawr   _imgimgDrawselfargskwargs	__class__s      r   r   zSquareModuleDrawer.initialize    s-    D+F+ ~~dhhmm4r   	is_activec                 l    |r2| j                   j                  || j                  j                         y y )Nfill)r   	rectangler   paint_colorr    boxr$   s      r   drawrectzSquareModuleDrawer.drawrect$   s+    LL""3TXX-A-A"B r   )r   r   r   r   r   boolr,   __classcell__r#   s   @r   r   r      s    5Ct 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                     || _         y r   )
size_ratio)r    r3   s     r   __init__z!GappedSquareModuleDrawer.__init__1   s	    $r   c                     t        |   |i | t        j                  | j                  j
                        | _        d| j                  z
  | j                  j                  z  dz  | _	        y )N      )
r   r   r   r   r   r   r   r3   box_sizedeltar   s      r   r   z#GappedSquareModuleDrawer.initialize4   sQ    D+F+ ~~dhhmm4$//)TXX->->>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                  j                         y y )Nr   r6   r&   )r9   r   r(   r   r)   )r    r+   r$   smaller_boxs       r   r,   z!GappedSquareModuleDrawer.drawrect9   s    Aq	DJJ&Aq	DJJ&Aq	DJJ&Aq	DJJ&	K LL"";TXX5I5I"J r   g?)	r   r   r   r   r4   r   r-   r,   r.   r/   s   @r   r1   r1   )   s!    %C
Kt 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        |   |i | | j                  j                  }|t        z  }t        j                  | j                  j                  ||f| j                  j                  j                        | _
        t        j                  | j                        j                  dd||f| j                  j                         | j                  j                  ||ft
        j                   j"                        | _
        y )Nr   r&   )r   r   r   r8   ANTIALIASING_FACTORr   newmode
color_mask
back_colorcircler   r   ellipser)   resize
ResamplingLANCZOS)r    r!   r"   r8   	fake_sizer#   s        r   r   zCircleModuleDrawer.initializeK   s    D+F+88$$22	iiHHMM	"HH**

 	t{{#++9i(txx/C/C 	, 	
 kk(((H)=u?O?O?W?WXr   r$   c                     |r?| j                   j                  j                  | j                  |d   d   |d   d   f       y y Nr   r6   )r   r   pasterE   r*   s      r   r,   zCircleModuleDrawer.drawrectY   s;    HHMMc!fQiQ-CD r   )	r   r   r   r   rE   r   r-   r,   r.   r/   s   @r   r>   r>   D   s#     FYEt Er   r>   c                   P     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).
    Tc                     || _         y r   )radius_ratio)r    rQ   s     r   r4   zRoundedModuleDrawer.__init__j   s
    (r   c                     t        |   |i | t        | j                  j                  dz        | _        | j                          y )Nr7   )r   r   intr   r8   corner_widthsetup_cornersr   s      r   r   zRoundedModuleDrawer.initializem   s=    D+F+ 1 1A 5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                  |      }|j                  dd||f|       |j                  |d||f|       |j                  d|||f|       |j                  | j                  | j                  ft
        j                   j"                        | _        | j$                  j'                  t
        j(                  j*                        | _        | j$                  j'                  t
        j(                  j.                        | _        | j$                  j'                  t
        j(                  j2                        | _        y Nr7   r   r&   )r   rB   rC   rD   r)   r   rA   rT   SQUAREr@   rQ   r   r   rF   r(   rG   rH   rI   NW_ROUND	transpose	TransposeFLIP_TOP_BOTTOMSW_ROUND
ROTATE_180SE_ROUNDFLIP_LEFT_RIGHTNE_ROUND)	r    rB   rD   front_color
fake_widthradiusdiameterbase	base_draws	            r   rU   z!RoundedModuleDrawer.setup_cornersr   s   xx}}XX((33
hh**ii4$$d&7&78+
 &&)<<
""Z/A:yy:z*J
 NN4(	1a84;GVQ
J?kRQ
J?kR 1 12E4D4D4L4L
 //0O0OP//0J0JK//0O0OPr   r+   r$   r	   c                    |sy |j                    xr |j                   }|j                   xr |j                   }|j                   xr |j                   }|j                   xr |j                    }|r| j                  n| j
                  }|r| j                  n| j
                  }|r| j                  n| j
                  }	|r| j                  n| j
                  }
| j                  j                  j                  ||d   d   |d   d   f       | j                  j                  j                  ||d   d   | j                  z   |d   d   f       | j                  j                  j                  |	|d   d   | j                  z   |d   d   | j                  z   f       | j                  j                  j                  |
|d   d   |d   d   | j                  z   f       y rL   )WNESrY   rX   ra   r_   r]   r   r   rM   rT   )r    r+   r$   
nw_rounded
ne_rounded
se_rounded
sw_roundednwnesesws              r   r,   zRoundedModuleDrawer.drawrect   s   "_8Y[[
"_8Y[[
"_8Y[[
"_8Y[[
(T]]dkk(T]]dkk(T]]dkk(T]]dkkBQCF1I 67BQT->->!>Aq	 JKQT...Aq	D<M<M0MN	
 	BQCF1I8I8I,I JKr   )r6   )r   r   r   r   needs_neighborsr4   r   rU   r   rS   r,   r.   r/   s   @r   rO   rO   ^   s>     O)
Q2LDcO L8M Lr   rO   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).
    Tc                     || _         y r   )horizontal_shrink)r    ry   s     r   r4   zVerticalBarsDrawer.__init__   s
    !2r   c                     t        |   |i | t        | j                  j                  dz        | _        t        d| j                  z
  | j
                  z        | _        | j                          y Nr7   r6   )	r   r   rS   r   r8   half_heightry   r9   setup_edgesr   s      r   r   zVerticalBarsDrawer.initialize   s_    D+F+txx00145!d4448H8HHI
r   c                    | 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                  |	      }
|
j                  dd||dz  f|       |	j                  ||ft        j                   j"                        | _        | j$                  j'                  t        j(                  j*                        | _        y rW   )r   rB   rC   rD   r)   r|   rS   ry   r   rA   rX   r@   r   r   rF   rG   rH   rI   	ROUND_TOPrZ   r[   r\   ROUND_BOTTOM)r    rB   rD   rb   heightwidthshrunken_widthrc   fake_heightrf   rg   s              r   r}   zVerticalBarsDrawer.setup_edges   s   xx}}XX((33
hh**!!
UT%;%;;<ii~v&>L00
22yy:{+Z
 NN4(	1a[1_=KPnf%=u?O?O?W?WX NN44U__5T5TUr   c                    |r|j                    }|j                   }|r| j                  n| j                  }|r| j                  n| j                  }| j
                  j                  j                  ||d   d   | j                  z   |d   d   f       | j
                  j                  j                  ||d   d   | j                  z   |d   d   | j                  z   f       y y rL   )
rj   rl   r   rX   r   r   r   rM   r9   r|   )r    r+   r$   top_roundedbottom_roundedtopbottoms          r   r,   zVerticalBarsDrawer.drawrect   s    'kk/K!*_N$/$..T[[C*8T&&dkkFHHMMc!fQi$**&<c!fQi%HIHHMMQTZZ/QT=M=M1MN r   r<   r$   r	   
r   r   r   r   ru   r4   r   r}   r,   r.   r/   s   @r   rw   rw      s$     O3V*r   rw   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).
    Tc                     || _         y r   )vertical_shrink)r    r   s     r   r4   zHorizontalBarsDrawer.__init__   s
    .r   c                     t        |   |i | t        | j                  j                  dz        | _        t        d| j                  z
  | j
                  z        | _        | j                          y r{   )	r   r   rS   r   r8   
half_widthr   r9   r}   r   s      r   r   zHorizontalBarsDrawer.initialize   s\    D+F+dhh//!34!d222dooEF
r   c                    | 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                  |	      }
|
j                  dd|dz  |f|       |	j                  ||ft        j                   j"                        | _        | j$                  j'                  t        j(                  j*                        | _        y rW   )r   rB   rC   rD   r)   r   rS   r   r   rA   rX   r@   r   r   rF   rG   rH   rI   
ROUND_LEFTrZ   r[   r`   ROUND_RIGHT)r    rB   rD   rb   r   r   shrunken_heightrc   r   rf   rg   s              r   r}   z HorizontalBarsDrawer.setup_edges   s   xx}}XX((33
hh**ft';';;<iiuo&>L00
22yy:{+Z
 NN4(	1aa=KP++O$e&6&6&>&>
  ??44U__5T5TUr   c                    |r|j                    }|j                   }|r| j                  n| j                  }|r| j                  n| j                  }| j
                  j                  j                  ||d   d   |d   d   | j                  z   f       | j
                  j                  j                  ||d   d   | j                  z   |d   d   | j                  z   f       y y rL   )
ri   rk   r   rX   r   r   r   rM   r9   r   )r    r+   r$   left_roundedright_roundedleftrights          r   r,   zHorizontalBarsDrawer.drawrect   s    ({{?L )OM&24??D(5D$$4;;EHHMMs1vay#a&)djj2H&IJHHMMAq	DOO3SVAY5KL r   r<   r   r   r/   s   @r   r   r      s$     O/V.r   r   N)typingr   r   PILr   r   &qrcode.image.styles.moduledrawers.baser   qrcode.image.styledpilr   qrcode.mainr	   r@   r   r   r1   r>   rO   rw   r   r   r   r   <module>r      s    &   A5/  	n 	C0 CK6 K6E0 E4?L1 ?LD20 2j42 4r   