U
    g                     @   s   d dl mZmZ d dlmZmZ d dlmZ d dlm	Z	 ddddgZ
d	Zd
d ZeddG dd dZeddG dd dZG dd dZG dd dZdS )    )	dataclassfield)DictOptional)generic)BasePdfFileWriterShapeResult
FontEngineFontSubsetCollectionFontEngineFactoryABCDEFGHIJKLMNOPQRSTUVWXYZc                      s$   dd l  d fddtdD S )Nr    c                 3   s   | ]}t  d d V  qdS )r      N)ALPHABETrandint).0_random >/tmp/pip-unpacked-wheel-owvgwkas/pyhanko/pdf_utils/font/api.py	<genexpr>   s     z)generate_subset_prefix.<locals>.<genexpr>   )r   joinranger   r   r   r   generate_subset_prefix   s    r   T)frozenc                   @   sB   e Zd ZU eed< eedZee	e df ed< edddZ
dS )	r
   base_postscript_name)default_factoryr	   subsetsreturnc                 C   s   t  }|| jkr |S q d S N)r   r   )selfprefixr   r   r   
add_subset#   s    
zFontSubsetCollection.add_subsetN)__name__
__module____qualname__str__annotations__r   dictr   r   r   r%   r   r   r   r   r
      s   
c                   @   s*   e Zd ZU dZeed< eed< eed< dS )r   z#Result of shaping a Unicode string.Zgraphics_opsZ	x_advanceZ	y_advanceN)r&   r'   r(   __doc__bytesr*   floatr   r   r   r   r   *   s
   
c                   @   sX   e Zd ZdZdeeedddZedd Z	ee
dd	d
ZejdddZdd ZdS )r	   z4General interface for text shaping and font metrics.N)writerr   embedded_subsetc                 C   sB   | |}|r|  | _}n
d  | _}| |j|< || _|| _d S r"   )Zget_subset_collectionr%   Zsubset_prefixr   r/   
obj_stream)r#   r/   r   r0   r1   Zfscr$   r   r   r   __init__=   s    


zFontEngine.__init__c                 C   s   dS )a  
        If ``True``, this font engine expects the line matrix to always be equal
        to the text matrix when exiting and entering :meth:`shape`.
        In other words, the current text position is where ``0 0 Td`` would
        move to.

        If ``False``, this method does not use any text positioning operators,
        and therefore uses the PDF standard's 'natural' positioning rules
        for text showing operators.

        The default is ``True`` unless overridden.
        Tr   r#   r   r   r   uses_complex_positioningM   s    z#FontEngine.uses_complex_positioning)txtr!   c                 C   s   t dS )zRender a string to a format suitable for inclusion in a content
        stream and measure its total cursor advancement vector in em units.

        :param txt:
            String to shape.
        :return:
            A shaping result.
        NNotImplementedError)r#   r5   r   r   r   shape]   s    	zFontEngine.shaper    c                 C   s   t dS )a  Convert a :class:`.FontEngine` to a PDF object suitable for embedding
        inside a resource dictionary.

        .. note::
            If the PDF object is an indirect reference, the caller must not
            attempt to dereference it. In other words, implementations can
            use preallocated references to delay subsetting until the last
            possible moment (this is even encouraged, see
            :meth:`prepare_write`).

        :return:
            A PDF dictionary.
        Nr6   r3   r   r   r   as_resourceh   s    zFontEngine.as_resourcec                 C   s   dS )z
        Called by the writer that manages this font resource before the PDF
        content is written to a stream.

        Subsetting operations and the like should be carried out as part of
        this method.
        Nr   r3   r   r   r   prepare_writex   s    zFontEngine.prepare_write)N)r&   r'   r(   r,   r   r)   boolr2   propertyr4   r   r8   r   Z	PdfObjectr9   r:   r   r   r   r   r	   :   s    
c                   @   s   e Zd ZddedddZdS )r   Nr   )r/   r!   c                 C   s   t d S r"   r6   )r#   r/   r1   r   r   r   create_font_engine   s    z$FontEngineFactory.create_font_engine)N)r&   r'   r(   r	   r=   r   r   r   r   r      s
    N)Zdataclassesr   r   typingr   r   Zpyhanko.pdf_utilsr   Zpyhanko.pdf_utils.writerr   __all__r   r   r
   r   r	   r   r   r   r   r   <module>   s    I