o
    f                     @   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:   K/home/ubuntu/webapp/venv/lib/python3.10/site-packages/pdfminer/pdfinterp.pyr5   -       r5   c                   @   r4   )PDFInterpreterErrorNr6   r:   r:   r:   r;   r=   1   r<   r=   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__@   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>)
rH   rI   rJ   rK   rL   rM   rN   rO   rD   rE   rQ   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)rC   rH   rI   rJ   rK   rL   rM   rN   rO   rD   rE   rR   objr:   r:   r;   copy`   s   zPDFTextState.copyc                 C   s   t | _d| _d S )Nr   r   )r-   rD   rE   rQ   r:   r:   r;   rP   n      
zPDFTextState.resetrF   N)rF   rC   )r7   r8   r9   r.   __annotations__r/   rS   strrT   rX   rP   r:   r:   r:   r;   rC   <   s   
 

rC   c                   @   s.   e Zd Zd	ddZd
ddZdefddZdS )PDFGraphicStaterF   Nc                 C   s:   d| _ d | _d | _d | _d | _d | _d | _d | _d | _d S Nr   		linewidthlinecaplinejoin
miterlimitdashintentflatnessscolorncolorrQ   r:   r:   r;   rS   {   s   
zPDFGraphicState.__init__c                 C   sR   t  }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	|S rU   )
r^   ra   rb   rc   rd   re   rf   rg   rh   ri   rV   r:   r:   r;   rX      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`   rQ   r:   r:   r;   rT      s   zPDFGraphicState.__repr__r[   )rF   r^   )r7   r8   r9   rS   rX   r]   rT   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cachingrF   Nc                 C   s   || _ i | _d S rU   )rk   _cached_fonts)rR   rk   r:   r:   r;   rS      rZ   zPDFResourceManager.__init__procsc                 C   s$   |D ]}|t u r	q|tu rq	 qd S rU   )LITERAL_PDFLITERAL_TEXT)rR   rm   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 rU   )r   get_cmapCMapNotFoundr   )rR   rr   rs   r:   r:   r;   rt      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)rz   MMType1TrueTypeType3)CIDFontType0CIDFontType2Type0DescendantFontsr   )Encoding	ToUnicodezInvalid Font spec: %r)rl   logdebugr   STRICTLITERAL_FONTr   r,   r   r   r   r   r   r   rX   r    get_fontrk   )rR   rv   rw   rH   subtypedfontssubspeckr:   r:   r;   r      sF   
(


zPDFResourceManager.get_font)T)F)r7   r8   r9   __doc__boolrS   r   objectrq   r]   r   rt   r   r   r   r:   r:   r:   r;   rj      s    	"rj   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streamsrF   Nc                 C   s   || _ d| _t| d  d S r_   )r   istreamr(   rS   )rR   r   r:   r:   r;   rS      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)rR   strmr:   r:   r;   fillfp   s   zPDFContentParser.fillfpposc                 C   s   |    t| | d S rU   )r   r(   seek)rR   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BUFSIZrQ   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)rR   r   r   idatacicjr:   r:   r;   get_inline_data  s8   




z PDFContentParser.get_inline_datac                 C   s   | j |    d S rU   )add_resultspopallrQ   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_BI
start_type
KEYWORD_IDend_typer   formatr'   r2   r   r   push
KEYWORD_EIr   r   )	rR   r   r   _objs	error_msgdr   rW   r:   r:   r;   
do_keyword;  s&   



zPDFContentParser.do_keywordr[   )r   )r7   r8   r9   r   r   rS   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devicerF   Nc                 C   s   || _ || _d S rU   )r   r   )rR   r   r   r:   r:   r;   rS   [  s   zPDFPageInterpreter.__init__c                 C   s   |  | j| jS rU   )	__class__r   r   rQ   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.Nrw   rF   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   ICCBasedr   r   NDeviceN)	
isinstancelistr,   r   r   r!   r   r   get)rw   namer:   r:   r;   get_colorspacel  s   

z9PDFPageInterpreter.init_resources.<locals>.get_colorspacezResource: %r: %rr@   
ColorSpaceProcSetXObject)r   fontmapxobjmapr   rX   csmapr   r   r   r   itemsr   r   r   r   rv   r   r   r    rq   r   )rR   r   r   r   r   fontidrw   rv   csid
colorspacexobjid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_ctmrC   	textstater^   graphicstatecurpathargstackscsncsr   nextitervalues)rR   r   r:   r:   r;   
init_state  s   zPDFPageInterpreter.init_staterW   c                 C   s   | j | d S rU   )r   appendrV   r:   r:   r;   r     s   zPDFPageInterpreter.pushnc                 C   s2   |dkrg S | j | d  }| j d |  | _ |S r_   )r   )rR   r   xr:   r:   r;   pop  s
   zPDFPageInterpreter.popc                 C   s   | j | j | j fS rU   )r   r   rX   r   rQ   r:   r:   r;   get_current_state  s   z$PDFPageInterpreter.get_current_statestatec                 C   s"   |\| _ | _| _| j| j  d S rU   )r   r   r   r   r   )rR   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   rQ   r:   r:   r;   do_q  s   zPDFPageInterpreter.do_qc                 C   s   | j r| | j   dS )zRestore graphics stateN)r   r   r   rQ   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   )rR   r   r   r   r   r   r   r:   r:   r;   do_cm  s    
zPDFPageInterpreter.do_cmra   c                 C      t t|| j_dS )zSet line widthN)r
   floatr   ra   )rR   ra   r:   r:   r;   do_w     zPDFPageInterpreter.do_wrb   c                 C      || j _dS )zSet line cap styleN)r   rb   )rR   rb   r:   r:   r;   do_J     zPDFPageInterpreter.do_Jrc   c                 C   r  )zSet line join styleN)r   rc   )rR   rc   r:   r:   r;   do_j  r  zPDFPageInterpreter.do_jrd   c                 C   r  )zSet miter limitN)r   rd   )rR   rd   r:   r:   r;   do_M  r  zPDFPageInterpreter.do_Mre   phasec                 C   s   ||f| j _dS )zSet line dash patternN)r   re   )rR   re   r  r:   r:   r;   do_d     zPDFPageInterpreter.do_drf   c                 C   r  )zSet color rendering intentN)r   rf   )rR   rf   r:   r:   r;   do_ri  r  zPDFPageInterpreter.do_rirg   c                 C   r  )zSet flatness toleranceN)r   rg   )rR   rg   r:   r:   r;   do_i  r  zPDFPageInterpreter.do_ir   c                 C      dS )z7Set parameters from graphics state parameter dictionaryNr:   rR   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   rR   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  )rR   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  )rR   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  )rR   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   rQ   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   )rR   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   
paint_pathr   r   rQ   r:   r:   r;   do_S6     zPDFPageInterpreter.do_Sc                 C      |    |   dS )zClose and stroke pathN)r%  r+  rQ   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)  rQ   r:   r:   r;   do_fB  r,  zPDFPageInterpreter.do_fc                 C   s   |   S )z6Fill path using nonzero winding number rule (obsolete))r0  rQ   r:   r:   r;   do_FH  s   zPDFPageInterpreter.do_Fc                 C   r(  )zFill path using even-odd ruleFTNr)  rQ   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)  rQ   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)  rQ   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%  r3  rQ   r:   r:   r;   do_b^  r/  zPDFPageInterpreter.do_bc                 C   r-  )z0Close, fill, and stroke path using even-odd ruleN)r%  r4  rQ   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   rQ   r:   r:   r;   do_nj  s   zPDFPageInterpreter.do_nc                 C   r  )z3Set clipping path using nonzero winding number ruleNr:   rQ   r:   r:   r;   do_Wo     zPDFPageInterpreter.do_Wc                 C   r  )z%Set clipping path using even-odd ruleNr:   rQ   r:   r:   r;   do_W_as  r9  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_CSw  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_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   rh   r   r   rR   r@  r:   r:   r;   do_G     zPDFPageInterpreter.do_Gc                 C   rA  )z)Set gray level for nonstroking operationsrB  Nr
   r   r   ri   r   r   rD  r:   r:   r;   do_g  rF  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	DeviceRGBNrC  rR   rI  rJ  rK  r:   r:   r;   do_RG      zPDFPageInterpreter.do_RGc                 C   rL  )z(Set RGB color for nonstroking operationsrM  NrG  rN  r:   r:   r;   do_rg  rP  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
DeviceCMYKNrC  rR   r   r  r  r   r:   r:   r;   do_K     zPDFPageInterpreter.do_Kc                 C   rR  )z)Set CMYK color for nonstroking operationsrS  NrG  rT  r:   r:   r;   do_k  rV  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   rh   rR   r   r:   r:   r;   do_SCN     
zPDFPageInterpreter.do_SCNc                 C   rX  )$Set color for nonstroking operationsrY  r   N)
r   rZ  r   r   r=   r
   r[  r   r   ri   r\  r:   r:   r;   do_scn  r^  zPDFPageInterpreter.do_scnc                 C      |    dS )z!Set color for stroking operationsN)r]  rQ   r:   r:   r;   do_SC  r  zPDFPageInterpreter.do_SCc                 C   ra  )r_  N)r`  rQ   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  r9  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   rP   rQ   r:   r:   r;   do_BT  s   
zPDFPageInterpreter.do_BTc                 C   r  )zEnd a text objectNr:   rQ   r:   r:   r;   do_ET  r9  zPDFPageInterpreter.do_ETc                 C   r  )zBegin compatibility sectionNr:   rQ   r:   r:   r;   do_BX  r9  zPDFPageInterpreter.do_BXc                 C   r  )zEnd compatibility sectionNr:   rQ   r:   r:   r;   do_EX  r9  zPDFPageInterpreter.do_EXtagc                 C      | j tt| dS )zDefine marked-content pointNr   do_tagr
   r&   rR   rj  r:   r:   r;   do_MP     zPDFPageInterpreter.do_MPpropsc                 C      | j tt|| dS )z.Define marked-content point with property listNrl  rR   rj  rq  r:   r:   r;   do_DP     zPDFPageInterpreter.do_DPc                 C   rk  )zBegin marked-content sequenceNr   	begin_tagr
   r&   rn  r:   r:   r;   do_BMC  rp  zPDFPageInterpreter.do_BMCc                 C   rr  )z0Begin marked-content sequence with property listNrv  rs  r:   r:   r;   do_BDC  ru  zPDFPageInterpreter.do_BDCc                 C   re  )zEnd marked-content sequenceN)r   end_tagrQ   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   rJ   rR   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   rK   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   rL   )rR   r  r:   r:   r;   do_Tz!     zPDFPageInterpreter.do_TzrM   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   rM   )rR   rM   r:   r:   r;   do_TL)  s   zPDFPageInterpreter.do_TLr   rI   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   rH   r=  r   r   r=   r   r   r
   r   rI   )rR   r   rI   r:   r:   r;   do_Tf3  s   zPDFPageInterpreter.do_TfrN   c                 C   r   )zSet the text rendering modeN)r
   r   r   rN   )rR   rN   r:   r:   r;   do_TrC  r  zPDFPageInterpreter.do_TrrO   c                 C   r   )z`Set the text rise

        :param rise: a number expressed in unscaled text space units
        N)r
   r   r   rO   )rR   rO   r:   r:   r;   do_TsH  r  zPDFPageInterpreter.do_Tstxtyc           	      C   sh   t t|}t t|}| jj\}}}}}}|||||| ||  | || ||  | f| j_d| j_dS )zMove text positionrY   N)r
   r   r   rD   rE   	rR   r  r  arK  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 leadingrY   N)r
   r   r   rD   rM   rE   r  r:   r:   r;   do_TDY  s   

4zPDFPageInterpreter.do_TDr  r   r  r  c                 C   s&   t t||||||f| j_d| j_dS )z$Set text matrix and text line matrixrY   N)r
   r.   r   rD   rE   rR   r  rK  r   r   r  r  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 linerY   N)r   rD   rM   rE   r  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   rH   r   r   r=   r   r   render_stringr
   r   r   rX   )rR   r  r:   r:   r;   do_TJ  s   zPDFPageInterpreter.do_TJsc                 C   s   |  |g dS )z	Show textN)r  rR   r  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)r  r  r  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~  r  )rR   r  r  r  r:   r:   r;   do__w  s   

zPDFPageInterpreter.do__wc                 C   r  )zBegin inline image objectNr:   rQ   r:   r:   r;   do_BI  r9  zPDFPageInterpreter.do_BIc                 C   r  )zBegin inline image dataNr:   rQ   r:   r:   r;   do_ID  r9  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   r]   idr   begin_figurer-   render_image
end_figure)rR   rW   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: %rry   BBoxr.   	Resourcesr   WidthHeightr  )r
   r]   r,   r!   r   r=  r   r   r=   r   r   r   LITERAL_FORMr   r1   r   r.   r-   r   r   rX   r   r  render_contentsr3   r   r  LITERAL_IMAGEr  )
rR   r  r   xobjr   interpreterbboxrD   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)rR   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   )rR   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'_qzexec: %s %rzexec: %szUnknown operator: %r)r   r$   
nextobjectr   r%   r*   replacehasattrgetattr__code__co_argcountr   r   r   r   r   r   r=   r   )rR   r   parserr   rW   r   methodfuncnargsargsr   r:   r:   r;   r    sD   




zPDFPageInterpreter.execute)rF   r   r[   )dr7   r8   r9   r   rj   r   rS   r   r   r   r   r.   r   	PDFStackTr   r   r   r   r   rC   r^   r   r   r   r   r   r   r  r  r  r  r
  r  r  r  r  r  r   r"  r%  r'  r+  r.  r0  r1  r2  r3  r4  r5  r6  r7  r8  r:  r>  r?  rE  rH  rO  rQ  rU  rW  r]  r`  rb  rc  rd  rf  rg  rh  ri  ro  rt  rx  ry  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   U  s   
*

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


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

	


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