Ë
    £ëiA  ã                   ó¾   — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZ d„ Zd„ Zdd„Z G d„ de«      Z G d„ d«      Zy)aa  Transform a "before layout" box tree into an "after layout" tree.

Break boxes across lines and pages; determine the size and dimension of each
box fragement.

Boxes in the new tree have *used values* in their ``position_x``,
``position_y``, ``width`` and ``height`` attributes, amongst others.

See https://www.w3.org/TR/CSS21/cascade.html#used-value

é    )Údefaultdict)Úpartial)Úinfé   )ÚboxesÚbuild)ÚPROGRESS_LOGGERé   )Úabsolute_box_layoutÚabsolute_layout)Úlayout_backgrounds)Úblock_level_layout)Úmake_all_pagesÚmake_margin_boxesc                 ój  — g | _         |j                  d   }|dk(  rd}nJ|dk(  rd}nB|dk(  r|j                  d   dk(  }n*|d	k(  r|j                  d   d
k(  }n|j                  d   dk(  }d}d|j                  «       d   dœ}dgddgidhgg f}ddg g dœ}| j                   j                  |||||f«       y)zoInitialize ``context.page_maker``.

    Collect the pagination's states required for page based counters.

    Úbreak_beforeÚrightTÚleftFÚrectoÚ	directionÚltrÚversoÚrtlNÚanyr   )ÚbreakÚpageÚpages)Úcontent_changedÚpages_wantedÚanchorsÚcontent_lookups)Ú
page_makerÚstyleÚpage_valuesÚappend)ÚcontextÚroot_boxÚ
page_breakÚ
right_pageÚ	resume_atÚ	next_pageÚ
page_stateÚremake_states           úZ/var/www/html/chat/reports/venv/lib/python3.12/site-packages/weasyprint/layout/__init__.pyÚinitialize_page_makerr/      sü   € ð €GÔð —‘ Ñ/€Jð �WÒØ‰
Ø	�vÒ	Ø‰
Ø	�wÒ	Ø—^‘^ KÑ0°EÑ9‰
Ø	�wÒ	Ø—^‘^ KÑ0°EÑ9‰
à—^‘^ KÑ0°EÑ9ˆ
Ø€IØ¨×)=Ñ)=Ó)?ÀÑ)BÑC€Ið 
ˆØ	�1�#ˆØ
ˆˆØ
ð€Jð !ØØØñ	€Lð ×Ñ×ÑØ�9˜j¨*°lðDõ Eó    c              #   ó  K  — |D ]ƒ  }|j                   D ]r  }t        |t        j                  «      r|j	                  «       }g }t        | |||t         d¬«      \  }}|–— |sŒOg }|D ]  }t        | |||t         d¬«       Œ |}|rŒ$Œt Œ… y­w)zBLay out and yield fixed boxes of ``pages`` on ``containing_page``.N)Úbottom_spaceÚ
skip_stack)Úfixed_boxesÚ
isinstancer   ÚReplacedBoxÚcopyr   r   r   )	r&   r   Úcontaining_pager   ÚboxÚabsolute_boxesÚabsolute_boxÚ_Únew_absolute_boxess	            r.   Úlayout_fixed_boxesr>   N   s±   è ø€ àò 4ˆØ×#Ñ#ò 	4ˆCô ˜#œu×0Ñ0Ô1Ø—h‘h“j�ð  ˆNÜ1Ø˜˜o¨~Ü!˜T¨dô4‰OˆL˜!ð ÒÚ Ø%'Ð"Ø)ò <�CÜ#Ø  oÐ7IÜ&) T°dö<ð<ð "4�ó !ñ	4ñ4ùs   ‚A BÁ##BÂBc           
   #   ó(  K  — t        ||«       g }g }d}t        |«      D ]¶  }|dkD  r+t        j                  d|«       |j	                  «       |_        |}|dk(  r|j
                  j	                  «       }t        t        ||| |«      «      }t        |«      }d}	d}
|j                  D ]'  }|\  }}}}}|d   }|g|d<   |d   rd}	|d   sŒ#||k7  }
Œ) |	rŒ³|
rŒ¶ n g }g }g }t        |«      D �]‡  \  }}|j                  |dz      \  }}}}}|d   }|j                  «       D �]P  }|j                  ro|j                  j                  d	«      r|}n |j                  j                  d
«      r|}n|}|j                  |v rd|_        n|j!                  |j                  «       |j"                  r|j$                  j&                  j)                  «       D ]X  \  \  }}}|j"                  |k(  sŒ|dk7  sŒ|dk(  r|j                  sŒ1|j+                  |«       |dk(  sŒH|j                  |_        ŒZ |j,                  }|s�Œ|dk7  s�Œ!|D ]+  }|\  }}|j,                  |   |dz      j!                  |«       Œ- �ŒS �ŒŠ t        |«      D �]  \  }}g }|j.                  \  }} |j1                  t3        ||d| |«      «       |j1                  |j.                  «       |j1                  t3        |||dz   d |«      «       ||_        |dz   |_        |j                  |j4                     d   }!|f|_        | j.                  r|xj.                  | fz  c_        |xj.                  t7        t9        |||!«      «      z  c_        t;        ||j<                  «       |–— �Œ y­w)a¦  Lay out the whole document.

    This includes line breaks, page breaks, absolute size and position for all
    boxes. Page based counters might require multiple passes.

    :param root_box:
        Root of the box tree (formatting structure of the HTML). The page boxes
        are created from that tree, this structure is not lost during
        pagination.
    :returns:
        A list of laid out Page objects.

    r   z+Step 5 - Creating layout - Repagination #%dFr
   r   r   Tr   z::beforez::afterÚ Úcontentzbookmark-labelÚnoneNé   )r/   Úranger	   Úinfor7   Ú	footnotesÚlistr   Úlenr"   Ú	enumerateÚdescendantsÚbookmark_labelÚelement_tagÚendswithÚelementr%   Úmissing_linkÚtarget_collectorÚcounter_lookup_itemsÚitemsÚparse_againÚ
string_setÚchildrenÚextendr>   Úcurrent_pageÚtupler   r   Úget_image_from_uri)"Úhtmlr'   r&   Ú	max_loopsr   Úoriginal_footnotesÚactual_total_pagesÚloopÚinitial_total_pagesÚreloop_contentÚreloop_pagesÚ	page_datar<   r,   r-   Úpage_counter_valuesÚwatch_elementsÚwatch_elements_beforeÚwatch_elements_afterÚir   ÚchildÚ	checklistr9   Ú	css_tokenÚitemÚstring_setsrT   Ústring_nameÚtextÚroot_childrenÚrootÚfootnote_areaÚstates"                                     r.   Úlayout_documentrs   g   sÕ  è ø€ ô ˜' 8Ô,Ø€EØÐØÐä�iÓ ò ˆØ�!Š8Ü× Ñ Ø=¸tôEà 2× 7Ñ 7Ó 9ˆGÔà0ÐØ�1Š9Ø!(×!2Ñ!2×!7Ñ!7Ó!9ÐÜ”^ G¨X°t¸UÓCÓDˆÜ  ›ZÐð ˆØˆØ ×+Ñ+ò 	IˆIà09Ñ-ˆAˆq�!�Z Ø",¨Q¡-ÐØ,>Ð+?Ð Ñ(ØÐ-Ò.Ø!%�Ø˜NÓ+Ø2Ð6HÑH‘ð	Iò ¢lÙð7ðF €NØÐØÐÜ˜UÓ#ó %F‰ˆˆ4à!(×!3Ñ!3°A¸±EÑ!:Ñˆˆ1ˆa�˜QØ(¨™mÐà×%Ñ%Ó'ó  	FˆEà×#Ò#Ø×$Ñ$×-Ñ-¨jÔ9Ø 5‘IØ×&Ñ&×/Ñ/°	Ô:Ø 4‘Ià .�IØ—=‘= IÑ-Ø+-�EÕ(à×$Ñ$ U§]¡]Ô3à×!Ò!à×0Ñ0×EÑE×KÑKÓMòFÑ*Ñ$�S˜) dà×)Ñ)¨SÓ0°YÀ)Ó5KØ%Ð)9Ò9Ø$)×$8Ò$8à$Ø×(Ñ(Ð)<Ô=ð %Ð(8Ó8Ø36×3EÑ3E˜EÕ0ðFð  ×*Ñ*ˆKÛ˜{¨fÔ4Ø"-ò F�JØ(2Ñ%�K Ø×&Ñ& {Ñ3°A°a±CÑ8×?Ñ?ÀÕEòFò= 	Fð%FôP ˜UÓ#ó ‰ˆˆ4ØˆØ"Ÿm™mÑˆˆmØ×ÑÔ/°¸¸rÀ¸ÀDÓIÔJØ×Ñ˜TŸ]™]Ô+Ø×ÑÔ/°¸¸qÀ1¹u¸v¸ÈÓMÔNØ%ˆŒØ  1™uˆÔð ×"Ñ" 7×#7Ñ#7Ñ8¸Ñ;ˆØ˜ˆŒØ×!Ò!Ø�MŠM˜mÐ-Ñ-�MØ�ŠœÔ0°¸$ÀÓFÓGÑG�Ü˜4 ×!;Ñ!;Ô<ØŒ
ñ!ùs8   ‚CNÃ		NÃNÃDNÇ&NÇ,(NÈ!NÈ8NÈ?ENc                   ó   — e Zd ZdZd„ Zy)ÚFakeListu)   List in which you canâ€™t append objects.c                  ó   — y ©N© )Úselfrk   s     r.   r%   zFakeList.appendÝ   s   € Ør0   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   rx   r0   r.   ru   ru   Û   s
   „ Ù3ór0   ru   c                   ó¬   — e Zd Zd„ Zd„ Zed„ «       Zed„ «       Zej                  d„ «       Zdd„Z
dd„Zd	„ Zd
„ Zd„ Zdd„Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚLayoutContextc                 óh  — || _         t        || ¬«      | _        || _        || _        || _        g | _        i | _        g | _        i | _	        g | _
        g | _        d | _        d | _        t        d„ «      | _        t        d„ «      | _        d | _        d| _        i | _        d| _        i | _        i | _        y )N)r&   c                  ó    — t        t        «      S rw   ©r   rG   rx   r0   r.   ú<lambda>z(LayoutContext.__init__.<locals>.<lambda>ñ   s   € ¬k¼$Ó.?€ r0   c                  ó    — t        t        «      S rw   r‚   rx   r0   r.   rƒ   z(LayoutContext.__init__.<locals>.<lambda>ò   s   € ´KÄÓ4E€ r0   F)Ú	style_forr   rY   Úfont_configÚcounter_stylerP   Ú_excluded_shapes_root_boxesÚ_excluded_shapesrF   Úpage_footnotesÚcurrent_page_footnotesÚreported_footnotesÚcurrent_footnote_areaÚpage_bottomr   rT   Úrunning_elementsrW   Úforced_breakÚbroken_out_of_flowÚ	in_columnÚtablesÚdictionaries)ry   r…   rY   r†   r‡   rP   s         r.   Ú__init__zLayoutContext.__init__â   s»   € à"ˆŒÜ")Ð*<ÀdÔ"KˆÔØ&ˆÔØ*ˆÔØ 0ˆÔØ+-ˆÔ(Ø "ˆÔØˆŒØ ˆÔØ&(ˆÔ#Ø"$ˆÔØ%)ˆÔ"ØˆÔÜ%Ñ&?Ó@ˆŒÜ +Ñ,EÓ FˆÔØ ˆÔØ!ˆÔØ"$ˆÔØˆŒð ˆŒØˆÕr0   c                 ó@   — | j                  | j                  |z
  |«      S rw   )Ú	overflowsrŽ   )ry   r2   Ú
position_ys      r.   Úoverflows_pagezLayoutContext.overflows_pageü   s   € Ø�~‰~˜d×.Ñ.°Ñ=¸zÓJÐJr0   c                 ó   — || dz  kD  S )Ng0¸D   ð?rx   )Úbottomr˜   s     r.   r—   zLayoutContext.overflowsÿ   s   € ð ˜F hÑ/Ñ/Ð/r0   c                 ó:   — | j                   | j                  d      S ©Néÿÿÿÿ©r‰   rˆ   )ry   s    r.   Úexcluded_shapeszLayoutContext.excluded_shapes  s   € à×$Ñ$ T×%EÑ%EÀbÑ%IÑJÐJr0   c                 ó<   — || j                   | j                  d   <   y r�   rŸ   )ry   r    s     r.   r    zLayoutContext.excluded_shapes	  s   € àFUˆ×Ñ˜d×>Ñ>¸rÑBÒCr0   Nc                 óž   — || j                   vsJ ‚| j                   j                  |«       || j                  vr|€g n|| j                  |<   y y rw   )rˆ   r%   r‰   )ry   r'   Únew_lists      r.   Úcreate_block_formatting_contextz-LayoutContext.create_block_formatting_context  sT   € Ø˜t×?Ñ?Ñ?Ð?Ð?Ø×(Ñ(×/Ñ/°Ô9Ø˜4×0Ñ0Ñ0Ø4<Ð4D©bÈ(ˆD×!Ñ! (Ò+ð 1r0   c                 ó¢  — |r•|j                   d   dk(  rƒ| j                  rw|j                  «       |j                  z   }t	        | j                  D �cg c]  }|j
                  |j                  «       z   ‘Œ! c}|gz   «      }|xj                  ||z
  z  c_        | j                  j                  | j                  j                  «       «       y c c}w )NÚheightÚauto)
r#   r    Úcontent_box_yr¦   Úmaxr˜   Úmargin_heightr‰   Úpoprˆ   )ry   r'   Ú
box_bottomÚshapeÚmax_shape_bottoms        r.   Úfinish_block_formatting_contextz-LayoutContext.finish_block_formatting_context  s¹   € á˜Ÿ™ xÑ0°FÒ:¸t×?SÒ?SØ!×/Ñ/Ó1°H·O±OÑCˆJÜ"à!×1Ñ1ö$3àð × Ñ  5×#6Ñ#6Ó#8Ó8ò$3à6@°\ñ$Bó  CÐð �OŠOÐ/°*Ñ<Ñ<�OØ×Ñ×!Ñ! $×"BÑ"B×"FÑ"FÓ"HÕIùò	$3s   Á$Cc                 ó8   — | j                  |t        «       «       y rw   )r¤   ru   ©ry   r'   s     r.   Úcreate_flex_formatting_contextz,LayoutContext.create_flex_formatting_context  s   € Ø×,Ñ,¨X´x³zÕBr0   c                 ó&   — | j                  |«       y rw   )r¯   r±   s     r.   Úfinish_flex_formatting_contextz,LayoutContext.finish_flex_formatting_context   s   € Ø×,Ñ,¨XÕ6r0   c                 óD   — ||| j                   d   |f| j                  |<   y r�   )rˆ   r‘   )ry   Únew_boxr9   Úcontaining_blockr*   s        r.   Úadd_broken_out_of_flowz$LayoutContext.add_broken_out_of_flow#  s*   € àÐ! 4×#CÑ#CÀBÑ#GÈð,Tˆ×Ñ Ò(r0   c                 ó>   — | j                  | j                  |||«      S )z!Resolve value of string function.)Úget_string_or_element_forrT   ©ry   r   ÚnameÚkeywords       r.   Úget_string_set_forz LayoutContext.get_string_set_for'  s"   € à×-Ñ-Ø�O‰O˜T 4¨ó2ð 	2r0   c                 ó>   — | j                  | j                  |||«      S )z"Resolve value of element function.)rº   r�   r»   s       r.   Úget_running_element_forz%LayoutContext.get_running_element_for,  s$   € à×-Ñ-Ø×!Ñ! 4¨¨wó8ð 	8r0   c                 ó¸  — | j                   ||   v r–||   | j                      d   }||   | j                      d   }|dk(  r|S |dk(  rS|}|r\|j                  d   dk7  r |j                  d   D ]  \  }}	||k(  sŒ|c S  |j                  r|j                  d   }ŒPn|dk(  r|S |dk(  ry	t        | j                   d
z
  dd«      D ]  }
|
||   v sŒ||   |
   d   c S  y	)aZ  Resolve value of string or element function.

        We'll have something like this that represents all assignments on a
        given page:

        {1: ['First Header'], 3: ['Second Header'],
         4: ['Third Header', '3.5th Header']}

        Value depends on current page.
        https://drafts.csswg.org/css-gcpm/#funcdef-string

        :param dict store:
            Dictionary where the resolved value is stored.
        :param page:
            Current page.
        :param str name:
            Name of the named string or running element.
        :param str keyword:
            Indicates which value of the named string or running element to
            use. Default is the first assignment on the current page else the
            most recent assignment.
        :returns:
            Text for string set, box for running element.

        r   rž   ÚfirstÚstartrT   rB   Úlastzfirst-exceptNr
   )rW   r#   rU   rD   )ry   Ústorer   r¼   r½   Úfirst_stringÚlast_stringrN   rm   r<   Úprevious_pages              r.   rº   z'LayoutContext.get_string_or_element_for1  s  € ð4 ×Ñ  d¡Ñ+à  ™; t×'8Ñ'8Ñ9¸!Ñ<ˆLØ ™+ d×&7Ñ&7Ñ8¸Ñ<ˆKØ˜'Ò!Ø#Ð#Ø˜GÒ#Ø�ÙØ—}‘} \Ñ2°fÒ<Ø07·±¸lÑ0Kò 4Ñ,˜[¨!Ø*¨dÓ2Ø'3Ò 3ð4ð ×'Ò'Ø")×"2Ñ"2°1Ñ"5˜Ø ØØ˜FÒ"Ø"Ð"Ø˜NÒ*Øä" 4×#4Ñ#4°qÑ#8¸!¸RÓ@ò 	6ˆMØ  d¡Ò+Ø˜T‘{ =Ñ1°"Ñ5Ò5ñ	6r0   c                 óŽ   — | j                   j                  |«       | j                  j                  |«       | j	                  «       S )z+Add a footnote to the layout for this page.)rF   Úremover‹   r%   Ú_update_footnote_area©ry   Úfootnotes     r.   Úlayout_footnotezLayoutContext.layout_footnotee  s7   € à�‰×Ñ˜hÔ'Ø×#Ñ#×*Ñ*¨8Ô4Ø×)Ñ)Ó+Ð+r0   c                 ó  — || j                   vr| j                   j                  |«       || j                  v r| j                  j                  |«       n)|| j                  v r| j                  j                  |«       | j                  «        yy)z@Remove a footnote from the layout and return it to the waitlist.N)rF   r%   r‹   rÊ   rŒ   rË   rÌ   s     r.   Úunlayout_footnotezLayoutContext.unlayout_footnotek  sw   € ð ˜4Ÿ>™>Ñ)Ø�N‰N×!Ñ! (Ô+Ø˜4×6Ñ6Ñ6Ø×+Ñ+×2Ñ2°8Õ<Ø˜T×4Ñ4Ñ4Ø×'Ñ'×.Ñ.¨xÔ8Ø×&Ñ&Õ(ð *r0   c                 ó�   — | j                   j                  |«       | j                  j                  |«       | j	                  «        y)z0Mark a footnote as being moved to the next page.N)r‹   rÊ   rŒ   r%   rË   rÌ   s     r.   Úreport_footnotezLayoutContext.report_footnotew  s6   € à×#Ñ#×*Ñ*¨8Ô4Ø×Ñ×&Ñ& xÔ0Ø×"Ñ"Õ$r0   c                 ó¸  — | j                   j                  dk7  r9| j                  s-| xj                  | j                   j	                  «       z  c_        | j
                  | j                   _        | j                   j                  �rt        j                  | j                   j                  «       «      }t        | |t         d| j                   j                  «      d   }|j                  | j                   _        | j                  s#| xj                  |j	                  «       z  c_        |j                  d   }|j                  |j	                  «       z   |j                  z
  }|j                  |j	                  «       z   |j                  z
  }||kD  }|S d| j                   _        | j                  s-| xj                  | j                   j	                  «       z  c_        y)z9Update the page bottom size and our footnote area height.r§   Nr   rž   F)r�   r¦   r’   rŽ   rª   r‹   rU   r   Úcreate_anonymous_boxesÚdeepcopyr   r   r   r˜   Úmargin_bottom)ry   rq   Ú
last_childÚlast_child_bottomÚfootnote_area_bottomÚoverflows         r.   rË   z#LayoutContext._update_footnote_area}  s”  € à×%Ñ%×,Ñ,°Ò6¸t¿~º~Ø×Ò × :Ñ :× HÑ HÓ JÑJÕØ.2×.IÑ.Iˆ×"Ñ"Ô+Ø×%Ñ%×.Ó.Ü!×8Ñ8Ø×*Ñ*×3Ñ3Ó5ó7ˆMä.Ø�m¤c T¨4Ø×*Ñ*×/Ñ/ó1à12ñ4ˆMð 1>×0DÑ0DˆD×&Ñ&Ô-Ø—>’>Ø× Ò  M×$?Ñ$?Ó$AÑAÕ Ø&×/Ñ/°Ñ3ˆJà×%Ñ%¨
×(@Ñ(@Ó(BÑBØ×(Ñ(ñ)ð ð ×(Ñ(¨=×+FÑ+FÓ+HÑHØ×+Ñ+ñ,ð !ð )Ð+?Ñ?ˆHØˆOà01ˆD×&Ñ&Ô-Ø—>’>Ø× Ò  D×$>Ñ$>×$LÑ$LÓ$NÑNÕ Ør0   )NNrw   )rÂ   )rz   r{   r|   r•   r™   Ústaticmethodr—   Úpropertyr    Úsetterr¤   r¯   r²   r´   r¸   r¾   rÀ   rº   rÎ   rÐ   rÒ   rË   rx   r0   r.   r   r   á   s”   „ òò4Kð ñ0ó ð0ð
 ñKó ðKð ×ÑñVó ðVóSóJòCò7òTó2ó
8ò
26òh,ò
)ò%ór0   r   N)é   )r}   Úcollectionsr   Ú	functoolsr   Úmathr   Úformatting_structurer   r   Úloggerr	   Úabsoluter   r   Ú
backgroundr   Úblockr   r   r   r   r/   r>   rs   rG   ru   r   rx   r0   r.   ú<module>rç      sR   ðñ
õ $Ý Ý ç /Ý $ß :Ý *Ý %ß 3ò2Eòj4ó2qôhˆtô ÷wò wr0   