HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/pydyf/__pycache__/__init__.cpython-310.pyc
o

we9R�@s�dZddlZddlZddlmZddlmZddlmZm	Z	dZ
Zdd�ZGd	d
�d
�Z
Gdd�de
e�ZGd
d�de
�ZGdd�de
�ZGdd�de
e�ZGdd�d�ZdS)z
A low-level PDF generator.

�N)�BOM_UTF16_BE)�md5)�ceil�logz0.8.0cCs|t|t�r|St|t�r|jSt|t�r+|��r!t|�d��d�S|d��d��d�St|t�r7|d��d�St	|��d�S)zConvert item to bytes.�d�ascii�f�0)
�
isinstance�bytes�Object�data�float�
is_integer�int�encode�rstrip�str)�item�r�G/home/arjun/projects/env/lib/python3.10/site-packages/pydyf/__init__.py�	_to_bytess



rc@sHeZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	dS)
rzBase class for PDF objects.cCsd|_d|_d|_d|_dS)Nr�n)�number�offset�
generation�free��selfrrr�__init__!s
zObject.__init__cCs&|j�d|j�d���}||jdS)z%Indirect representation of an object.� z obj
s
endobj)rrrr
)r�headerrrr�indirect,szObject.indirectcCs|j�d|j�d���S)zObject identifier.r z R)rrrrrrr�	reference2szObject.referencecCst��)z@Data contained in the object. Shall be defined in each subclass.)�NotImplementedErrorrrrrr
7szObject.datacCs|jo	t|t�S)z7Whether the object can be included in an object stream.)rr
�Streamrrrr�compressible<szObject.compressibleN)
�__name__�
__module__�__qualname__�__doc__r�propertyr"r#r
r&rrrrrs


rc@�&eZdZdZddd�Zedd��ZdS)�
DictionaryzPDF Dictionary object.NcCst�|�t�||pi�dS�N)rr�dict)r�valuesrrrrD�
zDictionary.__init__cCs$dd�|��D�}dd�|�dS)NcSs(g|]\}}dt|�dt|��qS)�/� �r)�.0�key�valuerrr�
<listcomp>Js��z#Dictionary.data.<locals>.<listcomp>�<<��>>)�items�join)r�resultrrrr
Hs�zDictionary.datar.�r'r(r)r*rr+r
rrrrr-B�

r-csveZdZdZdV�fdd�	ZdWdd�Zdd	�ZdXd
d�Zdd
�ZdXdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdXdd�ZdXd d!�ZdXd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�ZdXd2d3�ZdXd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+e,dTdU��Z-�Z.S)Yr%zPDF Stream object.NFcs(t���|pg|_|p
i|_||_dSr.)�superr�stream�extra�compress)rrBrCrD��	__class__rrrRs



zStream.__init__cCsF|j�d|���|dur|j�d�dS|j�|�|j�d�dS)zBegin marked-content sequence.�/NsBMCsBDC�rB�append)r�tag�
property_listrrr�begin_marked_content[s
zStream.begin_marked_contentcC�|j�d�dS)zBegin a text object.sBTNrHrrrr�
begin_textd�zStream.begin_textcC�|j�|r
d�dSd�dS)aModify current clipping path by intersecting it with current path.

        Use the nonzero winding number rule to determine which regions lie
        inside the clipping path by default.

        Use the even-odd rule if ``even_odd`` set to ``True``.

        sW*�WNrH�r�even_oddrrr�cliphs	zStream.clipcCrM)z�Close current subpath.

        Append a straight line segment from the current point to the starting
        point of the subpath.

        �hNrHrrrr�closesszStream.closecC�(|j�dt|�d|rdnd�dS)zwSet the nonstroking color space.

        If stroke is set to ``True``, set the stroking color space instead.

        r2r3sCSscsN�rBrIr)r�space�strokerrr�color_space|��zStream.color_spacecC�<|j�d�t|�t|�t|�t|�t|�t|�df��dS)u�Add cubic Bézier curve to current path.

        The curve shall extend from ``(x3, y3)`` using ``(x1, y1)`` and ``(x2,
        y2)`` as the Bézier control points.

        r3�cN�rBrIr=r)r�x1�y1�x2�y2�x3�y3rrr�curve_to�s

�zStream.curve_toc	C�0|j�d�t|�t|�t|�t|�df��dS)u�Add cubic Bézier curve to current path

        The curve shall extend to ``(x3, y3)`` using the current point and
        ``(x2, y2)`` as the Bézier control points.

        r3�vNr_)rrbrcrdrerrr�curve_start_to��
�zStream.curve_start_toc	Crg)u�Add cubic Bézier curve to current path

        The curve shall extend to ``(x3, y3)`` using `(x1, y1)`` and ``(x3,
        y3)`` as the Bézier control points.

        r3�yNr_)rr`rardrerrr�curve_end_to�rjzStream.curve_end_tocC�|j�dt|�d�dS)zDraw object given by reference.r2s DoNrX)rr#rrr�
draw_x_object��zStream.draw_x_objectcCrM)z%End path without filling or stroking.�nNrHrrrr�end�rOz
Stream.endcCrM)zEnd marked-content sequence.sEMCNrHrrrr�end_marked_content�rOzStream.end_marked_contentcCrM)zEnd text object.sETNrHrrrr�end_text�rOzStream.end_textcCrP)znFill path using nonzero winding rule.

        Use even-odd rule if ``even_odd`` is set to ``True``.

        sf*�fNrHrRrrr�fill��zStream.fillcCrP)zyFill and stroke path usign nonzero winding rule.

        Use even-odd rule if ``even_odd`` is set to ``True``.

        sB*�BNrHrRrrr�fill_and_stroke�rvzStream.fill_and_strokecCrP)z�Fill, stroke and close path using nonzero winding rule.

        Use even-odd rule if ``even_odd`` is set to ``True``.

        sb*�bNrHrRrrr�fill_stroke_and_close�rvzStream.fill_stroke_and_closecC�$|j�d�t|�t|�df��dS)z0Add line from current point to point ``(x, y)``.r3�lNr_�r�x�yrrr�line_to��$zStream.line_tocCr{)z8Begin new subpath by moving current point to ``(x, y)``.r3�mNr_r}rrr�move_to�r�zStream.move_tocCr{)zAMove text to next line at ``(x, y)`` distance from previous line.r3sTdNr_r}rrr�move_text_to�r�zStream.move_text_tocCrm)z@Paint shape and color shading using shading dictionary ``name``.r2s shNrX)r�namerrr�shading�rozStream.shadingcCrM)zRestore graphic state.�QNrHrrrr�	pop_state�rOzStream.pop_statecCrM)zSave graphic state.�qNrHrrrr�
push_state�rOzStream.push_statec	Crg)z�Add rectangle to current path as complete subpath.

        ``(x, y)`` is the lower-left corner and width and height the
        dimensions.

        r3sreNr_)rr~r�width�heightrrr�	rectangle�rjzStream.rectanglecCs2|j�d�t|�t|�t|�|rdndf��dS)z�Set RGB color for nonstroking operations.

        Set RGB color for stroking operations instead if ``stroke`` is set to
        ``True``.

        r3sRGsrgNr_)r�r�g�brZrrr�
set_color_rgb�s

�zStream.set_color_rgbcCrW)z{Set color for nonstroking operations.

        Set color for stroking operation if ``stroke`` is set to ``True``.

        r2r3sSCNsscnNrX)rr�rZrrr�set_color_special�r\zStream.set_color_specialcCs&|j�d�t|�jt|�df��dS)z�Set dash line pattern.

        :param dash_array: Dash pattern.
        :type dash_array: :term:`iterable`
        :param dash_phase: Start of dash phase.
        :type dash_phase: :obj:`int`

        r3�dN)rBrIr=�Arrayr
r)r�
dash_array�
dash_phaserrr�set_dashs
	�zStream.set_dashcCs(|j�dt|�dt|�d�dS)zSet font name and size.r2r3s TfNrX)r�font�sizerrr�
set_font_sizes�zStream.set_font_sizecC�|j�t|�d�dS)zSet text rendering mode.s TrNrX)r�moderrr�set_text_rendering�zStream.set_text_renderingcCr�)zSet text rise.s TsNrX)rr�rrr�
set_text_riser�zStream.set_text_risecCr�)zSet line cap style.s JNrX)r�line_caprrr�set_line_capr�zStream.set_line_capcCr�)zSet line join style.s jNrX)r�	line_joinrrr�
set_line_join#r�zStream.set_line_joincCr�)zSet line width.s wNrX)rr�rrr�set_line_width'r�zStream.set_line_widthcCr�)zSet miter limit.s MNrX)r�miter_limitrrr�set_miter_limit+r�zStream.set_miter_limitcCrm)zkSet specified parameters in graphic state.

        :param state_name: Name of the graphic state.

        r2s gsNrX)r�
state_namerrr�	set_state/szStream.set_statecCrm)z4Show text strings with individual glyph positioning.�[s] TJNrX�r�textrrr�	show_text7rozStream.show_textcCs|j�t|�jd�dS)zShow single text string.s TjN)rBrI�Stringr
r�rrr�show_text_string;szStream.show_text_stringcCrM)zStroke path.�SNrHrrrrrZ?rOz
Stream.strokecCrM)zStroke and close path.�sNrHrrrr�stroke_and_closeCrOzStream.stroke_and_closecCr])apSet text matrix and text line matrix.

        :param a: Top left number in the matrix.
        :type a: :obj:`int` or :obj:`float`
        :param b: Top middle number in the matrix.
        :type b: :obj:`int` or :obj:`float`
        :param c: Middle left number in the matrix.
        :type c: :obj:`int` or :obj:`float`
        :param d: Middle middle number in the matrix.
        :type d: :obj:`int` or :obj:`float`
        :param e: Bottom left number in the matrix.
        :type e: :obj:`int` or :obj:`float`
        :param f: Bottom middle number in the matrix.
        :type f: :obj:`int` or :obj:`float`

        r3sTmNr_�r�ar��cr�errrr�text_matrixG�
�zStream.text_matrixcCr])apModify current transformation matrix.

        :param a: Top left number in the matrix.
        :type a: :obj:`int` or :obj:`float`
        :param b: Top middle number in the matrix.
        :type b: :obj:`int` or :obj:`float`
        :param c: Middle left number in the matrix.
        :type c: :obj:`int` or :obj:`float`
        :param d: Middle middle number in the matrix.
        :type d: :obj:`int` or :obj:`float`
        :param e: Bottom left number in the matrix.
        :type e: :obj:`int` or :obj:`float`
        :param f: Bottom middle number in the matrix.
        :type f: :obj:`int` or :obj:`float`

        r3scmNr_r�rrr�	transform\r�zStream.transformcCstd�dd�|jD��}t|j���}|jr*d|d<tjdd�}|�|�}||��7}t	|�|d<d�|j
d	|d
f�S)N�
cs��|]}t|�VqdSr.r4)r5rrrr�	<genexpr>s��zStream.data.<locals>.<genexpr>z/FlateDecode�Filter�	)�level�Lengthsstreams	endstream)r=rBr-rC�copyrD�zlib�compressobj�flush�lenr
)rrBrCr�rrrr
qs
zStream.data�NNFr.)F)/r'r(r)r*rrLrNrTrVr[rfrirlrnrqrrrsrurxrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZr�r�r�r+r
�
__classcell__rrrErr%PsX
		

		




	r%cs.eZdZdZd�fdd�	Zedd��Z�ZS)r�zPDF String object.�cst���||_dSr.)rAr�string)rr�rErrr�s

zString.__init__cCs^zt�ddt|j��}d|dWSty.tt|j��d�}d|����dYSw)Ns
([\\\(\)])s\\\1�(�)z	utf-16-be�<�>)	�re�subrr��UnicodeEncodeErrorrrr�hex)r�escaped�encodedrrrr
�s�zString.data)r�)r'r(r)r*rr+r
r�rrrErr�~s
r�c@r,)r�zPDF Array object.NcCst�|�t�||pg�dSr.)rr�list)r�arrayrrrr�r1zArray.__init__cCsdd�dd�|D��dS)Nr�r3csr�r.r4)r5�childrrrr��r�zArray.data.<locals>.<genexpr>�])r=rrrrr
�roz
Array.datar.r?rrrrr��r@r�c@sHeZdZdZddd�Zdd�Zdd	�Zed
d��Zdd
�Z	ddd�Z
dS)�PDFz
PDF document.�1.7NcCs�t|�|_||_g|_t�}d|_d|_|�|�tdt	g�dd��|_
|�|j
�ti�|_|�|j�td|j
jd��|_
|�|j
�d|_d|_dS)	z�Create a PDF document.

        :param bytes version: PDF version.
        :param bytes identifier: PDF file identifier.

        i��rz/Pagesr)�Type�Kids�Countz/Catalog)r��PagesN)r�version�
identifier�objectsrrr�
add_objectr-r��pages�infor#�catalog�current_position�
xref_position)rr�r��zero_objectrrrr�s,


�

�
zPDF.__init__cCs8|jdd7<|�|�|jd�|jddg�dS)zfAdd page to the PDF.

        :param page: New page.
        :type page: :class:`Dictionary`

        r��r�r�RN)r�r��extendr)r�pagerrr�add_page�s
zPDF.add_pagecCst|j�|_|j�|�dS)zAdd object to the PDF.N)r�r�rrI)r�object_rrrr��szPDF.add_objectcCs"tdd�|jdddd�D��S)Ncss �|]}|�d��d�VqdS)z 0 RrN)r)r5�
object_numberrrrr��s
��
�z&PDF.page_references.<locals>.<genexpr>r��)�tupler�rrrr�page_references�s�zPDF.page_referencescCs(|jt|�d7_|�|d�dS)z�Write line to output.

        :param content: Content to write.
        :type content: :obj:`bytes`
        :param output: Output stream.
        :type output: binary :term:`file object`

        r�r�N)r�r��write)r�content�outputrrr�
write_line�s	zPDF.write_lineFc	sh|dur|jnt|�}|dur|jn|}|�d||�|�d|�|dk�rm|�rmg}|jD]}|jdkr7q/|jr@|�|�q/|j|_	|�|j
|�q/gg}d}t|�D]#\}	}|j}
|�|
�|d�|j
�|d�|�|t|
�d7}qUd�d	d
�|dD��|d<dt|�t|d�dd�}t|||�}|j|_	|�|�|�|j
|�g}
d}|jD] }|jr�|
�d
|j
|f�|d7}q�|
�t|j
�|j	|jf�q�|
�d|jdf�tt|jdd��}tdd
�|jD��}ttt|t|��dd��}d||f�d��fdd
�|
D��}dtdt|j�df�t��t|j�d|jj|jjd�}|du�rRd�dd
�|jD��}
t|
�����}tt|�jt|�jf�|d<t|g||�}|j|_|_	|�|�|�|j
|�n�|jD]}|jdk�rz�qp|j|_	|�|j
|��qp|j|_|�d|�|�dt|j�����|�|jD]}|�|j	d�d|jd�d|j�d���|��q�|�d|�|�d|�|�dt|j�����|�|�d|jj|�|�d|jj|�|du�rd�dd
�|jD��}
t|
�����}|�d t|�jd!t|�jd"|�|�d#|�|�d$|�|�|j���|�|�d%|�dS)&a&Write PDF to output.

        :param output: Output stream.
        :type output: binary :term:`file object`
        :param bytes version: PDF version.
        :param bytes identifier: PDF file identifier.
        :param bool compress: whether the PDF uses a compressed object stream.

        Ns%PDF-s%🖤s1.5rrr�r csr�r.)r)r5�irrrr�r�zPDF.write.<locals>.<genexpr>z/ObjStm)r��N�First��css�|]}|jVqdSr.)r)r5r�rrrr�-s�
�r:c3s0�|]}t�|�D]\}}|�|d�Vq	qdS)�bigN)�zip�to_bytes)r5�line�lengthr7��xref_lengthsrrr�2s�
�
��z/XRef)r��Index�W�Size�Root�Infocs� �|]}|jdkr|jVqdS�rN�rr
�r5�objrrrr�>����IDsxrefz0 �010�05strailerr9z/Size s/Root s/Info csrrr	r
rrrr�_rs/ID [r3r�r;s	startxrefs%%EOF) r�rr�r�r�rr&rIr�rr"�	enumerater
rr�r=r%r��boolrrr�maxr�r�r#r�r�	hexdigestrr�r�)rr�r�r�rD�compressed_objectsr�rB�positionr�r
rC�
object_stream�xref�
dict_index�field2_size�max_generation�field3_size�xref_stream�	data_hash�dict_streamrrrr��s�



�


���
��

�
�


��

����z	PDF.write)r�Nr�)r'r(r)r*rr�r�r+r�r�r�rrrrr��s
,
r�)r*r�r��codecsr�hashlibr�mathrr�VERSION�__version__rrr/r-r%r�r�r�r�rrrr�<module>s #0