o
    Zh0hC                     @   sL   d Z ddlmZmZ ddlmZ ddlmZmZ dd Z	dd	 Z
d
d ZdS )zLayout for columns.    )floorinf   )absolute_layout)
percentageresolve_percentagesc	           ?      C   s4	  ddl m}	m}
m}m}m} |j}|d }|d }|d }|}d| _|d dkr*g }||j	}| j
|||j 7  _
|d	kr^|jd
kr^|jdksLJ d}| j|  |j }t||}nd}||| |d dkrp|d }nt|d |j}|d	kr|d	krtd|j|d |  | }n:|d	kr|d	krtdt|j| ||  }|j| | | }ntdt|t|j| ||  }|j| | | }g }g }|r| nd\}t|j	|d |dD ],\}}|jd dkr|r||t| |f ||| f g }q||  q|r||d t| |f |r'd|| i}|j	s2ddd}d}g }| }g }d}d}d} | jjd	krIdn| j g}!d}"|D ]\}#}$t|$ts|$}%t|%| |  |%_!||%_
|
| |%|||||||	\}&}'}}}(}(d}|&du rd}d}  nQ||& |&" |&#  }||&j$ |'rd}d} |'} n2d}qS|$}|||7 }g }t%|||||})| j| |  }}*|}t&}+| j'dd },|}-d } }.}/	 t| j't|,kr| j'(  t| j't|,ks|}g }0g }1t)|D ]}|	| |)| j| | |||p|/ g g g ddd\}2}'}}(}(}(|2du r-ddi} nw|1|2 |'}dd |2j	D }3|3r|3d  |3d j
 | }4||4 }|r|	| |)t&||dg g g dddd }5|5j	D ]}|* rt| }6 nqg|| |5gg g  n	d}6nd }4 }}6|0|4 |6| dkrt|+|6| }+|'du r nq| jjd	krdn| j }"|| |1g g  |rn}|/r|du rnt|+t&krdn|+}7||77 }||*kr|*}d}.n]nZ|"|!vr||"|!d  8 }|!|" q| ot|0|*k}8|8r|*|"8 }*|d dks|#|d d k rd}/t+|0| }nn||!d 7 }t|!dkr1t|"|!d }"||"8 }d}.nqt|| j| | }d}d}9g }:	 t%|||||})|d d krm|) j!|j|d |  ||  7  _!n|) j!|||  7  _!|	| |)||||-||dddd\}&}};}(}(}(|&du rg }:d} n'|;}|}|:|& t|9|& }9|du r|}n|d7 }||kr|snqK|t|*|97 }|:D ]}<|9|<_||< qd}d}|.r nqSt,| |" |j	r|sd| _dd!dddg dfS ||_	|||7 }||  }|jd	kr||_d}=n|j| }=|j-d	kr0|j-|jkr0|=|j-|j 7 }=|j-|_|ddd D ]}|j.rF| j|=7  _q7 |d dkr^|D ]}>t/| |>|||dd" qP|ro| \}|#| || i}n| rv|#di}| jjd	kr|  j|!d 7  _|  j| j 8  _d| _|||g dfS )#zLay out a multi-column ``box``.r   )block_box_layoutblock_level_layoutblock_level_widthcollapse_marginremove_placeholderscolumn_widthcolumn_countheightTpositionrelativeauto%pxF
column_gapnormal	font_sizer   )r   N)startcolumn_spanallany)breakpage)discard	max_linesc                 S   s   g | ]}|  r|qS  )is_in_normal_flow).0childr    r    N/var/www/html/rh/venv/lib/python3.10/site-packages/weasyprint/layout/column.py
<listcomp>   s    z"columns_layout.<locals>.<listcomp>column_fillbalance   	directionrtl)r   N)
skip_stack)0blockr   r	   r
   r   r   style	in_columncopy_with_childrenchildren
position_y
margin_topunitpage_bottomcontent_box_yvaluemaxr   widthr   minkeys	enumerateappendlencopycurrent_footnote_arear   margin_height
isinstancelistr   content_box_x
position_xborder_heightborder_box_ymargin_bottom_create_column_boxr   excluded_shapespopranger!   sum_report_footnotes
min_height	is_columnr   )?contextboxbottom_spacer,   containing_blockpage_is_emptyabsolute_boxesfixed_boxesadjoining_marginsr   r	   r
   r   r   r.   r9   countr   original_bottom_spaceheight_definedempty_spacegapcolumns_and_blockscolumn_childrenskipir#   	next_pagecurrent_position_ynew_childrencolumn_skip_stack	last_loop
break_pagefootnote_area_heightslast_footnotes_heightindexcolumn_children_or_blockr-   	new_child	resume_at_
column_box
max_height
lost_spaceoriginal_excluded_shapesoriginal_page_is_emptystop_rendering	balancingconsumed_heights	new_boxesnew_boxin_flow_childrenconsumed_heightnext_boxnext_box_height
add_heighteverything_fitsmax_column_heightcolumnscolumn_next_pagecolumnheight_differenceabsolute_boxr    r    r$   columns_layout	   s$  

"



















 &


"




r   c                 C   sx   | j sdS d}| j |kr!| | j d  |d7 }| j |ks|dkr:| jd| d d }|| j| d< dS dS )z4Report footnotes above the defined footnotes height.Nr   r&   r   r)   )current_page_footnotesr@   rA   report_footnotereported_footnotes)rQ   footnotes_heightr   extrar    r    r$   rN     s   rN   c                 C   s8   | j | |d}t|| d|_||_|  |_||_|S )z-Create a column box including given children.)r1   T)anonymous_fromr   rP   r9   rD   rE   r2   )rR   rT   r1   r9   r2   ro   r    r    r$   rI     s   

rI   N)__doc__mathr   r   absoluter   percentr   r   r   rN   rI   r    r    r    r$   <module>   s      