U
    Nf:                      @   s  d Z dZd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 dd	lmZmZmZmZmZmZmZmZmZmZ dd
lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl	m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 e
ed dddZ1d<e
ede2ee2 ee3e2f f ed dddZ4d=ee2e5f ede2ee2 ee3e2f f eeef dddZ6e%7 Z8G dd dZ9dddd d!d"d#d$d%dd&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;g Z:dS )>zHImplementation of generic PDF objects (dictionary, number, string, ...).zMathieu Fenniakzbiziqe@mathieu.fenniak.net    )DictListOptionalTupleUnion   )
StreamTypedeprecate_with_replacement)OutlineFontFlag   )
BooleanObjectByteStringObjectFloatObjectIndirectObject
NameObject
NullObjectNumberObject	PdfObjectTextStringObjectencode_pdfdocencoding)
ArrayObjectContentStreamDecodedStreamObjectDestinationDictionaryObjectEncodedStreamObjectFieldStreamObject
TreeObjectread_object)Fit)OutlineItemRectangleObject)create_string_objectdecode_pdfdocencoding
hex_to_rgbread_hex_string_from_streamread_string_from_stream)ViewerPreferences)r   r   )streamreturnc                 C   s   t ddd t| S )z,Deprecated, use read_hex_string_from_stream.readHexStringFromStreamr'   4.0.0)r	   r'   )r*    r.   :/tmp/pip-unpacked-wheel-zevpxvmc/pypdf/generic/__init__.pyr,   I   s      r,   N)r*   forced_encodingr+   c                 C   s   t ddd t| |S )z(Deprecated, use read_string_from_stream.readStringFromStreamr(   r-   )r	   r(   )r*   r0   r.   r.   r/   r1   S   s      r1   )stringr0   r+   c                 C   s   t ddd t| |S )z%Deprecated, use create_string_object.createStringObjectr$   r-   )r	   r$   )r2   r0   r.   r.   r/   r3   ^   s    r3   c                   @   s4  e Zd ZdZddlmZ ed-eeee	e	e	e	f f e
eeedddZed.e
eeee	e	e	e	f f e
eee
e
ee
 ee
 ed
ddZeddddeeee	e	e	e	f f eee eedddZed/ee	e	f ee	e	f eeee	e	e	e	f f e
ee
 edddZeeee	e	f  edddZed0eeee	e	e	e	f f ee
 edddZedd eeee	e	e	e	f f ee
ed!d"d#Zed1eeee	e	e	e	f f ee
 edd$d%Zeeee	e	f  edd&d'Zd(d)lmZ edddefeeee	e	e	e	f f ee ee
 ee eed*d+d,ZdS )2AnnotationBuilderz
    The AnnotationBuilder is deprecated.

    Instead, use the annotation classes in pypdf.annotations.

    See `adding PDF annotations <../user/adding-pdf-annotations.html>`_ for
    it's usage combined with PdfWriter.
    r   r"   Fr   )recttextopenflagsr+   c                 C   s(   t ddd ddlm} || |||d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.
        AnnotationBuilder.textzpypdf.annotations.Textr-   r   )Text)r5   r6   r7   r8   )r	   annotationsr:   )r5   r6   r7   r8   r:   r.   r.   r/   r6   v   s      r9   	Helvetica14pt000000ffffff)
r6   r5   fontbolditalic	font_size
font_colorborder_colorbackground_colorr+   c	           
      C   s2   t ddd ddlm}	 |	| ||||||||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.
        AnnotationBuilder.free_textzpypdf.annotations.FreeTextr-   r   )FreeText)	r6   r5   r@   rA   rB   rC   rD   rF   rE   )r	   r;   rH   )
r6   r5   r@   rA   rB   rC   rD   rE   rF   rH   r.   r.   r/   	free_text   s"       rG   N)r8   parentr7   )r5   r8   rJ   r7   r+   c                 C   s0   t ddd ddlm} || ||d}||_|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.
        AnnotationBuilder.popupzpypdf.annotations.Popupr-   r   )Popup)r5   r7   rJ   )r	   r;   rL   r8   )r5   r8   rJ   r7   rL   popupr.   r.   r/   rM      s      rK    )p1p2r5   r6   	title_barr+   c                 C   s*   t ddd ddlm} || ||||d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.
        AnnotationBuilder.linezpypdf.annotations.Liner-   r   )Line)rO   rP   r5   r6   rQ   )r	   r;   rS   )rO   rP   r5   r6   rQ   rS   r.   r.   r/   line   s      rR   )verticesr+   c                 C   s"   t ddd ddlm} || d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.
        AnnotationBuilder.polylinezpypdf.annotations.PolyLiner-   r   )PolyLinerU   )r	   r;   rW   )rU   rW   r.   r.   r/   polyline  s      rV   )r5   interiour_colorr+   c                 C   s$   t ddd ddlm} || |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.
        AnnotationBuilder.rectanglezpypdf.annotations.Rectangler-   r   )	Rectangler5   rZ   )r	   r;   r\   )r5   rZ   r\   r.   r.   r/   	rectangle  s      r[   Zff0000)highlight_color)r5   quad_pointsr_   r+   c                 C   s&   t ddd ddlm} || ||d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 highlight.

        Returns:
            A dictionary object representing the annotation.
        AnnotationBuilder.highlightzpypdf.annotations.Highlightr-   r   )	Highlight)r5   r`   r_   )r	   r;   rb   )r5   r`   r_   rb   r.   r.   r/   	highlight2  s        ra   c                 C   s$   t ddd ddlm} || |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.
        AnnotationBuilder.ellipsezpypdf.annotations.Ellipser-   r   )Ellipser]   )r	   r;   re   )r5   rZ   re   r.   r.   r/   ellipseO  s      rd   c                 C   s"   t ddd ddlm} || dS )NAnnotationBuilder.polygonzpypdf.annotations.Polygonr-   r   )PolygonrX   )r	   r;   rh   )rU   rh   r.   r.   r/   polygoni  s      rg   r   )DEFAULT_FIT)r5   borderurltarget_page_indexfitr+   c                 C   s*   t ddd ddlm} || ||||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.
        AnnotationBuilder.linkzpypdf.annotations.Linkr-   r   )Link)r5   rk   rl   rm   rn   )r	   r;   rp   )r5   rk   rl   rm   rn   rp   r.   r.   r/   linkt  s    "  ro   )Fr   )r<   FFr=   r>   r>   r?   )rN   N)N)N)__name__
__module____qualname____doc__Zgeneric._rectangler#   staticmethodr   r   floatstrboolintr   r6   r   rI   rM   rT   r   rY   r^   r   rc   rf   ri   _fitrj   r    rq   r.   r.   r.   r/   r4   j   s   	         0#  

  r4   r   r   r   r   r   r   r   r   r   r    PAGE_FITr   r   r   r   r   r   r   r#   r   r   r)   r!   r
   r   r$   r   r%   r&   r'   r(   )N)N);ru   
__author____author_email__typingr   r   r   r   r   _utilsr   r	   	constantsr
   _baser   r   r   r   r   r   r   r   r   r   Z_data_structuresr   r   r   r   r   r   r   r   r   r   r{   r    Z_outliner!   Z
_rectangler#   r$   r%   r&   r'   r(   Z_viewerprefr)   r,   rx   rz   r1   bytesr3   rn   r|   r4   __all__r.   r.   r.   r/   <module>   s   00  

	  >