
    .i<\                     v   U d Z ddlZddlZddl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mZmZmZ ddlmZmZ erddlmZ ddlZdZeej        eej         f         Z!eee	f         Z" G d d	          Z#d
ede$fdZ%de&defdZ'dede(defdZ)	 	 d\dee$ef         dededefdZ*de(de(de(de(fdZ+de(de(de(de$de$f
d Z,d!e(de(de(de(de$de$fd"Z-ee.e.f         Z/ee.e.e.e.f         Z0ee.e.e.e.e.e.f         Z1eee         eee.e.f         eee.e.e.e.f         eee.e.e.e.e.e.f         f         Z2d#Z3e1e4d$<   dede0fd%Z5d&e1d'e1de1fd(Z6d)e1d*e/de1fd+Z7d)e1d*e/de/fd,Z8d)e1d-e0de0fd.Z9d)e1d*e/de/fd/Z:d0e&de;fd1Z< ed2          Z=d3ee=         dee=         fd4Z>d!e
e=ge;f         d3ee=         deee=         ee=         f         fd5Z?d6e.d7e.d8e(de@fd9ZAd:ee/         de0fd;ZB	 d]d<ee=         d=e
e=ge.f         d>ee=         dee=         fd?ZCd@e(d<ee=         deee=dAf                  fdBZDd^de$dCe(de(fdDZEdEF                    dF dGD                       ZGde$defdHZHd0edefdIZIdJe0defdKZJd)e1defdLZKdMdNdOdNde/fdPZL edQdNR          ZM G dS dTeeM                   ZNg dUZOg dVZPdWe(defdXZQdWe(defdYZRdZe$de$fd[ZSdS )_zMiscellaneous Routines.    N)escape)TYPE_CHECKINGAnyBinaryIOCallableDictGenericIterableIteratorListOptionalSetTextIOTupleTypeVarUnioncast)PDFTypeErrorPDFValueError)LTComponentic                   N    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
e	de	ddfdZ
dS )open_filenamezContext manager that allows opening a filename
    (str or pathlib.PurePath type is supported) and closes it on exit,
    (just like `open`), but does nothing for file-like objects.
    filenameargskwargsreturnNc                 r   t          |t          j                  rt          |          }t          |t                    rt	          |g|R i || _        d| _        d S t          |t          j                  r#t          t          |          | _        d| _        d S t          dt          |          z            )NTFzUnsupported input type: %s)
isinstancepathlibPurePathstropenfile_handlerclosingioIOBaser   AnyIOr   type)selfr   r   r   s       J/var/www/html/analyses/venv/lib/python3.11/site-packages/pdfminer/utils.py__init__zopen_filename.__init__/   s    h 011 	%8}}Hh$$ 	N'+H'Ft'F'F'Fv'F'FDDLLL"),, 	N $UH 5 5D DLLL;d8nnLMMM    c                     | j         S N)r#   r)   s    r*   	__enter__zopen_filename.__enter__;   s      r,   exc_typeexc_valexc_tbc                 J    | j         r| j                                         d S d S r.   )r$   r#   close)r)   r1   r2   r3   s       r*   __exit__zopen_filename.__exit__>   s1    < 	&##%%%%%	& 	&r,   )__name__
__module____qualname____doc__
FileOrNamer   r+   r'   r0   objectr6    r,   r*   r   r   )   s         

N 
NC 
N3 
N4 
N 
N 
N 
N!5 ! ! ! !& && && &T & & & & & &r,   r   in_strr   c                     t          | t                    s$J t          t          |                                 |                                 S )z'Converts to bytes, encoding to unicode.)r   r!   r(   encode)r>   s    r*   make_compat_bytesrA   C   s<    fc""55CV$5$5555==??r,   oc                     t          | t                    rOt          j        |           }	 |                     |d                   S # t
          $ r t          |           cY S w xY wt          |           S )z>Converts everything to string, if bytes guessing the encoding.encoding)r   bytescharset_normalizerdetectdecodeUnicodeDecodeErrorr!   )rB   encs     r*   make_compat_strrK   I   sv    !U  '**	88C
O,,,! 	 	 	q66MMM	 1vvs   A A"!A"ssizec                     |dk     r
| d |         S t          |           |k    r |dz
  dz  }| d |          d| | d           S | S )N         z ... )len)rL   rM   lengths      r*   shorten_strrT   U   s_    axx$x
1vv}}(qGVG*001fWXX;000r,   utf-8ignorebytesorstringrD   	erractionc                     t          | t                    r| S t          | t                    s$J t          t          |                                 |                     ||          S )z^When Py2 str.encode is called, it often means bytes.encode in Py3.

    This does either.
    )r   r!   rE   r(   rH   )rW   rD   rX   s      r*   compatible_encode_methodrZ   _   s`     -%% mU++EESm1D1D-E-EEEE)444r,   leftabove
upper_leftc                     | |z   |z
  }t          || z
            }t          ||z
            }t          ||z
            }||k    r||k    r| S ||k    r|S |S r.   )abs)r[   r\   r]   ppapbpcs          r*   paeth_predictorrd   n   sm     	uz!A	QXB	QYB	Q^		B 
RxxB"HH	rr,   colorscolumnsbitspercomponentdatac                 x   |dk    rd| }t          |          | |dz  z  }||z  }g }t          dt          |          |          D ]d}g }	t          |          D ];}
|||
z            }|
|k    r||	|
|z
           z  }|dz  }|	                    |           <|                    |	           et          |          S )zReverse the effect of the TIFF predictor 2

    Documentation: https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf (Section 14, page 64)
       z Unsupported `bitspercomponent': r      )r   rangerR   appendextendrE   )re   rf   rg   rh   	error_msgbppnbytesbuf
scanline_irawi	new_values               r*   apply_tiff_predictorrw      s     1I7GII	I&&&
$)
*Cs]FCAs4yy&11  
v 	" 	"AZ!^,ICxxSS\)	S 	JJy!!!!

3::r,   predc                     |dvrd|z  }t          |          ||z  |z  dz  }||z  dz  }g }t          d|z            }	t          dt          |          |dz             D ]}
||
         }||
dz   |
dz   |z            }g }|dk    rt          |          }n|dk    rXt	          |          D ]F\  }}||z
  dk     rd}nt          |||z
                     }||z   dz  }|                    |           Gnb|dk    r5t          ||	          D ]"\  }}||z   dz  }|                    |           #n'|d	k    rrt	          |          D ]a\  }}||z
  dk     rd}nt          |||z
                     }t          |	|                   }|||z   dz  z   dz  }|                    |           bn|d
k    rt	          |          D ]\  }}||z
  dk     rd}d}n0t          |||z
                     }t          |	||z
                     }t          |	|                   }t          |||          }||z   dz  }|                    |           nt          d|z            |	                    |           |}	t          |          S )zxReverse the effect of the PNG predictor

    Documentation: http://www.libpng.org/pub/png/spec/1.2/PNG-Filters.html
    )rj      z"Unsupported `bitspercomponent': %drj       r   rz      rQ         zUnsupported predictor value: %d)r   listrl   rR   	enumerateintrm   ziprd   rn   rE   )rx   re   rf   rg   rh   msgrq   rp   rr   
line_abovers   filter_typeline_encodedrt   jsub_x	raw_x_bppraw_xup_xprior_x	average_xpaeth_xprior_x_bpppaeths                           r*   apply_png_predictorr      s%    v%%25EEC   g 00A5F
#
#q
(C
Cg'((JAs4yy&1*55 N N
:&JNZ!^f-DDE!|$$CCA &l33 " "5s7Q;; !II #CCL 1 1I*c1

5!!!!" A "%\:!>!> " "g3.

5!!!!" A !*, 7 7 " "9s7Q;; !II #CCL 1 1Ijm,,"i'&9a%??3F

5!!!!" A (55 
" 
"
7s7Q;; !I"#KK #CCL 1 1I"%jS&9":":Kjm,,'	7KHH 5C/

5!!!!
"   AK OPPP

3

::r,   )rz   r   r   rz   r   r   MATRIX_IDENTITYc                     	 | \  }}}}t          |          t          |          t          |          t          |          fS # t          $ r t          d          w xY w)NzCould not parse rectangle)float
ValueErrorr   )rB   x0y0x1y1s        r*   
parse_rectr     sf    9RRRyy%))U2YYb		99 9 9 978889s   A A Am1m0c                     | \  }}}}}}|\  }}	}
}}}	 ||z  |
|z  z   |	|z  ||z  z   ||z  |
|z  z   |	|z  ||z  z   ||z  |
|z  z   |z   |	|z  ||z  z   |z   fS r.   r=   )r   r   a1b1c1d1e1f1a0b0c0d0e0f0s                 r*   mult_matrixr     s    !RRR!RRR5
R"r'
R"r'
R"r'
R"r'
R"r'B
R"r'B r,   mvc                 ^    | \  }}}}}}|\  }}	||||||z  |	|z  z   |z   ||z  |	|z  z   |z   fS )zTranslates a matrix by (x, y) inside the projection.

    The matrix is changed so that its origin is at the specified point in its own
    coordinate system. Note that this is different from translating it within the
    original coordinate system.r=   
r   r   abcdefxys
             r*   translate_matrixr   #  sT     Q1aAFQaAq1uq1u}q(!a%!a%-!*;;;r,   c                 V    | \  }}}}}}|\  }}	||z  ||	z  z   |z   ||z  ||	z  z   |z   fS )zApplies a matrix to a point.r=   r   s
             r*   apply_matrix_ptr   .  sJ    Q1aAFQq51q5=1a!ea!ema///r,   rectc           	      T   |\  }}}}||f}||f}||f}||f}	t          | |          \  }
}t          | |          \  }}t          | |          \  }}t          | |	          \  }}t          |
|||          t          ||||          t          |
|||          t          ||||          fS )a  Applies a matrix to a rectangle.

    Note that the result is not a rotated rectangle, but a rectangle with the same
    orientation that tightly fits the outside of the rotated content.

    :param m: The rotation matrix.
    :param rect: The rectangle coordinates (x0, y0, x1, y1), where x0 < x1 and y0 < y1.
    :returns a rectangle with the same orientation, but that would fit the rotated
        content.
    )r   minmax)r   r   r   r   r   r   left_bottomright_bottom	right_topleft_topleft1bottom1right1bottom2right2top1left2top2s                     r*   apply_matrix_rectr   5  s     RRr(K8LRIBxH&q+66UG'<88VW$Q	22NVT#Ax00MUD 	E5&&))GWdD))E5&&))GWdD))	 r,   c                 J    | \  }}}}}}|\  }}	||z  ||	z  z   ||z  ||	z  z   fS )zCEquivalent to apply_matrix_pt(M, (p,q)) - apply_matrix_pt(M, (0,0))r=   )
r   r   r   r   r   r   r   r   r`   qs
             r*   apply_matrix_normr   S  s@    Q1aAFQq51q5=!a%!a%-''r,   r   c                 :    t          | t          t          f          S r.   )r   r   r   r   s    r*   isnumberr   ]  s    a#u&&&r,   _Tobjsc              #   l   K   t                      }| D ] }||v r|                    |           |V  !dS )zEliminates duplicated elements.N)setadd)r   doneobjs      r*   uniqr   d  sN      55D  $;;					 r,   c                     g }g }|D ]8} | |          r|                     |           #|                     |           9||fS )z9Split a list into two classes according to the predicate.)rm   )rx   r   tr   r   s        r*   fsplitr   n  sV    
A
A  499 	HHSMMMMHHSMMMMa4Kr,   v0v1r   c                 h    t          t          |           |z  t          ||z             |z            S )zReturns a discrete range.)rl   r   )r   r   r   s      r*   dranger   z  s+    RAs26{{a/000r,   ptsc                     t           t           t            t            f}|\  }}}}| D ]E\  }}t          ||          }t          ||          }t          ||          }t          ||          }F||||fS )z7Compute a minimal rectangle that covers all the points.)INFr   r   )r   limitr   r   r   r   r   r   s           r*   	get_boundr     sy    cTC4(ERR  1QZZQZZQZZQZZr2r>r,   seqfuncmaxobjc                 B    d}| D ]} ||          }|||k     r||}}|S )z;Picks the object obj where func(obj) has the highest value.Nr=   )r   r   r   maxscorer   scores         r*   pickr     sD     H . .S		x%//"'vXMr,   n.c              #      K   g }|D ]=}|                     |           t          |          | k    rt          |          V  g }>dS )z$Groups every n elements of the list.N)rm   rR   tuple)r   r   rr   s       r*   choplistr     sW      
A  	q66Q;;((NNNA	 r,   defaultc                 b    t          |           }|s|S t                              | dd          S )z7Unpacks variable-length unsigned integers (big endian).bigF)	byteordersigned)rR   r   
from_bytes)rL   r   rS   s      r*   nunpackr     s3    VVF @~~a5~???r,    c              #   4   K   | ]}t          |          V  d S r.   )chr).0r   s     r*   	<genexpr>r     sD       D D	 FFD D D D D Dr,   (   r   rz   rQ   r}   r~   rP      rO   rj   	   
                                       r  i  i  i  i  i  i  i  i      !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~   r   i"   i    i!   i&   i   i   i  iD   i9   i:   i"  i0   i   i   i   i   i   i   i"!  i  i  iA  iR  i`  ix  i}  i1  iB  iS  ia  i~  r   i                                       r                                                                                                                                                                                                                                                      r|   c                     |                      d          rt          | dd         dd          S d                    d | D                       S )z+Decodes a PDFDocEncoding string to Unicode.s   rQ   Nzutf-16berV   r   c              3   0   K   | ]}t           |         V  d S r.   )PDFDocEncoding)r   r   s     r*   r   zdecode_text.<locals>.<genexpr>  s'      44Q~a(444444r,   )
startswithr!   join)rL   s    r*   decode_textr    sQ    ||K   51QRR5*h///ww44!444444r,   c                 N    t          | t                    rdS t          |           S )z"Encodes a string for SGML/XML/HTMLr   )r   rE   r   r   s    r*   rJ   rJ     s%    !U r!99r,   bboxc                 2    | \  }}}}|dd|dd|dd|dS )Nz.3f,r=   )r  r   r   r   r   s        r*   bbox2strr    s@    RR111r1111111111r,   c                 J    | \  }}}}}}d|dd|dd|dd|dd|dd|ddS )N[z.2fr  z, (z)]r=   )r   r   r   r   r   r   r   s          r*   
matrix2strr    s_    Q1aABqBBBqBBBqBBBqBBBBBBBBBBBr,   obj1r   obj2c                 *   t          | j        |j                  t          | j        |j                  }}t          | j        |j                  t          | j        |j                  }}||z
  ||z
  }}|| j        z
  |j        z
  || j        z
  |j        z
  }	}|dk     rX|	dk     rR| j        | j        z   dz  | j        | j        z   dz  }}
|j        |j        z   dz  |j        |j        z   dz  }}|
|z
  ||z
  fS t          d|          t          d|	          fS )a  A distance function between two TextBoxes.

    Consider the bounding rectangle for obj1 and obj2.
    Return vector between 2 boxes boundaries if they don't overlap, otherwise
    returns vector betweeen boxes centers

             +------+..........+ (x1, y1)
             | obj1 |          :
             +------+www+------+
             :          | obj2 |
    (x0, y0) +..........+------+
    r   rQ   )r   r   r   r   r   r   widthheight)r  r  r   r   r   r   owohiwihxc1yc1xc2yc2s                 r*   vecBetweenBoxesr    s    DGTW%%s47DG'<'<RDGTW%%s47DG'<'<RRbRTZ$*,b4;.>.LR	Avv"q&&w(A-$'0AQ/Fcw(A-$'0AQ/FcSy#)##1bzz3q"::%%r,   LTComponentT)boundc                       e Zd ZdZddededdfdZdefdZde	e
         fd	Zdefd
ZdedefdZdede	e         fdZdee
         ddfdZde
ddfdZde
ddfdZdede	e
         fdZdS )PlanezA set-like data structure for objects placed on a plane.

    Can efficiently find objects in a certain rectangular area.
    It maintains two parallel lists of objects, each of
    which is sorted by its x or y coordinate.
    r  r  gridsizer   Nc                     g | _         t                      | _        i | _        || _        |\  | _        | _        | _        | _        d S r.   )	_seqr   _objs_gridr  r   r   r   r   )r)   r  r  s      r*   r+   zPlane.__init__  s<    (*	(+
68
 /3,$'47DGGGr,   c                 &    dt          |           z  S )Nz<Plane objs=%r>)r   r/   s    r*   __repr__zPlane.__repr__  s     4::--r,   c                 *      fd j         D             S )Nc              3   .   K   | ]}|j         v |V  d S r.   r  )r   r   r)   s     r*   r   z!Plane.__iter__.<locals>.<genexpr>  s/      >>C4:,=,=,=,=,=,=>>r,   )r  r/   s   `r*   __iter__zPlane.__iter__  s    >>>>ty>>>>r,   c                 *    t          | j                  S r.   )rR   r  r/   s    r*   __len__zPlane.__len__  s    4:r,   r   c                     || j         v S r.   r  )r)   r   s     r*   __contains__zPlane.__contains__  s    dj  r,   c              #     K   |\  }}}}|| j         k    s!| j        |k    s|| j        k    s| j        |k    rd S t	          | j         |          }t	          | j        |          }t          | j        |          }t          | j        |          }t          ||| j                  D ]!}t          ||| j                  D ]}||fV  	"d S r.   )r   r   r   r   r   r   r   r  )r)   r  r   r   r   r   grid_ygrid_xs           r*   	_getrangezPlane._getrange  s      RR==DGrMMR47]]dgmmF""""RT]33 	' 	'F R77 ' 'v&&&&&'	' 	'r,   r   c                 :    |D ]}|                      |           d S r.   )r   )r)   r   r   s      r*   rn   zPlane.extend  s,     	 	CHHSMMMM	 	r,   c                 >   |                      |j        |j        |j        |j        f          D ]:}|| j        vrg }|| j        |<   n| j        |         }|                    |           ;| j                            |           | j        	                    |           dS )zPlace an object.N)
r  r   r   r   r   r  rm   r  r  r   )r)   r   kr   s       r*   r   z	Plane.add  s     @AA 	 	A
""(* !
1JqMHHSMMMM	
sr,   c                 
   |                      |j        |j        |j        |j        f          D ]:}	 | j        |                             |           $# t          t          f$ r Y 7w xY w| j	                            |           dS )zDisplace an object.N)
r  r   r   r   r   r  removeKeyErrorr   r  )r)   r   r  s      r*   r  zPlane.remove   s     @AA 	 	A
1$$S))))j)   
#s    AA&%A&c              #   .  K   |\  }}}}t                      }|                     |          D ]g}|| j        vr| j        |         D ]M}||v r|                    |           |j        |k    s!||j        k    s|j        |k    s||j        k    rI|V  NhdS )z)Finds objects that are in a certain area.N)r   r  r  r   r   r   r   r   )	r)   r  r   r   r   r   r   r  r   s	            r*   findz
Plane.find)  s      RRuu%% 		 		A
""z!}  $;;6R<<2<<36R<<2<<						 		r,   )r  )r7   r8   r9   r:   Rectr   r+   r!   r  r   r  r  r  r<   boolr  Pointr  r
   rn   r   r  r  r=   r,   r*   r  r    s|        4 4T 4S 4$ 4 4 4 4.# . . . .?(<0 ? ? ? ?    ! !4 ! ! ! !
'd 
'x 
' 
' 
' 
'8L1 d    
| 
 
 
 
 
, 4     (<"8      r,   r  )ru   r   r   r   )r   lr   valuec                 x   d| cxk     rdk     sn J g }d}| dk    r
t          | d          \  } }|dk    rF|                    dt          |                    |                    dt          |dz                       n|dk    rC|                    dt          |                    |                    dt          |                    nV|dk    }|r&|                    dt          |                    |dz  }|                    |rdndt          |         |z             |dz  }| dk    
d                    |          S )	z,Format a number as lowercase Roman numerals.r   i  r   r   rz   r~   rP   r   )divmodinsert
ROMAN_ONESROMAN_FIVESr  )r  resultindex	remainder	over_fives        r*   format_int_romanr  =  sN   utFE
1**!%,,y>>MM!Z.///MM!Z	23333!^^MM!Z.///MM![/0000!QI aU!3444Q	MMy/!!aE1BY1NOOO
 1**  776??r,   c                 $   | dk    sJ g }| dk    rXt          | dz
  t          t          j                            \  } }|                    t          j        |                    | dk    X|                                 d                    |          S )z5Format a number as lowercase letters a-z, aa-zz, etc.r   rz   r   )r	  rR   stringascii_lowercaserm   reverser  )r  r  r  s      r*   format_int_alphar  V  s    19999F
1**!%!)S1G-H-HIIyf,Y7888 1** NN776??r,   paddedc                     t          |           dk    r| S | d         dk    r| S t          |           k    r| S t          fd|  d         D                       r| d          S | S )a1  Remove block padding as described in PDF 1.7 section 7.6.2:

    > For an original message length of M, the pad shall consist of 16 -
    (M mod 16) bytes whose value shall also be 16 - (M mod 16).
    > Note that the pad is present when M is evenly divisible by 16;
    it contains 16 bytes of 0x10.
    r   r  c              3   $   K   | ]
}|k    V  d S r.   r=   )r   r   paddings     r*   r   zunpad_aes.<locals>.<genexpr>u  s'      
3
3A1<
3
3
3
3
3
3r,   N)rR   all)r  r  s    @r*   	unpad_aesr  c  s     6{{aRjG||V

3
3
3
3		!2
3
3
333 !ixi  Mr,   )rU   rV   r.   )r   )Tr:   r%   r   r  htmlr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   pdfminer.pdfexceptionsr   r   pdfminer.layoutr   rF   r   r    r!   r&   r;   r'   r   rE   rA   r<   rK   r   rT   rZ   rd   rw   r   r   r  r  MatrixPathSegmentr   __annotations__r   r   r   r   r   r   r  r   r   r   r   rl   r   r   r   r   r   r  r  r  rJ   r  r  r  r  r  r  r  r  r  r  r=   r,   r*   <module>r%     s      				                                           & ? > > > > > > > ,++++++     7#S")34
fh& & & & & & & &4c e    	v 	# 	 	 	 	3 c c     5 5$55 5 		5 5 5 5# c s s    $14<A
   4b
bb b 	b
 b b b b bJ 	eUlUE5%'(	ueUE5%7	8	#J	#ue
	#ueUE
)*	#ueUE5%
78: - , , ,9# 9$ 9 9 9 9F  6    < <5 <V < < < <0v 0% 0E 0 0 0 0 t     <( (E (e ( ( ( (' '4 ' ' ' ' WT]]x|     	2$*% 	Xb\ 	eDHdSUhDV>W 	 	 	 	1u 1% 1C 1E 1 1 1 1
	8E? 	t 	 	 	 	   	"
B4;
 RL b\	    (2, 8E"c'N+C    @ @u @s @3 @ @ @ @  D DAD D D D DN55 5S 5 5 5 53 3    24 2C 2 2 2 2
C& CS C C C C
&- &} & & & & &4 w~];;;M M M M MGL! M M M` "!!
ooC C    2
C 
C 
 
 
 
e       r,   