o
    gi(                     @   s   d Z ddl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
 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 G dd deZdS )z
This file contains all the classes needed to perform layout of text-elements.
This includes; ChunkOfText, LineOfText, Paragraph and Heading
    N)Decimal)Color)HexColor)Font)	Rectangle)Hyphenation)	Alignment)
LineOfText)TextToLineSplitter)Pagec                ?       s  e Zd ZdZddeddededededddedddededejddddddededededddejejfd	e	d
e
je dedededededededededede
je de
jee	f dededede
je de
je de
je de
je de
je de
je d ed!ed"ed#ed$ed%ed&ed'ef> fd(d)Zd*efd+d,Zd-ed*efd.d/Zd0ed-ed*dfd1d2Zd3ed*e
je	 fd4d5Z  ZS )6	Paragraphu  
    A paragraph (from the Ancient Greek παράγραφος, parágraphos, "to write beside")
    is a self-contained unit of discourse in writing dealing with a particular point or idea.
    A paragraph consists of one or more sentences. Though not required by the syntax of any language,
    paragraphs are usually an expected part of formal writing, used to organize longer prose.
    NF000000r      	Helvetica   textbackground_colorborder_bottomborder_colorborder_leftborder_radius_bottom_leftborder_radius_bottom_rightborder_radius_top_leftborder_radius_top_rightborder_right
border_topborder_widthfixed_leadingfont
font_color	font_sizehorizontal_alignmenthyphenationmargin_bottommargin_leftmargin_right
margin_topmultiplied_leadingpadding_bottompadding_leftpadding_rightpadding_toprespect_newlines_in_textrespect_spaces_in_texttext_alignmentvertical_alignmentc                      s   t  jdi d|d|d|d|d|d|d|d|
d	|d
|d|d|	d|d|d|d|d|d|d|d|d|d|d|d|d|d|d| || _|| _|| _|tjtjtjtj	fv soJ || _
d | _d S )Nr   r   r    r/   r!   r   r   r   r   r   r   r   r   r   r   r   r+   r*   r(   r)   r&   r%   r#   r$   r'   r   r    )super__init___respect_newlines_in_text_respect_spaces_in_text_hyphenationr   LEFTCENTEREDRIGHT	JUSTIFIED_text_alignment_previous_lines_of_text) selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   	__class__r0   Y/home/ubuntu/.local/lib/python3.10/site-packages/borb/pdf/canvas/layout/text/paragraph.pyr2   "   s   "	


zParagraph.__init__returnc                 C   s   | j | j| j| j| j| j| j| j| j| j	| j
| j| j| j| j| j| j| j| j| j| j| j| j| j| j| j| jg}d}|D ]}t|}|||d> A dA d N }q<|d d S )NiMr   iM[l   4~2 i i6)_text_font
_font_size_vertical_alignment_horizontal_alignment_font_color_border_top_border_right_border_bottom_border_left_border_radius_top_left_border_radius_top_right_border_radius_bottom_right_border_radius_bottom_left_border_color_border_width_padding_top_padding_right_padding_bottom_padding_left_margin_top_margin_right_margin_bottom_margin_left_multiplied_leading_fixed_leading_background_colorhash)r<   attrattr_hash_for_layoutahr0   r0   r?   __hash__u   sB   zParagraph.__hash__available_spacec           	         s
   j d usJ  fdd |D } jtjkrtj|d _ j d us&J  j } jd ur3| j9 } jd ur=| j7 }|t| }t	d}t
|D ]%\}}|t| | |  |d |  | |}t|| }qK| _t| | |  | ||S )Nc                    s2   g | ]}t | j j j j j j jd qS ))r   r    r   r!   r'   r.   r   )r	   rC   rD   rG   r:   rZ   r[   ).0xr<   r0   r?   
<listcomp>   s    z.Paragraph._get_content_box.<locals>.<listcomp>r   r   )rD   _split_textr:   r   r9   r6   rZ   r[   lenr   	enumerate_get_content_boxr   get_xget_y
get_height	get_widthmaxr;   )	r<   rc   lines_of_textline_heightra   willboxr0   rf   r?   rl      sF   






zParagraph._get_content_boxpagec              	   C   s  |  | | jd usJ | j}| jd ur|| j9 }| jd ur#|| j7 }| |r1d}|d|  | jd us8J t| dt|t	| j dk rP| 
| J t| jD ]\}}||t| | |  |d |  | | qU| |r|d d S d S )Nr   z
/Standard <</MCID %d>>
BDC
   Fr   z
EMC
)rl   rD   rZ   r[   _needs_to_be_taggedappend_to_content_streamr;   roundro   rj   ri   rk   paintr   rm   rn   rp   )r<   rx   rc   rs   	next_mcidru   rv   r0   r0   r?   _paint_content_box   sB   








zParagraph._paint_content_boxbounding_boxc              	   C   s*   t j||  |  |  | j| j| jdS )N)r   r   r    r   r"   respect_newlinesrespect_spaces)r
   text_to_linesget_fontget_font_sizeget_textr5   r3   r4   )r<   r   r0   r0   r?   ri     s   zParagraph._split_text)__name__
__module____qualname____doc__r   r   r   r6   TOPstrtypingOptionalr   boolUnionr   r   r2   intrb   r   rl   r   r   Listri   __classcell__r0   r0   r=   r?   r      s    	
 S$A ,r   )r   r   decimalr   borb.pdf.canvas.color.colorr   r   borb.pdf.canvas.font.fontr   "borb.pdf.canvas.geometry.rectangler   .borb.pdf.canvas.layout.hyphenation.hyphenationr   %borb.pdf.canvas.layout.layout_elementr   (borb.pdf.canvas.layout.text.line_of_textr	   1borb.pdf.canvas.layout.text.text_to_line_splitterr
   borb.pdf.page.pager   r   r0   r0   r0   r?   <module>   s   