o
    vh                     @   s   d dl mZ d dlmZ d dlmZ d dlZd dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZ d	d
lmZmZ ddgZeddG dd deZG dd deZdS )    )	dataclass)datetime)OptionalN)layout)LayoutError)DEFAULT_BOX_LAYOUTTextBoxTextBoxStyle)BasePdfFileWriter   )	BaseStampBaseStampStyleTextStampStyle	TextStampT)frozenc                   @   sn   e Zd ZU dZe Zeed< 	 dZee	j
 ed< 	 dZeed< 	 dZeed< 	 d	ed
e	jdeddfddZdS )r   z
    Style for text-based stamps.

    Roughly speaking, this stamp type renders some predefined (but parametrised)
    piece of text inside a text box, and possibly applies a background to it.
    text_box_styleNinner_content_layoutz%(ts)s
stamp_textz%Y-%m-%d %H:%M:%S %Ztimestamp_formatwriterboxtext_paramsreturnr   c                 C   s   t || ||dS )N)r   styler   r   )r   )selfr   r   r    r   P/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pyhanko/stamp/text.pycreate_stamp7   s   zTextStampStyle.create_stamp)__name__
__module____qualname____doc__r	   r   __annotations__r   r   r   SimpleBoxLayoutRuler   strr   r
   BoxConstraintsdictr   r   r   r   r   r      s&   
 		c                       s^   e Zd ZdZ		ddedeej f fddZdd Z	d	d
 Z
dd Zdd Zdd Z  ZS )r   zf
    Class that renders a text stamp as specified by an instance
    of :class:`.TextStampStyle`.
    Nr   r   c                    s"   t  j|||d || _d | _d S )N)r   r   r   )super__init__r   text_box)r   r   r   r   r   	__class__r   r   r(   H   s   
zTextStamp.__init__c                 C   s"   t jt d}d|| jjiS )aQ  
        Compute values for the default string interpolation parameters
        to be applied to the template string specified in the stamp
        style. This method does not take into account the ``text_params``
        init parameter yet.

        :return:
            A dictionary containing the parameters and their values.
        )tzts)r   nowtzlocalget_localzonestrftimer   r   )r   r-   r   r   r   get_default_text_paramsT   s   
z!TextStamp.get_default_text_paramsc              
   C   s   t | jj| j| jd d | _}|  }| jd ur|| j z| jj	| }W n t
y= } ztd|jd  dd }~ww ||_| S )N)r   	resourcesr   zStamp text parameter 'r   z' is missing)r   r   r   r   r3   r)   r2   r   updater   KeyErrorr   argscontentrender)r   tb_text_paramstexter   r   r   _text_layoutc   s"   
zTextStamp._text_layoutc                 C   s"   |   }| jj}|g|j|jffS N)r=   r)   r   widthheight)r   text_commandsinn_boxr   r   r   _inner_layout_natural_sizex   s   z$TextStamp._inner_layout_natural_sizec                 C   s   | j jptS r>   )r   r   r   )r   r   r   r   _inner_content_layout_rule   s   z$TextStamp._inner_content_layout_rulec                 C   sX   dg}|   \}\}}|  }| j}||||}||  || |d |S )N   q   Q)rC   rD   r   fitappendas_cmextend)r   command_streaminn_commands	inn_width
inn_heightinner_layoutbboxinn_positionr   r   r   _render_inner_content   s   

zTextStamp._render_inner_content)NN)r   r   r    r!   r
   r   r   r%   r(   r2   r=   rC   rD   rR   __classcell__r   r   r*   r   r   B   s    	)dataclassesr   r   typingr   r/   pyhanko.pdf_utilsr   pyhanko.pdf_utils.layoutr   pyhanko.pdf_utils.textr   r   r	   pyhanko.pdf_utils.writerr
   baser   r   __all__r   r   r   r   r   r   <module>   s    1