o
    ë6WjQ'  ã                   @   sz   d dl mZmZ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 G dd	„ d	ƒZd
S )é    )ÚOptionalÚTupleÚUnioné   )ÚBooleanObjectÚFloatObjectÚ
NameObjectÚNumberObjectÚTextStringObject)ÚArrayObjectÚDictionaryObject)ÚDEFAULT_FITÚFit)ÚRectangleObject)Ú
hex_to_rgbc                   @   sŒ  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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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d„ƒZe	 d-dee	e
eeeef f d!ee d
efd"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d(d)„ƒZd S ).Ú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ÚZoomArgTypeFr   ÚrectÚtextÚopenÚflagsÚreturnc                 C   sT   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_obj© r    új/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/PyPDF2/generic/_annotations.pyr      s   úÿ
zAnnotationBuilder.textÚ	HelveticaÚ14ptÚ000000ÚffffffÚfontÚboldÚitalicÚ	font_sizeÚ
font_colorÚborder_colorÚbackground_colorc	                 C   sà   d}	|du r
|	d }	|du r|	d }	|	| d | }	|	d | }	d}
t |ƒD ]
}|
t|ƒ d }
q&|
d }
tƒ }| td	ƒtd
ƒtdƒtdƒtdƒt|ƒtdƒt| ƒtdƒt|	ƒtdƒt|
ƒtdƒtdd„ t |ƒD ƒƒi¡ |S )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/Cc                 S   ó   g | ]}t |ƒ‘qS r    ©r   ©Ú.0Únr    r    r!   Ú
<listcomp>n   ó    z/AnnotationBuilder.free_text.<locals>.<listcomp>)r   Ústrr   Úupdater   r   r
   r   )r   r   r&   r'   r(   r)   r*   r+   r,   Úfont_strÚbg_color_strÚstÚ	free_textr    r    r!   r<   :   s2   ÿöÿzAnnotationBuilder.free_textr.   Úp1Úp2Ú	title_barc                 C   s²   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   )r=   r>   r   r   r?   Úline_objr    r    r!   Úlinet   s6   



üÿþÿýÿæÿzAnnotationBuilder.lineNÚinteriour_colorc                 C   sR   t tdƒtdƒtdƒtdƒtdƒt| ƒiƒ}|r'tdd„ t|ƒD ƒƒ|tdƒ< |S )	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   c                 S   r0   r    r1   r2   r    r    r!   r5   ¾   r6   z/AnnotationBuilder.rectangle.<locals>.<listcomp>r@   )r   r   r   r   r   )r   rC   Ú
square_objr    r    r!   Ú	rectangle¨   s   ýÿÿzAnnotationBuilder.rectangleÚborderÚurlÚtarget_page_indexÚfitc              
   C   sB  ddl m} |du}|du}|s|stdƒ‚|r$|r$td|› d|› �ƒ‚|durJdd„ |dd	… D ƒ}t|ƒd
krItdd„ |d	 D ƒƒ}	| |	¡ ntdƒgd	 }ttdƒtdƒtdƒtdƒtdƒt	| ƒtdƒt|ƒiƒ}
|r‰ttdƒtdƒtdƒtdƒtdƒt
|ƒiƒ|
tdƒ< |rŸt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.


        :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 Fit fit: Page fit or 'zoom' option.
        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                 S   r0   r    ©r   r2   r    r    r!   r5   ò   r6   z*AnnotationBuilder.link.<locals>.<listcomp>é   é   c                 S   r0   r    rK   r2   r    r    r!   r5   ô   r6   r   r   r   r   z/Linkr   z/Borderz/Sz/URIz/Actionz/A)rH   rI   Úfit_argsz/Dest)ÚtypesrJ   Ú
ValueErrorÚlenr   Úappendr	   r   r   r   r
   Úfit_typerN   )r   rF   rG   rH   rI   rJ   Úis_externalÚis_internalÚ
border_arrÚdash_patternÚlink_objÚdest_deferredr    r    r!   ÚlinkÃ   sR    ÿÿ
€üÿýÿýÿzAnnotationBuilder.link)Fr   )r"   FFr#   r$   r$   r%   )r.   r.   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   r   r   Ústaticmethodr   r   r   Úfloatr7   ÚboolÚintr   r   r<   rB   r   rE   r   r   r   rZ   r    r    r    r!   r      s²    
üÿþýüû÷ÿþýüûúùø	÷
ö9û
ÿ
þýüûú3þÿþýûÿþýüûúr   N)Útypingr   r   r   Ú_baser   r   r   r	   r
   Ú_data_structuresr   r   Ú_fitr   r   Ú
_rectangler   Ú_utilsr   r   r    r    r    r!   Ú<module>   s    