
     hC                         d dl mZmZmZmZmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZmZ  ed           Zd
eeeef                  defdZ G d d          ZdS )    )TYPE_CHECKINGListOptionalTupleUnion   )AnnotationFlag   )BooleanObjectFloatObject
NameObjectNumberObjectTextStringObject)ArrayObjectDictionaryObject)DEFAULT_FITFit)RectangleObject)
hex_to_rgblogger_warningverticesreturnc                 ,   | d         d         | d         d         }}| d         d         | d         d         }}| D ]E\  }}t          ||          }t          ||          }t          ||          }t          ||          }Ft          ||||f          }|S )Nr   r
   )minr   )r   x_miny_minx_maxy_maxxyrects           V/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pypdf/generic/_annotations.py_get_bounding_rectangler#      s    A;q>8A;q>5EA;q>8A;q>5E  1E1E1E1E1E5%788DK    c                      e Zd ZdZddlmZmZ e	 	 d1dee	e
eeeef         f         deded	ed
ef
d            Ze	 	 	 	 	 	 	 d2dedee	e
eeeef         f         dedededededee         dee         d
efd            Zeeddddee	e
eeeef         f         d	edee         ded
ef
d            Ze	 	 d3d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!ee
eef                  d
efd"            Ze	 d4dee	e
eeeef         f         d#ee         d
efd$            Zed%d&dee	e
eeeef         f         d'ed(ed
efd)            Ze	 d4dee	e
eeeef         f         d#ee         d
efd*            Zed!ee
eef                  d
efd+            Ze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fd0            Z dS )5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.
    r   )FitTypeZoomArgTypeFr   r!   textopenflagsr   c                 t   t          t          d          t          d          t          d          t          d          t          d          t          |           t          d          t          |          t          d          t	          |          t          d          t          |          i          }|S )	a^  
        Add text annotation.

        Args:
            rect: array of four integers ``[xLL, yLL, xUR, yUR]``
                specifying the clickable rectangular area
            text: The text that is added to the document
            open:
            flags:

        Returns:
            A dictionary object representing the annotation.
        /Type/Annot/Subtypez/Text/Rect	/Contents/Openz/Flags)r   r   r   r   r   r   )r!   r)   r*   r+   text_objs        r"   r)   zAnnotationBuilder.text,   s    * $7##Z%9%9:&&
7(;(;7##_T%:%:;'')9$)?)?7##]4%8%88$$l5&9&9	
 	
 r$   	Helvetica14pt000000fffffffontbolditalic	font_size
font_colorborder_colorbackground_colorc	                    d}	|du r|	 d}	|du r|	 d}	|	 | d| }	|	 d| }	d}
|rt          |          D ]	}|
 | d}

|
 d}
t                      }|                    t          d	          t          d
          t          d          t          d          t          d          t	          |          t          d          t          |           t          d          t          |	          t          d          t          |
          i           |;t          t          d          t          d          i          |t          d          <   |6t          d t          |          D                       |t          d          <   |S )a@  
        Add text in a rectangle to a page.

        Args:
            text: Text to be added
            rect: array of four integers ``[xLL, yLL, xUR, yUR]``
                specifying the clickable rectangular area
            font: Name of the Font, e.g. 'Helvetica'
            bold: Print the text in bold
            italic: Print the text in italic
            font_size: How big the text will be, e.g. '14pt'
            font_color: Hex-string for the color, e.g. cdcdcd
            border_color: Hex-string for the border color, e.g. cdcdcd.
                Use ``None`` for no border.
            background_color: Hex-string for the background of the annotation,
                e.g. cdcdcd. Use ``None`` for transparent background.

        Returns:
            A dictionary object representing the annotation.
        zfont: Tzbold zitalic  z;text-align:left;color:# rgr-   r.   r/   z	/FreeTextr0   r1   z/DSz/DANz/Wr   z/BSc                 ,    g | ]}t          |          S  r   .0ns     r"   
<listcomp>z/AnnotationBuilder.free_text.<locals>.<listcomp>   s    FFFAQFFFr$   /C)r   r   updater   r   r   r   r   )r)   r!   r8   r9   r:   r;   r<   r=   r>   font_strdefault_appearance_stringst	free_texts                r"   rO   zAnnotationBuilder.free_textM   s   @ 4<<")))HT>>"+++H222y22DD
DD$&! 	I .. P P/H,O",O,O,O))+D(H(H(H%$&&	7##Z%9%9:&&
;(?(?7##_T%:%:;'')9$)?)?5!!#3H#=#=5!!#34M#N#N
	
 
	
 
	
 +; t$$l1oo, ,Ij''( '*5FF4D)E)EFFF+ +Ij&&' r$   N)r+   parentr*   rP   c                    t          t          d          t          d          t          d          t          d          t          d          t          |           t          d          t          |          t          d          t	          |          i          }|r>	 |j        |t          d          <   n%# t          $ r t          d	t                     Y nw xY w|S )
a  
        Add a popup to the document.

        Args:
            rect:
                Specifies the clickable rectangular area as `[xLL, yLL, xUR, yUR]`
            flags:
                1 - invisible, 2 - hidden, 3 - print, 4 - no zoom,
                5 - no rotate, 6 - no view, 7 - read only, 8 - locked,
                9 - toggle no view, 10 - locked contents
            open:
                Whether the popup should be shown directly (default is False).
            parent:
                The contents of the popup. Create this via the AnnotationBuilder.

        Returns:
            A dictionary object representing the annotation.
        r-   r.   r/   z/Popupr0   r2   z/Fz/Parentz0Unregistered Parent object : No Parent field set)	r   r   r   r   r   indirect_referenceAttributeErrorr   __name__)r!   r+   rP   r*   	popup_objs        r"   popupzAnnotationBuilder.popup   s    4 %7##Z%9%9:&&
8(<(<7##_T%:%:7##]4%8%84  ,u"5"5
 
	  	393L	*Y//00!   F     s   B7 7CCrA   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.

        Args:
            p1: First point
            p2: Second point
            rect: array of four integers ``[xLL, yLL, xUR, yUR]``
                specifying the clickable rectangular area
            text: Text to be displayed as the line annotation
            title_bar: Text to be displayed in the title bar of the
                annotation; by convention this is the name of the author

        Returns:
            A dictionary object representing the annotation.
        r-   r.   r/   z/Liner0   z/Tz/Lr   r
   z/LEN/ICg      ?r1   )r   r   r   r   r   r   )rW   rX   r!   r)   rY   line_objs         r"   linezAnnotationBuilder.line   sW   . $7##Z%9%9:&&
7(;(;7##_T%:%:4  "29"="=4  +#BqE**#BqE**#BqE**#BqE**	# # 5!!;"4(("4(($ $ 5!!;#C((#C((#C(($ $ ;'')9$)?)?5
 
< r$   r   c                    t          |           dk    rt          d          g }| D ]I\  }}|                    t          |                     |                    t          |                     Jt	          t          d          t          d          t          d          t          d          t          d          t          |          t          d          t          t          |                     i          }|S )	z
        Draw a polyline on the PDF.

        Args:
            vertices: Array specifying the vertices (x, y) coordinates of the poly-line.

        Returns:
            A dictionary object representing the annotation.
        r   6A polygon needs at least 1 vertex with two coordinatesr-   r.   r/   z	/PolyLine	/Verticesr0   	len
ValueErrorappendr   r   r   r   r   r#   )r   
coord_listr   r    polyline_objs        r"   polylinezAnnotationBuilder.polyline   s     x==AUVVV
 	/ 	/DAql1oo...l1oo....'7##Z%9%9:&&
;(?(?;''Z)@)@7##_5LX5V5V%W%W	
 
 r$   interiour_colorc           
      <   t          t          d          t          d          t          d          t          d          t          d          t          |           i          }|r6t          d t	          |          D                       |t          d          <   |S )a  
        Draw a rectangle on the PDF.

        This method uses the /Square annotation type of the PDF format.

        Args:
            rect: array of four integers ``[xLL, yLL, xUR, yUR]``
                specifying the clickable rectangular area
            interiour_color: None or hex-string for the color, e.g. cdcdcd
                If None is used, the interiour is transparent.

        Returns:
            A dictionary object representing the annotation.
        r-   r.   r/   z/Squarer0   c                 ,    g | ]}t          |          S rD   rE   rF   s     r"   rI   z/AnnotationBuilder.rectangle.<locals>.<listcomp>5      EEEAQEEEr$   r[   r   r   r   r   r   )r!   rh   
square_objs      r"   	rectanglezAnnotationBuilder.rectangle  s    & &7##Z%9%9:&&
9(=(=7##_T%:%:
 

  	,7EEO)D)DEEE- -Jz%(() r$   ff0000)highlight_colorquad_pointsrp   c                 P   t          t          d          t          d          t          d          t          d          t          d          t          |           t          d          |t          d          t          d t	          |          D                       i          }|S )	a  
        Add a highlight annotation to the document.

        Args:
            rect: Array of four integers ``[xLL, yLL, xUR, yUR]``
                specifying the highlighted area
            quad_points: An ArrayObject of 8 FloatObjects. Must match a word or
                a group of words, otherwise no highlight will be shown.
            highlight_color: The color used for the hightlight

        Returns:
            A dictionary object representing the annotation.
        r-   r.   r/   z
/Highlightr0   z/QuadPointsrJ   c                 ,    g | ]}t          |          S rD   rE   rF   s     r"   rI   z/AnnotationBuilder.highlight.<locals>.<listcomp>U  s    III[^^IIIr$   rl   )r!   rq   rp   objs       r"   	highlightzAnnotationBuilder.highlight:  s    ( 7##Z%9%9:&&
<(@(@7##_T%:%:=));4  +IIZ-H-HIII# #

 

 
r$   c           
      <   t          t          d          t          d          t          d          t          d          t          d          t          |           i          }|r6t          d t	          |          D                       |t          d          <   |S )a  
        Draw a rectangle on the PDF.

        This method uses the /Circle annotation type of the PDF format.

        Args:
            rect: array of four integers ``[xLL, yLL, xUR, yUR]`` specifying
                the bounding box of the ellipse
            interiour_color: None or hex-string for the color, e.g. cdcdcd
                If None is used, the interiour is transparent.

        Returns:
            A dictionary object representing the annotation.
        r-   r.   r/   z/Circler0   c                 ,    g | ]}t          |          S rD   rE   rF   s     r"   rI   z-AnnotationBuilder.ellipse.<locals>.<listcomp>x  rk   r$   r[   rl   )r!   rh   ellipse_objs      r"   ellipsezAnnotationBuilder.ellipse[  s    & '7##Z%9%9:&&
9(=(=7##_T%:%:
 
  	-8EEO)D)DEEE. .K
5))* r$   c                 6   t          |           dk    rt          d          g }| D ]I\  }}|                    t          |                     |                    t          |                     Jt	          t          d          t          d          t          d          t          d          t          d          t          |          t          d          t          d	          t          d
          t          t          |                     i          }|S )Nr   r_   r-   r.   r/   z/Polygonr`   z/ITPolygonCloudr0   ra   )r   re   r   r    rt   s        r"   polygonzAnnotationBuilder.polygon}  s    x==AUVVV
 	/ 	/DAql1oo...l1oo....7##Z%9%9:&&
:(>(>;''Z)@)@5!!:n#=#=7##_5LX5V5V%W%W
 
 
r$   borderurltarget_page_indexfitc                    t           rddlm} |du}|du}|s|st          d          |r|rt          d| d|           |\d |dd         D             }t	          |          d	k    r4t          d
 |d         D                       }	|                    |	           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          <   |rIt          t          |          t          |j                  |j        d          }||
t          d          <   |
S )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.

        Args:
            rect: array of four integers ``[xLL, yLL, xUR, yUR]``
                specifying the clickable rectangular area
            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
            url: Link to a website (if you want to make an external link)
            target_page_index: index of the page to which the link should go
                (if you want to make an internal link)
            fit: Page fit or 'zoom' option.

        Returns:
            A dictionary object representing the annotation.
        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=c                 ,    g | ]}t          |          S rD   r   rF   s     r"   rI   z*AnnotationBuilder.link.<locals>.<listcomp>  s    <<<A*Q--<<<r$         c                 ,    g | ]}t          |          S rD   r   rF   s     r"   rI   z*AnnotationBuilder.link.<locals>.<listcomp>  s    +M+M+MaJqMM+M+M+Mr$   r   r-   r.   r/   z/Linkr0   z/Borderz/Sz/URIz/Actionz/A)r   r   fit_argsz/Dest)r   typesr   rc   rb   r   rd   r   r   r   r   r   fit_typer   )r!   r}   r~   r   r   r   is_externalis_internal
border_arrdash_patternlink_objdest_deferreds               r"   linkzAnnotationBuilder.link  sF   D  	0//////o't3 	; 	Z    	; 	DD D0AD D   <<<<<J6{{a*+M+M6!9+M+M+MNN!!,///&q//*Q.J#7##Z%9%9:&&
7(;(;7##_T%:%:9%%{:'>'>	
 
  	)9t$$j&8&8w''I)>)>v&&(8(=(=* *HZ%%&  		:,)56G)H)H%cl33 #  M -:HZ(()r$   )Fr   )r4   FFr5   r6   r6   r7   )rA   rA   )N)!rT   
__module____qualname____doc__r   r'   r(   staticmethodr   r   r   floatstrboolintr   r)   r   rO   NO_FLAGSr	   rV   r]   r   rg   rn   r   ru   ry   r|   r   r   r   rD   r$   r"   r&   r&      s         -,,,,,,, 	 OU5%+E%FFG  	
 
   \@   "&.*2E EEOU5%+E%FFGE E 	E
 E E E smE #3-E 
E E E \EN  !)-1, , ,OU5%+E%FFG, , )*	,
 , 
, , , \,\ 
 4 4%,4%,4 OU5%+E%FFG4 	4
 4 
4 4 4 \4l uUE\*+	   \8  *. OU5%+E%FFG!# 
   \B 
  (	  OU5%+E%FFG ! 	
 
   \@  *. OU5%+E%FFG!# 
   \B $uUE\23 8H    \&  )-!+/S SOU5%+E%FFGS%S c]S $C=	S
 S 
S S S \S S Sr$   r&   N)typingr   r   r   r   r   	constantsr	   _baser   r   r   r   r   _data_structuresr   r   _fitr   r   
_rectangler   _utilsr   r   r   r   r#   r&   rD   r$   r"   <module>r      s^   > > > > > > > > > > > > > > & & & & & &              < ; ; ; ; ; ; ; " " " " " " " " ' ' ' ' ' ' . . . . . . . .>!	d5+>&? 	O 	 	 	 	F F F F F F F F F Fr$   