o
    h                     @   s$  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 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+m,Z,m-Z-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB e CeDZEG dd deZFG dd deZGe4dZHe4dZIe4dZJe4dZKe4dZLG dd dZMeeNe
eNeNeNf e
eNeNeNeNf f ZOG dd dZPG dd dZQG dd  d e7ee5e*f  ZRe8e* ZS	 G d!d" d"ZTdS )#    N)BytesIO)DictListMappingOptionalSequenceTupleUnioncast)settings)
safe_float)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;   E/var/www/html/venv/lib/python3.10/site-packages/pdfminer/pdfinterp.pyr6   6       r6   c                   @   r5   )PDFInterpreterErrorNr7   r;   r;   r;   r<   r>   :   r=   r>   ZPDFTextFontZFormZ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>)
rF   rG   rH   rI   rJ   rK   rL   rM   rB   rC   rO   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)rA   rF   rG   rH   rI   rJ   rK   rL   rM   rB   rC   rP   objr;   r;   r<   copyi   s   zPDFTextState.copyc                 C   s   t | _d| _d S )Nr   r   )r.   rB   rC   rO   r;   r;   r<   rN   w      
zPDFTextState.resetrD   N)rD   rA   )r8   r9   r:   r/   __annotations__r1   rQ   strrR   rV   rN   r;   r;   r;   r<   rA   E   s   
 

rA   c                   @   s.   e Zd Zd	ddZd
ddZdefddZdS )PDFGraphicStaterD   Nc                 C   s:   d| _ d | _d | _d | _d | _d | _d | _d | _d | _d S Nr   		linewidthlinecaplinejoin
miterlimitdashintentflatnessscolorncolorrO   r;   r;   r<   rQ      s   
zPDFGraphicState.__init__c                 C   sR   t  }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	|S rS   )
r\   r_   r`   ra   rb   rc   rd   re   rf   rg   rT   r;   r;   r<   rV      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>r^   rO   r;   r;   r<   rR      s   zPDFGraphicState.__repr__rY   )rD   r\   )r8   r9   r:   rQ   rV   r[   rR   r;   r;   r;   r<   r\      s    

r\   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cachingrD   Nc                 C   s   || _ i | _d S rS   )ri   _cached_fonts)rP   ri   r;   r;   r<   rQ      rX   zPDFResourceManager.__init__procsc                 C   s"   |D ]}|t u s|tu rq	 qd S rS   )LITERAL_PDFLITERAL_TEXT)rP   rk   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 rS   )r   get_cmapZCMapNotFoundr   )rP   rp   rq   r;   r;   r<   rr      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)rw   ZMMType1ZTrueTypeZType3)ZCIDFontType0ZCIDFontType2ZType0ZDescendantFontsr   )ZEncoding	ToUnicodezInvalid Font spec: %r)rj   logdebugr   STRICTLITERAL_FONTr   r-   r   r   r   r   r!   r    rV   r"   get_fontri   )rP   rs   rt   rF   subtypeZdfontsZsubspeckr;   r;   r<   r}      sF   
(


zPDFResourceManager.get_font)T)F)r8   r9   r:   __doc__boolrQ   r   objectro   r[   r   rr   r   r   r}   r;   r;   r;   r<   rh      s    "rh   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streamsrD   Nc                 C   s   || _ d| _t| d  d S r]   )r   istreamr*   rQ   )rP   r   r;   r;   r<   rQ      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)rP   strmr;   r;   r<   fillfp  s   zPDFContentParser.fillfpposc                 C   s   |    t| | d S rS   )r   r*   seek)rP   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   tellZbufposreadZBUFSIZrO   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)rP   r   r   idatacicjr;   r;   r<   get_inline_data  s<   



z PDFContentParser.get_inline_datac                 C   s   | j |    d S rS   )Zadd_resultsZpopallrO   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;   )r-   r"   ).0r   vr;   r;   r<   
<dictcomp>O  s    z/PDFContentParser.do_keyword.<locals>.<dictcomp>r   Fs   ~>s   ID )r   )
KEYWORD_BIZ
start_type
KEYWORD_IDZend_typer   r%   r3   get
isinstancer)   r   r   r   push
KEYWORD_EIr   r{   )rP   r   r   _Zobjs	error_msgdZeosfilterr   rU   r;   r;   r<   
do_keywordE  s<   




zPDFContentParser.do_keywordrY   )r   )r8   r9   r:   r   r   rQ   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devicerD   Nc                 C   s   || _ || _d S rS   )r   r   )rP   r   r   r;   r;   r<   rQ   o  rX   zPDFPageInterpreter.__init__c                 C   s   |  | j| jS rS   )	__class__r   r   rO   r;   r;   r<   dups     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.Nrt   rD   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   ZICCBasedr   r   NZDeviceN)	r   listr-   r   r   r#   r!   r   r   )rt   namer;   r;   r<   get_colorspace  s   

z9PDFPageInterpreter.init_resources.<locals>.get_colorspacezResource: %r: %rr@   Z
ColorSpaceZProcSetZXObject)r   fontmapxobjmapr   rV   csmapr   r   r   r    itemsry   rz   r   r   rs   r   r}   r"   ro   r!   )rP   r   r   r   r   fontidrt   rs   csidZ
colorspacexobjidZxobjstrmr;   r;   r<   init_resourcesv  s>   


z!PDFPageInterpreter.init_resourcesctmc                 C   sj   g | _ || _| j| j t | _t | _g | _g | _	d| _
d| _| jr3tt| j  | _
| _dS dS )z<Initialize the text and graphic states for rendering a page.N)gstackr   r   set_ctmrA   	textstater\   graphicstatecurpathargstackscsncsr   nextitervalues)rP   r   r;   r;   r<   
init_state  s   zPDFPageInterpreter.init_staterU   c                 C   s   | j | d S rS   )r   appendrT   r;   r;   r<   r     r   zPDFPageInterpreter.pushnc                 C   s2   |dkrg S | j | d  }| j d |  | _ |S r]   )r   )rP   r   xr;   r;   r<   pop  s
   zPDFPageInterpreter.popc                 C   s   | j | j | j fS rS   )r   r   rV   r   rO   r;   r;   r<   get_current_state  s   z$PDFPageInterpreter.get_current_statestatec                 C   s"   |\| _ | _| _| j| j  d S rS   )r   r   r   r   r   )rP   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   rO   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   rO   r;   r;   r<   do_Q  s   zPDFPageInterpreter.do_Qa1b1c1d1e1f1c              	   C   s2   t tt||||||f| j| _| j| j dS )z3Concatenate matrix to current transformation matrixN)r4   r
   r/   r   r   r   )rP   r   r   r   r   r   r   r;   r;   r<   do_cm  s    
zPDFPageInterpreter.do_cmr_   c                 C      t t|| j_dS )zSet line widthN)r
   floatr   r_   )rP   r_   r;   r;   r<   do_w     zPDFPageInterpreter.do_wr`   c                 C      || j _dS )zSet line cap styleN)r   r`   )rP   r`   r;   r;   r<   do_J     zPDFPageInterpreter.do_Jra   c                 C   r   )zSet line join styleN)r   ra   )rP   ra   r;   r;   r<   do_j  r   zPDFPageInterpreter.do_jrb   c                 C   r   )zSet miter limitN)r   rb   )rP   rb   r;   r;   r<   do_M  r   zPDFPageInterpreter.do_Mrc   phasec                 C   s   ||f| j _dS )zSet line dash patternN)r   rc   )rP   rc   r   r;   r;   r<   do_d     zPDFPageInterpreter.do_drd   c                 C   r   )zSet color rendering intentN)r   rd   )rP   rd   r;   r;   r<   do_ri  r   zPDFPageInterpreter.do_rire   c                 C   r   )zSet flatness toleranceN)r   re   )rP   re   r;   r;   r<   do_i  r   zPDFPageInterpreter.do_ir   c                 C      dS )z7Set parameters from graphics state parameter dictionaryNr;   rP   r   r;   r;   r<   do_gs      zPDFPageInterpreter.do_gsr   yc                 C   "   | j dtt|tt|f dS )zBegin new subpathmNr   r   r
   r   rP   r   r   r;   r;   r<   do_m     "zPDFPageInterpreter.do_mc                 C   r   )z$Append straight line segment to pathlNr   r   r;   r;   r<   do_l  r   zPDFPageInterpreter.do_lx1y1x2y2x3y3c                 C   sB   | j dtt|tt|tt|tt|tt|tt|f dS )z4Append curved segment to path (three control points)r   Nr   )rP   r  r  r  r  r  r  r;   r;   r<   do_c  s   
zPDFPageInterpreter.do_cc              	   C   2   | j dtt|tt|tt|tt|f dS )z8Append curved segment to path (initial point replicated)r   Nr   )rP   r  r  r  r  r;   r;   r<   do_v     $zPDFPageInterpreter.do_vc              	   C   r  )z6Append curved segment to path (final point replicated)r   Nr   )rP   r  r  r  r  r;   r;   r<   do_y  r
  zPDFPageInterpreter.do_yc                 C   s   | j d dS )zClose subpathhN)r   r   rO   r;   r;   r<   do_h$  r   zPDFPageInterpreter.do_hwr  c                 C   s   t t|}t t|}t t|}t t|}| jd||f | jd|| |f | jd|| || f | jd||| f | jd dS )zAppend rectangle to pathr   r   r  N)r
   r   r   r   )rP   r   r   r  r  r;   r;   r<   do_re(  s   



zPDFPageInterpreter.do_rec                 C   "   | j | jddd| j g | _dS )zStroke pathTFNr   Z
paint_pathr   r   rO   r;   r;   r<   do_S4     
zPDFPageInterpreter.do_Sc                 C      |    |   dS )zClose and stroke pathN)r  r  rO   r;   r;   r<   do_s9     zPDFPageInterpreter.do_sc                 C   s"   | j | jddd| j g | _dS )z+Fill path using nonzero winding number ruleFTNr  rO   r;   r;   r<   do_f>  r  zPDFPageInterpreter.do_fc                 C   r   )z6Fill path using nonzero winding number rule (obsolete)Nr;   rO   r;   r;   r<   do_FC  r   zPDFPageInterpreter.do_Fc                 C   r  )zFill path using even-odd ruleFTNr  rO   r;   r;   r<   do_f_aF  r  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  rO   r;   r;   r<   do_BK  r  zPDFPageInterpreter.do_Bc                 C   s"   | j | jddd| j g | _dS )z(Fill and stroke path using even-odd ruleTNr  rO   r;   r;   r<   do_B_aP  r  zPDFPageInterpreter.do_B_ac                 C   r  )z>Close, fill, and stroke path using nonzero winding number ruleN)r  r  rO   r;   r;   r<   do_bU  r  zPDFPageInterpreter.do_bc                 C   r  )z0Close, fill, and stroke path using even-odd ruleN)r  r  rO   r;   r;   r<   do_b_aZ  r  zPDFPageInterpreter.do_b_ac                 C   s
   g | _ dS )z$End path without filling or strokingN)r   rO   r;   r;   r<   do_n_  s   
zPDFPageInterpreter.do_nc                 C   r   )z3Set clipping path using nonzero winding number ruleNr;   rO   r;   r;   r<   do_Wc  r   zPDFPageInterpreter.do_Wc                 C   r   )z%Set clipping path using even-odd ruleNr;   rO   r;   r;   r<   do_W_af  r   zPDFPageInterpreter.do_W_ac                 C   >   z| j t| | _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   r-   r   KeyErrorr   r{   r>   r   r;   r;   r<   do_CSi  s   zPDFPageInterpreter.do_CSc                 C   r"  )z*Set color space for nonstroking operationsr#  N)r   r-   r   r$  r   r{   r>   r   r;   r;   r<   do_cst  s   zPDFPageInterpreter.do_csgrayc                 C      t t|| j_| jd | _dS )z&Set gray level for stroking operations
DeviceGrayNr
   r   r   rf   r   r   rP   r'  r;   r;   r<   do_G|     zPDFPageInterpreter.do_Gc                 C   r(  )z)Set gray level for nonstroking operationsr)  Nr
   r   r   rg   r   r   r+  r;   r;   r<   do_g  r-  zPDFPageInterpreter.do_grgbc                 C   0   t t|t t|t t|f| j_| jd | _dS )z%Set RGB color for stroking operations	DeviceRGBNr*  rP   r0  r1  r2  r;   r;   r<   do_RG      zPDFPageInterpreter.do_RGc                 C   r3  )z(Set RGB color for nonstroking operationsr4  Nr.  r5  r;   r;   r<   do_rg  r7  zPDFPageInterpreter.do_rgr   r   r   c                 C   8   t t|t t|t t|t t|f| j_| jd | _dS )z&Set CMYK color for stroking operations
DeviceCMYKNr*  rP   r   r   r   r   r;   r;   r<   do_K     zPDFPageInterpreter.do_Kc                 C   r9  )z)Set CMYK color for nonstroking operationsr:  Nr.  r;  r;   r;   r<   do_k  r=  zPDFPageInterpreter.do_kc                 C   :   | j r| j j}n	tjrtdd}tt| || j_	dS )z"Set color for stroking operations.No colorspace specified!r   N)
r   ncomponentsr   r{   r>   r
   Colorr   r   rf   rP   r   r;   r;   r<   do_SCN     
zPDFPageInterpreter.do_SCNc                 C   r?  )$Set color for nonstroking operationsr@  r   N)
r   rA  r   r{   r>   r
   rB  r   r   rg   rC  r;   r;   r<   do_scn  rE  zPDFPageInterpreter.do_scnc                 C      |    dS )z!Set color for stroking operationsN)rD  rO   r;   r;   r<   do_SC  r   zPDFPageInterpreter.do_SCc                 C   rH  )rF  N)rG  rO   r;   r;   r<   do_sc  r   zPDFPageInterpreter.do_scc                 C   r   )z%Paint area defined by shading patternNr;   r   r;   r;   r<   do_sh  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   rN   rO   r;   r;   r<   do_BT  s   zPDFPageInterpreter.do_BTc                 C   r   )zEnd a text objectNr;   rO   r;   r;   r<   do_ET  r   zPDFPageInterpreter.do_ETc                 C   r   )zBegin compatibility sectionNr;   rO   r;   r;   r<   do_BX  r   zPDFPageInterpreter.do_BXc                 C   r   )zEnd compatibility sectionNr;   rO   r;   r;   r<   do_EX  r   zPDFPageInterpreter.do_EXtagc                 C      | j tt| dS )zDefine marked-content pointNr   Zdo_tagr
   r)   rP   rQ  r;   r;   r<   do_MP     zPDFPageInterpreter.do_MPpropsc                 C      | j tt|| dS )z.Define marked-content point with property listNrS  rP   rQ  rW  r;   r;   r<   do_DP     zPDFPageInterpreter.do_DPc                 C   rR  )zBegin marked-content sequenceNr   Z	begin_tagr
   r)   rT  r;   r;   r<   do_BMC  rV  zPDFPageInterpreter.do_BMCc                 C   rX  )z0Begin marked-content sequence with property listNr\  rY  r;   r;   r<   do_BDC  r[  zPDFPageInterpreter.do_BDCc                 C   rL  )zEnd marked-content sequenceN)r   Zend_tagrO   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.
        N)r
   r   r   rH   rP   r`  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
        N)r
   r   r   rI   ra  r;   r;   r<   do_Tw  rc  zPDFPageInterpreter.do_Twscalec                 C   r   )zuSet the horizontal scaling.

        :param scale: is a number specifying the percentage of the normal width
        N)r
   r   r   rJ   )rP   re  r;   r;   r<   do_Tz     zPDFPageInterpreter.do_TzrK   c                 C   s   t t| | 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
        N)r
   r   r   rK   )rP   rK   r;   r;   r<   do_TL  s   zPDFPageInterpreter.do_TLr   rG   c                 C   s`   z| j t| | j_W n ty&   tjrtd| | j	di | j_Y nw t
t|| 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: %rN)r   r-   r   rF   r$  r   r{   r>   r   r}   r
   r   rG   )rP   r   rG   r;   r;   r<   do_Tf  s   zPDFPageInterpreter.do_TfrL   c                 C   r   )zSet the text rendering modeN)r
   r   r   rL   )rP   rL   r;   r;   r<   do_Tr  r   zPDFPageInterpreter.do_TrrM   c                 C   r   )z`Set the text rise

        :param rise: a number expressed in unscaled text space units
        N)r
   r   r   rM   )rP   rM   r;   r;   r<   do_Ts  rg  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 TdrW   )r   r   rB   r   r{   r   rC   rP   rl  rm  Ztx_Zty_ar2  r   r   efZe_newZ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 TDrW   )r   r   rB   r   r{   r   rK   rC   rn  r;   r;   r<   do_TD7  s   zPDFPageInterpreter.do_TDro  r   rp  rq  c                 C   s&   t t||||||f| j_d| j_dS )z$Set text matrix and text line matrixrW   N)r
   r/   r   rB   rC   rP   ro  r2  r   r   rp  rq  r;   r;   r<   do_TmN  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 linerW   N)r   rB   rK   rC   rt  r;   r;   r<   do_T_a[  s   zPDFPageInterpreter.do_T_aseqc                 C   sR   | j jdu rtjrtddS | jdusJ | j| j tt	|| j| j
  dS )z0Show text, allowing individual glyph positioningNzNo font specified!)r   rF   r   r{   r>   r   r   Zrender_stringr
   r   r   rV   )rP   rw  r;   r;   r<   do_TJh  s   zPDFPageInterpreter.do_TJsc                 C   s   |  |g dS )z	Show textN)rx  rP   ry  r;   r;   r<   do_Tjv  r   zPDFPageInterpreter.do_Tjc                 C   s   |    | |g dS )zPMove to next line and show text

        The ' (single quote) operator.
        N)rv  rx  rz  r;   r;   r<   do__qz  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)rd  rb  rx  )rP   r}  r~  ry  r;   r;   r<   do__w  s   

zPDFPageInterpreter.do__wc                 C   r   )zBegin inline image objectNr;   rO   r;   r;   r<   do_BI  r   zPDFPageInterpreter.do_BIc                 C   r   )zBegin inline image dataNr;   rO   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   r[   idr   begin_figurer.   render_image
end_figure)rP   rU   Z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: %rrv   ZBBoxr/   Z	Resourcesr   ZWidthZHeightr  )r-   r#   r   r$  r   r{   r>   ry   rz   r   LITERAL_FORMr   r
   r2   r!   r/   r.   r    r   rV   r   r  render_contentsr4   r   r  LITERAL_IMAGEr  )
rP   r  r   Zxobjr~   interpreterZbboxrB   Z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  )
ry   rz   Zmediaboxrotater   Z
begin_pager  r   contentsZend_page)rP   r  Zx0Z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)ry   rz   r   r   executer!   )rP   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*Z_a"_w'Z_qr   zexec: %s %rzexec: %szUnknown operator: %r)r   r$   Z
nextobjectr   r(   r,   replacehasattrgetattr__code__co_argcountr   ry   rz   r   r   r{   r>   r   )rP   r   parserr   rU   r   methodfuncnargsargsr   r;   r;   r<   r    sD   




zPDFPageInterpreter.execute)rD   r   rY   )dr8   r9   r:   r   rh   r   rQ   r   r   r   r   r/   r   	PDFStackTr   r   r   r   r   rA   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%  r&  r,  r/  r6  r8  r<  r>  rD  rG  rI  rJ  rK  rM  rN  rO  rP  rU  rZ  r]  r^  r_  rb  rd  rf  rh  ri  rj  rk  rr  rs  ru  rv  rx  r{  r|  r  r  r  r  r  r   r  r.   r   r  r  r;   r;   r;   r<   r   i  s   
)



























	


			


	
&

r   )Uloggingr   ior   typingr   r   r   r   r   r   r	   r
   Zpdfminerr   Zpdfminer.castingr   Zpdfminer.cmapdbr   r   r   Zpdfminer.pdfcolorr   r   Zpdfminer.pdfdevicer   r   Zpdfminer.pdfexceptionsr   r   Zpdfminer.pdffontr   r   r   r   r   r   Zpdfminer.pdfpager   Zpdfminer.pdftypesr   r   r   r    r!   r"   r#   Zpdfminer.psexceptionsr$   r%   Zpdfminer.psparserr&   r'   r(   r)   r*   r+   r,   r-   Zpdfminer.utilsr.   r/   r0   r1   r2   r3   r4   	getLoggerr8   ry   r6   r>   rl   rm   r|   r  r  rA   r   rB  r\   rh   r   r  r   r;   r;   r;   r<   <module>   sJ    ( $	($


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