U
    g                      @   s|  d dl mZ d dlmZ d dlmZmZ d dlmZ ddl	m
Z
 ddlmZmZmZ ejZd	d
ddgZeddG dd dZedddgeedededededededeeejddddgedededed ed!eded"ed ed#ed$ed%eded&eded'edid(ZG d)d
 d
eZG d*d	 d	eZe
d+d,dZd-S ).    )	dataclass)BytesIO)ListOptional)generic   )BasePdfFileWriter   )
FontEngineFontEngineFactoryShapeResultSimpleFontEngineFactorySimpleFontEngineSimpleFontMetaget_courierT)frozenc                   @   s4   e Zd ZU eed< eed< ee ed< ejed< dS )r   
first_char	last_charwidths
descriptorN)__name__
__module____qualname__int__annotations__r   r   DictionaryObject r   r   @/tmp/pip-unpacked-wheel-owvgwkas/pyhanko/pdf_utils/font/basic.pyr      s   
    iX  /Type/FontDescriptorz	/FontNamez/Courierz/Flags#   z	/FontBBoxiii  i%  z/Ascentiu  z/Descenticz
/CapHeightz/ItalicAnglez/StemV3   z/MissingWidthz	/AvgWidthz	/MaxWidth)r   r   r   r   c                       sT   e Zd ZdZedd Zdeeee	e
 d fddZedd	d
Zdd Z  ZS )r   z
    Simplistic font engine that effectively only works with PDF standard fonts,
    and does not care about font metrics. Best used with monospaced fonts such
    as Courier.
    c                 C   s   dS )NFr   )selfr   r   r   uses_complex_positioning>   s    z)SimpleFontEngine.uses_complex_positioningN)writername	avg_widthmetac                    s(   || _ || _|| _t j||dd d S )NF)Zembedded_subset)r'   r&   r(   super__init__)r#   r%   r&   r'   r(   	__class__r   r   r*   B   s    zSimpleFontEngine.__init__)returnc                 C   s@   t  }t|| |d t|| j }t| |ddS )Ns    Tjr   )Zgraphics_opsZ	x_advanceZ	y_advance)	r   r   ZTextStringObjectZwrite_to_streamwritelenr'   r   getvalue)r#   txtopsZ	total_lenr   r   r   shapeN   s    
  zSimpleFontEngine.shapec                 C   s   t tdtdtdtd| j tdtdtdtdi}| j}|d k	rt |j|d	< t |j|d
< t t	t j|j
|d< | jt |j|d< |S )Nr   z/Fontz	/BaseFont/z/Subtypez/Type1z	/Encodingz/WinAnsiEncodingz
/FirstCharz	/LastCharz/Widthsr    )r   r   pdf_namer&   r(   NumberObjectr   r   ArrayObjectmapr   r%   
add_objectr   )r#   Z	font_dictr(   r   r   r   as_resourceX   s,        

zSimpleFontEngine.as_resource)N)r   r   r   __doc__propertyr$   r   strfloatr   r   r*   r   r3   r:   __classcell__r   r   r+   r   r   7   s   
 
c                   @   s@   e Zd Zd
eeee dddZdedddZ	e
dd	 ZdS )r   N)r&   r'   r(   c                 C   s   || _ || _|| _d S N)r'   r&   r(   )r#   r&   r'   r(   r   r   r   r*   r   s    z SimpleFontEngineFactory.__init__)r%   c                 C   s   t || j| j| jS r@   )r   r&   r'   r(   )r#   r%   Z
obj_streamr   r   r   create_font_enginey   s    z*SimpleFontEngineFactory.create_font_enginec                   C   s   t ddtS )z
        :return:
            A :class:`.FontEngineFactory` instance representing the Courier
            standard font.
        ZCourierg333333?)r   COURIER_METAr   r   r   r   default_factory|   s    z'SimpleFontEngineFactory.default_factory)N)N)r   r   r   r=   r>   r   r   r*   r   rA   staticmethodrC   r   r   r   r   r   q   s      Z
pdf_writerc                 C   s   t  |  S )z
    Quick-and-dirty way to obtain a Courier font resource.

    :param pdf_writer:
        A PDF writer.
    :return:
        A resource dictionary representing the standard Courier font
        (or one of its metric equivalents).
    )r   rC   rA   r:   rE   r   r   r   r      s    N)Zdataclassesr   ior   typingr   r   Zpyhanko.pdf_utilsr   r%   r   apir
   r   r   Z
NameObjectr5   __all__r   r   r6   r7   r8   rB   r   r   r   r   r   r   r   <module>   sd               :