+
    ¿ÌjÚ;  ã                   óŽ   € R t ^ RIt^ RIHtHtHtHtH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# )aÖ  
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 union stage, behind find_tables(union=True): fuse the layout
analyzer's table grids with the line-based finder's candidates. Table,
TableFinder and _iou come from pymupdf.table; find_tables is imported lazily.
N)ÚCHARSÚEDGESÚTableÚTableFinderÚ_iouÚlines_strictgÍÌÌÌÌÌì?Tg      @g333333ë?g      Ð?c                ó¶  € . pV P                   ;'       g    .  EF±  p\        V\        4      '       g   K  VP                  R4      R8w  d   K4  VP                  R4      pVP                  R4      pV'       d   Vf   Kd  V^ ,          V^,          V^,          V^,          3w  rVrxV.VP                   U	u. uF  q™V,           NK  	  up	,           V.,           p
V.VP
                   Uu. uF  q»V,           NK  	  up,           V.,           p. p\        \        V
4      ^,
          4       Fu  p. p\        \        V4      ^,
          4       F@  pVP                  VV,          W®,          VV^,           ,          W®^,           ,          34       KB  	  VP                  V4       Kw  	  VP                  \        P                  ! VR,          4      V34       EK´  	  V# u up	i u upi )a`  Primary table grids from the raw layout analyzer result.

Reads page.layout_information in its raw (return_raw=True) form and yields a
``(bbox, grid)`` pair per "table" group -- ``grid`` is the full row-major cell
grid built from the group box plus its interior GridPrediction lines, in
layout (reading) order. Boxes without a usable grid are skipped.
Ú
class_nameÚtableÚ
group_bboxÚ
table_grid:Né   N)Úlayout_informationÚ
isinstanceÚdictÚgetÚh_linesÚv_linesÚrangeÚlenÚappendÚpymupdfÚRect)ÚpageÚgridsÚgroupr   Ú	grid_predÚx0Úy0Úx1Úy1Úhr   Úvr   ÚgridÚiÚrowÚjs   &                Ún/home/l0st/web/w4ttz.lol/public_html/toolz/MsgDoxxer/venv/lib/python3.14/site-packages/pymupdf/_table_union.pyÚ_layout_table_gridsr(   :   s�  € ð €EØ×)Ñ)×/Ð/¨RÓ/ˆÜ˜%¤×&Ò&ñ Ø�9‰9�\Ó" gÔ-ÙØ—Y‘Y˜|Ó,ˆ
Ø—I‘I˜lÓ+ˆ	ß˜YÒ.ÙØ# A�¨
°1­°zÀ!µ}ÀjÐQRÅmÐS‰ˆ�Ø�$¨)×*;Ò*;Ó<Ñ*; Q˜bŸ&˜&Ñ*;Ñ<Õ<À¸tÕCˆØ�$¨)×*;Ò*;Ó<Ñ*; Q˜bŸ&˜&Ñ*;Ñ<Õ<À¸tÕCˆØˆÜ”s˜7“| aÕ'Ö(ˆAØˆCÜœ3˜w›<¨!Õ+Ö,�Ø—
‘
˜G A�J¨­
°G¸AÀ½EµNÀGÐPQÍEÅNÐSÖTñ -à�K‰K˜Öñ	 )ð
 	�‰”g—l’l :¨b¥>Ó2°DÐ9×:ñ) 0ð* €Lùò =ùÚ<s   Â2GÃ$Gc           	     óv  € ^ RI Hp V! V \        RR7      p. p\        4       p\	        VRR4      ;'       g    .  FØ  p \
        P                  ! VP                  4      pTP                  '       d   K8  TP                  ;'       g    .  UUu. uF  qwP                   Uu. uF  qˆNK  	  upNK  	  p	ppT	'       g   K�  \        ;QJ d    . R T 4       F  NK  	  5M! R T 4       4      p
Y¤9   d   Kµ  TP                  T
4       TP                  Yi34       KÚ  	  W23#   \        \        3 d     Kó  i ; iu upi u uppi )aa  Line-based table candidates for the union stage as ``(bbox, grid)`` pairs.

Runs a nested find_tables (strategy=_UNION_STRATEGY, use_layout=False) and
keeps each detected table's bbox and row-major cell grid (Table.rows, None
for a gap), deduped by rounded bbox. Returns ``(candidates, finder)``; the
finder is reused as the returned TableFinder shell.
)Úfind_tablesF)ÚstrategyÚ
use_layoutÚtablesNc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5i)N)Úround)Ú.0Úvalues   & r'   Ú	<genexpr>Ú)_union_line_candidates.<locals>.<genexpr>s   s   é € Ð3©d U”E˜%—L�L«dùs   ‚)Úpymupdf.tabler*   Ú_UNION_STRATEGYÚsetÚgetattrr   r   ÚbboxÚ
ValueErrorÚ	TypeErrorÚis_emptyÚrowsÚcellsÚtupleÚaddr   )r   r*   ÚfinderÚ
candidatesÚseenÚtabr8   r%   Úcellr#   Úkeys   &          r'   Ú_union_line_candidatesrF   [   s  € õ *Ù˜¬ÀEÔJ€FØ€JÜ‹5€DÜ˜ ¨$Ó/×5Ð5°2Ò5ˆð	Ü—<’< §¡Ó)ˆDð �=�=ˆ=ÙØ9<¿¹¿¸ÀR¸ÔI¹°§)¢)Ó,¡)˜$’¡)Ô,¹ˆÑIßÙßŒeÑ3©dÓ3�e‰eÑ3©dÓ3Ó3ˆØŒ;ÙØ�‰�ŒØ×Ñ˜4˜,Ö'ñ 6ð ÐÐøô œIÐ&ô 	Úð	üò -ùÓIs)   ½ DÂ
D5Â
D0Â&D5ÄD-Ä,D-Ä0D5c                 óÌ   € \        R \        V P                  V P                  ,
          4      4      \        R \        V P                  V P
                  ,
          4      4      ,          # ©ç        )ÚmaxÚfloatr   r   r    r   )Úrects   &r'   Ú_union_rect_arearM   {   s?   € Üˆs”E˜$Ÿ'™' D§G¡GÕ+Ó,Ó-´°C¼¸t¿w¹wÈÏÉÕ?PÓ9QÓ0RÕRÐRó    c                 óØ  € \        \        V P                  4      \        VP                  4      4      p\        \        V P                  4      \        VP                  4      4      p\	        \        V P
                  4      \        VP
                  4      4      p\	        \        V P                  4      \        VP                  4      4      pWB8:  g   WS8:  d   R # WB,
          WS,
          ,          # rH   )rJ   rK   r   r   Úminr   r    )ÚleftÚrightr   r   r   r    s   &&    r'   Ú_union_intersection_arearS      s�   € Ü	ŒU�4—7‘7‹^œU 5§8¡8›_Ó	-€BÜ	ŒU�4—7‘7‹^œU 5§8¡8›_Ó	-€BÜ	ŒU�4—7‘7‹^œU 5§8¡8›_Ó	-€BÜ	ŒU�4—7‘7‹^œU 5§8¡8›_Ó	-€BØ	„x�2”8ÙØ�G˜�Õ Ð rN   c           
      óè   € \        R \        \        V P                  4      \        VP                  4      4      \        \        V P                  4      \        VP                  4      4      ,
          4      # rH   )rJ   rP   rK   r   r   )rQ   rR   s   &&r'   Ú_union_x_overlaprU   ‰   sE   € Üˆs”Cœ˜dŸg™g›¬¨e¯h©h«Ó8¼3¼uÀTÇWÁW»~ÌuÐUZ×U]ÑU]ËÓ;_Õ_Ó`Ð`rN   c                ó2  € \        V 4      pV^ 8:  d   R# RpRpRp\        V4       Fl  w  rg\        V4      p\        W4      p	V	^ 8:  g   V^ 8:  d   K+  W’,          p
W˜,          pV
\        8¼  d   W¤8”  d   TpT
pKR  V
\        8¼  g   V\        8¼  g   Kj  RpKn  	  W53# )a&  The primary a split candidate belongs inside, plus an ambiguity flag.

Returns ``(owner_index, ambiguous)``: owner is the best-contained primary
(candidate>=_UNION_OWNER_CONTAINMENT inside it), else None; ambiguous is True
when the candidate overlaps some primary enough to be unsafe to append.NTrI   F)NT)rM   Ú	enumeraterS   Ú_UNION_OWNER_CONTAINMENTÚ_UNION_OWNER_AMBIGUOUS_OVERLAP)Úcandidate_bboxÚexisting_bboxesÚcandidate_areaÚ
best_ownerÚbest_containmentÚ	ambiguousÚindexÚexisting_bboxÚexisting_areaÚ
inter_areaÚcandidate_containmentÚexisting_coverages   &&          r'   Ú_union_find_ownerrf   �   s±   € ô & nÓ5€NØ˜ÔØÐØ€JØÐØ€IÜ )¨/Ö :ÑˆÜ(¨Ó7ˆÜ-¨nÓLˆ
Ø˜Œ?˜m¨qÔ0ÙØ *Õ ;ÐØ&Õ6ÐØ Ô$<Ô<ÐAVÔAiØˆJØ4ÒØ"Ô&DÔDÐHYÔ]{ÖH{ØŠIñ !;ð Ð Ð rN   c                ó€  € \        V RR4      pVe   V# . pV P                  R4      P                  R. 4      ;'       g    .  FÙ  pVP                  R. 4      ;'       g    .  F¶  pVP                  R. 4      ;'       g    .  F“  p\        VP                  R4      ;'       g    R4      P	                  4       '       g   K=  VP                  R	4      pV'       g   KX  \
        P                  ! V4      pVP                  '       d   K‚  VP                  V4       K•  	  K¸  	  KÛ  	   \        V RV4       V#   \         d     T# i ; i)
z…Non-empty page text-span rects, cached on the page.

Drives the grid-ref span-multiplicity gate: every non-blank span as a bare
rect.Ú_union_text_spans_cacheNr   ÚblocksÚlinesÚspansÚtextÚ r8   )r7   Úget_textr   ÚstrÚstripr   r   r;   r   ÚsetattrÚ	Exception)r   Úcachedrk   ÚblockÚlineÚspanr8   rL   s   &       r'   Ú_union_text_span_rectsrw   ¨   s  € ô
 �TÐ4°dÓ;€FØÒØˆØ€EØ—‘˜vÓ&×*Ñ*¨8°RÓ8×>Ð>¸BÒ>ˆØ—I‘I˜g rÓ*×0Ð0¨bÒ0ˆDØŸ™ ¨"Ó-×3Ð3°Ò3�Ü˜4Ÿ8™8 FÓ+×1Ð1¨rÓ2×8Ñ8×:Ò:ÙØ—x‘x Ó'�ßÙÜ—|’| DÓ)�Ø—}—}’}Ø—L‘L Ö&ó 4ó 1ñ ?ðÜ�Ð/°Ô7ð €Løô ô ØØ€Lðús   ÄD. Ä.D=Ä<D=c                ó˜  € . pV EFg  p\        VP                  4      \        VP                  4      ,           R,          pV\        V P                  4      R,
          8  g"   V\        V P                  4      R,           8”  d   K~  \        W04      R8:  d   K�  \	        \        V P
                  4      \        VP
                  4      4      p\        \        V P                  4      \        VP                  4      4      pWe8:  d   Kü  \        V4       FG  w  pw  r‰\        WH,
          4      R8:  g   K   V	P                  WV34       W„,           R,          V	3W'&    EKP  	  VP                  WEV3.34       EKj  	  ^ p
V FQ  w  r¹^ pRp\        V	4       F.  w  rVVe   W],
          R8”  d   V^,          pTpK#  \	        WÖ4      pK0  	  \	        W¬4      p
KS  	  V
# )zNMax horizontally-separated text-span groups on any single text line in a cell.g       @g      ð?g      @N)rK   r   r    rU   rJ   r   rP   r   rW   Úabsr   Úsorted)rD   Ú
text_spansÚ
line_bandsrv   Úcenter_yr   r   r`   Úband_yÚ	intervalsÚbestÚ_ÚgroupsÚlast_x1s   &&            r'   Ú_union_cell_span_group_countr„   Ã   s|  € à€JÜˆÜ˜$Ÿ'™'“N¤U¨4¯7©7£^Õ3°sÕ:ˆØ”e˜DŸG™G“n sÕ*Ô*¨h¼¸t¿w¹w»È#Õ9MÔ.MÙÜ˜DÓ'¨3Ô.ÙÜ”�t—w‘w“¤ t§w¡w£Ó0ˆÜ”�t—w‘w“¤ t§w¡w£Ó0ˆØŒ8ÙÜ*3°JÖ*?Ñ&ˆEÑ&�FÜ�8Õ$Ó%¨Ö,Ø× Ñ  " Ô*Ø&,Õ&7¸3Õ%>À	Ð$J�
Ñ!Ûñ	 +@ð ×Ñ˜x¨r¨(¨Ð4×5ñ! ð" €DÛ"‰ˆØˆØˆÜ˜YÖ'‰FˆBØŠ "¥,°Ô"4Ø˜!•�Ø’ä˜gÓ*’ñ (ô �4Ó Šñ #ð €KrN   c                ó  € V f   R# \        V 4      pRpV Fa  pV FX  pVf   K	  \        P                  ! V4      pVP                  '       d   K3  \	        Wb4      pV^ 8”  g   KG  Vf   TM
\        W74      pKZ  	  Kc  	  Ve   \        V4      # R# )zEMax cell span-group count over a grid (high => under-segmented grid).N)rw   r   r   r;   r„   rJ   rK   )r   r#   r{   r€   r%   rD   rL   Úcounts   &&      r'   Ú_union_span_multiplicityr‡   å   s†   € à‚|ÙÜ'¨Ó-€JØ€DÛˆÛˆDØŠ|ÙÜ—<’< Ó%ˆDØ�}�}ˆ}ÙÜ0°ÓBˆEØ�qŽyØ $¢‘u´#°dÓ2B’ó ñ ð Ò*Œ5�‹;Ð4°Ð4rN   c               ó¢  € / p/ p\        V 4       FŠ  w  pw  rš\        V4       Fs  w  pw  rÍ\        Wœ4      pWâ8¼  g   K  VP                  V. 4      P                  V\	        V4      34       VP                  V. 4      P                  V\	        V4      34       Ku  	  KŒ  	  / p\        4       pVP                  4        F�  w  pp\        V4      ^8w  d   K  V^ ,          w  pp\        VP                  V. 4      4      ^8w  d   KF  V'       d'   \        W1V,          ^,          4      pVe
   VV8¼  d   Kt  W,          Wø&   VP                  V4       K‘  	  VV3# )aM  Primaries a candidate can grid-ref (replace grid with), 1:1 by IoU.

``existing``/``candidates`` are ``(bbox, grid)`` lists. Returns ``(refs,
consumed)``: ``refs`` maps a primary index to the candidate supplying its
grid (mutual 1:1 IoU>=threshold matches passing the span-multiplicity gate),
``consumed`` the candidate indexes used.)rW   r   Ú
setdefaultr   rK   r6   Úitemsr   r   r‡   r?   )ÚexistingrA   Úiou_thresholdr   Úspan_mult_gateÚspan_mult_thresholdÚexisting_matchesÚcandidate_matchesÚexisting_indexra   Ú_gridÚcandidate_indexrZ   Ú_cgridÚiouÚrefsÚconsumedÚmatchesr�   Ú	span_mults   &&$$$$              r'   Ú_union_one_to_one_grid_refsrš   ø   sK  € ð ÐØÐÜ2;¸HÖ2EÑ.ˆÑ.˜Ü9BÀ:Ö9NÑ5ˆOÑ5˜nÜ�}Ó5ˆCØÖ#Ø ×+Ñ+¨N¸BÓ?×FÑFÈÔY^Ð_bÓYcÐGdÔeØ!×,Ñ,¨_¸bÓA×HÑHÈ.ÔZ_Ð`cÓZdÐIeÖfó	 :Oñ 3Fð €DÜ‹u€HØ#3×#9Ñ#9Ö#;Ñˆ˜Üˆw‹<˜1ÔÙØ$ Q�ZÑˆ˜ÜÐ ×$Ñ$ _°bÓ9Ó:¸aÔ?ÙßÜ0°À/Õ7RÐSTÕ7UÓVˆIØÒ$¨Ð6IÔ)IÙØ)Õ:ˆÑØ�‰�_Ö%ñ $<ð �ˆ>ÐrN   c          
     ó$  € V  Uu. uF  qw^ ,          NK  	  ppV'       d   \        V VVVVVR7      w  ršM/ \        4       r©/ p. p\        V4       Fe  w  rÞWÚ9   d   K  \        V^ ,          V4      w  ppVe$   VP	                  V. 4      P                  V4       KJ  V'       d   KT  VP                  V4       Kg  	  VP                  4        UUu/ uF'  w  pp\        V4      ^8¼  g   K  V\        VR R7      bK)  	  ppp. p\        V 4       Fi  w  ppVV9   d   VP                  VV,          4       K'  VV	9   d+   VP                  V^ ,          V	V,          ^,          34       KX  VP                  V4       Kk  	  VP                  V4       V# u upi u uppi )a  Fuse primary and candidate ``(bbox, grid)`` entries.

Applies grid-ref replacement, split replacement (>=2 candidates owned by one
primary replace it, ordered by y0/x0) and append of unowned candidates,
returning the fused entry list in the contractual order.)rŒ   r   r�   rŽ   c                 ór   € \        V ^ ,          P                  4      \        V ^ ,          P                  4      3# )é    )rK   r   r   )Úentrys   &r'   Ú<lambda>Ú'_union_replace_append.<locals>.<lambda>7  s$   € ´°e¸Aµh·k±kÓ0BÄEÈ%ÐPQÍ(Ï+É+ÓDVÑ/WrN   )rE   )
rš   r6   rW   rf   r‰   r   rŠ   r   rz   Úextend)r‹   rA   r   Úgrid_refÚgrid_ref_iour�   rŽ   rž   r[   Ú	grid_refsr—   ÚreplacementsÚappend_candidatesr“   Ú	candidateÚowner_indexr_   r`   rŠ   Úfinal_replacementsÚentriess   &&$$$$$              r'   Ú_union_replace_appendr«     sŒ  € ñ .6Ó6©X E˜Q—x�x©X€OÐ6ßÜ9ØØØ&ØØ)Ø 3ô
Ñˆ	�8ð !¤#£%�8Ø€LØÐÜ&/°
Ö&;Ñ"ˆØÔ&ÙÜ!2°9¸Qµ<ÀÓ!QÑˆ�YØÒ"Ø×#Ñ# K°Ó4×;Ñ;¸IÖFßÙà×$Ñ$ YÖ/ñ '<ð )×.Ñ.Ô0ôá0‰LˆE�5Üˆu‹:˜‰?ô 	YˆŒv�eÑ!WÔXÒXÙ0ð ñ ð
 €GÜ! (Ö+‰ˆˆuØÐ&Ô&Ø�N‰NÐ-¨eÕ4Ö5Ø�iÔà�N‰N˜E !�H i°Õ&6°qÕ&9Ð:Ö;à�N‰N˜5Ö!ñ ,ð ‡N�NÐ$Ô%Ø€NùòO 7ùó0s   …FÃ
FÃ$Fc           
     óâ  € V P                   f   V P                  RR7       \        V 4      p\        V 4      w  r#\	        VVV R\
        \        \        R7      pVf6   \        P                  ! 4        \        P                  ! 4        \        V 4      p. pV FK  w  rgV UU	u. uF  qˆ F
  q™f   K  V	NK  	  K  	  p
pp	V
'       g   K/  VP                  \        W
VR7      4       KM  	  WSn        V# u up	pi )aŒ  Detect a page's tables by fusing layout grids with line-based candidates.

Ensures the raw layout (computed only when page.layout_information is None,
like the official use_layout path), reads primary grids, detects candidates,
applies grid-ref / split / append, and returns a TableFinder whose .tables
carry the fused grids in contractual order (grid-ref tables keep their
explicit layout bbox).T)Ú
return_raw)r   r¢   r£   r�   rŽ   )r8   )r   Ú
get_layoutr(   rF   r«   Ú_UNION_GRID_REF_IOUÚ_UNION_GRID_REF_SPAN_MULT_GATEÚ#_UNION_GRID_REF_SPAN_MULT_THRESHOLDr   Úclearr   r   r   r   r-   )r   Ú	primariesrA   r@   rª   r-   r8   r#   r%   rD   Úflats   &          r'   Ú_find_tables_unionrµ   H  sÓ   € ð ×ÑÒ&Ø�‰ 4ˆÔ(Ü# DÓ)€IÜ/°Ó5Ñ€JÜ#ØØØØÜ(Ü5Ü?ô€Gð ‚~ô
 	�ŠŒÜ�ŠŒÜ˜TÓ"ˆØ€FÛ‰
ˆÙ $ÔI¡˜²¨—�±‘¡ˆÑIßÙØ�‰”e˜D¨TÔ2Ö3ñ	 ð
 „MØ€Mùó Js   Â	C+Â,
C+)Ú__doc__r   r4   r   r   r   r   r   r5   r¯   r°   r±   rX   rY   r(   rF   rM   rS   rU   rf   rw   r„   r‡   rš   r«   rµ   © rN   r'   Ú<module>r¸      s}   ðñó< ç @Õ @ð" !€ØÐ Ø!%Ð Ø&)Ð #ØÐ Ø!%Ð òòBò@Sò!òaò!ò6ò6òD5ò&ò@-ô`$rN   