§
    ¥”jT3  ã                   óZ  — d dl Z d dlZd dlmZ d dlmZ ddl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 g d	¢Z G d
„ de¦  «        Z G d„ de¦  «        Zd„ Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d¦  «        Z G d„ de¦  «        ZdS )é    N)ÚEnum)ÚOptionalé   )ÚDictionaryObjectÚIndirectObjectÚ
NameObjectÚ	PdfObjectÚStreamObjectÚpdf_name)ÚBoxConstraints)ÚPdfFileReader©ÚBasePdfFileWriter)ÚImportedPdfPageÚ
PdfContentÚPdfResourcesÚ
RawContentÚResourceManagementErrorÚResourceTypeÚAnnotAppearancesÚAppearanceContentc                   ó¸   — e Zd ZdZ ed¦  «        Z	  ed¦  «        Z	  ed¦  «        Z	  ed¦  «        Z	  ed¦  «        Z		  ed¦  «        Z
	  ed¦  «        Zd	S )
r   u|   
    Enum listing resources that can be used as keys in a resource dictionary.

    See ISO 32000-1, Â§ 7.8.3 Table 34.
    z
/ExtGStatez/ColorSpacez/Patternz/Shadingz/XObjectz/Fontz/PropertiesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚEXT_G_STATEÚCOLOR_SPACEÚPATTERNÚSHADINGÚXOBJECTÚFONTÚ
PROPERTIES© ó    úh/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/pyhanko/pdf_utils/content.pyr   r   !   s³   € € € € € ðð ð �(˜<Ñ(Ô(€Kðð
 �(˜=Ñ)Ô)€Kðð
 ˆh�zÑ"Ô"€Gðð
 ˆh�zÑ"Ô"€Gðð
 ˆh�zÑ"Ô"€Gðð
 ˆ8�GÑÔ€Dðð
 �˜-Ñ(Ô(€Jðð r%   r   c                   ó   — e Zd ZdZdS )r   z=
    Used to signal problems with resource dictionaries.
    N)r   r   r   r   r$   r%   r&   r   r   S   s   € € € € € ðð ð 	€Dr%   r   c                 ór   — |                      ¦   «         D ]!\  }}|| v rt          d|› d�¦  «        ‚|| |<   Œ"| S )NzResource with name z occurs in both dictionaries.)Úitemsr   )Údict1Údict2ÚkÚv2s       r&   Ú_res_merge_helperr.   [   sX   € Ø—’‘”ð ð ‰ˆˆ2Ø�ˆ:ˆ:Ý)ØF aÐFÐFÐFñô ð ð ˆˆa‰ˆØ€Lr%   c                   ó6   — e Zd ZdZd„ Zdefd„Zdefd„Zd„ Z	dS )	r   a8  
    Representation of a PDF resource dictionary.

    This class implements :meth:`__getitem__` with :class:`.ResourceType` keys
    for dynamic access to its attributes.
    To merge two instances of :class:`.PdfResources` into one another,
    the class overrides :meth:`__iadd__`, so you can write.

    .. code-block:: python

        res1 += res2

    *Note:* Merging two resource dictionaries with conflicting resource names
    will produce a :class:`.ResourceManagementError`.

    *Note:* This class is currently only used for new resource dictionaries.
    c                 ó  — t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        d S ©N)r   Úext_g_stateÚcolor_spaceÚpatternÚshadingÚxobjectÚfontÚ
properties©Úselfs    r&   Ú__init__zPdfResources.__init__x   sc   € Ý+Ñ-Ô-ˆÔÝ+Ñ-Ô-ˆÔÝ'Ñ)Ô)ˆŒÝ'Ñ)Ô)ˆŒÝ'Ñ)Ô)ˆŒÝ$Ñ&Ô&ˆŒ	Ý*Ñ,Ô,ˆŒˆˆr%   Úitemc                 óP   — t          | |j                             ¦   «         ¦  «        S r1   )ÚgetattrÚnameÚlower)r:   r<   s     r&   Ú__getitem__zPdfResources.__getitem__�   s   € Ý�t˜TœYŸ_š_Ñ.Ô.Ñ/Ô/Ð/r%   Úreturnc                 óP   ‡ — ˆ fd„}t          d„  |¦   «         D ¦   «         ¦  «        S )zj
        Render this instance of :class:`.PdfResources` to an actual resource
        dictionary.
        c               3   óJ   •K  — t           D ]} ‰|          }|r| j        |fV — Œd S r1   )r   Úvalue)r,   Úvalr:   s     €r&   Ú_genz(PdfResources.as_pdf_object.<locals>._genŠ   sD   øè è € Ý!ð 'ð '�Ø˜1”g�Øð 'Øœ' 3˜,Ð&Ð&Ð&øð'ð 'r%   c                 ó   — i | ]\  }}||“Œ	S r$   r$   )Ú.0r,   Úvs      r&   ú
<dictcomp>z.PdfResources.as_pdf_object.<locals>.<dictcomp>�   s   € Ð 9Ð 9Ð 9©$¨!¨Q  AÐ 9Ð 9Ð 9r%   )r   )r:   rG   s   ` r&   Úas_pdf_objectzPdfResources.as_pdf_object„   sA   ø€ ð	'ð 	'ð 	'ð 	'ð 	'õ  Ð 9Ð 9°$°$±&´&Ð 9Ñ 9Ô 9Ñ:Ô:Ð:r%   c                 óR   — t           D ]}t          | |         ||         ¦  «         Œ| S )a(  
        Merge another resource dictionary into this one.
        :param other:
            Another instance of :class:`.PdfResources`
        :return:
            Always returns ``self``
        :raises ResourceManagementError:
            Raised when there is a resource name conflict.
        )r   r.   )r:   Úotherr,   s      r&   Ú__iadd__zPdfResources.__iadd__’   s3   € õ ð 	1ð 	1ˆAÝ˜d 1œg u¨Q¤xÑ0Ô0Ð0Ð0Øˆr%   N)
r   r   r   r   r;   r   rA   r   rL   rO   r$   r%   r&   r   r   e   ss   € € € € € ðð ð$-ð -ð -ð0 ð 0ð 0ð 0ð 0ð;Ð/ð ;ð ;ð ;ð ;ðð ð ð ð r%   r   c                   óæ   — e Zd ZdZdZ	 	 	 	 ddee         dee         dee         fd„Z	e
defd„¦   «         Zd	ed
edefd„Zdefd„Ze
defd„¦   «         Zdefd„Zdefd„Zd„ Z	 ddededefd„ZdS )r   z¿
    Abstract representation of part of a PDF content stream.

    .. warning::

        Whether :class:`.PdfContent` instances can be reused or not
        is left up to the subclasses.
    NÚ	resourcesÚboxÚwriterc                 óh   — |pt          ¦   «         | _        |pt          ¦   «         | _        || _        d S r1   )r   Ú
_resourcesr   rR   rS   )r:   rQ   rR   rS   s       r&   r;   zPdfContent.__init__´   s1   € ð )2Ð(Cµ\±^´^ˆŒØ#&Ð#:­.Ñ*:Ô*:ˆŒØˆŒˆˆr%   rB   c                 ó<   — | j         €t          d¦  «        ‚| j         S )NzPDF writer is not set)rS   Ú
ValueErrorr9   s    r&   Ú_ensure_writerzPdfContent._ensure_writer¾   s!   € àŒ;ÐÝÐ4Ñ5Ô5Ð5ØŒ{Ðr%   Úcategoryr?   rE   c                 ó&   — || j         |         |<   dS )a2  Set a value in the resource dictionary associated with this content
        fragment.

        :param category:
            The resource category to which the resource belongs.
        :param name:
            The resource's (internal) name.
        :param value:
            The resource's value.
        N©rU   )r:   rY   r?   rE   s       r&   Úset_resourcezPdfContent.set_resourceÆ   s   € ð +0ˆŒ˜Ô! $Ñ'Ð'Ð'r%   c                 ó&   — | xj         |z  c_         dS )zíImport resources from another resource dictionary.

        :param resources:
            An instance of :class:`.PdfResources`.
        :raises ResourceManagementError:
            Raised when there is a resource name conflict.
        Nr[   )r:   rQ   s     r&   Úimport_resourceszPdfContent.import_resourcesÕ   s   € ð 	ˆŒ˜9Ñ$ˆŒˆˆr%   c                 ó   — | j         S )z}
        :return:
            The :class:`.PdfResources` instance associated with this
            content fragment.
        r[   r9   s    r&   rQ   zPdfContent.resourcesß   s   € ð ŒÐr%   c                 ó   — t           ‚)z<
        Compile the content to graphics operators.
        )ÚNotImplementedErrorr9   s    r&   ÚrenderzPdfContent.renderè   s
   € õ "Ð!r%   c                 óª   — ddl m} |                      ¦   «         } ||| j        j        | j        j        | j                             ¦   «         ¬¦  «        S )uŠ  
        Render the object to a form XObject to be referenced by another
        content stream. See ISO 32000-1, Â§ 8.8.

        *Note:* Even if :attr:`writer` is set, the resulting form XObject will
        not be registered. This is left up to the caller.

        :return:
            A :class:`~.generic.StreamObject` instance representing
            the resulting form XObject.
        r   )Úinit_xobject_dictionary)Úcommand_streamÚ	box_widthÚ
box_heightrQ   )Úpyhanko.pdf_utils.writerrd   rb   rR   ÚwidthÚheightrU   rL   )r:   rd   re   s      r&   Úas_form_xobjectzPdfContent.as_form_xobjectð   s`   € ð 	EÐDÐDÐDÐDÐDàŸš™œˆØ&Ð&Ø)Ø”h”nØ”x”Ø”o×3Ò3Ñ5Ô5ð	
ñ 
ô 
ð 	
r%   c                 ó   — || _         dS )zš
        Override the currently registered writer object.

        :param writer:
            An instance of :class:`~.writer.BasePdfFileWriter`.
        N)rS   )r:   rS   s     r&   Ú
set_writerzPdfContent.set_writer  s   € ð ˆŒˆˆr%   FÚpage_ixÚprependc                 óÎ   — t          i |                      ¦   «         ¬¦  «        }|                     ||                     |¦  «        | j                             ¦   «         |¬¦  «        S )aæ  
        Convenience wrapper around :meth:`.BasePdfFileWriter.add_stream_to_page`
        to turn a :class:`.PdfContent` instance into a page
        content stream.

        :param writer:
            A PDF file writer.
        :param page_ix:
            Index of the page to modify.
            The first page has index `0`.
        :param prepend:
            Prepend the content stream to the list of content streams, as
            opposed to appending it to the end.
            This has the effect of causing the stream to be rendered
            underneath the already existing content on the page.
        :return:
            An :class:`~.generic.IndirectObject` reference to the page object
            that was modified.
        )Ústream_data)rQ   ro   )r
   rb   Úadd_stream_to_pageÚ
add_objectrQ   rL   )r:   rS   rn   ro   Ú	as_streams        r&   Úadd_to_pagezPdfContent.add_to_page  sc   € õ, ! °·²±´Ð?Ñ?Ô?ˆ	Ø×(Ò(ØØ×Ò˜iÑ(Ô(Ø”n×2Ò2Ñ4Ô4Øð	 )ñ 
ô 
ð 	
r%   )NNN)F)r   r   r   r   rS   r   r   r   r   r;   ÚpropertyrX   r   r   r	   r\   r^   rQ   Úbytesrb   r
   rk   rm   ÚintÚboolru   r$   r%   r&   r   r   ¡   s�  € € € € € ðð ð €Fðð -1Ø(,Ø.2ð	ð à˜LÔ)ðð �nÔ%ðð Ð*Ô+ð	ð ð ð ð ðÐ 1ð ð ð ñ „Xðð0Ø$ð0Ø,6ð0Ø?Hð0ð 0ð 0ð 0ð%¨,ð %ð %ð %ð %ð ð˜<ð ð ð ñ „Xðð"˜ð "ð "ð "ð "ð
 ð 
ð 
ð 
ð 
ð,ð ð ð HMð
ð 
Ø'ð
Ø25ð
Ø@Dð
ð 
ð 
ð 
ð 
ð 
r%   r   c                   óZ   ‡ — e Zd ZdZ	 	 d	dedee         dee         fˆ fd„Zdefd„Z	ˆ xZ
S )
r   z,Raw byte sequence to be used as PDF content.NÚdatarQ   rR   c                 óZ   •— t          ¦   «                              ||¦  «         || _        d S r1   )Úsuperr;   r{   )r:   r{   rQ   rR   Ú	__class__s       €r&   r;   zRawContent.__init__1  s*   ø€ õ 	‰Œ×Ò˜ CÑ(Ô(Ð(ØˆŒ	ˆ	ˆ	r%   rB   c                 ó   — | j         S r1   )r{   r9   s    r&   rb   zRawContent.render:  s
   € ØŒyÐr%   ©NN)r   r   r   r   rw   r   r   r   r;   rb   Ú__classcell__©r~   s   @r&   r   r   .  s‘   ø€ € € € € Ø6Ð6ð
 -1Ø(,ð	ð àðð ˜LÔ)ðð �nÔ%ð	ð ð ð ð ð ð˜ð ð ð ð ð ð ð ð r%   r   c                   ó0   ‡ — e Zd ZdZdˆ fd„	Zdefd„Zˆ xZS )r   z,Import a page from another PDF file (lazily)r   c                 ód   •— || _         || _        t          ¦   «                              ¦   «          d S r1   )Ú	file_namern   r}   r;   )r:   r…   rn   r~   s      €r&   r;   zImportedPdfPage.__init__A  s-   ø€ Ø"ˆŒØˆŒÝ‰Œ×ÒÑÔÐÐÐr%   rB   c                 ó  — ddl m} | j        }t          | j        d¦  «        5 }t          |¦  «        }|                     || j        ¬¦  «        }d d d ¦  «         n# 1 swxY w Y   dt          j	        t          j        ¦   «         j        ¦  «        z   }|| j        j        |                     d¦  «        <   |                     ¦   «         d         \  }}}	}
t#          t%          ||	z
  ¦  «        t%          ||
z
  ¦  «        ¬¦  «        | _        |d	z   S )
Nr   r   Úrb)rn   s   /ImportÚasciiz/BBox)ri   rj   s    Do)rS   r   rX   Úopenr…   r   Úimport_page_as_xobjectrn   ÚbinasciiÚhexlifyÚuuidÚuuid4rw   rQ   r6   ÚdecodeÚ
get_objectr   ÚabsrR   )r:   r   ÚwÚinfÚrÚxobjÚresource_nameÚx1Úy1Úx2Úy2s              r&   rb   zImportedPdfPage.renderF  sE  € Ø-Ð-Ð-Ð-Ð-Ð-à#Ô2ˆÝ�$”. $Ñ'Ô'ð 	E¨3Ý˜cÑ"Ô"ˆAØ×+Ò+¨A°t´|Ð+ÑDÔDˆDð	Eð 	Eð 	Eñ 	Eô 	Eð 	Eð 	Eð 	Eð 	Eð 	Eð 	Eøøøð 	Eð 	Eð 	Eð 	Eð #¥XÔ%5µd´j±l´lÔ6HÑ%IÔ%IÑIˆØ@DˆŒÔ˜}×3Ò3°GÑ<Ô<Ñ=ð ŸšÑ*Ô*¨7Ô3‰ˆˆB��BÝ!­¨B°©G©¬½SÀÀbÁ¹\¼\ÐJÑJÔJˆŒØ˜vÑ%Ð%s   £,AÁAÁ"A)r   )r   r   r   r   r;   rw   rb   r�   r‚   s   @r&   r   r   >  s^   ø€ € € € € Ø6Ð6ðð ð ð ð ð ð
&˜ð &ð &ð &ð &ð &ð &ð &ð &r%   r   c                   óP   — e Zd ZdZ	 	 d	dedee         dee         fd„Zdefd„ZdS )
r   up  
    Convenience abstraction to set up an appearance dictionary for a PDF
    annotation.

    Annotations can have three appearance streams, which can be roughly
    characterised as follows:

    * *normal*: the only required one, and the default one;
    * *rollover*: used when mousing over the annotation;
    * *down*: used when clicking the annotation.

    These are given as references to form XObjects.

    .. note::
        This class only covers the simple case of an appearance dictionary
        for an annotation with only one appearance state.

    See Â§ 12.5.5 in ISO 32000-1 for further information.
    NÚnormalÚrolloverÚdownc                 ó0   — || _         || _        || _        d S r1   )rœ   r�   rž   )r:   rœ   r�   rž   s       r&   r;   zAnnotAppearances.__init__l  s   € ð ˆŒØ ˆŒØˆŒ	ˆ	ˆ	r%   rB   c                 óÄ   — t          t          d¦  «        | j        i¦  «        }| j        �| j        |t          d¦  «        <   | j        �| j        |t          d¦  «        <   |S )a  
        Convert the :class:`.AnnotationAppearances` instance to a PDF
        dictionary.

        :return:
            A :class:`~.pdf_utils.generic.DictionaryObject` that can be plugged
            into the ``/AP`` entry of an annotation dictionary.
        z/NNz/Rz/D)r   r   rœ   r�   rž   )r:   Úress     r&   rL   zAnnotAppearances.as_pdf_objectv  sW   € õ ¥¨¡¤°´Ð<Ñ=Ô=ˆØŒ=Ð$Ø"&¤-ˆC•˜‘”ÑØŒ9Ð Ø"&¤)ˆC•˜‘”ÑØˆ
r%   r€   )	r   r   r   r   r   r   r;   r   rL   r$   r%   r&   r   r   W  s�   € € € € € ðð ð. .2Ø)-ð	ð àðð ˜>Ô*ðð �~Ô&ð	ð ð ð ðÐ/ð ð ð ð ð ð r%   r   c                   ó\   ‡ — e Zd Z	 d
dedee         fˆ fd„Zdefd„Zde	fd„Z
defd	„Zˆ xZS )r   NrS   rR   c                 ój   •— t          ¦   «                              ||¬¦  «         d| _        d | _        d S )N)rR   rS   F)r}   r;   Ú_resources_readyÚ_content_xobj_ref)r:   rS   rR   r~   s      €r&   r;   zAppearanceContent.__init__‰  s8   ø€ õ
 	‰Œ×Ò˜S¨ÐÑ0Ô0Ð0Ø %ˆÔØ;?ˆÔÐÐr%   rB   c                 ó†   — | j         }|€7| j        }|                      ¦   «         }|                     |¦  «        x| _         }|S )a  
        Register the content with the writer coupled to this instance, and
        cache the returned reference.

        This works by calling :meth:`.PdfContent.as_form_xobject`.

        :return:
            An indirect reference to the form XObject containing the content.
        )r¥   rX   rk   rs   )r:   Úxobj_refÚwrÚ	form_xobjs       r&   ÚregisterzAppearanceContent.register’  sI   € ð Ô)ˆØÐØÔ$ˆBØ×,Ò,Ñ.Ô.ˆIØ02·²¸iÑ0HÔ0HÐHˆDÔ" XØˆr%   c                 óJ   — |                       ¦   «         }t          |¬¦  «        S )a  
        Turn this content into an appearance dictionary for an annotation
        (or a form field widget), after rendering it.
        Only the normal appearance will be defined.

        :return:
            An instance of :class:`.AnnotAppearances`.
        )rœ   )rª   r   )r:   Ú	stamp_refs     r&   Úas_appearancesz AppearanceContent.as_appearances£  s"   € ð —M’M‘O”Oˆ	Ý yÐ1Ñ1Ô1Ð1r%   Ú
annot_dictc                 óœ   — |                       ¦   «                              ¦   «         |d<   	 |t          d¦  «        = dS # t          $ r Y dS w xY w)z¹
        Set this appearance content as the appearance of an annotation.

        :param annot_dict:
            The annotation dictionary to which the appearance should apply.
        z/APz/ASN)r­   rL   r   ÚKeyError)r:   r®   s     r&   Úapply_appearancez"AppearanceContent.apply_appearance±  sa   € ð !×/Ò/Ñ1Ô1×?Ò?ÑAÔAˆ
�5Ñð	à�8 E™?œ?Ð+Ð+Ð+øÝð 	ð 	ð 	ØˆDˆDð	øøøs   «= ½
AÁ
Ar1   )r   r   r   r   r   r   r;   r   rª   r   r­   r   r±   r�   r‚   s   @r&   r   r   ˆ  sº   ø€ € € € € ð )-ð@ð @à!ð@ð �nÔ%ð@ð @ð @ð @ð @ð @ð˜.ð ð ð ð ð"2Ð 0ð 2ð 2ð 2ð 2ðÐ+;ð ð ð ð ð ð ð ð r%   r   )r‹   r�   Úenumr   Útypingr   Úgenericr   r   r   r	   r
   r   Úlayoutr   Úreaderr   rS   r   Ú__all__r   rW   r   r.   r   r   r   r   r   r   r$   r%   r&   ú<module>r¸      sC  ðØ €€€Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð #Ð "Ð "Ð "Ð "Ð "Ø !Ð !Ð !Ð !Ð !Ð !Ø %Ð %Ð %Ð %Ð %Ð %ð	ð 	ð 	€ð/ð /ð /ð /ð /�4ñ /ô /ð /ðd	ð 	ð 	ð 	ð 	˜jñ 	ô 	ð 	ðð ð ð9ð 9ð 9ð 9ð 9ñ 9ô 9ð 9ðxJ
ð J
ð J
ð J
ð J
ñ J
ô J
ð J
ðZð ð ð ð �ñ ô ð ð &ð &ð &ð &ð &�jñ &ô &ð &ð2.ð .ð .ð .ð .ñ .ô .ð .ðb5ð 5ð 5ð 5ð 5˜
ñ 5ô 5ð 5ð 5ð 5r%   