
     h                      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        j        ej        j                  ZdZ ed
           G d de                      Z G d de          ZdS )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                 B   t                                          |           	 |d         }t          |t                    r*|                    d          s$|                    d          st          d          ddlm}  ||          |d<   d S # t          $ r Y d S 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       R/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/pdf_utils/text.pyr   zTextStyle.process_entries$   s    ,,,	V$Bb#&& F##'){{6':': )*  
 POOOOO"9"9""="=K 	 	 	DD	s   A*B 
BB)__name__
__module____qualname____doc__r   r   r   r   r   __annotations__r   intr   r   classmethodr   __classcell__r#   s   @r$   r   r      s         44#e/?  D
   
 Is "GXc]!!!     [        r   )x_aligny_alignr   c                   X    e Zd ZU dZdZeed<   	 dZee	j
                 ed<   	 dZeed<   dS )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   @   sc         AAL# =AOXf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.
    NF1style	resourcesboxc                     t                                          |||           || _        d | _        d x| _        | _        || _        |j                            |          | _	        dx| _
        | _        d S )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>   rE   r#   s         r$   rA   zTextBox.__init__`   sw     	6s;;;
488d1" :88@@788 4 4 4r.   c                 t   | j         }|                    |          }|j        | j        j        z  }|j        | j        j        z  }|j        }|j        rO| }| }| j        j        }	| j	        }
|	r||
z  }t          |          }n||
z  }t          |          }|d||fz  z  }n|dz  }t          |          }||fS )Ns	    %g %g Tds    T*)rG   shape	x_advancer<   r   	y_advancegraphics_opsuses_complex_positioningr5   r   abs)rJ   txtrG   shape_resultrM   rN   ops	newline_x	newline_yverticalr   extents               r$   put_string_linezTextBox.put_string_linep   s    &"((-- *TZ-AA	 *TZ-AA	'/ 	$"
I"
I z/HlG (W$	YW$	Y<9i"888CC6MC^^FF{r.   c                     | j         S )zZ
        :return:
            Text content of the text box, broken up into lines.
        )rC   rJ   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.
        )rB   r[   s    r$   contentzTextBox.content   s     }r.   c                    || _         d}d}| j        }g }| j        j        }|                    d          D ]x}|                     |          \  }}	t          t          |	                    }
|rt          ||
          }||z  }nt          ||
          }||z  }|	                    |           y|| _
        |                    d          | _        || _        || _        d S )Nr   
)rB   r   r<   r5   splitrY   r*   roundmaxappendrD   rC   rI   rH   )rJ   r^   natural_text_widthnatural_text_heightr   linesrW   linewrapped_linerX   rounded_extents              r$   r^   zTextBox.content   s      ,:+MM$'' 		' 		'D#'#7#7#=#= L& v//N /&)*=~&N&N#"g-""%();^%L%L"#w.#LL&&&&#%mmD111 3r.   c                 :    | j         }|j        |j        n|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   )rJ   r<   s     r$   r   zTextBox.leading   s      
"'-"7uU]Jr.   c                    | j         }|                     t          j        t	          d| j        z             | j                                                   | j        }| j	        }| j
        }| j         j        }| j         j        }|>t          j                            t                     }t"                              |          }|                    | j        ||          }g }	|j        r4|	                    d|j        | j        j        | j        j        fz             |	                    |                                           |	dd| j                            d          |j        |fz  gz  }	|rd||j        z  |dz  z
  ||j        z  fz  }
nd	||j        z  |z
  z  }
|	                    |
           |	                    | j                   |	                    d
           d                     |	          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   rE   rG   as_resourcer   rI   rH   r5   r4   r   MarginsuniformDEFAULT_TEXT_BOX_MARGINDEFAULT_BOX_LAYOUTsubstitute_marginsfitr>   r3   rd   widthheightas_cmencoder   x_scaley_scaleextendrD   join)rJ   r<   r   nat_text_widthnat_text_heightrW   
box_layoutmarginspositioningcommand_streamtext_cursor_starts              r$   renderzTextBox.render   s   
!&#.//"..00 	 	
 	
 	

 ,-/:+Z/
n,,-DEEG+>>wGGJ nnTX~OO  	!!*%tx~txGH   	k//11222~$$X..IJ
 	
  
	 + !44w{B+"55	/ ! !++"55?! 	/000d1222e$$$yy(((r.   )NNr;   )r%   r&   r'   r(   r2   r   r
   r   BoxConstraintsrA   rY   propertyr\   r^   setterr   r   r,   r-   s   @r$   r:   r:   X   s         -1/39 99 L)	9
 f+,9 9 9 9 9 9   8 # # X# 	 	 X	 ^4 4 ^44 	K 	K X	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_MIDrz   ry   r2   r:   r8   r.   r$   <module>r      s   3 3 ( ( ( ( ( ( ( (       0 0 0 0 0 0 4 4 4 4 4 4 $ $ $ $ $ $ L L L L L L L L L L M M M M M M M M . . . . . . $& & & & &! & & &R 0V/ * *   
   $    9   .i) i) i) i) i)j i) i) i) i) i)r.   