o
    h                     @   s4  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 d dlmZ d dlmZmZmZmZmZ d dlmZmZmZ d dlmZmZ d dlmZm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)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> d dl?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF e GeHZIG dd de ZJG dd de ZKe8dZLe8dZMe8dZNe8dZOe8dZPG dd dZQeeRe
eReReRf e
eReReReRf f ZSG dd dZTG dd dZUG dd  d e;ee9e.f  ZVe<e. ZW	 G d!d" d"ZXdS )#    N)BytesIO)DictListMappingOptionalSequenceTupleUnioncast)settings)	safe_cmyk
safe_floatsafe_intsafe_matrixsafe_rgb)CMapCMapBaseCMapDB)PREDEFINED_COLORSPACEPDFColorSpace)	PDFDevice
PDFTextSeq)PDFExceptionPDFValueError)
PDFCIDFontPDFFontPDFFontErrorPDFTrueTypeFontPDFType1FontPDFType3Font)PDFPage)LITERALS_ASCII85_DECODE	PDFObjRef	PDFStream
dict_value
list_valueresolve1stream_value)PSEOFPSTypeError)KWDLIT	PSKeyword	PSLiteralPSStackParserPSStackTypekeyword_nameliteral_name)MATRIX_IDENTITYMatrixPathSegmentPointRectchoplistmult_matrixc                   @      e Zd ZdS )PDFResourceErrorN__name__
__module____qualname__ r?   r?   K/var/www/html/govbot/env/lib/python3.10/site-packages/pdfminer/pdfinterp.pyr:   6       r:   c                   @   r9   )PDFInterpreterErrorNr;   r?   r?   r?   r@   rB   :   rA   rB   PDFTextFontFormImagec                   @   sJ   e Zd ZU eed< eed< dddZdefddZdd	d
Z	dddZ
dS )PDFTextStatematrix
linematrixreturnNc                 C   s<   d | _ d| _d| _d| _d| _d| _d| _d| _|   d S )Nr   d   )	fontfontsize	charspace	wordspacescalingleadingrenderriseresetselfr?   r?   r@   __init__I   s   zPDFTextState.__init__c                 C   s0   d| j | j| j| j| j| j| j| j| j| j	f
 S )Nz<PDFTextState: font=%r, fontsize=%r, charspace=%r, wordspace=%r, scaling=%r, leading=%r, render=%r, rise=%r, matrix=%r, linematrix=%r>)
rM   rN   rO   rP   rQ   rR   rS   rT   rI   rJ   rV   r?   r?   r@   __repr__V   s   zPDFTextState.__repr__c                 C   sZ   t  }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	| j
|_
|S N)rH   rM   rN   rO   rP   rQ   rR   rS   rT   rI   rJ   rW   objr?   r?   r@   copyi   s   zPDFTextState.copyc                 C   s   t | _d| _d S )Nr   r   )r2   rI   rJ   rV   r?   r?   r@   rU   w      
zPDFTextState.resetrK   N)rK   rH   )r<   r=   r>   r3   __annotations__r5   rX   strrY   r]   rU   r?   r?   r?   r@   rH   E   s   
 

rH   c                   @   s.   e Zd Zd	ddZd
ddZdefddZdS )PDFGraphicStaterK   Nc                 C   sN   d| _ d | _d | _d | _d | _d | _d | _d| _td | _	d| _
td | _d S )Nr   
DeviceGray)	linewidthlinecaplinejoin
miterlimitdashintentflatnessscolorr   scsncolorncsrV   r?   r?   r@   rX      s   
zPDFGraphicState.__init__c                 C   sR   t  }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	|S rZ   )
rc   re   rf   rg   rh   ri   rj   rk   rl   rn   r[   r?   r?   r@   r]      s   zPDFGraphicState.copyc              
   C   s,   d| j | j| j| j| j| j| j| j| jf	 S )Nz<PDFGraphicState: linewidth=%r, linecap=%r, linejoin=%r,  miterlimit=%r, dash=%r, intent=%r, flatness=%r,  stroking color=%r, non stroking color=%r>)	re   rf   rg   rh   ri   rj   rk   rl   rn   rV   r?   r?   r@   rY      s   zPDFGraphicState.__repr__r`   )rK   rc   )r<   r=   r>   rX   r]   rb   rY   r?   r?   r?   r@   rc      s    

rc   c                   @   sp   e Zd ZdZddeddfddZdee ddfd	d
Zdde	dede
fddZdedee	ef defddZdS )PDFResourceManagerzRepository of shared resources.

    ResourceManager facilitates reuse of shared resources
    such as fonts and images so that large objects are not
    allocated multiple times.
    TcachingrK   Nc                 C   s   || _ i | _d S rZ   )rq   _cached_fonts)rW   rq   r?   r?   r@   rX      r_   zPDFResourceManager.__init__procsc                 C   s"   |D ]}|t u s|tu rq	 qd S rZ   )LITERAL_PDFLITERAL_TEXT)rW   rs   procr?   r?   r@   get_procset   s
   zPDFResourceManager.get_procsetFcmapnamestrictc                 C   s.   zt |W S  t jy   |r t  Y S w rZ   )r   get_cmapCMapNotFoundr   )rW   rx   ry   r?   r?   r@   rz      s   
zPDFResourceManager.get_cmapobjidspecc                 C   sL  |r|| j v r| j | }|S td|| tjr"|d tur"tdd|v r-t|d }n	tjr4tdd}|dv r@t| |}nZ|dkrJt	| |}nP|d	krTt
| |}nF|d
v r^t| |}n<|dkrt|d }|slJ t|d  }dD ]}||v rt|| ||< qv| d |}ntjrtd| t| |}|r| jr|| j |< |S )Nz#get_font: create: objid=%r, spec=%rTypezType is not /FontSubtypezFont Subtype is not specified.Type1)r   MMType1TrueTypeType3)CIDFontType0CIDFontType2Type0DescendantFontsr   )Encoding	ToUnicodezInvalid Font spec: %r)rr   logdebugr   STRICTLITERAL_FONTr   r1   r   r   r   r   r%   r$   r]   r&   get_fontrq   )rW   r|   r}   rM   subtypedfontssubspeckr?   r?   r@   r      sF   
(


zPDFResourceManager.get_font)T)F)r<   r=   r>   __doc__boolrX   r   objectrw   rb   r   rz   r   r   r   r?   r?   r?   r@   rp      s    "rp   c                	   @   s   e Zd Zdee ddfddZdddZdeddfd	d
ZdddZ	ddede
deee
f fddZdddZedZedZedZdededdfddZdS )PDFContentParserstreamsrK   Nc                 C   s   || _ d| _t| d  d S Nr   )r   istreamr.   rX   )rW   r   r?   r?   r@   rX      s   zPDFContentParser.__init__c                 C   sT   | j s(| jt| jk rt| j| j }|  jd7  _ntdt| | _ d S d S )N   zUnexpected EOF, file truncated?)fpr   lenr   r'   r(   r   get_data)rW   strmr?   r?   r@   fillfp  s   zPDFContentParser.fillfpposc                 C   s   |    t| | d S rZ   )r   r.   seek)rW   r   r?   r?   r@   r     s   zPDFContentParser.seekc                 C   sT   | j t| jk r
d S 	 |   | j | _| j| j| _| jr!nd | _qd| _ d S )Nr   r   )	charposr   bufr   r   tellbufposreadBUFSIZrV   r?   r?   r@   fillbuf  s   
zPDFContentParser.fillbuf   EItargetc                 C   sB  |  | d}d}|t|kr|   |rL| j| j }t|f}||7 }|  jd7  _t||kr5| sD|t|k rI|t|| fkrI|d7 }n<d}n9z| j|d | j}|| j| j|d  7 }|d | _d}W n ty   || j| jd  7 }t| j| _Y nw |t|ks|d t|d   }t	
dd|}||fS )Nr       r   s   (\x0d\x0a|[\x0d\x0a])$)r   r   r   r   r   bytesisspaceindex
ValueErrorresub)rW   r   r   idatacicjr?   r?   r@   get_inline_data  s<   



z PDFContentParser.get_inline_datac                 C   s   | j |    d S rZ   )add_resultspopallrV   r?   r?   r@   flush@  s   zPDFContentParser.flushs   BIs   IDtokenc                 C   s6  || j u r| |d d S || ju rzq| d\}}t|d dkr+d|}t|dd td|D }d}|dd }|d urQt|t	rI|g}|d t
v rQd	}| j|td
 |d\}}	|dkrf|	|7 }	t||	}
| ||
f |dkr| || jf W d S W d S  ty   tjr Y d S w | ||f d S )Ninline   r   zInvalid dictionary construct: c                 S   s   i | ]\}}t |t|qS r?   )r1   r&   ).0r   vr?   r?   r@   
<dictcomp>Q  s    z/PDFContentParser.do_keyword.<locals>.<dictcomp>r   Fs   ~>s   ID )r   )
KEYWORD_BI
start_type
KEYWORD_IDend_typer   r)   r7   get
isinstancer-   r!   r   r#   push
KEYWORD_EIr   r   )rW   r   r   _objs	error_msgdeosfilterr   r\   r?   r?   r@   
do_keywordG  s<   




zPDFContentParser.do_keywordr`   )r   )r<   r=   r>   r   r   rX   r   intr   r   r   r   r   r   r*   r   r   r   r,   r   r?   r?   r?   r@   r      s    
	
 
!r   c                   @   s  e Zd ZdZdededdfddZddd	Zd
ee	e	f ddfddZ
deddfddZdeddfddZdedee fddZdeeeef fddZdeeeef ddfddZdddZdddZded ed!ed"ed#ed$eddfd%d&Zd'eddfd(d)Zd*eddfd+d,Zd-eddfd.d/Zd0eddfd1d2Zd3ed4eddfd5d6Zd7eddfd8d9Zd:eddfd;d<Z d=eddfd>d?Z!d@edAeddfdBdCZ"d@edAeddfdDdEZ#dFedGedHedIedJedKeddfdLdMZ$dHedIedJedKeddf
dNdOZ%dFedGedJedKeddf
dPdQZ&ddRdSZ'd@edAedTedUeddf
dVdWZ(ddXdYZ)ddZd[Z*dd\d]Z+dd^d_Z,dd`daZ-ddbdcZ.ddddeZ/ddfdgZ0ddhdiZ1ddjdkZ2ddldmZ3ddndoZ4d=eddfdpdqZ5d=eddfdrdsZ6dteddfdudvZ7dteddfdwdxZ8dyedzed{eddfd|d}Z9dyedzed{eddfd~dZ:dededAededdf
ddZ;dededAededdf
ddZ<dddZ=dddZ>dddZ?dddZ@d=e	ddfddZAdddZBdddZCdddZDdddZEdeddfddZFdededdfddZGdeddfddZHdededdfddZIdddZJdeddfddZKdeddfddZLdeddfddZMdeddfddZNdededdfddZOdeddfddZPdeddfddZQdededdfddZRdededdfddZSded{edededededdfddńZTdddǄZUdeddfddʄZVdeddfdd̈́ZWdeddfddτZXdedededdfddӄZYdddՄZZdddׄZ[deddfddلZ\deddfdd܄Z]de^ddfdd߄Z_e`fd
ee	e	f deae	 deddfddZbdeae	 ddfddZcdS )PDFPageInterpreterzhProcessor for the content of a PDF page

    Reference: PDF Reference, Appendix A, Operator Summary
    rsrcmgrdevicerK   Nc                 C   s   || _ || _d S rZ   )r   r   )rW   r   r   r?   r?   r@   rX   q  r_   zPDFPageInterpreter.__init__c                 C   s   |  | j| jS rZ   )	__class__r   r   rV   r?   r?   r@   dupu     zPDFPageInterpreter.dup	resourcesc                 C   s2  || _ i | _i | _t | _|sdS dtdtt fdd}t	|
 D ]s\}}td|| |dkrVt	|
 D ]\}}d}t|trF|j}t	|}| j||| j|< q8q#|dkrut	|
 D ]\}}|t|}	|	durs|	| j|< q`q#|d	kr| jt| q#|d
krt	|
 D ]	\}
}|| j|
< qq#dS )z@Prepare the fonts and XObjects listed in the Resource attribute.Nr}   rK   c                 S   s   t | trt| d }nt| }|dkr*t | tr*t| dkr*t|t| d d S |dkrDt | trDt| dkrDt|tt| d S t|S )Nr   ICCBasedr   r   NDeviceN)	r   listr1   r   r   r'   r%   r   r   )r}   namer?   r?   r@   get_colorspace  s   

z9PDFPageInterpreter.init_resources.<locals>.get_colorspacezResource: %r: %rrE   
ColorSpaceProcSetXObject)r   fontmapxobjmapr   r]   csmapr   r   r   r$   itemsr   r   r   r"   r|   r   r   r&   rw   r%   )rW   r   r   r   r   fontidr}   r|   csid
colorspacexobjidxobjstrmr?   r?   r@   init_resourcesx  s>   


z!PDFPageInterpreter.init_resourcesctmc                 C   s:   g | _ || _| j| j t | _t | _g | _g | _	dS )z<Initialize the text and graphic states for rendering a page.N)
gstackr   r   set_ctmrH   	textstaterc   graphicstatecurpathargstack)rW   r   r?   r?   r@   
init_state  s   
zPDFPageInterpreter.init_stater\   c                 C   s   | j | d S rZ   )r   appendr[   r?   r?   r@   r     r   zPDFPageInterpreter.pushnc                 C   s2   |dkrg S | j | d  }| j d |  | _ |S r   )r   )rW   r   xr?   r?   r@   pop  s
   zPDFPageInterpreter.popc                 C   s   | j | j | j fS rZ   )r   r   r]   r   rV   r?   r?   r@   get_current_state  s   z$PDFPageInterpreter.get_current_statestatec                 C   s"   |\| _ | _| _| j| j  d S rZ   )r   r   r   r   r   )rW   r   r?   r?   r@   set_current_state  s   z$PDFPageInterpreter.set_current_statec                 C   s   | j |   dS )zSave graphics stateN)r   r   r   rV   r?   r?   r@   do_q  s   zPDFPageInterpreter.do_qc                 C   s   | j r| | j   dS dS )zRestore graphics stateN)r   r   r   rV   r?   r?   r@   do_Q  s   zPDFPageInterpreter.do_Qa1b1c1d1e1f1c              	   C   s\   t ||||||}|du rtd||||||fd dS t|| j| _| j| j dS )z3Concatenate matrix to current transformation matrixNzUCannot concatenate matrix to current transformation matrix because not all values in  can be parsed as floats)r   r   warningr8   r   r   r   )rW   r   r   r   r   r  r  rI   r?   r?   r@   do_cm  s   
zPDFPageInterpreter.do_cmre   c                 C   2   t |}|du rtd|d dS || j_dS )zSet line widthNzCannot set line width because  is an invalid float value)r   r   r  r   re   )rW   re   linewidth_fr?   r?   r@   do_w  s   
zPDFPageInterpreter.do_wrf   c                 C      || j _dS )zSet line cap styleN)r   rf   )rW   rf   r?   r?   r@   do_J     zPDFPageInterpreter.do_Jrg   c                 C   r
  )zSet line join styleN)r   rg   )rW   rg   r?   r?   r@   do_j  r  zPDFPageInterpreter.do_jrh   c                 C   r
  )zSet miter limitN)r   rh   )rW   rh   r?   r?   r@   do_M  r  zPDFPageInterpreter.do_Mri   phasec                 C   s   ||f| j _dS )zSet line dash patternN)r   ri   )rW   ri   r  r?   r?   r@   do_d     zPDFPageInterpreter.do_drj   c                 C   r
  )zSet color rendering intentN)r   rj   )rW   rj   r?   r?   r@   do_ri  r  zPDFPageInterpreter.do_rirk   c                 C   r
  )zSet flatness toleranceN)r   rk   )rW   rk   r?   r?   r@   do_i  r  zPDFPageInterpreter.do_ir   c                 C      dS )z7Set parameters from graphics state parameter dictionaryNr?   rW   r   r?   r?   r@   do_gs       zPDFPageInterpreter.do_gsr   yc                 C   Z   t |}t |}|du s|du r d||f}td|d dS d||f}| j| dS )zBegin new subpathNmz3Cannot start new subpath because not all values in r  r   r   r  r   r   rW   r   r  x_fy_fpointr?   r?   r@   do_m  s   


zPDFPageInterpreter.do_mc                 C   r  )z$Append straight line segment to pathNlzFCannot append straight line segment to path because not all values in r  r  r  r?   r?   r@   do_l  s   


zPDFPageInterpreter.do_lx1y1x2y2x3y3c                 C   s   t |}t |}t |}	t |}
t |}t |}|du s0|du s0|	du s0|
du s0|du s0|du rDd||||||f}td|d dS d|||	|
||f}| j| dS )z4Append curved segment to path (three control points)Nr   ?Cannot append curved segment to path because not all values in r  r  )rW   r#  r$  r%  r&  r'  r(  x1_fy1_fx2_fy2_fx3_fy3_fr  r?   r?   r@   do_c  s$   

zPDFPageInterpreter.do_cc           
      C      t |}t |}t |}t |}|du s |du s |du s |du r2d||||f}	td|	d dS d||||f}	| j|	 dS )z8Append curved segment to path (initial point replicated)Nr   r)  r  r  )
rW   r%  r&  r'  r(  r,  r-  r.  r/  r  r?   r?   r@   do_v?      
zPDFPageInterpreter.do_vc           
      C   r1  )z6Append curved segment to path (final point replicated)Nr  r)  r  r  )
rW   r#  r$  r'  r(  r*  r+  r.  r/  r  r?   r?   r@   do_yN  r3  zPDFPageInterpreter.do_yc                 C   s   | j d dS )zClose subpathhN)r   r   rV   r?   r?   r@   do_h]  r  zPDFPageInterpreter.do_hwr6  c           
      C   s   t |}t |}t |}t |}|du s |du s |du s |du r1||||f}	td|	d dS | jd||f | jd|| |f | jd|| || f | jd||| f | jd dS )zAppend rectangle to pathNz:Cannot append rectangle to path because not all values in r  r  r!  r5  r  )
rW   r   r  r8  r6  r  r  w_fh_fvaluesr?   r?   r@   do_rea  s    
zPDFPageInterpreter.do_rec                 C   "   | j | jddd| j g | _dS )zStroke pathTFNr   
paint_pathr   r   rV   r?   r?   r@   do_St     
zPDFPageInterpreter.do_Sc                 C      |    |   dS )zClose and stroke pathN)r7  r@  rV   r?   r?   r@   do_sy     zPDFPageInterpreter.do_sc                 C   s"   | j | jddd| j g | _dS )z+Fill path using nonzero winding number ruleFTNr>  rV   r?   r?   r@   do_f~  rA  zPDFPageInterpreter.do_fc                 C   r  )z6Fill path using nonzero winding number rule (obsolete)Nr?   rV   r?   r?   r@   do_F  r  zPDFPageInterpreter.do_Fc                 C   r=  )zFill path using even-odd ruleFTNr>  rV   r?   r?   r@   do_f_a  rA  zPDFPageInterpreter.do_f_ac                 C   s"   | j | jddd| j g | _dS )z6Fill and stroke path using nonzero winding number ruleTFNr>  rV   r?   r?   r@   do_B  rA  zPDFPageInterpreter.do_Bc                 C   s"   | j | jddd| j g | _dS )z(Fill and stroke path using even-odd ruleTNr>  rV   r?   r?   r@   do_B_a  rA  zPDFPageInterpreter.do_B_ac                 C   rB  )z>Close, fill, and stroke path using nonzero winding number ruleN)r7  rH  rV   r?   r?   r@   do_b  rD  zPDFPageInterpreter.do_bc                 C   rB  )z0Close, fill, and stroke path using even-odd ruleN)r7  rI  rV   r?   r?   r@   do_b_a  rD  zPDFPageInterpreter.do_b_ac                 C   s
   g | _ dS )z$End path without filling or strokingN)r   rV   r?   r?   r@   do_n  s   
zPDFPageInterpreter.do_nc                 C   r  )z3Set clipping path using nonzero winding number ruleNr?   rV   r?   r?   r@   do_W  r  zPDFPageInterpreter.do_Wc                 C   r  )z%Set clipping path using even-odd ruleNr?   rV   r?   r?   r@   do_W_a  r  zPDFPageInterpreter.do_W_ac                 C   @   z| j t| | j_W dS  ty   tjrtd| Y dS w )zOSet color space for stroking operations

        Introduced in PDF 1.1
        Undefined ColorSpace: %rN)r   r1   r   rm   KeyErrorr   r   rB   r  r?   r?   r@   do_CS  s   zPDFPageInterpreter.do_CSc                 C   rO  )z*Set color space for nonstroking operationsrP  N)r   r1   r   ro   rQ  r   r   rB   r  r?   r?   r@   do_cs  s   zPDFPageInterpreter.do_csgrayc                 C   @   t |}|du rtd|d dS || j_| jd | j_dS )z&Set gray level for stroking operationsNCannot set gray level because r  rd   )r   r   r  r   rl   r   rm   rW   rT  gray_fr?   r?   r@   do_G     
zPDFPageInterpreter.do_Gc                 C   rU  )z)Set gray level for nonstroking operationsNrV  r  rd   )r   r   r  r   rn   r   ro   rW  r?   r?   r@   do_g  rZ  zPDFPageInterpreter.do_grgbc                 C   J   t |||}|du rtd|||fd dS || j_| jd | j_dS )z%Set RGB color for stroking operationsNz6Cannot set RGB stroke color because not all values in r  	DeviceRGB)r   r   r  r   rl   r   rm   rW   r\  r]  r^  rgbr?   r?   r@   do_RG     zPDFPageInterpreter.do_RGc                 C   r_  )z(Set RGB color for nonstroking operationsNz:Cannot set RGB non-stroke color because not all values in r  r`  )r   r   r  r   rn   r   ro   ra  r?   r?   r@   do_rg  rd  zPDFPageInterpreter.do_rgr   r  r   c                 C   N   t ||||}|du rtd||||fd dS || j_| jd | j_dS )z&Set CMYK color for stroking operationsNz7Cannot set CMYK stroke color because not all values in r  
DeviceCMYK)r   r   r  r   rl   r   rm   rW   r   r  r  r   cmykr?   r?   r@   do_K     zPDFPageInterpreter.do_Kc                 C   rf  )z)Set CMYK color for nonstroking operationsNz;Cannot set CMYK non-stroke color because not all values in r  rg  )r   r   r  r   rn   r   ro   rh  r?   r?   r@   do_k  rk  zPDFPageInterpreter.do_kc                 C     | j jj}| |}t||krtd| d|d dS t|dkrA|d }t|}|du r;td|d dS || j _dS t|d	kr`t	| }|du rZtd
|d dS || j _dS t|dkrt
| }|du rytd|d dS || j _dS tdt| d dS )z"Set color for stroking operations.z)Cannot set stroke color because expected  components but got !rr   r   Nz%Cannot set gray stroke color because r     z/Cannot set RGB stroke color because components  cannot be parsed as RGB   z0Cannot set CMYK stroke color because components  cannot be parsed as CMYKz Cannot set stroke color because T components are specified but only 1 (grayscale), 3 (rgb) and 4 (cmyk) are supported)r   rm   ncomponentsr   r   r   r  r   rl   r   r   rW   r   
componentsrT  rX  rb  ri  r?   r?   r@   do_SCN  >   




zPDFPageInterpreter.do_SCNc                 C   rm  )$Set color for nonstroking operationsz-Cannot set non-stroke color because expected rn  ro  r   r   Nz)Cannot set gray non-stroke color because r  rp  z3Cannot set RGB non-stroke color because components rq  rr  z4Cannot set CMYK non-stroke color because components rs  z$Cannot set non-stroke color because rt  )r   ro   ru  r   r   r   r  r   rn   r   r   rv  r?   r?   r@   do_scn1  ry  zPDFPageInterpreter.do_scnc                 C      |    dS )z!Set color for stroking operationsN)rx  rV   r?   r?   r@   do_SC^  r  zPDFPageInterpreter.do_SCc                 C   r|  )rz  N)r{  rV   r?   r?   r@   do_scb  r  zPDFPageInterpreter.do_scc                 C   r  )z%Paint area defined by shading patternNr?   r  r?   r?   r@   do_shf  r  zPDFPageInterpreter.do_shc                 C      | j   dS )zBegin text object

        Initializing the text matrix, Tm, and the text line matrix, Tlm, to
        the identity matrix. Text objects cannot be nested; a second BT cannot
        appear before an ET.
        N)r   rU   rV   r?   r?   r@   do_BTi  s   zPDFPageInterpreter.do_BTc                 C   r  )zEnd a text objectNr?   rV   r?   r?   r@   do_ETr  r  zPDFPageInterpreter.do_ETc                 C   r  )zBegin compatibility sectionNr?   rV   r?   r?   r@   do_BXu  r  zPDFPageInterpreter.do_BXc                 C   r  )zEnd compatibility sectionNr?   rV   r?   r?   r@   do_EXx  r  zPDFPageInterpreter.do_EXtagc                 C   0   t |tr| j| dS td|d dS )zDefine marked-content pointz+Cannot define marked-content point because  is not a PSLiteralNr   r-   r   do_tagr   r  rW   r  r?   r?   r@   do_MP{  
   

zPDFPageInterpreter.do_MPpropsc                 C   2   t |tr| j|| dS td|d dS )z.Define marked-content point with property listz>Cannot define marked-content point with property list because r  Nr  rW   r  r  r?   r?   r@   do_DP  
   

zPDFPageInterpreter.do_DPc                 C   r  )zBegin marked-content sequencez-Cannot begin marked-content sequence because r  Nr   r-   r   	begin_tagr   r  r  r?   r?   r@   do_BMC  r  zPDFPageInterpreter.do_BMCc                 C   r  )z0Begin marked-content sequence with property listz@Cannot begin marked-content sequence with property list because r  Nr  r  r?   r?   r@   do_BDC  r  zPDFPageInterpreter.do_BDCc                 C   r  )zEnd marked-content sequenceN)r   end_tagrV   r?   r?   r@   do_EMC  s   zPDFPageInterpreter.do_EMCspacec                 C   r  )zSet character spacing.

        Character spacing is used by the Tj, TJ, and ' operators.

        :param space: a number expressed in unscaled text space units.
        Nz(Could not set character spacing because r  )r   r   r  r   rO   )rW   r  rO   r?   r?   r@   do_Tc     
zPDFPageInterpreter.do_Tcc                 C   r  )zSet the word spacing.

        Word spacing is used by the Tj, TJ, and ' operators.

        :param space: a number expressed in unscaled text space units
        Nz#Could not set word spacing becuase r  )r   r   r  r   rP   )rW   r  rP   r?   r?   r@   do_Tw  r  zPDFPageInterpreter.do_Twscalec                 C   r  )zuSet the horizontal scaling.

        :param scale: is a number specifying the percentage of the normal width
        Nz)Could not set horizontal scaling because r  )r   r   r  r   rQ   )rW   r  scale_fr?   r?   r@   do_Tz     
zPDFPageInterpreter.do_TzrR   c                 C   s4   t |}|du rtd|d dS | | j_dS )zSet the text leading.

        Text leading is used only by the T*, ', and " operators.

        :param leading: a number expressed in unscaled text space units
        Nz#Could not set text leading because r  )r   r   r  r   rR   )rW   rR   	leading_fr?   r?   r@   do_TL  s   
zPDFPageInterpreter.do_TLr   rN   c                 C   s   z| j t| | j_W n ty&   tjrtd| | j	di | j_Y nw t
|}|du r:td|d dS || j_dS )zSet the text font

        :param fontid: the name of a font resource in the Font subdictionary
            of the current resource dictionary
        :param fontsize: size is a number representing a scale factor.
        zUndefined Font id: %rNz Could not set text font because r  )r   r1   r   rM   rQ  r   r   rB   r   r   r   r   r  rN   )rW   r   rN   
fontsize_fr?   r?   r@   do_Tf  s   
zPDFPageInterpreter.do_TfrS   c                 C   r  )zSet the text rendering modeNz*Could not set text rendering mode because z is an invalid int value)r   r   r  r   rS   )rW   rS   render_ir?   r?   r@   do_Tr  s   
zPDFPageInterpreter.do_TrrT   c                 C   r  )z`Set the text rise

        :param rise: a number expressed in unscaled text space units
        Nz Could not set text rise because r  )r   r   r  r   rT   )rW   rT   rise_fr?   r?   r@   do_Ts  r  zPDFPageInterpreter.do_Tstxtyc                 C   s   t |}t |}|dur9|dur9| jj\}}}}}	}
|| ||  |	 }|| ||  |
 }||||||f| j_ntjrGtd|d|dd| j_dS )zlMove to the start of the next line

        Offset from the start of the current line by (tx , ty).
        NzInvalid offset (z, z) for Tdr^   )r   r   rI   r   r   r   rJ   rW   r  r  tx_ty_ar^  r   r   efe_newf_newr?   r?   r@   do_Td  s   zPDFPageInterpreter.do_Tdc                 C   s   t |}t |}|dur9|dur9| jj\}}}}}	}
|| ||  |	 }|| ||  |
 }||||||f| j_ntjr@td|durH|| j_d| j_dS )zMove to the start of the next line.

        offset from the start of the current line by (tx , ty). As a side effect, this
        operator sets the leading parameter in the text state.
        Nz"Invalid offset ({tx}, {ty}) for TDr^   )r   r   rI   r   r   r   rR   rJ   r  r?   r?   r@   do_TD  s   zPDFPageInterpreter.do_TDr  r   r  r  c           	      C   sJ   ||||||f}t | }|du rtd|d dS || j_d| j_dS )z$Set text matrix and text line matrixNz4Could not set text matrix because not all values in r  r^   )r   r   r  r   rI   rJ   )	rW   r  r^  r   r   r  r  r;  rI   r?   r?   r@   do_Tm6  s   

zPDFPageInterpreter.do_Tmc                 C   sL   | j j\}}}}}}||||| j j| | | j j| | f| j _d| j _dS )zMove to start of next text liner^   N)r   rI   rR   rJ   )rW   r  r^  r   r   r  r  r?   r?   r@   do_T_aK  s   zPDFPageInterpreter.do_T_aseqc                 C   sF   | j jdu rtjrtddS | j| j tt|| j	j
| j	  dS )z0Show text, allowing individual glyph positioningNzNo font specified!)r   rM   r   r   rB   r   render_stringr
   r   r   ro   r]   )rW   r  r?   r?   r@   do_TJX  s   zPDFPageInterpreter.do_TJsc                 C   s   |  |g dS )z	Show textN)r  rW   r  r?   r?   r@   do_Tje  r  zPDFPageInterpreter.do_Tjc                 C   s   |    | |g dS )zPMove to next line and show text

        The ' (single quote) operator.
        N)r  r  r  r?   r?   r@   do__qi  s   zPDFPageInterpreter.do__qawacc                 C   s$   |  | | | | |g dS )zqSet word and character spacing, move to next line, and show text

        The " (double quote) operator.
        N)r  r  r  )rW   r  r  r  r?   r?   r@   do__wq  s   

zPDFPageInterpreter.do__wc                 C   r  )zBegin inline image objectNr?   rV   r?   r?   r@   do_BIz  r  zPDFPageInterpreter.do_BIc                 C   r  )zBegin inline image dataNr?   rV   r?   r?   r@   do_ID}  r  zPDFPageInterpreter.do_IDc                 C   s`   t |tr*d|v r,d|v r.tt|}| j|dt | j|| | j| dS dS dS dS )zEnd inline image objectWHr   r   r   r   N)	r   r#   rb   idr   begin_figurer2   render_image
end_figure)rW   r\   iobjidr?   r?   r@   do_EI  s   zPDFPageInterpreter.do_EI
xobjid_argc           
      C   s@  t |}z	t| j| }W n ty    tjrtd| Y dS w td| |	d}|t
u rzd|v rz|  }ttt|d }ttt|	dt}|	d}|rXt|}	n| j }	| j||| |j|	|gt|| jd | j| dS |tu rd	|v rd
|v r| j|dt | j|| | j| dS 	 dS )zInvoke named XObjectzUndefined xobject id: %rNzProcessing xobj: %rr   BBoxr3   	Resourcesr   WidthHeightr  )r1   r'   r   rQ  r   r   rB   r   r   r   LITERAL_FORMr   r
   r6   r%   r3   r2   r$   r   r]   r   r  render_contentsr8   r   r  LITERAL_IMAGEr  )
rW   r  r   xobjr   interpreterbboxrI   xobjresr   r?   r?   r@   do_Do  s<   




zPDFPageInterpreter.do_Dopagec                 C   s   t d| |j\}}}}|jdkrdddd| |f}n'|jdkr*dddd||f}n|jdkr9dddd|| f}n
dddd| | f}| j|| | j|j|j|d | j	| d S )	NzProcessing page: %rZ   r   r      i  r  )
r   r   mediaboxrotater   
begin_pager  r   contentsend_page)rW   r  x0y0r#  r$  r   r?   r?   r@   process_page  s   


zPDFPageInterpreter.process_pager   c                 C   s6   t d||| | | | | | t| dS )zTRender the content streams.

        This method may be called recursively.
        z1render_contents: resources=%r, streams=%r, ctm=%rN)r   r   r   r   executer%   )rW   r   r   r   r?   r?   r@   r    s   


z"PDFPageInterpreter.render_contentsc                 C   s  zt |}W n
 ty   Y d S w 	 z| \}}W n
 ty$   Y d S w t|tr}t|}d|dddddd }t| |rqt| |}|j	j
d	 }|rg| |}	td
||	 t|	|krf||	  ntd| |  ntjr|d| }
t|
n| | q)NTzdo_%s*_a"_w'_qr   zexec: %s %rzexec: %szUnknown operator: %r)r   r(   
nextobjectr   r,   r0   replacehasattrgetattr__code__co_argcountr   r   r   r   r   r   rB   r   )rW   r   parserr   r\   r   methodfuncnargsargsr   r?   r?   r@   r    sD   




zPDFPageInterpreter.execute)rK   r   r`   )dr<   r=   r>   r   rp   r   rX   r   r   r   r   r3   r   	PDFStackTr   r   r   r   r   rH   rc   r   r   r   r   r  r	  r  r  r  r  r  r  r  r   r"  r0  r2  r4  r7  r<  r@  rC  rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  rR  rS  rY  r[  rc  re  rj  rl  rx  r{  r}  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r    r  r2   r   r  r  r?   r?   r?   r@   r   k  s   
)





 














-
-


	

			
	


	
&

r   )Yloggingr   ior   typingr   r   r   r   r   r   r	   r
   pdfminerr   pdfminer.castingr   r   r   r   r   pdfminer.cmapdbr   r   r   pdfminer.pdfcolorr   r   pdfminer.pdfdevicer   r   pdfminer.pdfexceptionsr   r   pdfminer.pdffontr   r   r   r   r   r   pdfminer.pdfpager    pdfminer.pdftypesr!   r"   r#   r$   r%   r&   r'   pdfminer.psexceptionsr(   r)   pdfminer.psparserr*   r+   r,   r-   r.   r/   r0   r1   pdfminer.utilsr2   r3   r4   r5   r6   r7   r8   	getLoggerr<   r   r:   rB   rt   ru   r   r  r  rH   floatColorrc   rp   r   r  r   r?   r?   r?   r@   <module>   sJ    ( $	($


72Hj