+
    ¿ÌjZ  ã                   ó  € R t ^ RIt^ RIHtHt  ! R R4      tRR/R ltRR/R	 ltRR/R
 ltR t	R t
R tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR  tR! tR" t R# t!R$RR%R&/R' lt"R# )(aF  
Copyright (C) 2023 Artifex Software, Inc.

This file is part of PyMuPDF.

PyMuPDF is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.

PyMuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.

You should have received a copy of the GNU Affero General Public License
along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>

Alternative licensing terms are available from the licensor.
For commercial licensing, see <https://www.artifex.com/> or contact
Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
CA 94129, USA, for further information.

---------------------------------------------------------------------

PyMuPDF table cell-span resolution (opt-in extension).

Provides SpanCell and resolve_spans (plus the _span_* helpers), which
reconstruct a detected table's merged-cell (colspan / rowspan) structure.
Re-exported by pymupdf.table; never runs on the default find_tables() path.
Reuses the word-selection helpers of pymupdf._table_refine.
N)Ú_refine_is_vertical_or_rotatedÚ_refine_page_wordsc                   ó.   a € ] tR t^*t o RtRR ltRtV tR# )ÚSpanCella–  One reconstructed table cell after span resolution (PyMuPDF extension).

``bbox`` is the placement's ``(x0, y0, x1, y1)`` union rect, ``text`` the
page text it claims (lines joined by ``\n``), and ``colspan``/``rowspan``
how many grid columns/rows it covers. resolve_spans always sets a real bbox;
a caller padding its own grid may construct SpanCells with ``bbox=None``.

``tag`` is the cell's HTML tag (``"td"``/``"th"``), defaulting to ``"td"``.
resolve_spans leaves it at the default; find_tables(refine=True) overwrites
it from the resolved header region so Table.to_html() can serialize the grid
directly, and a caller building its own grid may set it too.c                óB   € Wn         W n        W0n        W@n        WPn        R # ©N)ÚbboxÚtextÚcolspanÚrowspanÚtag)Úselfr   r	   r
   r   r   s   &&&&&&Ún/home/l0st/web/w4ttz.lol/public_html/toolz/MsgDoxxer/venv/lib/python3.14/site-packages/pymupdf/_table_spans.pyÚ__init__ÚSpanCell.__init__7   s   € ØŒ	ØŒ	ØŒØŒØŽó    )r   r
   r   r   r	   N)Útd)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r   *   s   ø‡ € ñ
D÷ò r   r   Ú	toleranceg      @c               óž   € . p\        V 4       F;  pV'       d   W2R,          ,
          V8:  d   K!  VP                  \        V4      4       K=  	  V# )zÓGreedy 1-D clustering of edge coordinates into slot boundaries.

Keeps a sorted value only when it is more than ``tolerance`` from the last
kept boundary, so the first value of each run is the retained boundary.éÿÿÿÿ)ÚsortedÚappendÚfloat)Úvaluesr   Ú
boundariesÚvalues   &$  r   Ú_span_clustered_boundariesr$   @   sE   € ð
 €JÜ˜–ˆß˜%¨R¥.Õ0°IÔ=ÙØ×Ñœ% ›,Ö'ñ  ð Ðr   ç      ð?c               óü   € ^ p\        \        V4      ^,
          4       FP  pW%,          W%^,           ,          ,           R,          pW,
          Tu;8:  d   W,           8:  g   KC  M KG  V^,          pKR  	  \        ^V4      # )zKHow many [boundaries[i], boundaries[i+1]] slots the span start..end covers.ç       @)ÚrangeÚlenÚmax)ÚstartÚendr"   r   ÚcountÚindexÚmidpoints   &&&$   r   Ú_span_covered_slot_countr0   M   sd   € à€EÜ”s˜:“¨Õ*Ö+ˆØÕ%¨
¸1µ9Õ(=Õ=ÀÕDˆØÕ Ö;¨C­O×;Ò;Ø�Q�JŠEñ ,ô ˆq�%‹=Ðr   c               ón  € . p\        \        V4      ^,
          4       Fn  pW,          W^,           ,          ,           R,          pV P                  V,
          Tu;8:  d   V P                  V,           8:  g   KY  M K]  VP	                  V4       Kp  	  V'       g   R# \        V4      \        V4      ^,           3# )zIThe half-open column-slot range (first, last+1) a rect's x-extent covers.r'   )é    é   )r(   r)   Úx0Úx1r   Úminr*   )ÚrectÚx_boundariesr   Úhitsr.   r/   s   &&$   r   Ú_span_slot_ranger:   W   sˆ   € à€DÜ”s˜<Ó(¨1Õ,Ö-ˆØ Õ'¨,¸qµyÕ*AÕAÀSÕHˆØ�7‰7�YÕ (ÖA¨d¯g©g¸	Õ.A×AÒAØ�K‰K˜Öñ .÷ ØˆÜ�‹I”s˜4“y 1•}Ð%Ð%r   c                 ó^   € V ^ ,          V^,          8  ;'       d    V^ ,          V ^,          8  # ©r2   © ©ÚaÚbs   &&r   Ú_span_ranges_intersectrA   c   s(   € ØˆQ�4�!�A•$‰;×&Ð&˜1˜Q�4 ! A¥$™;Ð&r   c                 ó  € \        VP                  4      T u;8*  ;'       d    \        VP                  4      8*  Mu ;'       d=    \        VP                  4      Tu;8*  ;'       d    \        VP                  4      8*  # u # r   )r    r4   r5   Úy0Úy1)ÚxÚyr7   s   &&&r   Ú_span_point_in_rectrG   g   sS   € Ü�—‘‹>˜Q×0Ô0¤%¨¯©£.Ô0×ZÐZ´U¸4¿7¹7³^Àq×5ZÔ5ZÌEÐRV×RYÑRYËNÑ5ZÐZÑ5ZÐZr   c           	      ó´   € \         P                  ! \        R  V  4       4      \        R V  4       4      \        R V  4       4      \        R V  4       4      4      # )c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   )r4   ©Ú.0r7   s   & r   Ú	<genexpr>Ú#_span_rect_union.<locals>.<genexpr>m   ó   é € Ð&¡˜�GŽG£ùó   ‚c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   ©rC   rJ   s   & r   rL   rM   n   rN   rO   c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   )r5   rJ   s   & r   rL   rM   o   rN   rO   c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   ©rD   rJ   s   & r   rL   rM   p   rN   rO   )ÚpymupdfÚRectr6   r*   )Úrectss   &r   Ú_span_rect_unionrX   k   sK   € Ü�<Š<ÜÑ&¡Ó&Ó&ÜÑ&¡Ó&Ó&ÜÑ&¡Ó&Ó&ÜÑ&¡Ó&Ó&ó	ð r   c                 óŒ   € \        V P                  VP                  4      \        V P                  VP                  4      ,
          # r   )r6   r5   r*   r4   r>   s   &&r   Ú_span_x_overlaprZ   t   s)   € Üˆq�t‰t�Q—T‘T‹?œS §¡ q§t¡t›_Õ,Ð,r   c                ól   € \        W4      pVR8:  d   R# \        RVP                  4      pW#,          R8¬  # )a  True if a text span overlaps a cell by enough x to signal a merge.

A few points of overlap is noise (a span drifting across a column line with
trailing whitespace or a currency glyph); require >2pt and >=15% of the cell
width before treating it as a merged-cell signal.r'   Fr%   g333333Ã?)rZ   r*   Úwidth)Ú	span_rectÚ	cell_rectÚoverlapÚ
cell_widths   &&  r   Ú_span_substantial_x_overlapra   x   s6   € ô ˜iÓ3€GØ�#„~ÙÜ�S˜)Ÿ/™/Ó*€JØÕ 4Ñ'Ð'r   c                óÂ   € V '       g   . # . pV ^ ,          ;r#V R,           F)  pWC^,           8X  d   TpK  VP                  W#34       T;r#K+  	  VP                  W#34       V# )z>Collapse a sorted index list into (start, end) inclusive runs.:r3   NN)r   )ÚindicesÚrangesr+   r,   r.   s   &    r   Ú_span_contiguous_rangesre   …   sj   € çØˆ	Ø€FØ˜!•*Ð€EØ˜—�ˆØ˜!•GÔØˆCÙØ�‰�u�lÔ#ØÐˆ‘ñ ð ‡M�M�5�,ÔØ€Mr   c                óö   € . p\        V R R7       Fd  w  r#pW#8X  d   K  V'       d   W!R,          ^,          8”  d   VP                  W#V.34       K@  VR,          w  rVpV\        Wc4      Wt.,           3VR&   Kf  	  V# )zIMerge overlapping (start, end, text) intervals, accumulating their texts.c                 ó&   € V ^ ,          V ^,          3# r<   r=   ©Úitems   &r   Ú<lambda>Ú'_span_merge_intervals.<locals>.<lambda>˜   s   € ÀÀQÅÈÈaÍÑ?Qr   ©Úkeyr   )r   r   r*   )Ú	intervalsÚmergedr+   r,   r	   Ú
prev_startÚprev_endÚtextss   &       r   Ú_span_merge_intervalsrs   •   s{   € à€FÜ" 9Ñ2Q×RÑˆ�DØŒ<Ùß˜¨¥¨A¥Ô.Ø�M‰M˜5¨ vÐ.Ô/ÙØ&,¨R¥jÑ#ˆ
˜eØ ¤# hÓ"4°e¸fµnÐEˆˆr‹
ñ Sð €Mr   c                óD  € V P                  R. 4       Uu. uFo  p\        VP                  R4      ;'       g    R4      P                  4       '       g   K=  \        VP                  R4      ;'       g    R4      P                  4       NKq  	  ppRP                  V4      # u upi )z=Space-joined non-empty span texts of a get_text('dict') line.Úspansr	   Ú Ú )ÚgetÚstrÚstripÚjoin)ÚlineÚspanÚpartss   &  r   Ú_span_line_textr   ¤   s‡   € ð —H‘H˜W bÔ)óá)ˆDÜˆt�x‰x˜Ó×%Ð% 2Ó&×,Ñ,×.ô 	,ŒˆD�H‰H�VÓ×"Ð" Ó#×)Ñ)Ö+Ù)ð 
ð ð
 �8‰8�E‹?Ðùòs   •!B·BÁBÁ1Bc                óÜ  € V P                  R4      pV'       d+   \        P                  ! V4      pVP                  '       g   V# V P                  R. 4       Uu. uFK  pVP                  R4      '       g   K  \        P                  ! VP                  R4      ;'       g    . 4      NKM  	  ppV Uu. uF  q"P                  '       d   K  VNK  	  ppV'       g   R# \	        V4      # u upi u upi )zKBounding rect of a dict line (its bbox, else the union of its span bboxes).r   ru   N)rx   rU   rV   Úis_emptyrX   )r|   r   r7   r}   rW   s   &    r   Ú_span_line_rectr‚   ®   s»   € à�8‰8�FÓ€DßÜ�|Š|˜DÓ!ˆØ�}�}ˆ}ØˆKð —H‘H˜W bÔ)óá)ˆDØ�8‰8�F×ô 	-Œ�Š�T—X‘X˜fÓ%×+Ð+¨Ö,Ù)ð 
ð ñ
 $Ó9™e�d¯=­=�TˆT™e€EÐ9ßÙÜ˜EÓ"Ð"ùòùò
 :s   ÁC$Á6'C$ÂC$Â/C)ÃC)c                ó¸  € \        V RR4      pVe   V# . pV P                  R4      P                  R. 4       F  pVP                  R4      R9  d   K  VP                  R. 4       FN  p\        V4      '       g   K  \	        V4      pV'       g   K+  \        V4      pVf   K<  VP                  We34       KP  	  K�  	   \        V RV4       V#   \         d     T# i ; i)z–Vertical/rotated text lines as (rect, text), cached on the page.

Selects non-horizontal lines whose reading order get_text('dict') already
preserves.Ú_span_vertical_lines_cacheNÚdictÚblocksÚtypeÚlines)Nr2   )	ÚgetattrÚget_textrx   r   r   r‚   r   ÚsetattrÚ	Exception)ÚpageÚcachedrˆ   Úblockr|   r	   r7   s   &      r   Ú_span_vertical_text_linesr�   À   sÜ   € ô
 �TÐ7¸Ó>€FØÒØˆØ€EØ—‘˜vÓ&×*Ñ*¨8°RÖ8ˆØ�9‰9�VÓ IÔ-ÙØ—I‘I˜g rÖ*ˆDÜ1°$×7Ò7ÙÜ" 4Ó(ˆDßÙÜ" 4Ó(ˆDØŠ|ÙØ�L‰L˜$˜Ö&ó +ñ 9ðÜ�Ð2°EÔ:ð €Løô ô ØØ€Lðús   Â;C
 Ã
CÃCc                ó:  aa€ V'       g   R# . p\        V 4       F˜  w  rE\        VP                  4      \        VP                  4      ,           R,          o\        VP                  4      \        VP
                  4      ,           R,          o\        SSV4      '       g   K†  VP                  WE34       Kš  	  V'       g   R# ^ pV Fu  w  pw  r‰r«pWŠ,           R,          oW›,           R,          o\        ;QJ d     VV3R lV 4       F  '       g   K   RM	  RM! VV3R lV 4       4      '       g   Kl  V^,          pKw  	  V\        ^\        V4      4      ,          R8  d   R# \        R V 4       4      ^8  d   R# RP                  R	 \        VR
 R7       4       4      # )a  Text of vertical lines centered in rect, when they dominate the rect.

Returns the stacked line text only if vertical lines are centered in the rect,
cover >=60% of the rect's selected words, and carry >=2 tokens; else None so
the caller falls back to horizontal line synthesis.Nç      à?c              3   óB   <"  € T F  w  r\        SSV4      x € K  	  R # 5ir   )rG   )rK   Ú	line_rectÚ_ÚcxÚcys   &  €€r   rL   Ú/_span_vertical_text_for_rect.<locals>.<genexpr>ñ   s    øé € ÐUÉ*¹,¸)Ô" 2 r¨9×5Ð5Ë*ùs   ƒTFg333333ã?c              3   óX   "  € T F   w  r\        VP                  4       4      x € K"  	  R # 5ir   )r)   Úsplit©rK   r•   r	   s   &  r   rL   r˜   õ   s    é € Ð
7©J¡ Œ3ˆt�z‰z‹|×Ð«Jùs   ‚(*Ú
c              3   ó*   "  € T F	  w  rVx € K  	  R # 5ir   r=   r›   s   &  r   rL   r˜   ÷   s   é € ð ñ
‰GˆAõ 	ó
ùó   ‚c                 ó²   € \        V ^ ,          P                  4      \        V ^ ,          P                  V ^ ,          P                  ,           R,          4      ) 3# )r2   r’   )r    r4   rC   rD   rh   s   &r   rj   Ú._span_vertical_text_for_rect.<locals>.<lambda>û   s9   € œe D¨¥G§J¡JÓ/´%¸¸a½¿¹ÀdÈ1ÅgÇjÁjÕ9PÐTWÕ8WÓ2XÐ1XÑYr   rl   )r�   r    r4   r5   rC   rD   rG   r   Úanyr*   r)   Úsumr{   r   )r�   r7   Úselected_wordsÚ
candidatesr”   r	   Úvertical_hitsr•   Úwx0Úwy0Úwx1Úwy1r–   r—   s   &&&         @@r   Ú_span_vertical_text_for_rectrª   Ý   sF  ù€ ÷ ÙØ€JÜ4°TÖ:‰ˆ	Ü�I—L‘LÓ!¤E¨)¯,©,Ó$7Õ7¸3Õ>ˆÜ�I—L‘LÓ!¤E¨)¯,©,Ó$7Õ7¸3Õ>ˆÜ˜r 2 t×,Ô,Ø×Ñ˜yÐ/Ö0ñ	 ;÷
 ÙØ€MÛ&4Ñ"ˆÑ"ˆC�c Ø�i˜3ÕˆØ�i˜3Õˆß‹3ÕUÉ*ÓU�3�3Š3ÕUÉ*ÓU×UÔUØ˜QÕŠMñ	 '5ð
 ”s˜1œc .Ó1Ó2Õ2°SÔ8ÙÜ
Ñ
7©JÓ
7Ó7¸!Ô;ÙØ�9‰9ñ äØÙYõ
óó ð r   c                ó\  € V '       g   R# V  UUUu. uF  w  rr2\        RW1,
          4      NK  	  pppp\        V4      \        V4      ^,          ,          p\        RVR,          4      p. p\        V R R7       FÉ  w  rr9W,           R,          p
RpTpV F1  p\        V
\	        VR,          4      ,
          4      pWì8:  g   K-  TpTpK3  	  Vf   VP                  RV
R	W‰3./4       Km  VR	,          P                  W‰34       \        VR	,          4      p\	        VR,          4      V^,
          ,          V
,           V,          VR&   KË  	  . p\        VR
 R7       F=  pVP                  RP                  R \        VR	,          R R7       4       4      4       K?  	  RP                  V4      # u upppi )zÿJoin center-point-selected cell words into text, re-synthesizing lines.

``words`` are (y0, x0, y1, text) tuples; they are grouped into lines by an
adaptive median-height nearest-line rule, each line's words ordered by x, and
the lines joined by newlines.rv   gš™™™™™¹?r'   gš™™™™™á?c                 ó&   € V ^ ,          V ^,          3# r<   r=   rh   s   &r   rj   Ú*_span_words_to_line_text.<locals>.<lambda>  s   € ¸DÀ½GÀTÈ!ÅWÑ;Mr   rl   NÚcenter_yÚwordsc                 ó&   € \        V R ,          4      # )r®   )r    rh   s   &r   rj   r­     s   € ¬u°T¸*Õ5EÔ/Fr   rw   c              3   ó*   "  € T F	  w  rVx € K  	  R # 5ir   r=   r›   s   &  r   rL   Ú+_span_words_to_line_text.<locals>.<genexpr>  s   é € Ð"gÑ7f©G¨A¥4Ó7fùrž   c                 ó   € V ^ ,          # r<   r=   rh   s   &r   rj   r­     s   € Ð^bÐcdÖ^er   rœ   )r*   r   r)   Úabsr    r   r{   )r¯   rC   r•   rD   ÚheightsÚmedian_heightÚline_thresholdrˆ   r4   r	   r—   Ú	best_lineÚbest_distancer|   Údistancer-   Ú
text_liness   &                r   Ú_span_words_to_line_textr¼      s  € ÷ ÙÙ5:Õ;±U¡\ R¨BŒs�3˜�Ö ±U€GÒ;Ü˜7“O¤C¨£L°AÕ$5Õ6€MÜ˜˜m¨dÕ2Ó3€NØ€EÜ" 5Ñ.M×NÑˆ�Ø�g˜�_ˆØˆ	Ø&ˆÛˆDÜ˜2¤ d¨:Õ&6Ó 7Õ7Ó8ˆHØÖ(Ø �	Ø (’ñ	 ð
 ÒØ�L‰L˜* b¨'°R°J°<Ð@ÔAÙØ�'Õ×!Ñ! 2 *Ô-Ü�I˜gÕ&Ó'ˆÜ!& y°Õ'<Ó!=ÀÈÅÕ!KÈbÕ!PÐTYÕ Yˆ	�*Óñ Oð €JÜ�uÑ"F×GˆØ×Ñ˜#Ÿ(™(Ñ"g´v¸dÀ7½mÑQeÕ7fÓ"gÓgÖhñ Hà�9‰9�ZÓ Ð ùô- <s   ‘F'c                ób   € V w  rr4p\        V4      \        V4      \        V4      \        V4      3# )zKReorder a (x0, y0, x1, y1, text) word to the (y0, x0, y1, text) line tuple.)r    ry   )Úwordr4   rC   Ú_x1rD   r	   s   &     r   Ú_span_word_line_tuplerÀ   !  s-   € à Ñ€BˆC�TÜ�"‹I”u˜R“y¤%¨£)¬S°«YÐ7Ð7r   c                ó  € . p\        V 4       Fp  w  r4Vw  rVrxp	\        V	4      P                  4       '       g   K,  WW,           R,          p
Wh,           R,          p\        W«V4      '       g   K^  VP	                  W434       Kr  	  V# )zÙ(index, word) pairs whose center lies in rect, index into ``page_words``.

The index is what lets resolve_spans claim each page word for exactly one
placement (an earlier cell's word is not re-claimed by a later one).r’   )Ú	enumeratery   rz   rG   r   )Ú
page_wordsr7   Úselectedr.   r¾   r¦   r§   r¨   r©   r	   r–   r—   s   &&          r   Ú_span_select_words_in_rectrÅ   '  st   € ð
 €HÜ  Ö,‰ˆØ#'Ñ ˆ�#˜DÜ�4‹y�‰× Ò ÙØ�i˜3ÕˆØ�i˜3ÕˆÜ˜r t×,Ô,Ø�O‰O˜U˜MÖ*ñ -ð €Or   c           	     ó‚   € \        WV4      pVe   V# \        V UUu. uF  w  rE\        V4      NK  	  upp4      # u uppi )zIText for a rect: vertical-line text if it dominates, else line synthesis.)rª   r¼   rÀ   )r�   r7   r£   Úvertical_textr•   r¾   s   &&&   r   Ú_span_words_text_for_rectrÈ   8  sB   € ä0°¸^ÓL€MØÒ ØÐÜ#ÑP^Ô$_ÑP^ÁWÀQÔ%:¸4Ö%@ÑP^Ò$_Ó`Ð`ùÓ$_s   �;
c                ó¬   € \        W!4       UUu. uF  w  rEWC9  g   K  WE3NK  	  pppV F  w  rGVP                  V4       K  	  \        WV4      # u uppi )zKText of rect's words, skipping words already claimed and claiming the rest.)rÅ   ÚaddrÈ   )r�   r7   rÃ   Úclaimed_wordsr.   r¾   rÄ   r•   s   &&&&    r   Ú_span_claim_text_in_rectrÌ   @  sc   € ô 6°jÔGôáG‰KˆEØÑ%ô 	ˆ‹ÙGð ñ ó
 ‰ˆØ×Ñ˜%Ö ñ ä$ T°Ó:Ð:ùós
   �
AžAc                óZ  € \        V RR4      pVe   V# . pV P                  R4      P                  R. 4       FÐ  pVP                  R. 4       F·  pVP                  R. 4       Fž  p\        VP                  R4      ;'       g    R4      P	                  4       p\        V4      ^8  d   KG  VP                  R	4      pV'       g   Kb  \        P                  ! V4      pVP                  '       d   KŒ  VP                  W†34       K   	  K¹  	  KÒ  	   \        V RV4       V#   \         d     T# i ; i)
zÍPage text spans as (rect, text), length>=2, cached on the page.

These drive merged-cell detection: a single span whose x-extent crosses a
grid column line signals cells the line grid split but text joins.Ú_span_text_spans_cacheNr…   r†   rˆ   ru   r	   rv   r   )r‰   rŠ   rx   ry   rz   r)   rU   rV   r�   r   r‹   rŒ   )	r�   rŽ   ru   r�   r|   r}   r	   r   r7   s	   &        r   Ú_span_text_spansrÏ   L  s  € ô
 �TÐ3°TÓ:€FØÒØˆØ€EØ—‘˜vÓ&×*Ñ*¨8°RÖ8ˆØ—I‘I˜g rÖ*ˆDØŸ™ ¨"Ö-�Ü˜4Ÿ8™8 FÓ+×1Ð1¨rÓ2×8Ñ8Ó:�Ü�t“9˜q”=ÙØ—x‘x Ó'�ßÙÜ—|’| DÓ)�Ø—=—=�=ÙØ—‘˜d˜\Ö*ó .ó +ñ 9ðÜ�Ð.°Ô6ð €Løô ô ØØ€Lðús   ÄD ÄD*Ä)D*c           	     ó  € \        V 4      ^8  d   . # \        R V  4       4      p\        R V  4       4      p. pV F·  w  rVVP                  VP                  ,           R,          pWrR,
          8  g   WsR,           8”  d   KE  \        V 4       UU	u. uF  w  r‰\        WY4      '       g   K  VNK  	  p
pp	\        V
4      ^8  d   Kˆ  \        V
4       F   w  r¼WË8”  g   K  VP                  W¼V34       K"  	  K¹  	  \        V4      # u up	pi )a>  Column ranges within one grid row that a single text span crosses.

``entries`` are the row's cell rects (in column order). A text span centered
in the row band and substantially overlapping >=2 adjacent cells marks those
cells for merging; overlapping intervals are merged. Returns
(start, end, texts) with end>start.c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   rQ   ©rK   Úentrys   & r   rL   Ú+_span_crossing_intervals.<locals>.<genexpr>r  ó   é € Ð/¡w˜e—–£wùrO   c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   rT   rÒ   s   & r   rL   rÔ   s  rÕ   rO   r'   r%   )
r)   r6   r*   rC   rD   rÂ   ra   re   r   rs   )ÚentriesÚ
text_spansÚrow_y0Úrow_y1rn   r]   Ú	span_textr®   ÚpositionrÓ   Úhit_positionsr+   r,   s   &&           r   Ú_span_crossing_intervalsrÞ   i  sõ   € ô ˆ7ƒ|�aÔØˆ	ÜÑ/¡wÓ/Ó/€FÜÑ/¡wÓ/Ó/€FØ€IÛ *Ñˆ	Ø—L‘L 9§<¡<Õ/°3Õ6ˆØ˜s•lÔ" h¸#µÔ&=Ùô $-¨WÔ#5ô
á#5‘�Ü*¨9×<÷ ˆHÙ#5ð 	ñ 
ô
 ˆ}Ó Ô!ÙÜ1°-Ö@‰JˆEØŽ{Ø× Ñ  %¨iÐ!8Ö9ó Añ !+ô ! Ó+Ð+ùó
s   ÂDÂ(Dc                 óº   € W8¼  d   R # V FL  pVR,          R9  d   K  VR,          V 8:  g   VR,          V8¼  d   K1  \        WR,          4      '       g   KK   R # 	  R# )FÚroleÚrowÚcolsT>   ÚheaderÚheader_leafÚheader_group)rA   )Úrow_idxrâ   ÚbaseÚ
body_startÚothers   &&&& r   Ú_span_is_leaf_header_rangerê   Š  sV   € ØÔÙÛˆØ��=Ð IÔIÙØ��<˜7Ô" e¨E¥l°jÔ&@ÙÜ! $¨f­×6Ô6Úñ ñ r   c                óÆ  € . p\        V 4       F‰  w  rE\        V Uu. uF
  qff   K  VNK  	  up4       F`  w  rv\        P                  ! V4      p\        W�4      p	TP	                  RTRTRTRT	RV	^,          V	^ ,          ,
          RWB8¼  d   RMR/4       Kb  	  K‹  	  V F;  p
V
R,          R8w  d   K  \        V
R,          V
R,          W24      '       d   R	MR
V
R&   K=  	  V# u upi )zþDescribe every grid cell by row/slot-range/role for the strict-colspan gate.

Header cells split into ``header_leaf`` (no header cell below within body) vs
``header_group`` (spans over a lower leaf), which the reject rules compare
against the body split.rá   rÜ   r7   râ   r
   rà   Úbodyrã   rä   rå   )rÂ   rU   rV   r:   r   rê   )Úcellsr8   rè   rç   ræ   rá   ÚcellrÜ   r7   râ   ri   s   &&&        r   Ú_span_build_base_cellsrï   —  sê   € ð €DÜ! %Ö(‰ˆÜ'¹#Ó(R¹#°$¯¨¹#Ñ(RÖS‰NˆHÜ—<’< Ó%ˆDÜ# DÓ7ˆDØ�K‰Kà˜7Ø Ø˜DØ˜DØ˜t A�w¨¨a­Õ0Ø gÔ&;™FÀðö	ó Tñ )ó ˆØ��<˜8Ô#Ùô *¨$¨u­+°t¸Fµ|ÀT×VÒVñ àð 	ˆV‹ñ ð €Kùò+ )Ss
   œC
¦C
c           	     ó@  a € \        V Uu0 uF+  q3R,          R8X  g   K  VR,          V8¼  g   K"  VR,          kK-  	  up4      pV FË  pV Uu. uF@  pVR,          R8X  g   K  VR,          V8X  g   K#  \        S VR,          4      '       g   K>  VNKB  	  ppV'       g   KY  \        V4      ^8X  d   V^ ,          R,          S 8X  d   K€  \        V 3R lV 4       4      p\	        V 3R lV 4       4      pVS ^ ,          8:  g   Kº  VS ^,          8¼  g   KÊ   R# 	  R# u upi u upi )	zDTrue if some body row splits the column range ``cols`` into >1 cell.rà   rì   rá   râ   c              3   óf   <"  € T F&  p\        S^ ,          VR,          ^ ,          4      x € K(  	  R# 5i©r2   râ   N©r*   ©rK   ri   râ   s   & €r   rL   Ú._span_body_rows_split_under.<locals>.<genexpr>Ä  s'   øé € ÐKÁd¸dœC  Q¥¨¨f­°a­×9Ð9Ãdùó   ƒ.1c              3   óf   <"  € T F&  p\        S^,          VR,          ^,          4      x € K(  	  R# 5i©r3   râ   N©r6   rô   s   & €r   rL   rõ   Å  s'   øé € ÐIÁD¸Dœ#˜d 1�g t¨F¥|°A¥×7Ð7ÃDùrö   TF)r   rA   r)   r6   r*   )	râ   rç   rè   ri   Ú	body_rowsræ   r9   Úcovered_startÚcovered_ends	   f&&      r   Ú_span_body_rows_split_underrý   ·  s  ø€ ä±Óm±¨¸V½ÈÑ8NœÐSWÐX]ÕS^ÐblÑSlœ˜˜UŸ˜±ÑmÓn€IÛˆñ ó
á�Ø�F�|˜vÑ%ô à*.¨u­+¸Ñ*@ô äE[Ð\`ÐbfÐgmÕbn×Eo÷ ˆDÙð 	ð 
÷
 ÙÜˆt‹9˜Œ>˜d 1�g f�o°Ô5ÙÜÔKÁdÓKÓKˆÜÔIÁDÓIÓIˆØ˜D �GÖ#¨°t¸AµwÖ(>Úñ ñ ùò nùò
s'   ‹DŸD¯DÁDÁ!DÁ1DÂDc                óz  a € V Uu. uF/  q"R,          R8X  g   K  \        S VR,          4      '       g   K-  VNK1  	  ppV'       g   R# \        V4      ^8X  d   V^ ,          R,          S 8X  d   R# \        V 3R lV 4       4      p\        V 3R lV 4       4      pVS ^ ,          8*  ;'       d    VS ^,          8¬  # u upi )zGTrue if leaf-header cells split the column range ``cols`` into >1 cell.rà   rä   râ   Fc              3   óf   <"  € T F&  p\        S^ ,          VR,          ^ ,          4      x € K(  	  R# 5irò   ró   rô   s   & €r   rL   Ú0_span_header_leafs_split_over.<locals>.<genexpr>Ò  s'   øé € ÐGÁ$¸$œ˜D �G T¨&¥\°!¥_×5Ð5Ã$ùrö   c              3   óf   <"  € T F&  p\        S^,          VR,          ^,          4      x € K(  	  R# 5irø   rù   rô   s   & €r   rL   r   Ó  s'   øé € ÐEÁ¸”c˜$˜q�' 4¨¥<°¥?×3Ð3Ãùrö   )rA   r)   r6   r*   )râ   rç   ri   r9   rû   rü   s   f&    r   Ú_span_header_leafs_split_overr  Ë  sŸ   ø€ á!Ór™T�T¨&¥\°]Ñ%BŒDÔG]Ð^bÐdhÐioÕdp×Gq�DˆD™T€DÐrßÙÜ
ˆ4ƒy�A„~˜$˜q�' &�/¨TÔ1ÙÜÔGÁ$ÓGÓG€MÜÔEÁÓEÓE€KØ˜D �GÑ#×>Ð>¨°t¸AµwÑ(>Ð>ùò ss   †B8šB8µB8c                óÈ   € V^,          V^ ,          ,
          ^8:  d   R# W8  d+   \        WW#4      '       g   R# \        WV4      '       d   R# R# \        W4      '       d   R# R# )zJWhether to reject a candidate merge over ``cols`` as a (reason,) mismatch.)Frv   )TÚ.header_leaf_colspan_changed_against_body_split)TÚ.body_colspan_changed_against_header_leaf_split)rê   rý   r  ©ræ   râ   rç   rè   s   $$$$r   Ú#_span_reject_colspan_mismatch_merger  ×  sf   € àˆA…w��a•Õ˜AÔØÐØÔÜ)¨'¸×JÒJØÐÜ& t°:×>Ò>ØIÐIØÐÜ$ T×0Ò0ØEÐEØÐr   c                 óz   € . pWV^,             F)  p\        WF4      pVP                  \        WV4      4       K+  	  V# )r3   )rÅ   r   rÈ   )r�   r×   r+   r,   rÃ   rr   rÓ   r¯   s   &&&&&   r   Ú_span_cell_texts_for_entriesr	  æ  s?   € Ø€EØ  q¥Ó)ˆÜ*¨:Ó=ˆØ�‰Ô.¨t¸EÓBÖCñ *ð €Lr   c                ó�   € V R8w  d   R# \        WW4V4       Uu. uF  qfP                  4       NK  	  pp\        V4      '       * # u upi )zßAllow an otherwise-rejected header merge when a covered part is empty.

A header leaf that would be rejected against a body split is still merged if
one of the merged parts has no text (an empty header slot the body fills).r  F)r	  rz   Úall)Úreasonr�   r×   r+   r,   rÃ   r	   Ú
part_textss   $$$$$$  r   Ú0_span_allow_header_colspan_merge_with_empty_partr  î  sH   € ð
 ÐAÔAÙÜ+GÈÐW\ÐcmÔ+nÓoÑ+n 4—*‘*–,Ñ+n€JÐoÜ�:‹ÔÐùò ps   ™AÚheader_row_countÚstrict_colspanFc               óÖ  € \        V4      p. p. pV Fv  pV Fm  pVf   K	  \        P                  ! V4      p	VP                  V	P                  V	P
                  .4       VP                  V	P                  V	P                  .4       Ko  	  Kx  	  \        V4      p
\        V4      pV'       d*   \        ^\        \        T;'       g    ^4      V4      4      M^ pV'       d   \        WV4      M. p\        V 4      p\        V 4      p\        4       p. p\!        V4       EFÀ  w  pp. pV Uu. uF  qˆf   K  \        P                  ! V4      NK   	  pp\#        VV4      pV UUUu/ uF  w  pppVVV3bK  	  pppp^ pV\        V4      8  EdB   VP%                  V4      pVe�   Vw  pp\'        VVV^,            4      p	V'       dd   \)        Wš4      p\+        VVVVR7      w  pp V'       d   \-        V V VVVVR7      '       d   RpV'       d   VV,          p	V^,          pM&V^,           pMV^,           pMVV,          p	V^,          pV	P.                  '       d   KÛ  \1        V	P                  V	P
                  V
4      p!\1        V	P                  V	P                  V4      p"VP3                  \5        \7        V	4      \9        W	VV4      V!V"R7      4       EKR  VP3                  V4       EKÃ  	  V# u upi u upppi )am  Resolve a detected table's merged-cell (colspan/rowspan) structure.

``cells`` is a row-major grid: a list of rows, each a list of ``[x0, y0, x1,
y1]`` cell rectangles (``None`` for a gap) -- the same grid shape
:func:`refine_grid` accepts. Returns a row-major grid of :class:`SpanCell`
placements, ragged where cells span: each placement carries its union
``bbox``, the page ``text`` it claims, and its ``colspan``/``rowspan`` (how
many clustered column/row slots it covers). Every page word is claimed by at
most one placement.

``header_row_count`` is the number of leading header rows (default a
conservative 1); it only matters together with ``strict_colspan``.
``strict_colspan`` (default False), when set, refuses a merge whose colspan
would contradict the header/body column split. This is a PyMuPDF extension;
it reads page text/graphics but does not mutate the page.
r  )r  r�   r×   r+   r,   rÃ   F)r   r	   r
   r   )r)   rU   rV   Úextendr4   r5   rC   rD   r$   r*   r6   Úintrï   rÏ   r   ÚsetrÂ   rÞ   rx   rX   r:   r  r  r�   r0   r   r   ÚtuplerÌ   )#r�   rí   r  r  ÚrowsÚx_edgesÚy_edgesrá   rî   r7   r8   Úy_boundariesrè   Ú
base_cellsrØ   rÃ   rË   Ú
placementsræ   Úplacement_rowr×   rn   r+   r,   rr   Úintervals_by_startrÜ   ÚintervalÚend_positionÚ_crossing_textsÚcandidate_colsÚrejectr  r
   r   s#   &&$$                               r   Úresolve_spansr#  ù  sª  € ô" ˆu‹:€Dà€GØ€GÛˆÛˆDØŠ|ÙÜ—<’< Ó%ˆDØ�N‰N˜DŸG™G T§W¡WÐ-Ô.Ø�N‰N˜DŸG™G T§W¡WÐ-Ö.ó ñ ô .¨gÓ6€LÜ-¨gÓ6€LßBF”�QœœCÐ 0× 5Ð 5°AÓ6¸Ó=Ô>ÈA€JßLZÔ'¨¸ZÔHÐ`b€Jä! $Ó'€JÜ# DÓ)€JÜ“E€MØ€JÜ! %×(‰ˆ�ØˆÙ25ÓJ±#¨$Ô%”7—<’< Ö%±#ˆÐJÜ,¨W°jÓAˆ	ÙKTÕUÉ9Ñ6G°e¸SÀ%˜e c¨5 \Ò1É9ÐÒUØˆØœ˜W›Õ%Ø)×-Ñ-¨hÓ7ˆHØÒ#Ø08Ñ-�˜oÜ'¨°¸<È!Õ;KÐ(LÓM�ß!Ü%5°dÓ%I�NÜ%HØ 'Ø+Ø'Ø#-ô	&‘N�F˜F÷ Ô"RØ%Ø!Ø 'Ø&Ø(Ø#-÷#ó #ð "'˜ßØ& xÕ0˜Ø  A�™à#/°!Õ#3™à+¨aÕ/‘Hà˜xÕ(�Ø˜A•�à�}�}ˆ}ÙÜ.¨t¯w©w¸¿¹ÀÓNˆGÜ.¨t¯w©w¸¿¹ÀÓNˆGØ× Ñ ÜÜ˜t›Ü1°$¸jÈ-ÓXØ#Ø#ô	÷ð 	×Ñ˜-×(ñg )ðj Ðùòg KùäUs   Ä%KÄ/KÅK$
)#r   rU   Úpymupdf._table_refiner   r   r   r$   r0   r:   rA   rG   rX   rZ   ra   re   rs   r   r‚   r�   rª   r¼   rÀ   rÅ   rÈ   rÌ   rÏ   rÞ   rê   rï   rý   r  r  r	  r  r#  r=   r   r   Ú<module>r%     sÜ   ðñóB ÷÷ñ ð,
°Cô 
ðÀ#ô ð	&°cô 	&ò'ò[òò-ò
(òò òò#ò$ò: òF!òB8òò"aò	;òò:,òB
òò@ò(	?òòòð[°4ð [Èö [r   