o
    vho                  
   @   s   zd dl Z d dlmZmZ W n ey Z zededZ[ww d dlmZ d dlm	Z	 d dl
mZ ddgZd	efd
dZdZdd ZG dd deZG dd deZdS )    N)
BaseWritermm2pxzpyhanko.pdf_utils.barcodes requires pyHanko to be installed with the [image-support] option. You can install missing dependencies by running "pip install 'pyHanko[image-support]'".)
PdfContent)BoxConstraints)rd
BarcodeBoxPdfStreamBarcodeWriterreturnc                 C   s   | dkrdS dS )Nwhites   1 1 1s   0 0 0 )colourr   r   X/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pyhanko/pdf_utils/barcodes.pybarcode_colour_to_pdf   s   r   H   c                 C   s   t | d t S )Ngffffff9@)r   PDF_UUPI)mm_lenr   r   r   mm2uu!   s   r   c                   @   sP   e Zd ZdZdd Zdd Zdd Zdefd	d
Ze	defddZ
dd ZdS )r   z
    Implementation of writer class for the python-barcode library to output
    PDF graphics operators.
    Note: _paint_text is intentionally dummied out.
    Please use the functionality implemented in pyhanko.pdf_utils.text instead.
    c                 C   s*   dd }t | | j| j|| j d | _d S )Nc                  _      d S Nr   )_args_kwargsr   r   r   dummy.      z.PdfStreamBarcodeWriter.__init__.<locals>.dummy)r   __init___init_paint_module_finish_command_stream)selfr   r   r   r   r   -   s
   
zPdfStreamBarcodeWriter.__init__c                 C   sF   |  t|d t|\}}tt|ttt|tf| _dg| _d S )Nr      q)calculate_sizelenintr   r   sizer   )r   codewidthheightr   r   r   r   9   s   zPdfStreamBarcodeWriter._initc              	   C   s4   | j dt|t|t|t|t| jf  d S )Ns   %s rg %g %g %g %g re f)r   appendr   r   module_height)r   xposyposr%   colorr   r   r   r   >   s   z$PdfStreamBarcodeWriter._paint_moduler	   c                 C   s   | j d | jS )N   Q)r   r'   command_streamr   r   r   r   r   J   s   zPdfStreamBarcodeWriter._finishc                 C   s   d | jS )N   
)joinr   r.   r   r   r   r-   N   s   z%PdfStreamBarcodeWriter.command_streamc                 C   r   r   r   )r   filenameoutputr   r   r   saveS   r   zPdfStreamBarcodeWriter.saveN)__name__
__module____qualname____doc__r   r   r   bytesr   propertyr-   r3   r   r   r   r   r   %   s    c                       s.   e Zd ZdZ fddZdefddZ  ZS )r   z
    Thin wrapper around python-barcode functionality.

    This will render a barcode of the specified type as PDF graphics operators.
    c                    sR   || _ || _t }tj| j ||d}| | _|j\}}t j	t
||dd d S )N)r$   writer)r%   r&   )box)barcode_typer$   r   barcodeget_barcoderender_barcode_commandsr#   superr   r   )r   r<   r$   r:   bwh	__class__r   r   r   ^   s   

zBarcodeBox.__init__r	   c                 C   s   | j S r   )r@   r.   r   r   r   r?   l   s   zBarcodeBox.render)r4   r5   r6   r7   r   r8   r?   __classcell__r   r   rE   r   r   W   s    )r=   barcode.writerr   r   ImportErrorepyhanko.pdf_utils.contentr   pyhanko.pdf_utils.layoutr   pyhanko.pdf_utils.miscr   __all__r8   r   r   r   r   r   r   r   r   r   <module>   s&    		2