
    #jb                     P   d dl Z d dlZd dlmZmZmZ d dlmZmZ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mZ d dlmZ d d	lmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$  ej%        e&          Z' G d
 d          Z( G d d          Z) G d d          Z* G d d          Z+ G d de*          Z, G d de,          Z- G d de-          Z. G d de-          Z/ G d de,          Z0 G d de*e+          Z1 G d de,e+          Z2 ed e*!          Z3 G d" d#e,ee3                   Z4 G d$ d%e4e3                   Z5 G d& d'e5e3         e+          Z6e	e2e1f         Z7 G d( d)e6e7                   Z8 G d* d+e8          Z9 G d, d-e8          Z: G d. d/e6e8                   Z; G d0 d1e;          Z< G d2 d3e;          Z=e	e;d4f         Z> G d5 d4e6e>                   Z? G d6 d7e?          Z@ G d8 d9e?          ZA G d: d;e4e,                   ZB G d< d=eB          ZC G d> d?eB          ZDdS )@    N)IterableIteratorSequence)GenericTypeVarUnioncast)PDFColorSpace)PDFTypeErrorPDFValueError)PDFFont)ColorPDFGraphicState)	PDFStream)INFLTComponentTMatrixPathSegmentPlanePointRectapply_matrix_rectbbox2strfsplit	get_bound
matrix2struniqc                   (    e Zd Zd	deddfdZd
dZdS )IndexAssignerr   indexreturnNc                     || _         d S Nr    )selfr    s     W/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pdfminer/layout.py__init__zIndexAssigner.__init__$   s    


    objLTItemc                     t          |t                    r| j        |_        | xj        dz  c_        d S t          |t                    r|D ]}|                     |           d S d S N   )
isinstance	LTTextBoxr    LTTextGrouprun)r%   r)   xs      r&   r1   zIndexAssigner.run'   sv    c9%% 	
CIJJ!OJJJJ[)) 	  	 	 r(   r   )r)   r*   r!   N)__name__
__module____qualname__intr'   r1    r(   r&   r   r   #   sO         c $         r(   r   c                   d    e Zd ZdZ	 	 	 	 	 	 	 ddededed	ed
edz  dededdfdZddZdefdZ	dS )LAParamsa  Parameters for layout analysis

    :param line_overlap: If two characters have more overlap than this they
        are considered to be on the same line. The overlap is specified
        relative to the minimum height of both characters.
    :param char_margin: If two characters are closer together than this
        margin they are considered part of the same line. The margin is
        specified relative to the width of the character.
    :param word_margin: If two characters on the same line are further apart
        than this margin then they are considered to be two separate words, and
        an intermediate space will be added for readability. The margin is
        specified relative to the width of the character.
    :param line_margin: If two lines are are close together they are
        considered to be part of the same paragraph. The margin is
        specified relative to the height of a line.
    :param boxes_flow: Specifies how much a horizontal and vertical position
        of a text matters when determining the order of text boxes. The value
        should be within the range of -1.0 (only horizontal position
        matters) to +1.0 (only vertical position matters). You can also pass
        `None` to disable advanced layout analysis, and instead return text
        based on the position of the bottom left corner of the text box.
    :param detect_vertical: If vertical text should be considered during
        layout analysis
    :param all_texts: If layout analysis should be performed on text in
        figures.
          ?       @皙?Fline_overlapchar_marginline_marginword_margin
boxes_flowNdetect_vertical	all_textsr!   c                     || _         || _        || _        || _        || _        || _        || _        |                                  d S r#   )r>   r?   r@   rA   rB   rC   rD   	_validate)r%   r>   r?   r@   rA   rB   rC   rD   s           r&   r'   zLAParams.__init__L   sP     )&&&$."r(   c                     | j         Ud}t          | j         t          t          f          st	          |          d| j         cxk    rdk    sn t          |          d S d S )Nz@LAParam boxes_flow should be None, or a number between -1 and +1r-   )rB   r.   r7   floatr   r   )r%   boxes_flow_err_msgs     r&   rF   zLAParams._validate`   s{    ?&R  te== 7"#5666----A----#$6777 '& .-r(   c           	      N    d| j         dd| j        dd| j        dd| j        d	S )Nz<LAParams: char_margin=z.1fz, line_margin=z, word_margin=z all_texts=>)r?   r@   rA   rD   r%   s    r&   __repr__zLAParams.__repr__j   sZ    -d&6> - -+3- -+2- - - - -	
r(   )r;   r<   r;   r=   r;   FFr!   N)
r4   r5   r6   __doc__rI   boolr'   rF   strrN   r8   r(   r&   r:   r:   0   s         : "   #& %   	
  DL   
   (8 8 8 8
# 
 
 
 
 
 
r(   r:   c                   "    e Zd ZdZdeddfdZdS )r*   z)Interface for things that can be analyzedlaparamsr!   Nc                     dS )zPerform the layout analysis.Nr8   r%   rT   s     r&   analyzezLTItem.analyzev   s      r(   )r4   r5   r6   rP   r:   rW   r8   r(   r&   r*   r*   s   s<        33+ +T + + + + + +r(   r*   c                   *    e Zd ZdZdefdZdefdZdS )LTTextz#Interface for things that have textr!   c                 L    d| j         j         d|                                 dS N< rL   )	__class__r4   get_textrM   s    r&   rN   zLTText.__repr__}   s(    A4>*AAT]]__AAAAr(   c                     t           )zText contained in this objectNotImplementedErrorrM   s    r&   r_   zLTText.get_text   s    !!r(   N)r4   r5   r6   rP   rR   rN   r_   r8   r(   r&   rY   rY   z   sU        --B# B B B B"# " " " " " "r(   rY   c                       e Zd ZdZdeddfdZdefdZdede	fdZ
dede	fd	Zdede	fd
Zdede	fdZdeddfdZde	fdZdd de	fdZdd defdZdd defdZdd de	fdZdd defdZdd defdZdS )LTComponentzObject with a bounding boxbboxr!   Nc                 d    t                               |            |                     |           d S r#   )r*   r'   set_bboxr%   re   s     r&   r'   zLTComponent.__init__   s,    dr(   c                 L    d| j         j         dt          | j                   dS r[   )r^   r4   r   re   rM   s    r&   rN   zLTComponent.__repr__   s*    C4>*CCXdi-@-@CCCCr(   _c                     t           r#   r   r%   rj   s     r&   __lt__zLTComponent.__lt__       r(   c                     t           r#   rl   rm   s     r&   __le__zLTComponent.__le__   ro   r(   c                     t           r#   rl   rm   s     r&   __gt__zLTComponent.__gt__   ro   r(   c                     t           r#   rl   rm   s     r&   __ge__zLTComponent.__ge__   ro   r(   c                     |\  }}}}|| _         || _        || _        || _        ||z
  | _        ||z
  | _        || _        d S r#   )x0y0x1y1widthheightre   )r%   re   rw   rx   ry   rz   s         r&   rg   zLTComponent.set_bbox   sM    RR"W
2g			r(   c                 .    | j         dk    p
| j        dk    S Nr   )r{   r|   rM   s    r&   is_emptyzLTComponent.is_empty   s    zQ2$+"22r(   r)   c                     t          |t                    s$J t          t          |                                |j        | j        k    o| j        |j        k    S r#   )r.   rd   rR   typerw   ry   r%   r)   s     r&   is_hoverlapzLTComponent.is_hoverlap   I    #{++;;Sc^^;;+v 6TW%66r(   c                 *   t          |t                    s$J t          t          |                                |                     |          rdS t          t          | j        |j        z
            t          | j        |j        z
                      S r~   	r.   rd   rR   r   r   minabsrw   ry   r   s     r&   	hdistancezLTComponent.hdistance   z    #{++;;Sc^^;;+C   	E1s47SV+,,c$'CF2B.C.CDDDr(   c                 *   t          |t                    s$J t          t          |                                |                     |          rDt          t          | j        |j        z
            t          | j        |j        z
                      S dS r~   r   r   s     r&   hoverlapzLTComponent.hoverlap   y    #{++;;Sc^^;;+C   	s47SV+,,c$'CF2B.C.CDDD1r(   c                     t          |t                    s$J t          t          |                                |j        | j        k    o| j        |j        k    S r#   )r.   rd   rR   r   rx   rz   r   s     r&   is_voverlapzLTComponent.is_voverlap   r   r(   c                 *   t          |t                    s$J t          t          |                                |                     |          rdS t          t          | j        |j        z
            t          | j        |j        z
                      S r~   	r.   rd   rR   r   r   r   r   rx   rz   r   s     r&   	vdistancezLTComponent.vdistance   r   r(   c                 *   t          |t                    s$J t          t          |                                |                     |          rDt          t          | j        |j        z
            t          | j        |j        z
                      S dS r~   r   r   s     r&   voverlapzLTComponent.voverlap   r   r(   )r4   r5   r6   rP   r   r'   rR   rN   objectrQ   rn   rq   rs   ru   rg   r   r   rI   r   r   r   r   r   r8   r(   r&   rd   rd      s       $$T d    D# D D D D 4     4     4     4    T d    3$ 3 3 3 37} 7 7 7 7 7E] Eu E E E EM e    7} 7 7 7 7 7E] Eu E E E EM e      r(   rd   c                       e Zd ZdZ	 	 	 	 	 	 	 ddedee         dededed	edz  d
edz  dee	         dz  de
eef         dz  ddfdZdefdZdS )LTCurvezA generic Bezier curve

    The parameter `original_path` contains the original
    pathing information from the pdf (e.g. for reconstructing Bezier Curves).

    `dashing_style` contains the Dashing information if any.
    FN	linewidthptsstrokefillevenoddstroking_colornon_stroking_colororiginal_pathdashing_styler!   c
                     t                               | t          |                     || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        d S r#   )rd   r'   r   r   r   r   r   r   r   r   r   r   )
r%   r   r   r   r   r   r   r   r   r   s
             r&   r'   zLTCurve.__init__   si     	T9S>>222"	,"4**r(   c                 J    d                     d | j        D                       S )N,c              3   *   K   | ]} d j         | V  dS )z{:.3f},{:.3f}N)format).0ps     r&   	<genexpr>z"LTCurve.get_pts.<locals>.<genexpr>   s-      EEq..2EEEEEEr(   )joinr   rM   s    r&   get_ptszLTCurve.get_pts   s%    xxEEDHEEEEEEr(   FFFNNNN)r4   r5   r6   rP   rI   listr   rQ   r   r   tupler   r'   rR   r   r8   r(   r&   r   r      s          '++/266:+ ++ %[+ 	+
 + + + "DL+ K(4/+ VV^,t3+ 
+ + + +.F F F F F F Fr(   r   c                       e Zd ZdZ	 	 	 	 	 	 	 ddededededed	ed
edz  dedz  dee	         dz  de
eef         dz  ddfdZdS )LTLinezOA single straight line.

    Could be used for separating text or figures.
    FNr   p0p1r   r   r   r   r   r   r   r!   c                 P    t                               | |||g||||||	|

  
         d S r#   r   r'   )r%   r   r   r   r   r   r   r   r   r   r   s              r&   r'   zLTLine.__init__   sH     	H	
 	
 	
 	
 	
r(   r   )r4   r5   r6   rP   rI   r   rQ   r   r   r   r   r   r'   r8   r(   r&   r   r      s          '++/266:
 

 
 	

 
 
 
 
 "DL
 K(4/
 VV^,t3
 

 
 
 
 
 
r(   r   c                       e Zd ZdZ	 	 	 	 	 	 	 ddededededed	edz  d
edz  dee	         dz  de
eef         dz  ddfdZdS )LTRectzMA rectangle.

    Could be used for framing another pictures or figures.
    FNr   re   r   r   r   r   r   r   r   r!   c
                 r    |\  }
}}}t                               | ||
|f||f||f|
|fg|||||||	
  
         d S r#   r   )r%   r   re   r   r   r   r   r   r   r   rw   rx   ry   rz   s                 r&   r'   zLTRect.__init__  sk      RR"XBx"bB84	
 	
 	
 	
 	
r(   r   )r4   r5   r6   rP   rI   r   rQ   r   r   r   r   r   r'   r8   r(   r&   r   r     s          '++/266:
 

 
 	

 
 
 
 "DL
 K(4/
 VV^,t3
 

 
 
 
 
 
r(   r   c                   6    e Zd ZdZdedededdfdZdefdZdS )	LTImagezKAn image object.

    Embedded images can be in JPEG, Bitmap or JBIG2.
    namestreamre   r!   Nc                    t                               | |           || _        || _        |                    d          |                    d          f| _        |                    d          | _        |                    dd          | _        |                    d          | _        t          | j        t                    s| j        g| _        d S d S )N)WWidth)HHeight)IM	ImageMask)BPCBitsPerComponentr-   )CS
ColorSpace)rd   r'   r   r   get_anysrcsize	imagemaskbits
colorspacer.   r   )r%   r   r   re   s       r&   r'   zLTImage.__init__:  s    T4(((	~668W8WX(;<<NN#>BB	 ..)=>>$/400 	0#/DOOO	0 	0r(   c           	      l    d| j         j         d| j         dt          | j                   d| j        d	S Nr\   () r]   rL   )r^   r4   r   r   re   r   rM   s    r&   rN   zLTImage.__repr__E  sV    7' 7 7$) 7 7	""7 7%)\7 7 7	
r(   )	r4   r5   r6   rP   rR   r   r   r'   rN   r8   r(   r&   r   r   4  si         
	0S 	0) 	04 	0D 	0 	0 	0 	0
# 
 
 
 
 
 
r(   r   c                   .    e Zd ZdZdeddfdZdefdZdS )LTAnnoa  Actual letter in the text as a Unicode string.

    Note that, while a LTChar object has actual boundaries, LTAnno objects does
    not, as these are "virtual" characters, inserted by a layout analyzer
    according to the relationship between two characters (e.g. a space).
    textr!   Nc                     || _         d S r#   _text)r%   r   s     r&   r'   zLTAnno.__init__T  s    


r(   c                     | j         S r#   r   rM   s    r&   r_   zLTAnno.get_textW  
    zr(   )r4   r5   r6   rP   rR   r'   r_   r8   r(   r&   r   r   L  s[         S T    #      r(   r   c                   z    e Zd ZdZdededededededed	eeed
z  ef         z  de	de
dd
fdZdefdZdefdZd
S )LTCharz.Actual letter in the text as a Unicode string.matrixfontfontsizescalingriser   	textwidthtextdispNncsgraphicstater!   c                    t                               |            || _        || _        |j        | _        |	| _        |
| _        ||z  |z  | _        |                                rPt          |t                    sJ |\  }}||dz  n||z  dz  }d|z
  |z  dz  }| ||z   | j        z   | |z   ||z   f}n+|                                |z  }d||z   | j        ||z   |z   f}| j        \  }}}}}}||z  |z  dk    o||z  dk    | _        t          | j        |          \  }}}}||k     r||}}||k     r||}}t                              | ||||f           |                                r| j        | _        d S | j        | _        d S )Nr;   gMbP?i  r   )rY   r'   r   r   fontnamer   r   advis_verticalr.   r   get_descentuprightr   rd   r{   sizer|   )r%   r   r   r   r   r   r   r   r   r   r   vxvyre   descentabcd_e_frw   rx   ry   rz   s                            r&   r'   zLTChar.__init__^  s    	
(x''1 
	Lh.....HR#%:C2=53HB)x'%/BCdTX-sX~rDyIDD &&((83Gw~tx4(1JKD#{Aq!R1uw*9q1uz,T[$??RR77BR77BRTBB#3444 	$
DIIIDIIIr(   c                     d| j         j         dt          | j                   dt	          | j                   d| j        d| j         d|                                 dS )Nr\   r]    matrix=z font=z adv=z text=rL   )	r^   r4   r   re   r   r   r   r   r_   rM   s    r&   rN   zLTChar.__repr__  s    )' ) )(49*=*= ) ) --) )M) ) 8) ) MMOO	) ) )	
r(   c                     | j         S r#   r   rM   s    r&   r_   zLTChar.get_text  r   r(   )r4   r5   r6   rP   r   r   rI   rR   r   r
   r   r'   rN   r_   r8   r(   r&   r   r   [  s        88+$+$ +$ 	+$
 +$ +$ +$ +$ %e 344+$ +$ &+$ 
+$ +$ +$ +$Z
# 
 
 
 
#      r(   r   LTItemT)boundc                       e Zd ZdZdeddfdZdee         fdZde	fdZ
deddfd	Zd
ee         ddfdZdeddfdZdS )LTContainerz(Object that can be extended and analyzedre   r!   Nc                 J    t                               | |           g | _        d S r#   )rd   r'   _objsrh   s     r&   r'   zLTContainer.__init__  s#    T4((($&


r(   c                 *    t          | j                  S r#   )iterr   rM   s    r&   __iter__zLTContainer.__iter__  s    DJr(   c                 *    t          | j                  S r#   )lenr   rM   s    r&   __len__zLTContainer.__len__  s    4:r(   r)   c                 :    | j                             |           d S r#   )r   appendr   s     r&   addzLTContainer.add  s    
#r(   objsc                 :    |D ]}|                      |           d S r#   )r  )r%   r  r)   s      r&   extendzLTContainer.extend  s,     	 	CHHSMMMM	 	r(   rT   c                 D    | j         D ]}|                    |           d S r#   )r   rW   r%   rT   r)   s      r&   rW   zLTContainer.analyze  s2    : 	" 	"CKK!!!!	" 	"r(   )r4   r5   r6   rP   r   r'   r   r   r   r7   r   r  r   r  r:   rW   r8   r(   r&   r   r     s        22'T 'd ' ' ' ' (7+            w 4    8G,     " "T " " " " " "r(   r   c                   &    e Zd ZddZdeddfdZdS )LTExpandableContainerr!   Nc                 t    t                               | t          
 t          
 t           t           f           d S r#   )r   r'   r   rM   s    r&   r'   zLTExpandableContainer.__init__  s/    TSD3$sd#;<<<<<r(   r)   c           	      T   t                               | t          t          |                     |                     t          | j        |j                  t          | j        |j                  t          | j	        |j	                  t          | j
        |j
                  f           d S r#   )r   r  r	   r   rg   r   rw   rx   maxry   rz   r   s     r&   r  zLTExpandableContainer.add  s    d7C00111DGSV$$DGSV$$DGSV$$DGSV$$		
 	
 	
 	
 	
r(   rO   )r4   r5   r6   r'   rd   r  r8   r(   r&   r
  r
    sJ        = = = =
	
{ 	
t 	
 	
 	
 	
 	
 	
r(   r
  c                   "    e Zd ZddZdefdZdS )LTTextContainerr!   Nc                 n    t                               |            t                              |            d S r#   )rY   r'   r
  rM   s    r&   r'   zLTTextContainer.__init__  s.    &&t,,,,,r(   c                 @    d                     d | D                       S )N c              3      K   | ]@}t          |t                    t          t          |                                          V  Ad S r#   )r.   rY   r	   r_   )r   r)   s     r&   r   z+LTTextContainer.get_text.<locals>.<genexpr>  s[       
 
-0JsF<S<S
&&((
 
 
 
 
 
r(   )r   rM   s    r&   r_   zLTTextContainer.get_text  s4    ww 
 
48
 
 
 
 
 	
r(   rO   )r4   r5   r6   r'   rR   r_   r8   r(   r&   r  r    sC        - - - -
# 
 
 
 
 
 
r(   r  c                        e Zd ZdZdeddf fdZdefdZdeddfdZ	d	e
e         d
eded          fdZdef fdZ xZS )
LTTextLinezContains a list of LTChar objects that represent a single text line.

    The characters are aligned either horizontally or vertically, depending on
    the text's writing mode.
    rA   r!   Nc                 V    t                                                       || _        d S r#   )superr'   rA   )r%   rA   r^   s     r&   r'   zLTTextLine.__init__  s'    &r(   c                 v    d| j         j         dt          | j                   d|                                 dS r[   )r^   r4   r   re   r_   rM   s    r&   rN   zLTTextLine.__repr__  s:    W4>*WWXdi-@-@WW4==??WWWWr(   rT   c                     | j         D ]}|                    |           t                              | t	          d                     d S )N
)r   rW   r   r  r   r  s      r&   rW   zLTTextLine.analyze  sH    : 	" 	"CKK!!!!fTll+++++r(   planeratioc                     t           r#   ra   )r%   r  r  s      r&   find_neighborszLTTextLine.find_neighbors  s
    
 "!r(   c                     t                                                      p%|                                                                 S r#   )r  r   r_   isspace)r%   r^   s    r&   r   zLTTextLine.is_empty  s2    ww!!>T]]__%<%<%>%>>r(   )r4   r5   r6   rP   rI   r'   rR   rN   r:   rW   r   r   r   r  rQ   r   __classcell__r^   s   @r&   r  r    s         'E 'd ' ' ' ' ' 'X# X X X X, ,T , , , ,
"\"" " 
l		" " " "?$ ? ? ? ? ? ? ? ? ? ?r(   r  c                        e Zd ZdeddfdZdeddf fdZdee         dede	e
         fd	ZddededefdZddededefdZ	 ddededefdZddededefdZ xZS )LTTextLineHorizontalrA   r!   Nc                 V    t                               | |           t          
 | _        d S r#   )r  r'   r   _x1r%   rA   s     r&   r'   zLTTextLineHorizontal.__init__  %    D+...$r(   r)   c                 T   t          |t                    rd| j        r]| j        t          |j        |j                  z  }| j        |j        |z
  k     r(t          	                    | t          d                     |j        | _        t                      	                    |           d S Nr]   )r.   r   rA   r  r{   r|   r&  rw   r   r  r   ry   r  r%   r)   marginr^   s      r&   r  zLTTextLineHorizontal.add  s    c6"" 	3t'7 	3%CIsz(B(BBFx#&6/))fSkk2226Cr(   r  r  c                      | j         z  |                     j         j        z
   j         j        z   f          } fd|D             S )aB  Finds neighboring LTTextLineHorizontals in the plane.

        Returns a list of other LTTestLineHorizontals in the plane which are
        close to self. "Close" can be controlled by ratio. The returned objects
        will be the same height as self, and also either left-, right-, or
        centrally-aligned.
        c                     g | ]u}t          |t                                        |           .                    |           s.                    |           s                    |           s|vS )	tolerance)r.   r$  _is_same_height_as_is_left_aligned_with_is_right_aligned_with_is_centrally_aligned_withr   r)   r   r%   s     r&   
<listcomp>z7LTTextLineHorizontal.find_neighbors.<locals>.<listcomp>  s     
 
 
3 455	

 ++C1+==
 ..sa.@@
 223!2DD
 66sa6HH

 
 
r(   )r|   findrw   rx   ry   rz   r%   r  r  r  r   s   `   @r&   r  z#LTTextLineHorizontal.find_neighbors  sl     DKzz47DGaK$'A+FGG
 
 
 
 

 
 
 	
r(   r   otherr0  c                 B    t          |j        | j        z
            |k    S )z<Whether the left-hand edge of `other` is within `tolerance`.)r   rw   r%   r9  r0  s      r&   r2  z*LTTextLineHorizontal._is_left_aligned_with      58dg%&&)33r(   c                 B    t          |j        | j        z
            |k    S )z=Whether the right-hand edge of `other` is within `tolerance`.)r   ry   r;  s      r&   r3  z+LTTextLineHorizontal._is_right_aligned_with!  r<  r(   c                 n    t          |j        |j        z   dz  | j        | j        z   dz  z
            |k    S )z?Whether the horizontal center of `other` is within `tolerance`.   )r   rw   ry   r;  s      r&   r4  z/LTTextLineHorizontal._is_centrally_aligned_with%  8     EHux'1,$'0AQ/FFGG9TTr(   c                 B    t          |j        | j        z
            |k    S r#   )r   r|   r;  s      r&   r1  z'LTTextLineHorizontal._is_same_height_as-  s    5<$+-..);;r(   r3   )r4   r5   r6   rI   r'   rd   r  r   r   r   r  r  rQ   r2  r3  r4  r1  r!  r"  s   @r&   r$  r$    su       E d    { t      
\"
 
 
j		
 
 
 
84 4; 45 4QU 4 4 4 44 4K 4E 4RV 4 4 4 4 U UU U 
	U U U U< < < <d < < < < < < < <r(   r$  c                        e Zd ZdeddfdZdeddf fdZdee         dede	e
         fd	ZddededefdZddededefdZ	 ddededefdZdededefdZ xZS )LTTextLineVerticalrA   r!   Nc                 V    t                               | |           t           | _        d S r#   )r  r'   r   _y0r'  s     r&   r'   zLTTextLineVertical.__init__2  r(  r(   r)   c                 T   t          |t                    rd| j        r]| j        t          |j        |j                  z  }|j        |z   | j        k     r(t          	                    | t          d                     |j        | _        t                      	                    |           d S r*  )r.   r   rA   r  r{   r|   rz   rE  r   r  r   rx   r  r+  s      r&   r  zLTTextLineVertical.add8  s    c6"" 	3t'7 	3%CIsz(B(BBFv))fSkk2226Cr(   r  r  c                      | j         z  |                     j        z
   j         j        z    j        f          } fd|D             S )a>  Finds neighboring LTTextLineVerticals in the plane.

        Returns a list of other LTTextLineVerticals in the plane which are
        close to self. "Close" can be controlled by ratio. The returned objects
        will be the same width as self, and also either upper-, lower-, or
        centrally-aligned.
        c                     g | ]u}t          |t                                        |           .                    |           s.                    |           s                    |           s|vS r/  )r.   rC  _is_same_width_as_is_lower_aligned_with_is_upper_aligned_withr4  r5  s     r&   r6  z5LTTextLineVertical.find_neighbors.<locals>.<listcomp>N  s     
 
 
3 233	

 **3!*<<
 //q/AA
 223!2DD
 66sa6HH

 
 
r(   )r{   r7  rw   rx   ry   rz   r8  s   `   @r&   r  z!LTTextLineVertical.find_neighbors@  sl     DJzz47Q;1dgFGG
 
 
 
 

 
 
 	
r(   r   r9  r0  c                 B    t          |j        | j        z
            |k    S )z8Whether the lower edge of `other` is within `tolerance`.)r   rx   r;  s      r&   rJ  z)LTTextLineVertical._is_lower_aligned_with\  r<  r(   c                 B    t          |j        | j        z
            |k    S )z8Whether the upper edge of `other` is within `tolerance`.)r   rz   r;  s      r&   rK  z)LTTextLineVertical._is_upper_aligned_with`  r<  r(   c                 n    t          |j        |j        z   dz  | j        | j        z   dz  z
            |k    S )z=Whether the vertical center of `other` is within `tolerance`.r?  )r   rx   rz   r;  s      r&   r4  z-LTTextLineVertical._is_centrally_aligned_withd  r@  r(   c                 B    t          |j        | j        z
            |k    S r#   )r   r{   r;  s      r&   rI  z$LTTextLineVertical._is_same_width_asl  s    5;+,,	99r(   r3   )r4   r5   r6   rI   r'   rd   r  r   r   r   r  r  rQ   rJ  rK  r4  rI  r!  r"  s   @r&   rC  rC  1  sp       E d    { t      
\"
 
 
j		
 
 
 
84 4K 4E 4RV 4 4 4 44 4K 4E 4RV 4 4 4 4 U UU U 
	U U U U:{ :u : : : : : : : : :r(   rC  c                   2    e Zd ZdZddZdefdZdefdZdS )r/   zRepresents a group of text chunks in a rectangular area.

    Note that this box is created by geometric analysis and does not
    necessarily represents a logical boundary of the text. It contains a list
    of LTTextLine objects.
    r!   Nc                 H    t                               |            d| _        d S )NrH   )r  r'   r    rM   s    r&   r'   zLTTextBox.__init__x  s!      &&&


r(   c           	          d| j         j         d| j         dt          | j                   d|                                 d	S r   )r^   r4   r    r   re   r_   rM   s    r&   rN   zLTTextBox.__repr__|  s\    :' : :$* : :	"": :%)]]__: : :	
r(   c                     t           r#   ra   rM   s    r&   get_writing_modezLTTextBox.get_writing_mode  s    !!r(   rO   )r4   r5   r6   rP   r'   rR   rN   rT  r8   r(   r&   r/   r/   p  sh            
# 
 
 
 
"# " " " " " "r(   r/   c                   4     e Zd Zdeddf fdZdefdZ xZS )LTTextBoxHorizontalrT   r!   Nc                     t                                          |           | j                            d            d S )Nc                     | j          S r#   )rz   r)   s    r&   <lambda>z-LTTextBoxHorizontal.analyze.<locals>.<lambda>  
     r(   keyr  rW   r   sortr%   rT   r^   s     r&   rW   zLTTextBoxHorizontal.analyze  9    !!!
//00000r(   c                     dS )Nzlr-tbr8   rM   s    r&   rT  z$LTTextBoxHorizontal.get_writing_mode      wr(   r4   r5   r6   r:   rW   rR   rT  r!  r"  s   @r&   rV  rV    f        1 1T 1 1 1 1 1 1#        r(   rV  c                   4     e Zd Zdeddf fdZdefdZ xZS )LTTextBoxVerticalrT   r!   Nc                     t                                          |           | j                            d            d S )Nc                     | j          S r#   )ry   rY  s    r&   rZ  z+LTTextBoxVertical.analyze.<locals>.<lambda>  r[  r(   r\  r^  r`  s     r&   rW   zLTTextBoxVertical.analyze  ra  r(   c                     dS )Nztb-rlr8   rM   s    r&   rT  z"LTTextBoxVertical.get_writing_mode  rc  r(   rd  r"  s   @r&   rg  rg    re  r(   rg  r0   c                   4     e Zd Zdee         ddf fdZ xZS )r0   r  r!   Nc                 r    t                                                       |                     |           d S r#   )r  r'   r  )r%   r  r^   s     r&   r'   zLTTextGroup.__init__  s1    Dr(   )r4   r5   r6   r   TextGroupElementr'   r!  r"  s   @r&   r0   r0     sQ        X&67 D          r(   c                   (     e Zd Zdeddf fdZ xZS )LTTextGroupLRTBrT   r!   Nc                     t                                          |           |j        J |j        | j                            fd           d S )Nc                 J    dz
  | j         z  dz   | j        | j        z   z  z
  S r,   )rw   rx   rz   r)   rB   s    r&   rZ  z)LTTextGroupLRTB.analyze.<locals>.<lambda>  s+    Q^sv5:~#&36/23 r(   r\  r  rW   rB   r   r_  r%   rT   rB   r^   s     @r&   rW   zLTTextGroupLRTB.analyze  sl    !!!"...(

3 3 3 3 	 	
 	
 	
 	
 	
r(   r4   r5   r6   r:   rW   r!  r"  s   @r&   ro  ro    K        
 
T 
 
 
 
 
 
 
 
 
 
r(   ro  c                   (     e Zd Zdeddf fdZ xZS )LTTextGroupTBRLrT   r!   Nc                     t                                          |           |j        J |j        | j                            fd           d S )Nc                 L    dz    | j         | j        z   z  dz
  | j        z  z
  S r,   )rw   ry   rz   rr  s    r&   rZ  z)LTTextGroupTBRL.analyze.<locals>.<lambda>  s.    a*n-#&A:~'( r(   r\  rs  rt  s     @r&   rW   zLTTextGroupTBRL.analyze  sl    !!!"...(

( ( ( ( 	 	
 	
 	
 	
 	
r(   ru  r"  s   @r&   rx  rx    rv  r(   rx  c                       e Zd ZdeddfdZdedee         dee	         fdZ
dedee	         dee         fd	Zded
ee         dee         fdZdeddfdZdS )LTLayoutContainerre   r!   Nc                 J    t                               | |           d | _        d S r#   )r   r'   groupsrh   s     r&   r'   zLTLayoutContainer.__init__  s#    T4(((04r(   rT   r  c              #     K   d }d }|D ]}||                     |          oqt          |j        |j                  |j        z  |                    |          k     o8|                    |          t          |j        |j                  |j        z  k     }|j	        o|
                    |          oqt          |j        |j                  |j        z  |                    |          k     o8|                    |          t          |j        |j                  |j        z  k     }|rt          |t                    s|r+t          |t                    r|                    |           n||V  d }n|rA|s?t          |j                  }|                    |           |                    |           nr|rA|s?t          |j                  }|                    |           |                    |           n/t          |j                  }|                    |           |V  d }|}!|-t          |j                  }|J |                    |           |V  d S r#   )r   r   r|   r>   r   r   r  r{   r?   rC   r   r   r   r.   r$  rC  r  rA   )r%   rT   r  obj0lineobj1halignvaligns           r&   group_objectszLTLayoutContainer.group_objects  s     
 "& ?	 ?	D $$T** IDK558MMmmD))*I t,,$*dj11H4HHI	 . , K((..KDJ
33h6KKmmD))*K t,,$+t{33h6JJK    z$0DEE   )$0BCC  HHTNNNN%JJJDD  F  -h.BCCDHHTNNNHHTNNNN  F  /0DEEDHHTNNNHHTNNNN/0DEEDHHTNNNJJJDDD<'(<==D###HHTNNN




r(   linesc              #     K   t          | j                  }|                    |           i }|D ]}|                    ||j                  }|g}|D ]C}|                    |           ||v r(|                    |                    |                     Dt          |t                    rt                      }	nt                      }	t          |          D ]}
|	                    |
           |	||
<   t                      }|D ]A}||vr||         }	|	|v r|                    |	           |	                                s|	V  BdS )z$Group neighboring lines to textboxesN)r   re   r  r  r@   r  popr.   r$  rV  rg  r   r  setr   )r%   rT   r  r  boxesr  	neighborsmembersr  boxr)   dones               r&   group_textlinesz!LTLayoutContainer.group_textlines  sr      $)#3#3U-/ 	! 	!D++E83GHHIfG! 4 4t$$$5==NN599T??333$ 455 *!4!6!6'))G}} ! ! c

! uu 	 	D5  +Cd{{HHSMMM<<>> 				 	r(   r  c           
      B   t           t          t          f         }t          | j                  dt
          dt
          dt          fd}d|d|dt          |         ffd}g }t          t          |                    D ]t}||         }t          |dz   t          |                    D ]I}	||	         }
|
                    d |||
          t          |          t          |
          ||
f           Jut          j        |                               |           t                      }t          |          dk    rXt          j        |          \  }}}}}}||vr$||vr|s( |||          rt          j        |d	|||||f           ct#          |t$          t&          f          st#          |t$          t&          f          rt'          ||g          }nt)          ||g          }                    |                               |           |                    ||g           D ]A}t          j        |d |||          t          |          t          |          ||f           B                    |           t          |          dk    Xd
 D             S )ax  Group textboxes hierarchically.

        Get pair-wise distances, via dist func defined below, and then merge
        from the closest textbox pair. Once obj1 and obj2 are merged /
        grouped, the resulting group is considered as a new object, and its
        distances to other objects & groups are added to the process queue.

        For performance reason, pair-wise distances and object pair info are
        maintained in a heap of (idx, dist, id(obj1), id(obj2), obj1, obj2)
        tuples. It ensures quick access to the smallest element. Note that
        since comparison operators, e.g., __lt__, are disabled for
        LTComponent, id(obj) has to appear before obj in element tuples.

        :param laparams: LAParams object.
        :param boxes: All textbox objects to be grouped.
        :return: a list that has only one element, the final top level group.
        r  obj2r!   c                 (   t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }||z
  ||z
  z  | j        | j        z  z
  |j        |j        z  z
  S )a  A distance function between two TextBoxes.

            Consider the bounding rectangle for obj1 and obj2.
            Return its area less the areas of obj1 and obj2,
            shown as 'www' below. This value may be negative.
                    +------+..........+ (x1, y1)
                    | obj1 |wwwwwwwwww:
                    +------+www+------+
                    :wwwwwwwwww| obj2 |
            (x0, y0) +..........+------+
            )r   rw   rx   r  ry   rz   r{   r|   )r  r  rw   rx   ry   rz   s         r&   distz/LTLayoutContainer.group_textboxes.<locals>.distG  s     TWdg&&BTWdg&&BTWdg&&BTWdg&&BbR"W%*t{*+*t{*+r(   c                 N   t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }t                              ||||f                    }|                    | |f          S )z8Check if there's any other object between obj1 and obj2.)	r   rw   rx   r  ry   rz   r  r7  
difference)r  r  rw   rx   ry   rz   r  r  s          r&   isanyz0LTLayoutContainer.group_textboxes.<locals>.isany]  s    TWdg&&BTWdg&&BTWdg&&BTWdg&&Buzz2r2r"23344D??D$<000r(   r-   Fr   Tc                 8    g | ]}t          t          |          S r8   )r	   r0   )r   gs     r&   r6  z5LTLayoutContainer.group_textboxes.<locals>.<listcomp>  s"    444[!$$444r(   )r   r/   r0   r   re   rd   rI   r  ranger   r  idheapqheapifyr  heappopheappushr.   rg  rx  ro  removeupdater  )r%   rT   r  ElementTr  r  distsibox1jbox2r  
skip_isanyr   id1id2r  r  groupr9  r  s                       @r&   group_textboxesz!LTLayoutContainer.group_textboxes.  s   , K/0!&ty!1!1	{ 	+ 	% 	 	 	 	,	1 	1 	1S] 	1 	1 	1 	1 	1 	1 IKs5zz"" 	X 	XA8D1q5#e**-- X XQxeTT$%5%5r$xxD4QUVWWWWX 	eUuu%jj1nn49M%4H4H1ZCdD4coo! eeD$&7&7 N54CdD*IJJJd%6$HII :Z&8N N : *9$)F)FEE+T4L99ET"""T"""S#J'''"  ENUE 2 2BuIIr%yy%QVW    		%   / %jj1nn2 54e4444r(   c                    t          d |           \  }}|D ]}|                    |           |sd S t          |                     ||                    }t          d |          \  }}|D ]}|                    |           t          |                     ||                    }|j        [|D ]}|                    |           dt          dt          t          t          t          f         fd}	|
                    |	           nt|                     ||          | _        t                      }
| j        D ],}|                    |           |
                    |           -|
                    d            t          t          t                    |          |z   t          t          t                    |          z   | _        d S )Nc                 ,    t          | t                    S r#   )r.   r   rY  s    r&   rZ  z+LTLayoutContainer.analyze.<locals>.<lambda>  s    :c63J3J r(   c                 *    |                                  S r#   )r   rY  s    r&   rZ  z+LTLayoutContainer.analyze.<locals>.<lambda>  s    #,,.. r(   r  r!   c                 n    t          | t                    rd| j         | j         fS d| j         | j        fS )Nr   r-   )r.   rg  ry   rx   rw   r  s    r&   getkeyz)LTLayoutContainer.analyze.<locals>.getkey  s=    c#455 0w00w//r(   r\  c                     | j         S r#   r$   r  s    r&   rZ  z+LTLayoutContainer.analyze.<locals>.<lambda>  s    39 r(   )r   rW   r   r  r  rB   r/   r   r7   rI   r_  r  r~  r   r1   r	   rd   r   )r%   rT   textobjs	otherobjsr)   	textlinesempties	textboxestextboxr  assignerr  s               r&   rW   zLTLayoutContainer.analyze  s    !''J'JD Q Q9 	" 	"CKK!!!! 	F++Hh??@@	%&@&@)LL) 	" 	"CKK!!!!--h	BBCC	&$ * *))))0I 0%UE0A*B 0 0 0 0 NNvN&&&&..xCCDK$H $ $h'''U####NN44N555k"I..4$g../ 	


r(   )r4   r5   r6   r   r'   r:   r   rd   r   r  r  r/   r  r   r   r0   r  rW   r8   r(   r&   r|  r|    s       5T 5d 5 5 5 5
KK {#K 
*		K K K KZ   
#  
)		       D[5[5 	"[5 
k		[5 [5 [5 [5z#
 #
T #
 #
 #
 #
 #
 #
r(   r|  c                   F    e Zd ZdZdedededdfdZdefdZd	e	ddfd
Z
dS )LTFigurezRepresents an area used by PDF Form objects.

    PDF Forms can be used to present figures or pictures by embedding yet
    another PDF document within a page. Note that LTFigure objects can appear
    recursively.
    r   re   r   r!   Nc                     || _         || _        |\  }}}}||||z   ||z   f}t          ||          }t                              | |           d S r#   )r   r   r   r|  r'   )	r%   r   re   r   r2   ywhrects	            r&   r'   zLTFigure.__init__  s^    	Aq!1a!eQU# ..""4.....r(   c           
          d| j         j         d| j         dt          | j                   dt          | j                   d	S )Nr\   r   r   r   rL   )r^   r4   r   r   re   r   r   rM   s    r&   rN   zLTFigure.__repr__  s^    1' 1 1$) 1 1	""1 1 --1 1 1	
r(   rT   c                 N    |j         sd S t                              | |           d S r#   )rD   r|  rW   rV   s     r&   rW   zLTFigure.analyze  s.    ! 	F!!$11111r(   )r4   r5   r6   rP   rR   r   r   r'   rN   r:   rW   r8   r(   r&   r  r    s         /S / /f / / / / /
# 
 
 
 
2 2T 2 2 2 2 2 2r(   r  c            	       8    e Zd ZdZd
dedededdfdZdefd	Z	dS )LTPagezRepresents an entire page.

    Like any other LTLayoutContainer, an LTPage can be iterated to obtain child
    objects like LTTextBox, LTFigure, LTImage, LTRect, LTCurve and LTLine.
    r   pageidre   rotater!   Nc                 X    t                               | |           || _        || _        d S r#   )r|  r'   r  r  )r%   r  re   r  s       r&   r'   zLTPage.__init__  s*    ""4...r(   c           	      l    d| j         j         d| j        dt          | j                   d| j        d	S )Nr\   r   r   z rotate=rL   )r^   r4   r  r   re   r  rM   s    r&   rN   zLTPage.__repr__  sV    '' ' '$+ ' '	""' 'k' ' '	
r(   r3   )
r4   r5   r6   rP   r7   r   rI   r'   rR   rN   r8   r(   r&   r  r    sn          s $  d    

# 
 
 
 
 
 
r(   r  )Er  loggingcollections.abcr   r   r   typingr   r   r   r	   pdfminer.pdfcolorr
   pdfminer.pdfexceptionsr   r   pdfminer.pdffontr   pdfminer.pdfinterpr   r   pdfminer.pdftypesr   pdfminer.utilsr   r   r   r   r   r   r   r   r   r   r   r   r   	getLoggerr4   loggerr   r:   r*   rY   rd   r   r   r   r   r   r   r   r   r
  r  TextLineElementr  r$  rC  r/   rV  rg  rm  r0   ro  rx  r|  r  r  r8   r(   r&   <module>r     sY     8 8 8 8 8 8 8 8 8 8            , + + + + + > > > > > > > > $ $ $ $ $ $ 5 5 5 5 5 5 5 5 ' ' ' ' ' '                               
	8	$	$
 
 
 
 
 
 
 
@
 @
 @
 @
 @
 @
 @
 @
F+ + + + + + + +" " " " " " " "F F F F F& F F FR!F !F !F !F !Fk !F !F !FH
 
 
 
 
W 
 
 
B
 
 
 
 
W 
 
 
B
 
 
 
 
k 
 
 
0    VV   : : : : :[& : : :z ')6
*
*
*" " " " "+ww/ " " "2
 
 
 
 
K0 
 
 
$
 
 
 
 
+G4f 
 
 
 '? ? ? ? ?1 ? ? ?<<< << << << <<: << << <<~<: <: <: <: <: <: <: <:~" " " " "
+ " " ",    )       	    M12     /"23   	
 	
 	
 	
 	
k 	
 	
 	
	
 	
 	
 	
 	
k 	
 	
 	
u
 u
 u
 u
 u
K0 u
 u
 u
p2 2 2 2 2  2 2 2:
 
 
 
 
 
 
 
 
 
r(   