o
    ¾ÙøiùÁ  ã                   @   s@  d dl Z d dlZd dlmZmZ d dlmZ d dl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,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC e  DeE¡ZFG dd„ deƒZGG dd„ deƒZHe5dƒZIe5dƒZJe5dƒZKe5dƒZLe5dƒZMG dd„ dƒZNeeOePeOeOeOf ePeOeOeOeOf f ZQeeQeRePeQeRf f ZSG dd„ dƒZTG dd„ dƒZUG d d!„ d!e8ee6e+f  ƒZVe9e+ ZWG d"d#„ d#ƒZXdS )$é    N)ÚMappingÚSequence)ÚBytesIO)Ú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;   ú_/home/develop/edictos_py/central_edictos/env/lib/python3.10/site-packages/pdfminer/pdfinterp.pyr6   7   ó    r6   c                   @   r5   )ÚPDFInterpreterErrorNr7   r;   r;   r;   r<   r>   ;   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__J   s   zPDFTextState.__init__c                 C   sV   d| j ›d| j›d| j›d| j›d| j›d| j›d| j›d| j›d	| j›d
| j	›d�S )Nz<PDFTextState: font=z, fontsize=z, charspace=z, wordspace=z
, scaling=z
, leading=z	, render=z, rise=z	, matrix=z, linematrix=ú>)
rI   rJ   rK   rL   rM   rN   rO   rP   rE   rF   rR   r;   r;   r<   Ú__repr__W   s(   
ÿþýüûúùø	÷ÿzPDFTextState.__repr__c                 C   sZ   t ƒ }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	| j
|_
|S ©N)rD   rI   rJ   rK   rL   rM   rN   rO   rP   rE   rF   ©rS   Úobjr;   r;   r<   Úcopye   s   zPDFTextState.copyc                 C   s   t | _d| _d S )N©r   r   )r.   rE   rF   rR   r;   r;   r<   rQ   s   ó   
zPDFTextState.reset©rG   N)rG   rD   )r8   r9   r:   r/   Ú__annotations__r1   rT   ÚstrrV   rZ   rQ   r;   r;   r;   r<   rD   F   s   
 

rD   c                   @   s.   e Zd Zd	dd„Zd
dd„Zdefdd„ZdS )ÚPDFGraphicStaterG   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ÚncsrR   r;   r;   r<   rT   Š   s   
zPDFGraphicState.__init__c                 C   sb   t ƒ }| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	| j
|_
| j|_|S rW   )r`   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rX   r;   r;   r<   rZ   ›   s   zPDFGraphicState.copyc                 C   sN   d| j ›d| j›d| j›d| j›d| j›d| j›d| j›d| j›d	| j›d
�S )Nz<PDFGraphicState: linewidth=z
, linecap=z, linejoin=z, miterlimit=z, dash=z	, intent=z, flatness=z, stroking color=z, non stroking color=rU   )	rb   rc   rd   re   rf   rg   rh   ri   rk   rR   r;   r;   r<   rV   ª   s(   ÿþýüûúùø	÷ÿzPDFGraphicState.__repr__r]   )rG   r`   )r8   r9   r:   rT   rZ   r_   rV   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 )ÚPDFResourceManagerz¸Repository of shared resources.

    ResourceManager facilitates reuse of shared resources
    such as fonts and images so that large objects are not
    allocated multiple times.
    TÚcachingrG   Nc                 C   s   || _ i | _d S rW   )rn   Ú_cached_fonts)rS   rn   r;   r;   r<   rT   Á   r\   zPDFResourceManager.__init__Úprocsc                 C   s"   |D ]}|t u s|tu rq	 qd S rW   )ÚLITERAL_PDFÚLITERAL_TEXT)rS   rp   Ú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 rW   )r   Úget_cmapÚCMapNotFoundr   )rS   ru   rv   r;   r;   r<   rw   Ì   s   
ýzPDFResourceManager.get_cmapÚobjidÚspecc                 C   sN  |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| |ƒ}n[|dkrJt	| |ƒ}nQ|d	krTt
| |ƒ}nG|d
v r^t| |ƒ}n=|dkrŒt|d ƒ}|slJ ‚t|d ƒ ¡ }dD ]}||v r„t|| ƒ||< qv|  d |¡}ntjr–t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: )ro   ÚlogÚdebugr   ÚSTRICTÚLITERAL_FONTr   r-   r   r   r   r   r!   r    rZ   r"   Úget_fontrn   )rS   ry   rz   rI   ÚsubtypeÚdfontsÚsubspecÚkr;   r;   r<   r‹   Ô   sD   
'Û€


zPDFResourceManager.get_font)T)F)r8   r9   r:   Ú__doc__ÚboolrT   r   Úobjectrt   r_   r   rw   r   r   r‹   r;   r;   r;   r<   rm   ¹   s    "rm   c                	   @   s¨   e Zd Zdee ddfdd„Zdefdd„Zdeddfd	d
„Z	def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ÚstreamsrG   Nc                 C   s   || _ d| _t | d ¡ d S ©Nr   )r”   Úistreamr*   rT   )rS   r”   r;   r;   r<   rT     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?TF)Úfpr–   Úlenr”   r#   r$   r   Úget_data)rS   Ústrmr;   r;   r<   Úfillfp	  s   zPDFContentParser.fillfpÚposc                 C   s   |   ¡  t | |¡ d S rW   )rœ   r*   Úseek)rS   r�   r;   r;   r<   rž     s   zPDFContentParser.seekc                 C   sX   | j t| jƒk r
dS d}	 |  ¡ }| j ¡ | _| j | j¡| _| jr#nd | _qd| _ |S )NFr—   r   )	Úcharposr™   Úbufrœ   r˜   ÚtellÚbufposÚreadÚBUFSIZ)rS   Ú
new_streamr;   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)rS   r�   r¨   ÚiÚdataÚciÚcÚjr;   r;   r<   Úget_inline_data&  s6   



þíz PDFContentParser.get_inline_datac                 C   s   | j |  ¡ Ž  d S rW   )Úadd_resultsÚpopallrR   r;   r;   r<   ÚflushD  s   zPDFContentParser.flushs   BIs   IDÚtokenc                 C   s4  || j u r|  |d¡ d S || ju r‘zp|  d¡\}}t|ƒd dkr+d|›�}t|ƒ‚dd„ td|ƒD ƒ}d}| d¡}|d urPt|t	ƒrH|g}|d t
v rPd	}| j|td
ƒ |d�\}}	|dkre|	|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>U  s    z/PDFContentParser.do_keyword.<locals>.<dictcomp>r§   ÚFs   ~>s   ID )r¨   )Ú
KEYWORD_BIÚ
start_typeÚ
KEYWORD_IDÚend_typer™   r%   r3   ÚgetÚ
isinstancer)   r   rµ   r   ÚpushÚ
KEYWORD_EIr   r‰   )rS   r�   r¹   Ú_ÚobjsÚ	error_msgÚdÚeosÚfilterr±   rY   r;   r;   r<   Ú
do_keywordK  s<   





ÿÿÿzPDFContentParser.do_keyword)r§   r]   )r8   r9   r:   r   r’   rT   r‘   rœ   Úintrž   r¦   rª   Útuplerµ   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dëdd	„Zdëd
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dìdd„Zdìd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d0d1„Zd2eddfd3d4„Zd5ed6eddfd7d8„Zd9eddfd:d;„Z d<eddfd=d>„Z!d?eddfd@dA„Z"dBedCeddfdDdE„Z#dBedCeddfdFdG„Z$dHedIedJedKedLedMeddfdNdO„Z%dJedKedLedMeddf
dPdQ„Z&dHedIedLedMeddf
dRdS„Z'dìdTdU„Z(dBedCedVedWeddf
dXdY„Z)dìdZd[„Z*dìd\d]„Z+dìd^d_„Z,dìd`da„Z-dìdbdc„Z.dìddde„Z/dìdfdg„Z0dìdhdi„Z1dìdjdk„Z2dìdldm„Z3dìdndo„Z4dìdpdq„Z5d?eddfdrds„Z6d?eddfdtdu„Z7dveddfdwdx„Z8dveddfdydz„Z9d{ed|ed}eddfd~d„Z:d{ed|ed}eddfd€d�„Z;d‚edƒedCed„eddf
d…d†„Z<d‚edƒedCed„eddf
d‡dˆ„Z=d‰ee dŠe>de?dB fd‹dŒ„Z@dìd�dŽ„ZAdìd�d�„ZBdìd‘d’„ZCdìd“d”„ZDd?e
ddfd•d–„ZEdìd—d˜„ZFdìd™dš„ZGdìd›dœ„ZHdìd�dž„ZIdŸeddfd d¡„ZJdŸed¢eddfd£d¤„ZKdŸeddfd¥d¦„ZLdŸed¢eddfd§d¨„ZMdìd©dª„ZNd«eddfd¬d­„ZOd«eddfd®d¯„ZPd°eddfd±d²„ZQd³eddfd´dµ„ZRd¶ed·eddfd¸d¹„ZSdºeddfd»d¼„ZTd½eddfd¾d¿„ZUdÀedÁeddfdÂdÃ„ZVdÀedÁeddfdÄdÅ„ZWdÆed}ed‚edÇedÈedÉeddfdÊdË„ZXdìdÌdÍ„ZYdÎeddfdÏdÐ„ZZdÑeddfdÒdÓ„Z[dÑeddfdÔdÕ„Z\dÖed×edÑeddfdØdÙ„Z]dìdÚdÛ„Z^dìdÜdÝ„Z_deddfdÞdß„Z`dàeddfdádâ„Zadãebddfdädå„Zcedfde	e
e
f dæeee
 deddfdçdè„Zfdæeee
 ddfdédê„ZgdS )íÚPDFPageInterpreterzhProcessor for the content of a PDF page

    Reference: PDF Reference, Appendix A, Operator Summary
    ÚrsrcmgrÚdevicerG   Nc                 C   s    || _ || _tƒ | _tƒ | _d S rW   )rÒ   rÓ   ÚsetÚ
stream_idsÚparent_stream_ids)rS   rÒ   rÓ   r;   r;   r<   rT   u  s   zPDFPageInterpreter.__init__c                 C   s   |   | j| j¡S rW   )Ú	__class__rÒ   rÓ   rR   r;   r;   r<   Údup}  ó   zPDFPageInterpreter.dupc                 C   s(   |   ¡ }|j | j¡ |j | j¡ |S )aX  Create a sub-interpreter for processing nested content streams.

        This is used when invoking Form XObjects to prevent circular references.
        Unlike dup(), this method propagates the stream ID tracking from the
        parent interpreter, allowing detection of circular references across
        nested XObject invocations.
        )rØ   rÖ   ÚupdaterÕ   )rS   Úinterpr;   r;   r<   Ú	subinterp€  s   zPDFPageInterpreter.subinterpÚ	resourcesc                 C   s2  || _ i | _i | _t ¡ | _|sdS dtdtdB 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r–t|ƒ 	¡ D ]	\}
}|| j|
< qŒq#dS )z@Prepare the fonts and XObjects listed in the Resource attribute.Nrz   rG   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Å   Úlistr-   r™   r   r#   r!   r   rÄ   )rz   Únamer;   r;   r<   Úget_colorspace–  s   

z9PDFPageInterpreter.init_resources.<locals>.get_colorspacezResource: %r: %rrA   Ú
ColorSpaceÚProcSetÚXObject)rÝ   ÚfontmapÚxobjmapr   rZ   Úcsmapr’   r   r    Úitemsr‡   rˆ   rÅ   r   ry   rÒ   r‹   r"   rt   r!   )rS   rÝ   rã   r�   r½   Úfontidrz   ry   ÚcsidÚ
colorspaceÚxobjidÚxobjstrmr;   r;   r<   Úinit_resources�  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_ctmrD   Ú	textstater`   ÚgraphicstateÚcurpathÚargstack)rS   rñ   r;   r;   r<   Ú
init_state¶  s   
zPDFPageInterpreter.init_staterY   c                 C   s   | j  |¡ d S rW   )r÷   ÚappendrX   r;   r;   r<   rÆ   Â  rÙ   zPDFPageInterpreter.pushÚnc                 C   s2   |dkrg S | j | d … }| j d | … | _ |S r•   )r÷   )rS   rú   Úxr;   r;   r<   ÚpopÅ  s
   zPDFPageInterpreter.popc                 C   s   | j | j ¡ | j ¡ fS rW   )rñ   rô   rZ   rõ   rR   r;   r;   r<   Úget_current_stateÌ  s   z$PDFPageInterpreter.get_current_stateÚstatec                 C   s"   |\| _ | _| _| j | j ¡ d S rW   )rñ   rô   rõ   rÓ   ró   )rS   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ý   rR   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ü   rR   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‡   Úwarningr4   rñ   rÓ   ró   )rS   r  r  r  r  r  r  rE   r;   r;   r<   Údo_cmß  s   
ÿÿzPDFPageInterpreter.do_cmrb   c                 C   sV   t |ƒ}|du rt d|›d�¡ dS | jd d | jd d  d }|| | j_dS )zSet line widthNzCannot set line width because ú is an invalid float valuer   r»   r—   g      à?)r	   r‡   r	  rñ   rõ   rb   )rS   rb   Úlinewidth_fÚscaler;   r;   r<   Údo_wõ  s   
ÿ zPDFPageInterpreter.do_wrc   c                 C   ó   || j _dS )zSet line cap styleN)rõ   rc   )rS   rc   r;   r;   r<   Údo_J   ó   zPDFPageInterpreter.do_Jrd   c                 C   r  )zSet line join styleN)rõ   rd   )rS   rd   r;   r;   r<   Údo_j  r  zPDFPageInterpreter.do_jre   c                 C   r  )zSet miter limitN)rõ   re   )rS   re   r;   r;   r<   Údo_M  r  zPDFPageInterpreter.do_Mrf   Úphasec                 C   s   ||f| j _dS )zSet line dash patternN)rõ   rf   )rS   rf   r  r;   r;   r<   Údo_d  ó   zPDFPageInterpreter.do_drg   c                 C   r  )zSet color rendering intentN)rõ   rg   )rS   rg   r;   r;   r<   Údo_ri  r  zPDFPageInterpreter.do_rirh   c                 C   r  )zSet flatness toleranceN)rõ   rh   )rS   rh   r;   r;   r<   Údo_i  r  zPDFPageInterpreter.do_irâ   c                 C   ó   dS )z7Set parameters from graphics state parameter dictionaryNr;   ©rS   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ù   ©rS   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   )rS   r(  r)  r*  r+  r,  r-  Úx1_fÚy1_fÚx2_fÚy2_fÚx3_fÚy3_fr$  r;   r;   r<   Údo_c9  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   )
rS   r*  r+  r,  r-  r1  r2  r3  r4  r$  r;   r;   r<   Údo_vZ  ó    ÿÿzPDFPageInterpreter.do_vc           
      C   r6  )z6Append curved segment to path (final point replicated)Nr  r.  r  r   )
rS   r(  r)  r,  r-  r/  r0  r3  r4  r$  r;   r;   r<   Údo_yj  r8  zPDFPageInterpreter.do_yc                 C   s   | j  d¡ dS )zClose subpath©ÚhN)rö   rù   rR   r;   r;   r<   Údo_hz  r  zPDFPageInterpreter.do_hÚwr;  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&  r:  r   )
rS   rû   r  r=  r;  r"  r#  Úw_fÚh_fÚvaluesr;   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ö   rR   r;   r;   r<   Údo_S’  ó   
zPDFPageInterpreter.do_Sc                 C   ó   |   ¡  |  ¡  dS )zClose and stroke pathN)r<  rE  rR   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 ruleFTNrC  rR   r;   r;   r<   Údo_fœ  rF  zPDFPageInterpreter.do_fc                 C   r  )z6Fill path using nonzero winding number rule (obsolete)Nr;   rR   r;   r;   r<   Údo_F¡  r  zPDFPageInterpreter.do_Fc                 C   rB  )zFill path using even-odd ruleFTNrC  rR   r;   r;   r<   Údo_f_a¤  rF  zPDFPageInterpreter.do_f_ac                 C   s"   | j  | jddd| j¡ g | _dS )z6Fill and stroke path using nonzero winding number ruleTFNrC  rR   r;   r;   r<   Údo_B©  rF  zPDFPageInterpreter.do_Bc                 C   s"   | j  | jddd| j¡ g | _dS )z(Fill and stroke path using even-odd ruleTNrC  rR   r;   r;   r<   Údo_B_a®  rF  zPDFPageInterpreter.do_B_ac                 C   rG  )z>Close, fill, and stroke path using nonzero winding number ruleN)r<  rM  rR   r;   r;   r<   Údo_b³  rI  zPDFPageInterpreter.do_bc                 C   rG  )z0Close, fill, and stroke path using even-odd ruleN)r<  rN  rR   r;   r;   r<   Údo_b_a¸  rI  zPDFPageInterpreter.do_b_ac                 C   s
   g | _ dS )z$End path without filling or strokingN)rö   rR   r;   r;   r<   Údo_n½  s   
zPDFPageInterpreter.do_nc                 C   r  )z3Set clipping path using nonzero winding number ruleNr;   rR   r;   r;   r<   Údo_WÁ  r  zPDFPageInterpreter.do_Wc                 C   r  )z%Set clipping path using even-odd ruleNr;   rR   r;   r;   r<   Údo_W_aÄ  r  zPDFPageInterpreter.do_W_ac              
   C   óV   z| j t|ƒ | j_W dS  ty* } ztjrtd|›�ƒ|‚W Y d}~dS d}~ww )zOSet color space for stroking operations

        Introduced in PDF 1.1
        úUndefined ColorSpace: N)ré   r-   rõ   rj   ÚKeyErrorr   r‰   r>   ©rS   râ   Úerrr;   r;   r<   Údo_CSÇ  s   ÿ€ÿzPDFPageInterpreter.do_CSc              
   C   rT  )z*Set color space for nonstroking operationsrU  N)ré   r-   rõ   rl   rV  r   r‰   r>   rW  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  ra   )r	   r‡   r	  rõ   ri   ré   rj   ©rS   r[  Úgray_fr;   r;   r<   Údo_GÚ  ó   
ÿzPDFPageInterpreter.do_Gc                 C   r\  )z)Set gray level for nonstroking operationsNr]  r  ra   )r	   r‡   r	  rõ   rk   ré   rl   r^  r;   r;   r<   Údo_gæ  ra  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õ   ri   ré   rj   ©rS   rc  rd  re  Úrgbr;   r;   r<   Údo_RGò  ó   ÿÿzPDFPageInterpreter.do_RGc                 C   rf  )z(Set RGB color for nonstroking operationsNz:Cannot set RGB non-stroke color because not all values in r  rg  )r   r‡   r	  rõ   rk   ré   rl   rh  r;   r;   r<   Údo_rgÿ  rk  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õ   ri   ré   rj   ©rS   r³   r  r  r�   Úcmykr;   r;   r<   Údo_K  ó   
ÿÿzPDFPageInterpreter.do_Kc                 C   rm  )z)Set CMYK color for nonstroking operationsNz;Cannot set CMYK non-stroke color because not all values in r  rn  )r   r‡   r	  rõ   rk   ré   rl   ro  r;   r;   r<   Údo_k  rr  zPDFPageInterpreter.do_kÚ
componentsÚcontextc                 C   sÐ   t |ƒdkr t|d ƒ}|du rt d|› d|d ›d�¡ |S t |ƒdkr<t|Ž }|du r:t d|› d|›d	�¡ |S t |ƒd
krXt|Ž }|du rVt d|› d|›d�¡ |S t d|› dt |ƒ› d�¡ dS )aQ  Parse color components into StandardColor (gray, RGB, or CMYK).

        Args:
            components: List of 1, 3, or 4 numeric color components
            context: Description for error messages (e.g., "stroke", "non-stroke")

        Returns:
            Parsed color (float for gray, tuple for RGB/CMYK) or None if invalid
        r—   r   NzCannot set z color: r  é   z color: components z cannot be parsed as RGBé   z cannot be parsed as CMYKzR components specified, but only 1 (grayscale), 3 (RGB), and 4 (CMYK) are supported)r™   r	   r‡   r	  r   r   )rS   rt  ru  r[  ri  rp  r;   r;   r<   Ú_parse_color_components&  sB   ÿÿÿÿÿÿÿÿz*PDFPageInterpreter._parse_color_componentsc                 C   ó*  | j jj}|  |¡}t|ƒ|krt d|› d|›�¡ dS | j jjdkr6|  |d¡}|dur4|| j _	dS dS t|ƒdkr“|d }t
|tƒsVt dt|ƒj› d	|›d
�¡ dS t|ƒ}t|ƒdkrn|| j _	t d|› �¡ dS |dd… }|  |d¡}|du r€dS ||f| j _	t d|› d|› �¡ dS dS )a=  Set color for stroking operations.

        Handles Pattern color spaces per ISO 32000-1:2008 4.5.5 (PDF 1.7)
        and ISO 32000-2:2020 8.7.3 (PDF 2.0):
        - Colored patterns (PaintType=1): single operand (pattern name)
        - Uncolored patterns (PaintType=2): n+1 operands (colors + pattern name)
        z)Cannot set stroke color because expected ú components but got ÚPatternÚstrokeNr—   éÿÿÿÿú:Pattern color space requires name object (PSLiteral), got ú: z‹. Per ISO 32000 8.7.3.2, colored patterns use syntax '/name SCN'. Per ISO 32000 8.7.3.3, uncolored patterns use syntax 'c1...cn /name SCN'.zSet stroke pattern (colored): zstroke (uncolored pattern)z Set stroke pattern (uncolored): ú + )rõ   rj   Úncomponentsrü   r™   r‡   r	  râ   rx  ri   rÅ   r)   Útyper8   r-   rˆ   ©rS   rú   rt  ÚcolorÚpattern_componentÚpattern_nameÚbase_color_componentsÚ
base_colorr;   r;   r<   Údo_SCNU  óR   

ÿÿÿÿ
ÿÿÿÿÿÜzPDFPageInterpreter.do_SCNc                 C   ry  )uB  Set color for nonstroking operations.

        Handles Pattern color spaces per ISO 32000-1:2008 4.5.5 (PDF 1.7)
        and ISO 32000-2:2020 Â§8.7.3 (PDF 2.0):
        - Colored patterns (PaintType=1): single operand (pattern name)
        - Uncolored patterns (PaintType=2): n+1 operands (colors + pattern name)
        z-Cannot set non-stroke color because expected rz  r{  z
non-strokeNr—   r}  r~  r  z‹. Per ISO 32000 8.7.3.2, colored patterns use syntax '/name scn'. Per ISO 32000 8.7.3.3, uncolored patterns use syntax 'c1...cn /name scn'.z"Set non-stroke pattern (colored): znon-stroke (uncolored pattern)z$Set non-stroke pattern (uncolored): r€  )rõ   rl   r�  rü   r™   r‡   r	  râ   rx  rk   rÅ   r)   r‚  r8   r-   rˆ   rƒ  r;   r;   r<   Údo_scn”  rŠ  zPDFPageInterpreter.do_scnc                 C   ó   |   ¡  dS )z!Set color for stroking operationsN)r‰  rR   r;   r;   r<   Údo_SCÓ  r  zPDFPageInterpreter.do_SCc                 C   rŒ  )z$Set color for nonstroking operationsN)r‹  rR   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 )zÓBegin 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ô   rQ   rR   r;   r;   r<   Údo_BTÞ  s   zPDFPageInterpreter.do_BTc                 C   r  )zEnd a text objectNr;   rR   r;   r;   r<   Údo_ETç  r  zPDFPageInterpreter.do_ETc                 C   r  )zBegin compatibility sectionNr;   rR   r;   r;   r<   Údo_BXê  r  zPDFPageInterpreter.do_BXc                 C   r  )zEnd compatibility sectionNr;   rR   r;   r;   r<   Údo_EXí  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	  ©rS   r•  r;   r;   r<   Údo_MPð  s
   

ÿ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˜  ©rS   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  s   
ÿÿ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_tagrR   r;   r;   r<   Údo_EMC  s   zPDFPageInterpreter.do_EMCÚspacec                 C   ó2   t |ƒ}|du rt d|›d�¡ dS || j_dS )zªSet 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ô   rK   )rS   r§  rK   r;   r;   r<   Údo_Tc  ó   ÿÿzPDFPageInterpreter.do_Tcc                 C   r¨  )z£Set 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 because r  )r	   r‡   r	  rô   rL   )rS   r§  rL   r;   r;   r<   Údo_Tw+  rª  zPDFPageInterpreter.do_Twr  c                 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ô   rM   )rS   r  Úscale_fr;   r;   r<   Údo_Tz;  s   ÿÿzPDFPageInterpreter.do_TzrN   c                 C   s4   t |ƒ}|du rt d|›d�¡ dS | | j_dS )z©Set 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ô   rN   )rS   rN   Ú	leading_fr;   r;   r<   Údo_TLJ  s   ÿÿzPDFPageInterpreter.do_TLrë   rJ   c              
   C   s–   z| j t|ƒ | j_W n& ty1 } ztjrtd|›�ƒ|‚| j 	di ¡| j_W Y d}~nd}~ww t
|ƒ}|du rEt d|›d�¡ dS || j_dS )zÞSet 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: Nz Could not set text font because r  )rç   r-   rô   rI   rV  r   r‰   r>   rÒ   r‹   r	   r‡   r	  rJ   )rS   rë   rJ   rX  Ú
fontsize_fr;   r;   r<   Údo_TfZ  s    €ýÿÿzPDFPageInterpreter.do_TfrO   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ô   rO   )rS   rO   Úrender_ir;   r;   r<   Údo_Trq  s   ÿÿzPDFPageInterpreter.do_TrrP   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ô   rP   )rS   rP   Úrise_fr;   r;   r<   Údo_Ts}  s   
ÿ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ô   rE   r   r‰   r   rF   ©rS   r¶  r·  Útx_Úty_Úare  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 )zÃMove 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ô   rE   r   r‰   r   rN   rF   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ô   rE   rF   )	rS   r»  re  r³   rË   r¼  r½  r@  rE   r;   r;   r<   Údo_Tm´  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ô   rE   rN   rF   )rS   r»  re  r³   rË   r¼  r½  r;   r;   r<   Údo_T_aÊ  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ô   rI   r   r‰   r>   rÓ   Úrender_stringr   r   rõ   rl   rZ   )rS   rÄ  r;   r;   r<   Údo_TJ×  s   üzPDFPageInterpreter.do_TJÚsc                 C   s   |   |g¡ dS )z	Show textN)rÆ  ©rS   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Æ  )rS   rË  rÌ  rÇ  r;   r;   r<   Údo__wð  s   

zPDFPageInterpreter.do__wc                 C   r  )zBegin inline image objectNr;   rR   r;   r;   r<   Údo_BIù  r  zPDFPageInterpreter.do_BIc                 C   r  )zBegin inline image dataNr;   rR   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)rS   rY   Úiobjidr;   r;   r<   Údo_EIÿ  s   üzPDFPageInterpreter.do_EIÚ
xobjid_argc              
   C   sT  t |ƒ}z	t| j| ƒ}W n ty+ } ztjr td|›�ƒ|‚W Y d}~dS d}~ww t d|¡ | 	d¡}|t
u r„d|v r„|  ¡ }ttt|d ƒƒ}ttt| 	dt¡ƒƒ}| 	d¡}	|	rbt|	ƒn| j ¡ }
| j |||¡ |j|
|gt|| jƒd� | j |¡ dS |tu r§d	|v r§d
|v r§| j |dt¡ | j ||¡ | j |¡ dS 	 dS )zInvoke named XObjectzUndefined xobject id: NzProcessing xobj: %rr|   ÚBBoxr/   Ú	Resources©rñ   ÚWidthÚHeightrÒ  )r-   r#   rè   rV  r   r‰   r>   r‡   rˆ   rÄ   ÚLITERAL_FORMrÜ   r   r2   r!   r/   r.   r    rÝ   rZ   rÓ   rÔ  Úrender_contentsr4   rñ   rÖ  ÚLITERAL_IMAGErÕ  )rS   rÙ  rî   ÚxobjrX  rŒ   ÚinterpreterÚbboxrE   Ú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: %réZ   r   r}  r—   é´   i  rÜ  )
r‡   rˆ   ÚmediaboxÚrotaterÓ   Ú
begin_pagerà  rÝ   ÚcontentsÚend_page)rS   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!   )rS   rÝ   r”   rñ   r;   r;   r<   rà  9  s   
ü

z"PDFPageInterpreter.render_contentsc                 C   sv  g }| j  ¡  |D ],}t|ƒ}|jd u rt d|¡ q	|j| jv r)t d|j¡ q	| |¡ | j  |j¡ q	zt	|ƒ}W n
 t
yF   Y d S w 	 z| ¡ \}}W n
 t
yZ   Y d S w t|tƒrµt|ƒ}d | dd¡ dd¡ d	d
¡¡}t| |ƒr¨t| |ƒ}	|	jjd }
|
rž|  |
¡}t d||¡ t|ƒ|
kr�|	|Ž  nt d|¡ |	ƒ  ntjr´d|›�}t|ƒ‚n|  |¡ qH)Nz8Execute called on non-indirect object (inline image?) %rz;Refusing to execute circular reference to content stream %dTzdo_{}Ú*Ú_aú"Ú_wú'Ú_qr—   zexec: %s %rzexec: %szUnknown operator: )rÕ   Úclearr#   ry   r‡   r	  rÖ   rù   Úaddr“   r$   Ú
nextobjectrÅ   r(   r,   ÚformatÚreplaceÚhasattrÚgetattrÚ__code__Úco_argcountrü   rˆ   r™   r   r‰   r>   rÆ   )rS   r”   Úvalid_streamsrY   ÚstreamÚparserrÈ   râ   ÚmethodÚfuncÚnargsÚargsrÊ   r;   r;   r<   rò  M  sl   

ÿþ
þÿ

þý


€
þ
âzPDFPageInterpreter.execute)rG   rÑ   r]   )hr8   r9   r:   r�   rm   r   rT   rØ   rÜ   Údictr’   rð   r/   rø   Ú	PDFStackTrÆ   rÏ   rá   rü   rÐ   rD   r`   rý   rÿ   r   r  r
  r  r  r  r  r  r  r  r  r%  r'  r5  r7  r9  r<  rA  rE  rH  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rY  rZ  r`  rb  rj  rl  rq  rs  r_   ÚStandardColorrx  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;   r<   rÑ   o  s&   

)þ
ý

þýüûúù
øþýüûúù
ø!












ÿÿ
þ
/
?
?


	

	



þýüûúù
ø

	
#ü
þýü
ûrÑ   )YÚloggingr®   Úcollections.abcr   r   Úior   Útypingr   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+   r,   r-   Úpdfminer.utilsr.   r/   r0   r1   r2   r3   r4   Ú	getLoggerr8   r‡   r6   r>   rq   rr   rŠ   rß  rá  rD   ÚfloatrÐ   r  r_   ÚColorr`   rm   r“   r
  rÑ   r;   r;   r;   r<   Ú<module>   sZ     $	($


3þÿÿþÿ	0Gl