
    :Qg*                     t    d dl mZmZmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ  G d d      Zy	)
    )OptionalTupleUnion   )BooleanObjectFloatObject
NameObject
NullObjectNumberObjectTextStringObject)ArrayObjectDictionaryObject)RectangleObject)
hex_to_rgbc                      e Zd ZdZddlmZmZ e	 	 d!dee	e
eeeef   f   dedededef
d	       Ze	 	 	 	 	 	 	 d"dedee	e
eeeef   f   d
edededededededefd       Ze	 	 d#de
eef   de
eef   dee	e
eeeef   f   dededefd       Ze	 d$dee	e
eeeef   f   dee   defd       Zedddd e       fdee	e
eeeef   f   dee   dee   dee   dede
edf   defd        Zy)%AnnotationBuildera>  
    The AnnotationBuilder creates dictionaries representing PDF annotations.

    Those dictionaries can be modified before they are added to a PdfWriter
    instance via `writer.add_annotation`.

    See `adding PDF annotations <../user/adding-pdf-annotations.html>`_ for
    it's usage combined with PdfWriter.
       )FitTypeZoomArgTyperecttextopenflagsreturnc                    t        t        d      t        d      t        d      t        d      t        d      t        |       t        d      t        |      t        d      t	        |      t        d      t        |      i      }|S )	z
        Add text annotation.

        :param Tuple[int, int, int, int] rect:
            or array of four integers specifying the clickable rectangular area
            ``[xLL, yLL, xUR, yUR]``
        :param bool open:
        :param int flags:
        /Type/Annot/Subtypez/Text/Rect	/Contentsz/Openz/Flags)r   r	   r   r   r   r   )r   r   r   r   text_objs        X/var/www/html/answerous/venv/lib/python3.12/site-packages/PyPDF2/generic/_annotations.pyr   zAnnotationBuilder.text   su    " $7#Z%9:&
7(;7#_T%:;')9$)?7#]4%88$l5&9	
     fontbolditalic	font_size
font_colorborder_colorbackground_colorc	                 <   d}	|du r|	dz   }	|du r|	dz   }	|	|z   dz   |z   }	|	dz   |z   }	d}
t        |      D ]  }|
t        |      z   dz   }
 |
dz   }
t               }|j                  t	        d	      t	        d
      t	        d      t	        d      t	        d      t        |      t	        d      t        |       t	        d      t        |	      t	        d      t        |
      t	        d      t        t        |      D cg c]  }t        |       c}      i       |S c c}w )a  
        Add text in a rectangle to a page.

        :param str text: Text to be added
        :param RectangleObject rect: or array of four integers
            specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]``
        :param str font: Name of the Font, e.g. 'Helvetica'
        :param bool bold: Print the text in bold
        :param bool italic: Print the text in italic
        :param str font_size: How big the text will be, e.g. '14pt'
        :param str font_color: Hex-string for the color
        :param str border_color: Hex-string for the border color
        :param str background_color: Hex-string for the background of the annotation
        zfont: Tzbold zitalic  z;text-align:left;color:# rgr   r   r   z	/FreeTextr   r    z/DSz/DAz/C)	r   strr   updater	   r   r   r   r   )r   r   r$   r%   r&   r'   r(   r)   r*   font_strbg_color_strst	free_textns                 r"   r4   zAnnotationBuilder.free_text:   s1   4 4<')HT>)+Hd?S(9488:E\* 	8B'#b'1C7L	8#d*$&	7#Z%9:&
;(?7#_T%:;')9$)?5!#3H#=5!#3L#A4 +-78H-IJ[^J#	
  	 Ks   9D&p1p2	title_barc                 (   t        t        d      t        d      t        d      t        d      t        d      t        |      t        d      t        |      t        d      t	        t        | d         t        | d	         t        |d         t        |d	         g      t        d
      t	        t        d      t        d      g      t        d      t	        t        d      t        d      t        d      g      t        d      t        |      i      }|S )a  
        Draw a line on the PDF.

        :param Tuple[float, float] p1: First point
        :param Tuple[float, float] p2: Second point
        :param RectangleObject rect: or array of four
                integers specifying the clickable rectangular area
                ``[xLL, yLL, xUR, yUR]``
        :param str text: Text to be displayed as the line annotation
        :param str title_bar: Text to be displayed in the title bar of the
            annotation; by convention this is the name of the author
        r   r   r   z/Liner   z/Tz/Lr   r   z/LEN/ICg      ?r    )r   r	   r   r   r   r   )r6   r7   r   r   r8   line_objs         r"   linezAnnotationBuilder.linet   s   ( $7#Z%9:&
7(;7#_T%:4 "29"=4 +#BqE*#BqE*#BqE*#BqE*	# 5!;"4("4($ 5!;#C(#C(#C($ ;')9$)?5
< r#   Ninteriour_colorc           
         t        t        d      t        d      t        d      t        d      t        d      t        |       i      }|r7t        t	        |      D cg c]  }t        |       c}      |t        d      <   |S c c}w )z
        Draw a rectangle on the PDF.

        :param RectangleObject rect: or array of four
                integers specifying the clickable rectangular area
                ``[xLL, yLL, xUR, yUR]``
        r   r   r   z/Squarer   r:   )r   r	   r   r   r   r   )r   r=   
square_objr5   s       r"   	rectanglezAnnotationBuilder.rectangle   s~     &7#Z%9:&
9(=7#_T%:

 ,7)3O)DEAQE-Jz%()  Fs   Bz/Fitborderurltarget_page_indexfitfit_args.c                    ddl m} |du}|du}|s|st        d      |r|rt        d| d|       |`|dd D 	cg c]  }	t        |	       }
}	t	        |      dk(  rFt        |d   D 	cg c]  }	t        |	       c}	      }|
j                  |       nt        d	      gdz  }
t        t        d
      t        d      t        d      t        d      t        d      t        |       t        d      t        |
      i      }|rSt        t        d      t        d      t        d
      t        d      t        d      t        |      i      |t        d      <   |r\|D cg c]  }|
t               n
t        |       }}t        t        |      t        |      t        |      d      }||t        d      <   |S c c}	w c c}	w c c}w )a  
        Add a link to the document.

        The link can either be an external link or an internal link.

        An external link requires the URL parameter.
        An internal link requires the target_page_index, fit, and fit args.


        :param RectangleObject rect: or array of four
            integers specifying the clickable rectangular area
            ``[xLL, yLL, xUR, yUR]``
        :param border: if provided, an array describing border-drawing
            properties. See the PDF spec for details. No border will be
            drawn if this argument is omitted.
            - horizontal corner radius,
            - vertical corner radius, and
            - border width
            - Optionally: Dash
        :param str url: Link to a website (if you want to make an external link)
        :param int target_page_index: index of the page to which the link should go
                                (if you want to make an internal link)
        :param str fit: Page fit or 'zoom' option (see below). Additional arguments may need
            to be supplied. Passing ``None`` will be read as a null value for that coordinate.
        :param Tuple[int, ...] fit_args: Parameters for the fit argument.


        .. list-table:: Valid ``fit`` arguments (see Table 8.2 of the PDF 1.7 reference for details)
           :widths: 50 200

           * - /Fit
             - No additional arguments
           * - /XYZ
             - [left] [top] [zoomFactor]
           * - /FitH
             - [top]
           * - /FitV
             - [left]
           * - /FitR
             - [left] [bottom] [right] [top]
           * - /FitB
             - No additional arguments
           * - /FitBH
             - [top]
           * - /FitBV
             - [left]
        r   )BorderArrayTypeNzHEither 'url' or 'target_page_index' have to be provided. Both were None.z=Either 'url' or 'target_page_index' have to be provided. url=z, target_page_index=      r   r   r   r   z/Linkr   z/Borderz/Sz/URIz/Actionz/A)rC   rD   rE   z/Dest)typesrG   
ValueErrorr	   lenr   appendr   r   r   r   r
   )r   rA   rB   rC   rD   rE   rG   is_externalis_internalr5   
border_arrdash_patternlink_objafit_arg_readydest_deferreds                   r"   linkzAnnotationBuilder.link   s   p 	,o't3;Z  ;OPSuThizh{| 
 17<A*Q-<J<6{a*6!9+MaJqM+MN!!,/&q/*Q.J#7#Z%9:&
7(;7#_T%:9%{:'>	
 )9t$j&8w'I)>v&(8(=*HZ%& HPCD	
|A>M  -)56G)H%c? +M :M -:HZ()I =+M,s   F4*F9F>)Fr   )	HelveticaFF14pt000000rY   ffffff)r-   r-   )N)__name__
__module____qualname____doc__rJ   r   r   staticmethodr   r   r   floatr/   boolintr   r   r4   r<   r   r@   tupler   rV    r#   r"   r   r      s    - 	OU5%+E%FFG  	
 
 8   "$ (77OU5%+E%FFG7 7 	7
 7 7 7 7 7 
7 7r 
 1%,1%,1 OU5%+E%FFG1 	1
 1 
1 1f  *.OU5%+E%FFG!# 
 4  )-!+/,1GjOU5%+E%FFGj%j c]j $C=	j
 j S()j 
j jr#   r   N)typingr   r   r   _baser   r   r	   r
   r   r   _data_structuresr   r   
_rectangler   _utilsr   r   rd   r#   r"   <module>rj      s,    ) )  < ' ^ ^r#   