
    )c|&                         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	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)    )absolute_import)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__     G/usr/lib/python3/dist-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!   r4   s     r   __init__z!GappedSquareModuleDrawer.__init__4   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   r4   box_sizedeltar    s      r   r   z#GappedSquareModuleDrawer.initialize7   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   r7   r'   )r:   r   r)   r   r*   )r!   r,   r%   smaller_boxs       r   r-   z!GappedSquareModuleDrawer.drawrect<   s    Aq	DJJ&Aq	DJJ&Aq	DJJ&Aq	DJJ&	K LL"";TXX5I5I"J r   g?)	r   r   r   r   r5   r   r.   r-   r/   r0   s   @r   r2   r2   ,   s!    %C
Kt Kr   r2   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   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.initializeN   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   r7   )r   r   pasterF   r+   s      r   r-   zCircleModuleDrawer.drawrect\   s;    HHMMc!fQiQ-CD r   )	r   r   r   r   rF   r   r.   r-   r/   r0   s   @r   r?   r?   G   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!   rR   s     r   r5   zRoundedModuleDrawer.__init__m   s
    (r   c                     t        |   |i | t        | j                  j                  dz        | _        | j                          y )Nr8   )r   r   intr   r9   corner_widthsetup_cornersr    s      r   r   zRoundedModuleDrawer.initializep   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 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_cornersu   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 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   "_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   )r7   )r   r   r   r   needs_neighborsr5   r   rV   r   rT   r-   r/   r0   s   @r   rP   rP   a   s>     O)
Q2LDcO L8M 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).
    Tc                     || _         y r   )horizontal_shrink)r!   rz   s     r   r5   zVerticalBarsDrawer.__init__   s
    !2r   c                     t        |   |i | t        | j                  j                  dz        | _        t        d| j                  z
  | j
                  z        | _        | j                          y Nr8   r7   )	r   r   rT   r   r9   half_heightrz   r:   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 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   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 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    '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   rv   r5   r   r~   r-   r/   r0   s   @r   rx   rx      s$     O3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).
    Tc                     || _         y r   )vertical_shrink)r!   r   s     r   r5   zHorizontalBarsDrawer.__init__   s
    .r   c                     t        |   |i | t        | j                  j                  dz        | _        t        d| j                  z
  | j
                  z        | _        | j                          y r|   )	r   r   rT   r   r9   
half_widthr   r:   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 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   xx}}XX((33
hh**ft';';;<iiuo&>L00
22yy:{+Z
 NN4(	1aa=KP++uo&>@P@P@X@XY??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 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&24??D(5D$$4;;EHHMMs1vay#a&)djj2H&IJHHMMAq	DOO3SVAY5KL r   r=   r   r   r0   s   @r   r   r      s$     O/V*r   r   N)
__future__r   typingr   r   qrcode.compat.pilr   r   &qrcode.image.styles.moduledrawers.baser   qrcode.image.styledpilr	   qrcode.mainr
   rA   r   r   r2   r?   rP   rx   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22 2r   