a
    [XhC                     @   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   sR	  ddl m}	m}
m}m}m} |j}|d }|d }|d }|}d| _|d dkrTg }||j	}| j
|||j 7  _
|d	kr|jd
kr|jdksJ d}| j|  |j }t||}nd}||| |d dkr|d }nt|d |j}|d	kr"|d	kr"td|j|d |  | }nx|d	krf|d	krftdt|j| ||  }|j| | | }n4t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|rL||d t| |f |r^d|| i}|j	stddd}d}g }| }g }d}d}d} | jjd	krdn| j g}!d}"|D ]\}#}$t|$tsp|$}%t|%| |  |%_!||%_
|
| |%|||||||	\}&}'}}}(}(d}|&du r*d}d}  q||& |&" |&#  }||&j$ |'rhd}d} |'} qd}q|$}|||7 }g }t%|||||})| j| |  }}*|}t&}+| j'dd },|}-d } }.}/t| j't|,kr| j'(  q|}g }0g }1t)|D ]H}|	| |)| j| | |||p(|/ g g g ddd\}2}'}}(}(}(|2du r\ddi} qN|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 ]}|* r| }6 qq|| |5gg g  nd}6nd }4 }}6|0|4 |6| dkr:t|+|6| }+|'du r qNq| jjd	kr`dn| j }"|| |1g g  |rq|/r|du rq|+t&krdn|+}7||77 }||*kr|*}d}.qn|"|!vr||"|!d  8 }|!|" q| ot|0|*k}8|8rJ|*|"8 }*|d dks2|#|d d k rd}/t+|0| }nqn8||!d 7 }t|!dkrrt|"|!d }"||"8 }d}.qqt|| j| | }d}d}9g }:t%|||||})|d d kr|) j!|j|d |  ||  7  _!n|) j!|||  7  _!|	| |)||||-||dddd\}&}};}(}(}(|&du r@g }:d} q|;}|}|:|& t|9|& }9|du rr|}q|d7 }||kr|sqq|t|*|97 }|:D ]}<|9|<_||< qd}d}|.r qԐqt,| |" |j	r|sd| _dd!dddg dfS ||_	|||7 }||  }|jd	kr<||_d}=n
|j| }=|j-d	krx|j-|jkrx|=|j-|j 7 }=|j-|_|ddd D ]$}|j.r| j|=7  _n qq|d dkr|D ]}>t/| |>|||dd" q|r| \}|#| || i}n| 	r
|#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_placeholdersZcolumn_widthZcolumn_countheightTpositionrelativeauto%ZpxFZ
column_gapnormalZ	font_sizer   )r   N)startZcolumn_spanallany)breakpage)discard	max_linesc                 S   s   g | ]}|  r|qS  )is_in_normal_flow).0childr   r   ]/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/weasyprint/layout/column.py
<listcomp>   s   z"columns_layout.<locals>.<listcomp>Zcolumn_fillZbalance   	directionrtl)r   N)
skip_stack)0blockr   r	   r
   r   r   styleZ	in_columnZcopy_with_childrenchildren
position_yZ
margin_topunitZpage_bottomZcontent_box_yvaluemaxr   widthr   minkeys	enumerateappendlencopycurrent_footnote_arear   margin_height
isinstancelistr   content_box_x
position_xZborder_heightZborder_box_yZmargin_bottom_create_column_boxr   Zexcluded_shapespopranger   sum_report_footnotesZ
min_height	is_columnr   )?contextboxZbottom_spacer$   containing_blockZpage_is_emptyZabsolute_boxesZfixed_boxesZadjoining_marginsr   r	   r
   r   r   r&   r,   countr   Zoriginal_bottom_spaceZheight_definedZempty_spaceZgapZcolumns_and_blocksZcolumn_childrenskipir   Z	next_pageZcurrent_position_yZnew_childrenZcolumn_skip_stackZ	last_loopZ
break_pageZfootnote_area_heightsZlast_footnotes_heightindexZcolumn_children_or_blockr%   	new_childZ	resume_at_
column_boxZ
max_heightZ
lost_spaceZoriginal_excluded_shapesZoriginal_page_is_emptyZstop_renderingZ	balancingZconsumed_heightsZ	new_boxesZnew_boxZin_flow_childrenZconsumed_heightZnext_boxZnext_box_heightZ
add_heightZeverything_fitsZmax_column_heightcolumnsZcolumn_next_pagecolumnZheight_differenceZabsolute_boxr   r   r   columns_layout	   s   

"




















&









rK   c                 C   sh   | j s
dS d}| j |kr6| | j d  |d7 }q|dkrd| jd| d d }|| j| d< dS )z4Report footnotes above the defined footnotes height.Nr   r    r   r!   )Zcurrent_page_footnotesr3   r4   Zreport_footnotereported_footnotes)r?   Zfootnotes_heightrL   extrar   r   r   r=     s    
r=   c                 C   s8   | j | |d}t|| d|_||_|  |_||_|S )z-Create a column box including given children.)r'   T)Zanonymous_fromr   r>   r,   r7   r8   r(   )r@   rA   r'   r,   r(   rH   r   r   r   r9     s    

r9   N)__doc__mathr   r   absoluter   percentr   r   rK   r=   r9   r   r   r   r   <module>   s       