
    r)h/                        S r SSKJr  SSKJrJrJrJrJr  SSK	J
r
JrJrJr  SSKJrJrJr  \(       a  SSKJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z0
Handles the creation of patterns and gradients
    )ABC)ListOptionalTYPE_CHECKINGTupleUnion   )
DeviceCMYK
DeviceGray	DeviceRGBconvert_to_device_color)NamePDFArray	PDFObject)FPDFc                   J   ^  \ rS rSrSrS\S   4U 4S jjr\S 5       rSr	U =r
$ )Pattern   z
Represents a PDF Pattern object.

Currently, this class supports only "shading patterns" (pattern_type 2),
using either a linear or radial gradient. Tiling patterns (pattern_type 1)
are not yet implemented.
shading)LinearGradientRadialGradientc                 \   > [         TU ]  5         [        S5      U l        SU l        Xl        g )Nr      )super__init__r   typepattern_type_shading)selfr   	__class__s     GC:\Users\13-19\Desktop\Lekcja\testEnv\Lib\site-packages\fpdf/pattern.pyr   Pattern.__init__   s&    O	    c                 P    U R                   R                  5       R                   S3$ )N 0 R)r   get_shading_objectidr   s    r!   r   Pattern.shading   s#    --224778==r#   )r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   propertyr   __static_attributes____classcell__r    s   @r!   r   r      s.     &H I   > >r#   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )Type2Function$   zTransition between 2 colorsc                    > [         TU ]  5         SU l        SU l        SSR	                  S UR
                   5       5       S3U l        SSR	                  S UR
                   5       5       S3U l        SU l        g )	Nr   [0 1][ c              3   (   #    U  H  oS  v   M
     g7f.2fN .0cs     r!   	<genexpr>)Type2Function.__init__.<locals>.<genexpr>,        B>aCz>   ]c              3   (   #    U  H  oS  v   M
     g7fr;   r=   r>   s     r!   rA   rB   -   rC   rD   r	   )	r   r   function_typedomainjoincolorsc0c1n)r   color_1color_2r    s      r!   r   Type2Function.__init__'   sl    chhB7>>BBC1EchhB7>>BBC1Er#   )rK   rL   rH   rG   rM   )r*   r+   r,   r-   r.   r   r0   r1   r2   s   @r!   r4   r4   $   s    % r#   r4   c                   <   ^  \ rS rSrSrU 4S jr\S 5       rSrU =r	$ )Type3Function1   zWhen multiple colors are used, a type 3 function is necessary to stitch type 2 functions together
and define the bounds between each color transitionc                    > [         TU ]  5         SU l        SU l        Xl        SSR                  S U 5       5       S3U l        SSR                  S U 5       5       S3U l        SU l        g )	N   r7   r8   r9   c              3   (   #    U  H  oS  v   M
     g7fr;   r=   )r?   bounds     r!   rA   )Type3Function.__init__.<locals>.<genexpr>;   s     "FveC[>vrD   rE   c              3   &   #    U  H  nS v   M	     g7f)z0 1Nr=   )r?   _s     r!   rA   rX   <   s     "<)Q5)s   r	   )	r   r   rG   rH   
_functionsrI   boundsencoderM   )r   	functionsr\   r    s      r!   r   Type3Function.__init__5   si    ##(("Fv"FFGqI#(("<)"<<=Q?r#   c                 N    SSR                  S U R                   5       5       S3$ )Nr8   r9   c              3   >   #    U  H  oR                    S 3v   M     g7f)r%   N)r'   )r?   fs     r!   rA   *Type3Function.functions.<locals>.<genexpr>A   s     C?attfDM?s   rE   )rI   r[   r(   s    r!   r^   Type3Function.functions?   s%    388C4??CCDAFFr#   )r[   r\   rH   r]   rG   rM   )
r*   r+   r,   r-   r.   r   r/   r^   r0   r1   r2   s   @r!   rR   rR   1   s#    ; G Gr#   rR   c                   j   ^  \ rS rSrS\S\\\\\	4      S\
S\\   S\\\4   S\S\4U 4S	 jjrS
rU =r$ )ShadingD   shading_type
backgroundcolor_spacecoordsfunctionextend_beforeextend_afterc                 *  > [         TU ]  5         Xl        U(       a&  SSR                  S UR                   5       5       S3OS U l        [        U5      U l        X@l        UR                   S3U l
        SU(       a  SOS SU(       a  SOS S3U l        g )Nr8   r9   c              3   (   #    U  H  oS  v   M
     g7fr;   r=   r>   s     r!   rA   #Shading.__init__.<locals>.<genexpr>R   s     ?->c7->rD   rE   r%   truefalse)r   r   rh   rI   rJ   ri   r   rj   rk   r'   rl   extend)	r   rh   ri   rj   rk   rl   rm   rn   r    s	           r!   r   Shading.__init__E   s     	(  ?Z->->??@B 	
  ,#;;-t,M&w?q<]d@eefgr#   )ri   rj   rk   rt   rl   rh   )r*   r+   r,   r-   intr   r   r   r   r
   strr   r4   rR   boolr   r0   r1   r2   s   @r!   rf   rf   D   sy    hh U9j*#DEFh 	h
 S	h }45h h h hr#   rf   c                   N    \ rS rSrS r\S\\\4   4S j5       r	S r
S rS rSrg	)
Gradient\   c                 *   U R                  U5      u  U l        U l        S U l        U(       a=  [	        U[
        [        [        [        45      (       a  [        U5      O[        U6 U l        U R                  (       a9  U R                  R                  R                  U R                  :w  a  [        S5      eX0l        X@l        U(       a  UOL[        [!        U R                  5      S-
  5       Vs/ s H   ofS-   [!        U R                  5      S-
  -  PM"     snU l        [!        U R"                  5      [!        U R                  5      S-
  :w  a  [        S5      eU R%                  5       U l        [)        U 5      U l        S U l        S U l        SU l        g s  snf )NzDThe background color must be of the same color space as the gradientr   r	   z>Bounds array length must be two less than the number of colorsr   )_convert_colorsrj   rJ   ri   
isinstancerw   r   r   r
   r   r    r*   
ValueErrorrm   rn   rangelenr\   _generate_functionsr^   r   pattern_shading_objectrk   rh   )r   rJ   ri   rm   rn   r\   is          r!   r   Gradient.__init__]   sT   (,(<(<V(D%$+ j3
Iz*RSS (
3,j9 O
 ??t88AATEUEUUV  +(  <A#dkkBRUVBV<WX<Wqq5S-12<WX 	
 t{{s4;;/!33P  113t}# Ys   ,'Freturnc                    / n[        U5      S:  a  [        S5      e[        5       nU Hp  n[        U[        [
        [        [        45      (       a  [        U5      O[        U6 nUR                  U5        UR                  [        U5      R                  5        Mr     [        U5      S:X  a  UR                  5       U4$ SU;   a  [        S5      e/ nU He  n[        U[
        5      (       a<  UR                  [        UR                  UR                  UR                  5      5        MT  UR                  U5        Mg     SU4$ )Nr   (A gradient must have at least two colorsr	   r
   z'Can't mix CMYK with other color spaces.r   )r   r   setr~   rw   r   r   r
   r   appendaddr   r*   popg)clsrJ   
color_listcolor_spacescolorcurrent_color	converteds          r!   r}   Gradient._convert_colors{   s   
v;?GHHuE ec:y*%MNN (.,e4 
 m,T-099:  |!##%z11<'FGG	E%,,  577EGGUWW!EF  '	  
 I%%r#   c           	         [        U R                  5      S:  a  [        S5      e[        U R                  5      S:X  a'  [        U R                  S   U R                  S   5      /$ [        U R                  5      n/ n[	        US-
  5       H;  nUR                  [        U R                  U   U R                  US-      5      5        M=     UR                  [        US S  U R                  5      5        U$ )Nr   r   r   r	   )r   rJ   r   r4   r   r   rR   r\   )r   number_of_colorsr^   r   s       r!   r   Gradient._generate_functions   s    t{{aGHHt{{q !$++a.$++a.ABBt{{+	'!+,A]4;;q>4;;q1u;MNO -y|T[[ABr#   c           
         U R                   (       df  [        U R                  U R                  U R                  [        U R                  5      U R                  S   U R                  U R                  S9U l         U R                   $ )N)rh   ri   rj   rk   rl   rm   rn   )
r   rf   rh   ri   rj   r   rk   r^   rm   rn   r(   s    r!   r&   Gradient.get_shading_object   si    ###*!..?? ,,,+"00!..$D  ###r#   c                     U R                   $ )N)r   r(   s    r!   get_patternGradient.get_pattern   s    ||r#   )r   ri   r\   rj   rJ   rk   rn   rm   r^   r   rh   N)r*   r+   r,   r-   r   classmethodr   rw   r   r}   r   r&   r   r0   r=   r#   r!   rz   rz   \   s:    < &c4i(8 & &4
$r#   rz   c                   b   ^  \ rS rSr    SSSS\S\S\S\S\S	\S
\S\\   4U 4S jjjrSrU =r	$ )r      fpdfr   from_xfrom_yto_xto_yrJ   rm   rn   r\   c                    > [         TU ]  XgXU
5        X!R                  U-
  XAR                  U-
  /nU Vs/ s H  oR                  U-  S PM     snU l        SU l        gs  snf )a%  
A shading pattern that creates a linear (axial) gradient in a PDF.

The gradient is defined by two points: (from_x, from_y) and (to_x, to_y),
along which the specified colors are interpolated. Optionally, you can set
a background color, extend the gradient beyond its start or end, and
specify custom color stop positions via `bounds`.

Args:
    fpdf (FPDF): The FPDF instance used for PDF generation.
    from_x (int or float): The x-coordinate of the starting point of the gradient,
        in user space units.
    from_y (int or float): The y-coordinate of the starting point of the gradient,
        in user space units.
    to_x (int or float): The x-coordinate of the ending point of the gradient,
        in user space units.
    to_y (int or float): The y-coordinate of the ending point of the gradient,
        in user space units.
    colors (List[str or Tuple[int, int, int]]): A list of colors along which the gradient
        will be interpolated. Colors may be given as hex strings (e.g., "#FF0000") or
        (R, G, B) tuples.
    background (str or Tuple[int, int, int], optional): A background color to use
        if the gradient does not fully cover the region it is applied to.
        Defaults to None (no background).
    extend_before (bool, optional): Whether to extend the first color beyond the
        starting point (from_x, from_y). Defaults to False.
    extend_after (bool, optional): Whether to extend the last color beyond the
        ending point (to_x, to_y). Defaults to False.
    bounds (List[float], optional): An optional list of floats in the range (0, 1)
        that represent gradient stops for color transitions. The number of bounds
        should be two less than the number of colors (for multi-color gradients).
        Defaults to None, which evenly distributes color stops.
r<   r   Nr   r   hkrk   rh   )r   r   r   r   r   r   rJ   ri   rm   rn   r\   rk   r@   r    s                r!   r   LinearGradient.__init__   sb    \ 	]&Q&&6/4$?4:;Fq&&1*S)*F; <s   Ark   rh   NFFN
r*   r+   r,   r-   rv   r   rx   r   r0   r1   r2   s   @r!   r   r      sw     #" 11 1 	1
 1 1 1 1 1 S	1 1r#   r   c                   j   ^  \ rS rSr    SSSS\S\S\S\S\S	\S
\S\S\S\\   4U 4S jjjrSrU =r	$ )r      r   r   start_circle_xstart_circle_ystart_circle_radiusend_circle_xend_circle_yend_circle_radiusrJ   rm   rn   r\   c                    > [         TU ]  XXU5        UUR                  U-
  UUUR                  U-
  U/nU Vs/ s H  oR                  U-  S PM     snU l        SU l        gs  snf )a  
A shading pattern that creates a radial (or circular/elliptical) gradient in a PDF.

The gradient is defined by two circles (start and end). Colors are blended from the
start circle to the end circle, forming a radial gradient. You can optionally set a
background color, extend the gradient beyond its circles, and provide custom color
stop positions via `bounds`.

Args:
    fpdf (FPDF): The FPDF instance used for PDF generation.
    start_circle_x (int or float): The x-coordinate of the inner circle's center,
        in user space units.
    start_circle_y (int or float): The y-coordinate of the inner circle's center,
        in user space units.
    start_circle_radius (int or float): The radius of the inner circle, in user space units.
    end_circle_x (int or float): The x-coordinate of the outer circle's center,
        in user space units.
    end_circle_y (int or float): The y-coordinate of the outer circle's center,
        in user space units.
    end_circle_radius (int or float): The radius of the outer circle, in user space units.
    colors (List[str or Tuple[int, int, int]]): A list of colors along which the gradient
        will be interpolated. Colors may be given as hex strings (e.g., "#FF0000") or
        (R, G, B) tuples.
    background (str or Tuple[int, int, int], optional): A background color to display
        if the gradient does not fully cover the region it's applied to. Defaults to None
        (no background).
    extend_before (bool, optional): Whether to extend the gradient beyond the start circle.
        Defaults to False.
    extend_after (bool, optional): Whether to extend the gradient beyond the end circle.
        Defaults to False.
    bounds (List[float], optional): An optional list of floats in the range (0, 1) that
        represent gradient stops for color transitions. The number of bounds should be one
        less than the number of colors (for multi-color gradients). Defaults to None,
        which evenly distributes color stops.
r<   rU   Nr   )r   r   r   r   r   r   r   r   rJ   ri   rm   rn   r\   rk   r@   r    s                  r!   r   RadialGradient.__init__   su    d 	]&QFF^#FF\!
 5;;Fq&&1*S)*F; <s   A#r   r   r   r2   s   @r!   r   r      s     #" << < 	<
 !< < < < < < < S	< <r#   r   N)r.   abcr   typingr   r   r   r   r   drawingr
   r   r   r   syntaxr   r   r   r   r   r   r4   rR   rf   rz   r   r   r=   r#   r!   <module>r      s     > > O O - ->i >*
I 
GI G&hi h0Ts Tn2X 2j=X =r#   