o
    i^.                     @   s  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	 d dl
mZ d dlmZ d dlmZ d dlmZm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 d dlmZ d dlmZ d dlZddgZ G dd dZ!G dd de!eZ"G dd de!eeZ#dS )    )array)AnyCallableDictOptionalTuple)MAX_F2DOT14floatToFixedToFloat)LogMixin)AbstractPointPenotRound)
LoggingPenPenError)TransformPenTransformPointPen)	ttProgram)flagOnCurve	flagCubic)Glyph)GlyphComponent)GlyphCoordinates)dropImpliedOnCurvePointsN
TTGlyphPenTTGlyphPointPenc                   @   s   e Zd Z	ddeeeef  deddfddZded	e	e
e
e
e
e
e
f fd
dZdd Zd ddZ	d!ded	e	e
e
e
e
e
e
f dee deddf
ddZdd Z		d"eddededee
gef defddZdS )#_TTGlyphBasePenTglyphSethandleOverflowingTransformsreturnNc                 C   s   || _ || _|   dS )a  
        Construct a new pen.

        Args:
            glyphSet (Dict[str, Any]): A glyphset object, used to resolve components.
            handleOverflowingTransforms (bool): See below.

        If ``handleOverflowingTransforms`` is True, the components' transform values
        are checked that they don't overflow the limits of a F2Dot14 number:
        -2.0 <= v < +2.0. If any transform value exceeds these, the composite
        glyph is decomposed.

        An exception to this rule is done for values that are very close to +2.0
        (both for consistency with the -2.0 case, and for the relative frequency
        these occur in real fonts). When almost +2.0 values occur (and all other
        values are within the range -2.0 <= x <= +2.0), they are clamped to the
        maximum positive value that can still be encoded as an F2Dot14: i.e.
        1.99993896484375.

        If False, no check is done and all components are translated unmodified
        into the glyf table, followed by an inevitable ``struct.error`` once an
        attempt is made to compile them.

        If both contours and components are present in a glyph, the components
        are decomposed.
        N)r   r   init)selfr   r    r!   h/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/fontTools/pens/ttGlyphPen.py__init__   s   z_TTGlyphBasePen.__init__	glyphNametransformationc                 C   s&   |  | |}t| j| | j| d S N)transformPengetattrr   
drawMethod)r    r$   r%   Ztpenr!   r!   r"   
_decompose9   s   z_TTGlyphBasePen._decomposec                 C   s   t )z6
        Check if the current path is closed.
        )NotImplementedErrorr    r!   r!   r"   	_isClosedA   s   z_TTGlyphBasePen._isClosedc                 C   s   g | _ g | _g | _g | _d S r&   )pointsendPtstypes
componentsr,   r!   r!   r"   r   G   s   
z_TTGlyphBasePen.initbaseGlyphName
identifierkwargsc                 K   s   | j ||f dS )z"
        Add a sub glyph.
        N)r1   append)r    r2   r%   r3   r4   r!   r!   r"   addComponentM   s   
z_TTGlyphBasePen.addComponentc                 C   s  | j rtdd | jD }g }| jD ]s\}}|| jvr&| jd| d q| js.| j r5|r5| || qt }||_	dd |dd  D \|_
|_tdd |d d D }|dkr}| j rptd	d |D rptd
d |D }|d d |dd  f|_||_|| q|S )Nc                 s   s6    | ]\}}|d d D ]}|dkp|dk V  qqd S )N      r!   ).0r$   r%   sr!   r!   r"   	<genexpr>]   s    
z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>z skipped non-existing component ''c                 s   s    | ]}t |V  qd S r&   r   r:   vr!   r!   r"   r<   n   s    r7   c                 s   s    | ]}t |d V  qdS )   N)r	   r>   r!   r!   r"   r<   q   s    

)   r   r   rA   c                 s   s(    | ]}t |  k od kn  V  qdS r8   Nr   r:   r;   r!   r!   r"   r<   u   s    
c                 s   s0    | ]}t |  k rd krn nt n|V  qdS rB   rC   rD   r!   r!   r"   r<   y   s
    
r8   )r   anyr1   r   logwarningr.   r*   r   r$   xytupleZ	transformflagsr5   )r    componentFlagsZoverflowingr1   r$   r%   	componentr!   r!   r"   _buildComponentsY   s:   

z _TTGlyphBasePen._buildComponentsr7   FroundrL   dropImpliedOnCurvesrP   c                C   s   |   std| |}t }t| j|_| j|_t	d| j
|_|   |r/||_d|_|S t|j|_t |_|jd |rFt| |jj|d |S )a  
        Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.

        Args:
            componentFlags: Flags to use for component glyphs. (default: 0x04)

            dropImpliedOnCurves: Whether to remove implied-oncurve points. (default: False)
        zDidn't close last contour.B    rO   )r-   r   rN   r   r   r.   Zcoordinatesr/   ZendPtsOfContoursr   r0   rK   r   r1   ZnumberOfContourslenr   ZProgramprogramZfromBytecoder   ZtoInt)r    rL   rQ   rP   r1   glyphr!   r!   r"   rW      s&   
	
z_TTGlyphBasePen.glyph)Tr   Nr&   )r7   F)__name__
__module____qualname__r   r   strr   boolr#   r   floatr*   r-   r   r6   rN   r   intr   r   rW   r!   r!   r!   r"   r      sT    
#



+r   c                	       s   e Zd ZdZdZeZ			d deee	e
f  deded	df fd
dZdeeef ded	dfddZd!ddZd	efddZdeeef d	dfddZdeeef d	dfddZd!ddZd!ddZd!ddZd!ddZ  ZS )"r   a  
    Pen used for drawing to a TrueType glyph.

    This pen can be used to construct or modify glyphs in a TrueType format
    font. After using the pen to draw, use the ``.glyph()`` method to retrieve
    a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
    ZdrawNTFr   r   outputImpliedClosingLiner   c                    s   t  || || _d S r&   )superr#   r`   )r    r   r   r`   	__class__r!   r"   r#      s   
zTTGlyphPen.__init__pttpc                 C   s   | j | | j| d S r&   )r.   r5   r0   )r    rd   re   r!   r!   r"   	_addPoint   s   zTTGlyphPen._addPointc                 C   s   | j   | j  d S r&   )r.   popr0   r,   r!   r!   r"   	_popPoint   s   
zTTGlyphPen._popPointc                 C   s&   | j  p| jo| jd t| j d kS )NrS   rA   )r.   r/   rU   r,   r!   r!   r"   r-      s   zTTGlyphPen._isClosedc                 C   s   |  |t d S r&   )rf   r   r    rd   r!   r!   r"   lineTo   s   zTTGlyphPen.lineToc                 C   s    |   std| |t d S )Nz+"move"-type point must begin a new contour.)r-   r   rf   r   ri   r!   r!   r"   moveTo   s   zTTGlyphPen.moveToc                 G   sV   t |d dks
J |d d D ]}| |t q|d d ur)| |d d d S d S )Nr8   rA   rS   )rU   rf   r   r    r.   rd   r!   r!   r"   curveTo   s   zTTGlyphPen.curveToc                 G   sR   t |dksJ |d d D ]}| |d q|d d ur'| |d d d S d S )NrA   rS   r   )rU   rf   rl   r!   r!   r"   qCurveTo   s   zTTGlyphPen.qCurveToc                 C   s   t | jd }|dks| jr|| jd d kr|   d S | js>d}| jr,| jd d }| j| | j| kr>|   |d8 }| j| d S )NrA   r   rS   )rU   r.   r/   rh   r`   r5   )r    ZendPtZstartPtr!   r!   r"   	closePath   s    zTTGlyphPen.closePathc                 C   s   |    d S r&   )ro   r,   r!   r!   r"   endPath   s   zTTGlyphPen.endPath)NTFrX   )rY   rZ   r[   __doc__r)   r   r'   r   r   r\   r   r]   r#   r   r^   r_   rf   rh   r-   rj   rk   rm   rn   ro   rp   __classcell__r!   r!   rb   r"   r      s2    	


	
	c                       s   e Zd ZdZdZeZd fddZdefddZ	dd	e
e d
eddfddZdddZ				ddeeef de
e dede
e d	e
e d
eddfddZ  ZS )r   a  
    Point pen used for drawing to a TrueType glyph.

    This pen can be used to construct or modify glyphs in a TrueType format
    font. After using the pen to draw, use the ``.glyph()`` method to retrieve
    a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
    Z
drawPointsr   Nc                    s   t    d | _d S r&   )ra   r   _currentContourStartIndexr,   rb   r!   r"   r     s   

zTTGlyphPointPen.initc                 C   s
   | j d u S r&   )rs   r,   r!   r!   r"   r-     s   
zTTGlyphPointPen._isClosedr3   r4   c                 K   s    |   stdt| j| _dS )z'
        Start a new sub path.
        zDidn't close previous contour.N)r-   r   rU   r.   rs   )r    r3   r4   r!   r!   r"   	beginPath  s   zTTGlyphPointPen.beginPathc                 C   s   |   rtd| jt| jkrd| _dS | jr| jd d nd}| jt| jd  d| _| j}t|t|D ].}|| dkrg|d }||k rOt|d }|| dkrct	||< |d8 }|| dksUt
||< q9dS )z+
        End the current sub path.
        zContour is already closed.NrS   rA   r   curve)r-   r   rs   rU   r.   r/   r5   r0   ranger   r   )r    ZcontourStartrK   ijr!   r!   r"   rp     s*   zTTGlyphPointPen.endPathFrd   segmentTypesmoothnamec                 K   s   |   rtd|du r| jd n%|dv r| jt n|dkr)| jt n|dkr4| jd nt|| j| dS )z6
        Add a point to the current sub path.
        z&Can't add a point to a closed contour.Nr   )linemoveZqcurveru   )r-   r   r0   r5   r   AssertionErrorr.   )r    rd   ry   rz   r{   r3   r4   r!   r!   r"   addPoint6  s   zTTGlyphPointPen.addPointrX   r&   )NFNN)rY   rZ   r[   rq   r)   r   r'   r   r]   r-   r   r\   r   rt   rp   r   r^   r   rr   r!   r!   rb   r"   r      s6    

)$r   typingr   r   r   r   r   ZfontTools.misc.fixedToolsr   r	   ZfontTools.misc.loggingToolsr
   ZfontTools.pens.pointPenr   ZfontTools.misc.roundToolsr   ZfontTools.pens.basePenr   r   ZfontTools.pens.transformPenr   r   ZfontTools.ttLib.tablesr   ZfontTools.ttLib.tables._g_l_y_fr   r   r   r   r   r   math__all__r   r   r   r!   r!   r!   r"   <module>   s(     T