
    Wwg                      f   d Z ddlmZmZ ddl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 ddlmZmZ dd	lmZ  ed
       G d de             Z ej,                  ej.                  j0                  ej.                  j0                        ZdZ ed
       G d de             Z G d de      Zy)z-Utilities related to text rendering & layout.    )	dataclassfield)Optional)ConfigurableMixin)ConfigurationError)layout)
PdfContentPdfResourcesResourceType)FontEngineFactorySimpleFontEngineFactory)pdf_nameT)frozenc                        e Zd ZU dZ eej                        Zee	d<   	 dZ
ee	d<   	 dZee   e	d<   	 e fd       Z xZS )		TextStylez*Container for basic test styling settings.)default_factoryfont
   	font_sizeNleadingc                     t         |   |       	 |d   }t        |t              r"|j	                  d      s|j	                  d      st        d      ddlm}  ||      |d<   y # t        $ r Y y w xY w)Nr   z.otfz.ttfz;'font' must be a path to an OpenType or TrueType font file.r   )GlyphAccumulatorFactory)	superprocess_entries
isinstancestrendswithr   pyhanko.pdf_utils.font.opentyper   KeyError)clsconfig_dictfcr   	__class__s       M/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/pdf_utils/text.pyr   zTextStyle.process_entries$   sy    ,	V$Bb#&F#r{{6':(* 
 P"9""=K 		s   AA& &	A21A2)__name__
__module____qualname____doc__r   r   r   r   r   __annotations__r   intr   r   classmethodr   __classcell__r#   s   @r$   r   r      s`    4#/??D
 
 Is "GXc]!      r   )x_aligny_alignr   c                   Z    e Zd ZU dZdZeed<   	 dZee	j                     ed<   	 dZeed<   y)TextBoxStylez7Extension of :class:`.TextStyle` for use in text boxes.r   border_widthNbox_layout_ruleFvertical_text)r%   r&   r'   r(   r3   r*   r)   r4   r   r   SimpleBoxLayoutRuler5   bool r.   r$   r2   r2   @   sB    AL# =AOXf889@  M4r.   r2   c                        e Zd ZdZ	 	 	 ddedee   deej                     f fdZ	d Z
ed        Zed        Zej                  d	        Zed
        Zd Z xZS )TextBoxzImplementation of a text box that implements the :class:`.PdfContent`
    interface.

    .. note::
        Text boxes currently don't offer automatic word wrapping.
    style	resourcesboxc                     t         |   |||       || _        d | _        d x| _        | _        || _        |j                  j                  |      | _	        dx| _
        | _        y )N)writerr=   r   )r   __init__r;   _content_content_lines_wrapped_lines	font_namer   create_font_enginefont_engine_nat_text_height_nat_text_width)selfr;   r?   r<   r=   rD   r#   s         r$   r@   zTextBox.__init__`   se     	6s;
488d1" ::88@788 4r.   c                    | j                   }|j                  |      }|j                  | j                  j                  z  }|j
                  | j                  j                  z  }|j                  }|j                  rY| }| }| j                  j                  }	| j                  }
|	r||
z  }t        |      }n||
z  }t        |      }|d||fz  z  }||fS |dz  }t        |      }||fS )Ns	    %g %g Tds    T*)rF   shape	x_advancer;   r   	y_advancegraphics_opsuses_complex_positioningr5   r   abs)rI   txtrF   shape_resultrL   rM   ops	newline_x	newline_yverticalr   extents               r$   put_string_linezTextBox.put_string_linep   s    &&"((- **TZZ-A-AA	 **TZZ-A-AA	''//"
I"
I zz//HllGW$	YW$	Y<9i"888C
 F{ 6MC^FF{r.   c                     | j                   S )zZ
        :return:
            Text content of the text box, broken up into lines.
        )rB   rI   s    r$   content_lineszTextBox.content_lines   s     """r.   c                     | j                   S )z
        :return:
            The actual text content of the text box.
            This is a modifiable property.

            In textboxes that don't have a fixed size, setting this property
            can cause the text box to be resized.
        )rA   rZ   s    r$   contentzTextBox.content   s     }}r.   c                    || _         d}d}| j                  }g }| j                  j                  }|j	                  d      D ]`  }| j                  |      \  }}	t        t        |	            }
|rt        ||
      }||z  }nt        ||
      }||z  }|j                  |       b || _
        |j	                  d      | _        || _        || _        y )Nr   
)rA   r   r;   r5   splitrX   r*   roundmaxappendrC   rB   rH   rG   )rI   r]   natural_text_widthnatural_text_heightr   linesrV   linewrapped_linerW   rounded_extents              r$   r]   zTextBox.content   s      ,,::++MM$' 		'D#'#7#7#= L& v/N&)*=~&N#"g-"%();^%L"#w.#LL&		' $%mmD11 3r.   c                 b    | j                   }|j                  |j                  S |j                  S )z
        :return:
            The effective leading value, i.e. the
            :attr:`~.TextStyle.leading` attribute of the associated
            :class:`.TextBoxStyle`, or :attr:`~.TextStyle.font_size` if
            not specified.
        )r;   r   r   )rI   r;   s     r$   r   zTextBox.leading   s)     

"'--"7uJU]]Jr.   c                 n   | j                   }| j                  t        j                  t	        d| j
                  z         | j                  j                                | j                  }| j                  }| j                  }| j                   j                  }| j                   j                  }|8t        j                  j                  t               }t"        j%                  |      }|j'                  | j(                  ||      }g }	|j*                  rI|	j-                  d|j*                  | j(                  j.                  | j(                  j0                  fz         |	j-                  |j3                                |	dd| j
                  j5                  d      |j6                  |fz  gz  }	|r(d||j8                  z  |dz  z
  ||j:                  z  fz  }
nd	||j:                  z  |z
  z  }
|	j-                  |
       |	j=                  | j>                         |	j-                  d
       djA                  |	      S )N/)categorynamevalues   q %g w 0 0 %g %g re S Qs   BTs   /%s %d Tf %d TLlatin1s   %g %g Td   s   0 %g Tds   ET    )!r;   set_resourcer   FONTr   rD   rF   as_resourcer   rH   rG   r5   r4   r   MarginsuniformDEFAULT_TEXT_BOX_MARGINDEFAULT_BOX_LAYOUTsubstitute_marginsfitr=   r3   rc   widthheightas_cmencoder   x_scaley_scaleextendrC   join)rI   r;   r   nat_text_widthnat_text_heightrV   
box_layoutmarginspositioningcommand_streamtext_cursor_starts              r$   renderzTextBox.render   s    

!&&#./""..0 	 	

 ,,--//::++ZZ//
nn,,-DEG+>>wGJ nnTXX~O !!*%%txx~~txxGH 	k//12~~$$X.IJ
 	
  + !4!44w{B+"5"55	/ ! !++"5"55?! 	/0d112e$yy((r.   )NNF1)r%   r&   r'   r(   r2   r   r
   r   BoxConstraintsr@   rX   propertyr[   r]   setterr   r   r,   r-   s   @r$   r:   r:   X   s     -1/399 L)	9
 f++,9 8 # # 	 	 ^^4 44 	K 	K:)r.   r:   N)r(   dataclassesr   r   typingr   pyhanko.config.apir   pyhanko.config.errorsr   pyhanko.pdf_utilsr   pyhanko.pdf_utils.contentr	   r
   r   pyhanko.pdf_utils.fontr   r   pyhanko.pdf_utils.genericr   r   r6   AxisAlignment	ALIGN_MIDry   rx   r2   r:   r8   r.   r$   <module>r      s    3 (  0 4 $ L L M . $&! & &R 0V//  **  ** 
   $9  .i)j i)r.   