
    .i2                        d dl Z d dlmZmZ d dlmZmZmZmZm	Z	m
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 ddlmZmZmZmZ ddlmZ er
d dlZ dd	l!m"Z"  G d
 d          Z#e#j$        dz   Z%e#j&        dz   Z'dZ(dZ)e
e	e*e*e*f         e	e*e*e*e*f         e+f         Z,e
e	edf         ee         ef         Z-	 dde
eef         dee j.                 de*de
e*e/f         dee+         de0dej1        j1        fdZ2 G d d          Z3dS )    N)BufferedReaderBytesIO)TYPE_CHECKINGAnyListOptionalTupleUnion   )utils)T_bboxT_numT_obj
T_obj_listT_pointT_seq)T_table_settingsTableTableFinderTableSettings)MalformedPDFException)Pagec                       e Zd ZdZdZdZdZdS )COLORS)   r   r   )r   r   r   )r   r   r   )r   r   r   r   N)__name__
__module____qualname__REDGREENBLUETRANSPARENT     N/var/www/html/analyses/venv/lib/python3.11/site-packages/pdfplumber/display.pyr   r      s"        
CEDKKKr$   r   )2      H   .Fstreampathpage_ix
resolutionpassword	antialiasreturnc                    |r|}n|                      d           | }	 t          j        ||          }n&# t          j        $ r}t	          |          d }~ww xY w|                    |          }	|	                    |dz  | | | d                                          }
|                                 |
	                    d          S )Nr   )r.   r)   T)scaleno_smoothtextno_smoothpathno_smoothimageprefer_bgrxRGB)
seek	pypdfium2PdfDocumentPdfiumErrorr   get_pagerenderto_pilcloseconvert)r*   r+   r,   r-   r.   r/   src
pdfium_docepdfium_pageimgs              r%   get_page_imagerF   $   s       	A'*3BBB

  ' ' '#A&&&' %%g..K&--2o#m#m$} .   fhh  ;;us   5 AAAc                      e Zd Zdeddfdddeej        j                 deee	f         de
de
f
d	Zd
edeeeeef         fdZdedeeef         fdZdDdZ	 	 	 	 dEdeeej        ef         dede
dedededdfdZdDdZeefdedededd fdZeefd eee         d!f         dededd fd"Zeefd#e dededd fd$Z!eefd%ee"e          d&f         dededd fd'Z#eefd#e dededd fd(Z$eefd%ee"e          d&f         dededd fd)Z%e&eefd*eee'f         d+edededd f
d,Z(e&eefd-ee"e         e)d!f         d+edededd f
d.Z*d/e&efd0eee'f         d1ed+ededd f
d2Z+d/e&efd3ee"e         e)d!f         d1ed+ededd f
d4Z,e&ed5fd6e-d+edededd f
d7Z.	 dFd8eee/e0e1f                  dd fd9Z2ee&ee3j4        e3j5        fded+eded:e d;e dd fd<Z6d=d>d?d? ed@          fefded+ededd fdAZ7de8fdBZ9dGdCZ:dS )H	PageImageNFpager   originalr-   r/   force_mediaboxc                    || _         |j        r|n|j        | _        || _        |At          |j        j        |j        j        |j	        dz
  |||j        j
                  | _        n|| _        | j        j        d         |j        d         |j        d         z
  z  | _        |j        |j        k    r|j        n|r|j        n|j        | _        |j        |j        k    r|                     |j                  }|                     | j                  }| j                            |d         |d         z
  |d         |d         z
  |d         |d         z
  |d         |d         z
  f          | _        |                                  d S )Nr   )r*   r+   r,   r-   r/   r.   r         )rI   is_original	root_pagerootr-   rF   pdfr*   r+   page_numberr.   rJ   sizecropboxr2   bboxmediabox_reproject_bboxcropreset)selfrI   rJ   r-   r/   rK   	crop_dims	bbox_dimss           r%   __init__zPageImage.__init__N   sy    	 ,@DD$.	$*xX](1,%#*  DMM %DM]'*dl1oQ.OP
 yDM)) II#1C$--t| 		 9$$,,T\::I,,TY77I M..aL9Q</aL9Q</aL9Q</aL9Q</	 DM 	

r$   rV   r0   c                     |\  }}}}|                      ||f          \  }}|                      ||f          \  }}	||||	fS N)
_reproject)
r[   rV   x0topx1bottom_x0_top_x1_bottoms
             r%   rX   zPageImage._reproject_bbox   sQ    "CVOORI..	TF|44WT3((r$   coordc                     |\  }}|| j         d         z
  | j        z  }|| j         d         z
  | j        z  }t          |          t          |          fS )z
        Given an (x0, top) tuple from the *root* coordinate system,
        return an (x0, top) tuple in the *image* coordinate system.
        r   r   )rV   r2   int)r[   rj   rb   rc   rf   rg   s         r%   ra   zPageImage._reproject   sR    
 CDIaL DJ.dil"dj0C#d))$$r$   c                     t           j                            d| j        j                  | _        | j                            | j                   t           j                            | j        d          | _	        | S )Nr7   RGBA)
PILImagenewrJ   rT   	annotatedpaste	ImageDrawDrawdrawr[   s    r%   rZ   zPageImage.reset   sV    udm.@AAT]+++M&&t~v>>	r$   PNGT      destformatquantizecolorsbitskwargsc                     |r?| j                             |t          j        j                                      d          }n| j         } |j        |f||| j        | j        fd| d S )N)methodP)r|   r   dpi)rr   r}   ro   rp   
FASTOCTREEr@   saver-   )r[   r{   r|   r}   r~   r   r   outs           r%   r   zPageImage.save   s      	!.))&9M)NNVV CC .C	
$/2		
 	

 	
 	
 	
 	
 	
r$   c                 B    |                      | j        | j                  S r`   )	__class__rI   rJ   rw   s    r%   copyzPageImage.copy   s    ~~di777r$   points_or_objstrokestroke_widthc                 Z   t          |t          t          f          r|}nNt          |t                    rd|v rd |d         D             }n"|}|d         |d         f|d         |d         ff}| j                            t          t          | j        |                    ||           | S )Nptsc                     g | ]	\  }}||f
S r#   r#   ).0xys      r%   
<listcomp>z'PageImage.draw_line.<locals>.<listcomp>   s     >>>Aq!f>>>r$   rb   rc   rd   re   fillwidth)
isinstancetuplelistdictrv   linemapra   )r[   r   r   r   pointsobjs         r%   	draw_linezPageImage.draw_line   s     meT]33 	K"FFt,, 	K-1G1G>>u)=>>>FF  C4y#e*-D	3x=/IJF	T_f--..V< 	 	
 	
 	
 r$   list_of_lineszpd.DataFramec                 d    t          j        |          D ]}|                     |||           | S Nr   r   )r   to_listr   )r[   r   r   r   r   s        r%   
draw_lineszPageImage.draw_lines   s?     }-- 	H 	HANN1V,NGGGGr$   locationc                     || j         d         || j         d         f}| j                            |                     |          ||           | S )Nr   rN   r   rV   rv   r   rX   r[   r   r   r   r   s        r%   
draw_vlinezPageImage.draw_vline   sK     DIaL(DIaLA	t++F33&UUUr$   	locationszpd.Series[float]c                 Z    t          |          D ]}|                     |||           | S r   )r   r   r[   r   r   r   r   s        r%   draw_vlineszPageImage.draw_vlines   ;     i 	I 	IAOOAf<OHHHHr$   c                     | j         d         || j         d         |f}| j                            |                     |          ||           | S )Nr   rM   r   r   r   s        r%   
draw_hlinezPageImage.draw_hline   sK     )A,$)A,A	t++F33&UUUr$   c                 Z    t          |          D ]}|                     |||           | S r   )r   r   r   s        r%   draw_hlineszPageImage.draw_hlines   r   r$   bbox_or_objr   c                 Z   t          |t          t          f          r|}n |}|d         |d         |d         |d         f}|\  }}}	}
|dz  }t          ||z   ||	z   dz            }t          ||z   ||
z   dz            }t	          |	|z
  ||	z   dz            }	t	          |
|z
  ||
z   dz            }
|                     |||	|
f          }| j                            ||t          j	                   |dk    r6||f|	|ff||
f|	|
ff||f||
ff|	|f|	|
ffg}| 
                    |||           | S )Nrb   rc   rd   re   rM   r   r   )r   r   r   minmaxrX   rv   	rectangler   r"   r   )r[   r   r   r   r   rV   r   rb   rc   rd   re   half	fill_bboxsegmentss                 r%   	draw_rectzPageImage.draw_rect   su    kE4=11 	EDDCIs5z3t9c(mDD"CVadR"WM**#*sV|q011dR"WM**Vd]S6\Q$677(("c2v)>??		ItV-?@@@!cRI&fF|,cRL)cRL)	H OOHV,OOOOr$   list_of_rectsc                 f    t          j        |          D ]}|                     ||||           | S )Nr   r   r   )r   r   r   )r[   r   r   r   r   r   s         r%   
draw_rectszPageImage.draw_rects  sA     }-- 	S 	SANN14\NRRRRr$      center_or_objradiusc                    t          |t                    r|}n*|}|d         |d         z   dz  |d         |d         z   dz  f}|\  }}||z
  ||z
  ||z   ||z   f}	| j                            |                     |	          ||           | S )Nrb   rd   rM   rc   re   )r   r   rv   ellipserX   )
r[   r   r   r   r   centerr   cxcyrV   s
             r%   draw_circlezPageImage.draw_circle(  s     mU++ 	U"FFC4y3t9,1CJX4NRS3STFBVR&["v+rF{C	$..t44dFCCCr$   list_of_circlesc                 f    t          j        |          D ]}|                     ||||           | S )N)r   r   r   )r   r   r   )r[   r   r   r   r   r   s         r%   draw_circleszPageImage.draw_circles9  sD     // 	I 	IAQvDHHHHr$   r   tablec                 B    |                      |j        |||           | S )z+
        Outline all found tables.
        r   )r   cells)r[   r   r   r   r   s        r%   debug_tablezPageImage.debug_tableD  s1     	Kd6 	 	
 	
 	
 r$   table_settingsc                    t          |t                    r|}nH|t          |t          t          f          r| j                            |          }nt          d          |j        D ]}|                     |           | 	                    |j
        d           |                     t          |j                                                  t          j        t          j        dz   d           | S )NzGArgument must be instance of TableFinderor a TableFinder settings dict.r   )r   r'   rN   )r   r   r   )r   r   r   r   rI   debug_tablefinder
ValueErrortablesr   r   edgesr   r   intersectionskeysr   r"   r!   )r[   r   finderr   s       r%   r   zPageImage.debug_tablefinderS  s     nk22 
	#FF#z]D1(
 (
# Y00@@FF2  
 ] 	$ 	$EU####1555%**,,--#;'	 	 	
 	
 	
 r$   x_tolerancey_tolerancec                 p    | j                             ||          }|                     ||||           | S )N)r   r   r   r   r   )rI   extract_wordsr   )r[   r   r   r   r   r   wordss          r%   outline_wordszPageImage.outline_wordsr  sF     	''# ( 
 
 	f4lSSSr$   )r   r   r   r   r   r   g     O@c                 L    |                      | j        j        |||           | S )Nr   )r   rI   chars)r[   r   r   r   s       r%   outline_charszPageImage.outline_chars  s3     	IOFL 	 	
 	
 	
 r$   c                 r    t                      }|                     |d           |                                S )Nrx   )r   r   getvalue)r[   bs     r%   
_repr_png_zPageImage._repr_png_  s-    II		!Uzz||r$   c                 8    | j                                          d S r`   )rr   showrw   s    r%   r   zPageImage.show  s    r$   )r0   rH   )rx   Try   rz   r`   )r0   N);r   r   r   DEFAULT_RESOLUTIONr   ro   rp   r
   rl   floatboolr^   r   r	   rX   r   ra   rZ   strpathlibPathr   r   r   r   DEFAULT_STROKEDEFAULT_STROKE_WIDTHT_contains_pointsT_colorr   r   r   r   r   r   r   r   r   DEFAULT_FILLr   r   r   r   r   r   r   r   r   r   r   r   r   DEFAULT_X_TOLERANCEDEFAULT_Y_TOLERANCEr   r   bytesr   r   r#   r$   r%   rH   rH   M   sb        /3(:$2 22 39?+2 #u*%	2
 2 2 2 2 2h)F )uS#sC5G/H ) ) ) )% %E#s(O % % % %    
 
Cw./
 
 	

 
 
 
 

 
 
 
08 8 8 8 )0	 (  	
 
   4 )0	 U#45~EF  	
 
    )0	   	
 
    )0	 e&889  	
 
    )0	   	
 
    )0	 e&889  	
 
    %(0 65=)  	
  
   H %(0	 	T&\:~EF	 	 		
 	 
	 	 	 	 $( We^,  	
  
   ( $(	 	tG}j.HI	 	 		
 	 
	 	 	 	 %(   	
  
   & 	  +}.>>?

 
   B )$0"6"6   	
   
   " +aCCLL10	
 

 
 	

 

 
 
 
E    
     r$   rH   )F)4r   ior   r   typingr   r   r   r   r	   r
   	PIL.Imagero   PIL.ImageDrawr9    r   _typingr   r   r   r   r   r   r   r   r   r   r   utils.exceptionsr   pandaspdrI   r   r   r!   r   r   r   r   r   rl   r   r   r   r   r   r   rp   rF   rH   r#   r$   r%   <module>r     sn    & & & & & & & & C C C C C C C C C C C C C C C C                   E E E E E E E E E E E E E E E E F F F F F F F F F F F F 3 3 3 3 3 3         {U"f$  
c3m$eCc3,>&?D
E%-tG}eCD  & &.')*&
7<
 & & c5j!	&
 sm& & 	Y_& & & &RF F F F F F F F F Fr$   