
    Csi                         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       G d de             Z G d de      Zy)    )	dataclass)datetime)OptionalN)layout)LayoutError)DEFAULT_BOX_LAYOUTTextBoxTextBoxStyle)BasePdfFileWriter   )	BaseStampBaseStampStyle	TextStampTextStampStyleT)frozenc                       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Zy)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                      t        || ||      S )N)r   styler   r   )r   )selfr   r   r   s       ^/var/www/python-projects/worksol/worksolenv/lib/python3.12/site-packages/pyhanko/stamp/text.pycreate_stampzTextStampStyle.create_stamp7   s     3K
 	
    )__name__
__module____qualname____doc__r
   r   __annotations__r   r   r   SimpleBoxLayoutRuler   strr   r   BoxConstraintsdictr    r    r   r   r      s     $0>NL1 BF(6#=#=>E J 3c2
!
 ""
 	

 

r    c                   j     e Zd ZdZ	 	 d
dedeej                     f fdZd Z	d Z
d Zd Zd	 Z xZS )r   zf
    Class that renders a text stamp as specified by an instance
    of :class:`.TextStampStyle`.
    r   r   c                 F    t         |   |||       || _        d | _        y )N)r   r   r   )super__init__r   text_box)r   r   r   r   r   	__class__s        r   r.   zTextStamp.__init__H   s(     	Sf=&+/r    c                     t        j                  t        j                               }d|j	                  | 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   r3   s     r   get_default_text_paramsz!TextStamp.get_default_text_paramsT   s=     \\W2245"++djj99:
 	
r    c                    t        | j                  j                  | j                  | j                  d       x| _        }| j                         }| j                  |j                  | j                         	 | j                  j                  |z  }||_        |j                         S # t        $ r!}t        d|j                  d    d      d }~ww xY w)N)r   	resourcesr   zStamp text parameter 'r   z' is missing)r	   r   r   r   r:   r/   r8   r   updater   KeyErrorr   argscontentrender)r   tb_text_paramstextes        r   _text_layoutzTextStamp._text_layoutc   s    $JJ%%;;nn	
 	
 335' 0 01	P::((<7D 
 yy{  	P 6qvvaykNOO	Ps   7B' '	C0CCc                     | j                         }| j                  j                  }|g|j                  |j                  ffS N)rD   r/   r   widthheight)r   text_commandsinn_boxs      r   _inner_layout_natural_sizez$TextStamp._inner_layout_natural_sizex   s9    ))+--## ???r    c                 >    | j                   j                  xs t        S rF   )r   r   r   )r   s    r   _inner_content_layout_rulez$TextStamp._inner_content_layout_rule   s    zz..D2DDr    c                    dg}| j                         \  }\  }}| j                         }| j                  }|j                  |||      }|j	                  |j                                |j                  |       |j	                  d       |S )N   q   Q)rK   rM   r   fitappendas_cmextend)r   command_streaminn_commands	inn_width
inn_heightinner_layoutbboxinn_positions           r   _render_inner_contentzTextStamp._render_inner_content   s     ++-	
 668xx $''iDl0023l+d#r    )NN)r!   r"   r#   r$   r   r   r   r(   r.   r8   rD   rK   rM   r\   __classcell__)r0   s   @r   r   r   B   sM     /3
0!
0
 f++,
0
*@Er    )dataclassesr   r   typingr   r5   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   <module>rf      s]    !    $ 0 L L 6 +(
) $.
^ .
 .
bW	 Wr    