o
    ۩Zh                     @   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 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% ddl"m&Z& ddl"m'Z' ddl"m(Z( ddl"m)Z) ddl*m+Z+ ddl*m,Z, ddl*m-Z- ddl*m.Z. ddl*m/Z/m0Z0 dd l*m1Z1 dd!l*m2Z2 dd"l*m3Z3 dd#l*m4Z4 dd$l5m6Z6 dd%l5m7Z7m8Z8m9Z9m:Z: dd&l5m;Z; dd'l5m<Z< e =e>Z?G d(d) d)e#Z@G d*d+ d+e#ZAe,d,ZBe,d-ZCe,d.ZDe,d/ZEe,d0ZFG d1d2 d2ZGeeHe
eHeHeHf e
eHeHeHeHf f ZIG d3d4 d4ZJG d5d6 d6ZKG d7d8 d8e1ee.e%f  ZLe2e% ZM	 G d9d: d:ZNdS );    N)BytesIO)DictListMappingOptionalSequenceTupleUnioncast   )settings)CMap)CMapBase)CMapDB)PDFColorSpace)PREDEFINED_COLORSPACE)	PDFDevice)
PDFTextSeq)
PDFCIDFont)PDFFont)PDFFontError)PDFTrueTypeFont)PDFType1Font)PDFType3Font)PDFPage)PDFException)	PDFObjRef)	PDFStream)
dict_value)
list_value)resolve1)stream_value)KWD)LIT)PSEOF)	PSKeyword)	PSLiteralPSTypeError)PSStackParser)PSStackType)keyword_nameliteral_name)MATRIX_IDENTITY)MatrixPointPathSegmentRect)choplist)mult_matrixc                   @      e Zd ZdS )PDFResourceErrorN__name__
__module____qualname__ r:   r:   I/var/www/html/lang_env/lib/python3.10/site-packages/pdfminer/pdfinterp.pyr5   -       r5   c                   @   r4   )PDFInterpreterErrorNr6   r:   r:   r:   r;   r=   1   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__@   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>)
rE   rF   rG   rH   rI   rJ   rK   rL   rA   rB   rN   r:   r:   r;   __repr__M   s   zPDFTextState.__repr__c                 C   sZ   t  }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	| j
|_
|S N)r@   rE   rF   rG   rH   rI   rJ   rK   rL   rA   rB   rO   objr:   r:   r;   copy`   s   zPDFTextState.copyc                 C   s   t | _d| _d S )Nr   r   )r-   rA   rB   rN   r:   r:   r;   rM   n      
zPDFTextState.resetrC   N)rC   r@   )r7   r8   r9   r.   __annotations__r/   rP   strrQ   rU   rM   r:   r:   r:   r;   r@   <   s   
 

r@   c                   @   s.   e Zd Zd	ddZd
ddZdefddZdS )PDFGraphicStaterC   Nc                 C   s:   d| _ d | _d | _d | _d | _d | _d | _d | _d | _d S Nr   		linewidthlinecaplinejoin
miterlimitdashintentflatnessscolorncolorrN   r:   r:   r;   rP   {   s   
zPDFGraphicState.__init__c                 C   sR   t  }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	|S rR   )
r[   r^   r_   r`   ra   rb   rc   rd   re   rf   rS   r:   r:   r;   rU      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]   rN   r:   r:   r;   rQ      s   zPDFGraphicState.__repr__rX   )rC   r[   )r7   r8   r9   rP   rU   rZ   rQ   r:   r:   r:   r;   r[   z   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cachingrC   Nc                 C   s   || _ i | _d S rR   )rh   _cached_fonts)rO   rh   r:   r:   r;   rP      rW   zPDFResourceManager.__init__procsc                 C   s$   |D ]}|t u r	q|tu rq	 qd S rR   )LITERAL_PDFLITERAL_TEXT)rO   rj   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 rR   )r   get_cmapZCMapNotFoundr   )rO   ro   rp   r:   r:   r;   rq      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)rv   ZMMType1ZTrueTypeZType3)ZCIDFontType0ZCIDFontType2ZType0ZDescendantFontsr   )ZEncoding	ToUnicodezInvalid Font spec: %r)ri   logdebugr   STRICTLITERAL_FONTr   r,   r   r   r   r   r   r   rU   r    get_fontrh   )rO   rr   rs   rE   subtypeZdfontsZsubspeckr:   r:   r;   r|      sF   
(


zPDFResourceManager.get_font)T)F)r7   r8   r9   __doc__boolrP   r   objectrn   rZ   r   rq   r   r   r|   r:   r:   r:   r;   rg      s    	"rg   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streamsrC   Nc                 C   s   || _ d| _t| d  d S r\   )r   istreamr(   rP   )rO   r   r:   r:   r;   rP      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 )Nr   zUnexpected EOF, file truncated?)fpr   lenr   r!   r$   r   get_data)rO   strmr:   r:   r;   fillfp   s   zPDFContentParser.fillfpposc                 C   s   |    t| | d S rR   )r   r(   seek)rO   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BUFSIZrN   r:   r:   r;   fillbuf
  s   
zPDFContentParser.fillbuf   EItargetc                 C   sL  |  | d}d}|t|kr|   |rQ| j| j }t|f}||7 }|  jd7  _t||kr:| r:|d7 }nP|t|k rN|t|| fkrN|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)rO   r   r   idatacicjr:   r:   r;   get_inline_data  s8   




z PDFContentParser.get_inline_datac                 C   s   | j |    d S rR   )Zadd_resultsZpopallrN   r:   r:   r;   flush4  s   zPDFContentParser.flushs   BIs   IDtokenc           	      C   s   || j u r| |d d S || ju rezD| d\}}t|d dkr+d|}t|dd td|D }| |td \}}t	||}| 
||f | 
|| jf W d S  tyd   tjra Y d S w | 
||f d S )Ninline   r   z"Invalid dictionary construct: {!r}c                 S   s   i | ]	\}}t ||qS r:   r+   ).0r~   vr:   r:   r;   
<dictcomp>E  s    z/PDFContentParser.do_keyword.<locals>.<dictcomp>s   ID )
KEYWORD_BIZ
start_type
KEYWORD_IDZend_typer   formatr'   r2   r   r   push
KEYWORD_EIr   rz   )	rO   r   r   _Zobjs	error_msgdr   rT   r:   r:   r;   
do_keyword;  s&   



zPDFContentParser.do_keywordrX   )r   )r7   r8   r9   r   r   rP   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devicerC   Nc                 C   s   || _ || _d S rR   )r   r   )rO   r   r   r:   r:   r;   rP   [  s   zPDFPageInterpreter.__init__c                 C   s   |  | j| jS rR   )	__class__r   r   rN   r:   r:   r;   dup`  s   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.Nrs   rC   c                 S   s   t | trt| d }nt| }|dkr*t | tr*dt| kr*t|t| d d S |dkrDt | trDdt| krDt|tt| d S t|S )Nr   ZICCBasedr   r   NZDeviceN)	
isinstancelistr,   r   r   r!   r   r   get)rs   namer:   r:   r;   get_colorspacel  s   

z9PDFPageInterpreter.init_resources.<locals>.get_colorspacezResource: %r: %rr?   Z
ColorSpaceZProcSetZXObject)r   fontmapxobjmapr   rU   csmapr   r   r   r   itemsrx   ry   r   r   rr   r   r|   r    rn   r   )rO   r   r   r~   r   fontidrs   rr   csidZ
colorspacexobjidZxobjstrmr:   r:   r;   init_resourcesc  s>   


z!PDFPageInterpreter.init_resourcesctmc                 C   sf   g | _ || _| j| j t | _t | _g | _g | _	d| _
d| _| jr1tt| j  | _
| _dS )z<Initialize the text and graphic states for rendering a page.N)gstackr   r   set_ctmr@   	textstater[   graphicstatecurpathargstackscsncsr   nextitervalues)rO   r   r:   r:   r;   
init_state  s   zPDFPageInterpreter.init_staterT   c                 C   s   | j | d S rR   )r   appendrS   r:   r:   r;   r     s   zPDFPageInterpreter.pushnc                 C   s2   |dkrg S | j | d  }| j d |  | _ |S r\   )r   )rO   r   xr:   r:   r;   pop  s
   zPDFPageInterpreter.popc                 C   s   | j | j | j fS rR   )r   r   rU   r   rN   r:   r:   r;   get_current_state  s   z$PDFPageInterpreter.get_current_statestatec                 C   s"   |\| _ | _| _| j| j  d S rR   )r   r   r   r   r   )rO   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   rN   r:   r:   r;   do_q  s   zPDFPageInterpreter.do_qc                 C   s   | j r| | j   dS )zRestore graphics stateN)r   r   r   rN   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)r3   r
   r.   r   r   r   )rO   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^   )rO   r^   r:   r:   r;   do_w     zPDFPageInterpreter.do_wr_   c                 C      || j _dS )zSet line cap styleN)r   r_   )rO   r_   r:   r:   r;   do_J     zPDFPageInterpreter.do_Jr`   c                 C   r   )zSet line join styleN)r   r`   )rO   r`   r:   r:   r;   do_j  r   zPDFPageInterpreter.do_jra   c                 C   r   )zSet miter limitN)r   ra   )rO   ra   r:   r:   r;   do_M  r   zPDFPageInterpreter.do_Mrb   phasec                 C   s   ||f| j _dS )zSet line dash patternN)r   rb   )rO   rb   r   r:   r:   r;   do_d     zPDFPageInterpreter.do_drc   c                 C   r   )zSet color rendering intentN)r   rc   )rO   rc   r:   r:   r;   do_ri  r   zPDFPageInterpreter.do_rird   c                 C   r   )zSet flatness toleranceN)r   rd   )rO   rd   r:   r:   r;   do_i  r   zPDFPageInterpreter.do_ir   c                 C      dS )z7Set parameters from graphics state parameter dictionaryNr:   rO   r   r:   r:   r;   do_gs  s   zPDFPageInterpreter.do_gsr   yc                 C   "   | j dtt|tt|f dS )zBegin new subpathmNr   r   r
   r   rO   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   )rO   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   )rO   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   )rO   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   rN   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   )rO   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   rN   r:   r:   r;   do_S6     zPDFPageInterpreter.do_Sc                 C      |    |   dS )zClose and stroke pathN)r	  r  rN   r:   r:   r;   do_s<     zPDFPageInterpreter.do_sc                 C   s"   | j | jddd| j g | _dS )z+Fill path using nonzero winding number ruleFTNr  rN   r:   r:   r;   do_fB  r  zPDFPageInterpreter.do_fc                 C   s   |   S )z6Fill path using nonzero winding number rule (obsolete))r  rN   r:   r:   r;   do_FH  s   zPDFPageInterpreter.do_Fc                 C   r  )zFill path using even-odd ruleFTNr  rN   r:   r:   r;   do_f_aL  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  rN   r:   r:   r;   do_BR  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  rN   r:   r:   r;   do_B_aX  r  zPDFPageInterpreter.do_B_ac                 C   r  )z>Close, fill, and stroke path using nonzero winding number ruleN)r	  r  rN   r:   r:   r;   do_b^  r  zPDFPageInterpreter.do_bc                 C   r  )z0Close, fill, and stroke path using even-odd ruleN)r	  r  rN   r:   r:   r;   do_b_ad  r  zPDFPageInterpreter.do_b_ac                 C   s
   g | _ dS )z$End path without filling or strokingN)r   rN   r:   r:   r;   do_nj  s   zPDFPageInterpreter.do_nc                 C   r   )z3Set clipping path using nonzero winding number ruleNr:   rN   r:   r:   r;   do_Wo     zPDFPageInterpreter.do_Wc                 C   r   )z%Set clipping path using even-odd ruleNr:   rN   r:   r:   r;   do_W_as  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   rz   r=   r   r:   r:   r;   do_CSw  s   zPDFPageInterpreter.do_CSc                 C   r  )z*Set color space for nonstroking operationsr  N)r   r,   r   r   r   rz   r=   r   r:   r:   r;   do_cs  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   re   r   r   rO   r#  r:   r:   r;   do_G     zPDFPageInterpreter.do_Gc                 C   r$  )z)Set gray level for nonstroking operationsr%  Nr
   r   r   rf   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&  rO   r,  r-  r.  r:   r:   r;   do_RG      zPDFPageInterpreter.do_RGc                 C   r/  )z(Set RGB color for nonstroking operationsr0  Nr*  r1  r:   r:   r;   do_rg  r3  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&  rO   r   r   r   r~   r:   r:   r;   do_K     zPDFPageInterpreter.do_Kc                 C   r5  )z)Set CMYK color for nonstroking operationsr6  Nr*  r7  r:   r:   r;   do_k  r9  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   rz   r=   r
   Colorr   r   re   rO   r   r:   r:   r;   do_SCN     
zPDFPageInterpreter.do_SCNc                 C   r;  )$Set color for nonstroking operationsr<  r   N)
r   r=  r   rz   r=   r
   r>  r   r   rf   r?  r:   r:   r;   do_scn  rA  zPDFPageInterpreter.do_scnc                 C      |    dS )z!Set color for stroking operationsN)r@  rN   r:   r:   r;   do_SC  r   zPDFPageInterpreter.do_SCc                 C   rD  )rB  N)rC  rN   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   rM   rN   r:   r:   r;   do_BT  s   
zPDFPageInterpreter.do_BTc                 C   r   )zEnd a text objectNr:   rN   r:   r:   r;   do_ET  r  zPDFPageInterpreter.do_ETc                 C   r   )zBegin compatibility sectionNr:   rN   r:   r:   r;   do_BX  r  zPDFPageInterpreter.do_BXc                 C   r   )zEnd compatibility sectionNr:   rN   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&   rO   rM  r:   r:   r;   do_MP     zPDFPageInterpreter.do_MPpropsc                 C      | j tt|| dS )z.Define marked-content point with property listNrO  rO   rM  rS  r:   r:   r;   do_DP     zPDFPageInterpreter.do_DPc                 C   rN  )zBegin marked-content sequenceNr   Z	begin_tagr
   r&   rP  r:   r:   r;   do_BMC  rR  zPDFPageInterpreter.do_BMCc                 C   rT  )z0Begin marked-content sequence with property listNrX  rU  r:   r:   r;   do_BDC  rW  zPDFPageInterpreter.do_BDCc                 C   rH  )zEnd marked-content sequenceN)r   Zend_tagrN   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   rG   rO   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   rH   r]  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
        N)r
   r   r   rI   )rO   ra  r:   r:   r;   do_Tz!     zPDFPageInterpreter.do_TzrJ   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   rJ   )rO   rJ   r:   r:   r;   do_TL)  s   zPDFPageInterpreter.do_TLr   rF   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   rE   r   r   rz   r=   r   r|   r
   r   rF   )rO   r   rF   r:   r:   r;   do_Tf3  s   zPDFPageInterpreter.do_TfrK   c                 C   r   )zSet the text rendering modeN)r
   r   r   rK   )rO   rK   r:   r:   r;   do_TrC  r   zPDFPageInterpreter.do_TrrL   c                 C   r   )z`Set the text rise

        :param rise: a number expressed in unscaled text space units
        N)r
   r   r   rL   )rO   rL   r:   r:   r;   do_TsH  rc  zPDFPageInterpreter.do_Tstxtyc           	      C   sh   t t|}t t|}| jj\}}}}}}|||||| ||  | || ||  | f| j_d| j_dS )zMove text positionrV   N)r
   r   r   rA   rB   	rO   rh  ri  ar.  r   r   efr:   r:   r;   do_TdP  s   

4zPDFPageInterpreter.do_Tdc           	      C   sp   t t|}t t|}| jj\}}}}}}|||||| ||  | || ||  | f| j_|| j_d| j_dS )z"Move text position and set leadingrV   N)r
   r   r   rA   rJ   rB   rj  r:   r:   r;   do_TDY  s   

4zPDFPageInterpreter.do_TDrk  r   rl  rm  c                 C   s&   t t||||||f| j_d| j_dS )z$Set text matrix and text line matrixrV   N)r
   r.   r   rA   rB   rO   rk  r.  r   r   rl  rm  r:   r:   r;   do_Tmc  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 linerV   N)r   rA   rJ   rB   rp  r:   r:   r;   do_T_aq  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   rE   r   rz   r=   r   r   Zrender_stringr
   r   r   rU   )rO   rs  r:   r:   r;   do_TJ  s   zPDFPageInterpreter.do_TJsc                 C   s   |  |g dS )z	Show textN)rt  rO   ru  r:   r:   r;   do_Tj  r   zPDFPageInterpreter.do_Tjc                 C   s   |    | |g dS )zPMove to next line and show text

        The ' (single quote) operator.
        N)rr  rt  rv  r:   r:   r;   do__q  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^  rt  )rO   ry  rz  ru  r:   r:   r;   do__w  s   

zPDFPageInterpreter.do__wc                 C   r   )zBegin inline image objectNr:   rN   r:   r:   r;   do_BI  r  zPDFPageInterpreter.do_BIc                 C   r   )zBegin inline image dataNr:   rN   r:   r:   r;   do_ID  r  zPDFPageInterpreter.do_IDc                 C   sT   t |tr(d|v r(d|v r(tt|}| j|dt | j|| | j| dS )zEnd inline image objectWHr   r   r   r   N)	r   r   rZ   idr   begin_figurer-   render_image
end_figure)rO   rT   Ziobjidr:   r:   r;   do_EI  s   zPDFPageInterpreter.do_EI
xobjid_argc           
      C   sF  t tt|}z	t| j| }W n ty#   tjr td| Y dS w t	
d| |d}|tu r}d|v r}|  }t tt|d }t tt|dt}|d}|r[t|}	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: %rru   ZBBoxr.   Z	Resourcesr   ZWidthZHeightr  )r
   rZ   r,   r!   r   r   r   rz   r=   rx   ry   r   LITERAL_FORMr   r1   r   r.   r-   r   r   rU   r   r  render_contentsr3   r   r  LITERAL_IMAGEr  )
rO   r  r   Zxobjr}   interpreterZbboxrA   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  )
rx   ry   Zmediaboxrotater   Z
begin_pager  r   contentsZend_page)rO   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)rx   ry   r   r   executer   )rO   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)Nr   zdo_%s*_a"_w'Z_qzexec: %s %rzexec: %szUnknown operator: %r)r   r$   Z
nextobjectr   r%   r*   replacehasattrgetattr__code__co_argcountr   rx   ry   r   r   rz   r=   r   )rO   r   parserr   rT   r   methodfuncnargsargsr   r:   r:   r;   r    sD   




zPDFPageInterpreter.execute)rC   r   rX   )dr7   r8   r9   r   rg   r   rP   r   r   r   r   r.   r   	PDFStackTr   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  r  r!  r"  r(  r+  r2  r4  r8  r:  r@  rC  rE  rF  rG  rI  rJ  rK  rL  rQ  rV  rY  rZ  r[  r^  r`  rb  rd  re  rf  rg  rn  ro  rq  rr  rt  rw  rx  r{  r|  r}  r  r  r   r  r-   r   r  r  r:   r:   r:   r;   r   U  s   
*

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


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

	


	%

r   )Ologgingr   ior   typingr   r   r   r   r   r   r	   r
    r   Zcmapdbr   r   r   Zpdfcolorr   r   Z	pdfdevicer   r   Zpdffontr   r   r   r   r   r   Zpdfpager   Zpdftypesr   r   r   r   r   r    r!   Zpsparserr"   r#   r$   r%   r&   r'   r(   r)   r*   r,   utilsr-   r.   r/   r0   r1   r2   r3   	getLoggerr7   rx   r5   r=   rk   rl   r{   r  r  r@   r   r>  r[   rg   r   r  r   r:   r:   r:   r;   <module>   sx    (
70J]