a
    —Æàg^.  ã                   @   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eeeef  eddœdd„Zee	e
e
e
e
e
e
f dœdd„Zd	d
„ Zddœdd„Zdee	e
e
e
e
e
e
f ee eddœdd„Zdd„ Zdedœeeee
gef edœdd„ZdS )Ú_TTGlyphBasePenTN)ÚglyphSetÚhandleOverflowingTransformsÚreturnc                 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!   úR/var/www/sistema_ama/venv/lib/python3.9/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 ‚dS )z6
        Check if the current path is closed.
        N)ÚNotImplementedError©r    r!   r!   r"   Ú	_isClosedA   s    z_TTGlyphBasePen._isClosed©r   c                 C   s   g | _ g | _g | _g | _d S r&   )ÚpointsÚendPtsÚtypesÚ
componentsr,   r!   r!   r"   r   G   s    z_TTGlyphBasePen.init)ÚbaseGlyphNamer%   Ú
identifierÚkwargsr   c                 K   s   | j  ||f¡ dS )z"
        Add a sub glyph.
        N)r2   Úappend)r    r3   r%   r4   r5   r!   r!   r"   ÚaddComponentM   s    
z_TTGlyphBasePen.addComponentc                 C   s  | j rtdd„ | jD ƒƒ}g }| jD ]æ\}}|| jvrL| j d|› d�¡ q$| js\| j rj|rj|  ||¡ q$tƒ }||_	dd„ |dd … D ƒ\|_
|_tdd„ |d d… D ƒƒ}|dkrú| j ràtd	d„ |D ƒƒràtd
d„ |D ƒƒ}|d d… |dd … f|_||_| |¡ q$|S )Nc                 s   s4   | ],\}}|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   ó    r8   c                 s   s   | ]}t |d ƒV  qdS )é   N)r	   r?   r!   r!   r"   r=   q   s   )é   r   r   rC   c                 s   s&   | ]}t |  k od kn  V  qdS ©r9   N©r   ©r;   r<   r!   r!   r"   r=   u   s   c                 s   s.   | ]&}t |  k rd kr"n nt n|V  qdS rD   rE   rF   r!   r!   r"   r=   y   s   ÿr9   )r   Úanyr2   r   ÚlogÚwarningr/   r*   r   r$   ÚxÚyÚtupleZ	transformÚflagsr6   )r    ÚcomponentFlagsZoverflowingr2   r$   r%   Ú	componentr!   r!   r"   Ú_buildComponentsY   s:    þ

ÿÿþz _TTGlyphBasePen._buildComponentsr8   F©Úround)rN   ÚdropImpliedOnCurvesrR   r   c                C   sœ   |   ¡ stdƒ‚|  |¡}tƒ }t| jƒ|_| j|_t	d| j
ƒ|_|  ¡  |r\||_d|_n<t|jƒ|_t ¡ |_|j d¡ |rŠt|ƒ |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éÿÿÿÿrA   rQ   )r-   r   rP   r   r   r/   Zcoordinatesr0   ZendPtsOfContoursr   r1   rM   r   r2   ZnumberOfContoursÚlenr   ZProgramÚprogramZfromBytecoder   ZtoInt)r    rN   rS   rR   r2   Úglyphr!   r!   r"   rX   ‚   s$    

z_TTGlyphBasePen.glyph)T)N)r8   F)Ú__name__Ú
__module__Ú__qualname__r   r   Ústrr   Úboolr#   r   Úfloatr*   r-   r   r7   rP   r   Úintr   r   rX   r!   r!   r!   r"   r      s<    ýü%ý
 üú+  ýûúr   c                       sà   e Zd ZdZdZeZdeee	e
f  eeddœ‡ fdd„Zeeef edd	œd
d„Zddœdd„Zedœdd„Zeeef ddœdd„Zeeef ddœdd„Zddœdd„Zddœdd„Zddœdd„Zd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drawNTF)r   r   ÚoutputImpliedClosingLiner   c                    s   t ƒ  ||¡ || _d S r&   )Úsuperr#   r`   )r    r   r   r`   ©Ú	__class__r!   r"   r#   ·   s    zTTGlyphPen.__init__)ÚptÚtpr   c                 C   s   | j  |¡ | j |¡ d S r&   )r/   r6   r1   )r    rd   re   r!   r!   r"   Ú	_addPointÀ   s    zTTGlyphPen._addPointr.   c                 C   s   | j  ¡  | j ¡  d S r&   )r/   Úpopr1   r,   r!   r!   r"   Ú	_popPointÄ   s    
zTTGlyphPen._popPointc                 C   s&   | j  p$| jo$| jd t| j ƒd kS )NrU   rC   )r/   r0   rV   r,   r!   r!   r"   r-   È   s    ÿzTTGlyphPen._isClosed)rd   r   c                 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   sR   t |ƒd dksJ ‚|d d… D ]}|  |t¡ q |d d urN|  |d d¡ d S )Nr9   rC   rU   )rV   rf   r   ©r    r/   rd   r!   r!   r"   ÚcurveToÕ   s
    zTTGlyphPen.curveToc                 G   sN   t |ƒdksJ ‚|d d… D ]}|  |d¡ q|d d urJ|  |d d¡ d S )NrC   rU   r   )rV   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rX| jd d }| j| | j| kr||  ¡  |d8 }| j |¡ d S )NrC   r   rU   )rV   r/   r0   rh   r`   r6   )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)NTF)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   «   s*      üû			c                	       s’   e Zd ZdZdZeZddœ‡ fdd„Zedœdd„Z	de
e edd	œd
d„Zddœdd„Zdeeef e
e ee
e e
e eddœ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
drawPointsNr.   c                    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._isClosed)r4   r5   r   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   rV   r/   rs   )r    r4   r5   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 ]R}|| dkrr|d }||k ržt|ƒd }|| dkr¼t	||< |d8 }qžt
||< qrdS )z+
        End the current sub path.
        zContour is already closed.NrU   rC   r   Úcurve)r-   r   rs   rV   r/   r0   r6   r1   Úranger   r   )r    ZcontourStartrM   ÚiÚjr!   r!   r"   rp     s$    
zTTGlyphPointPen.endPathF)rd   ÚsegmentTypeÚsmoothÚnamer4   r5   r   c                 K   s€   |   ¡ rtdƒ‚|du r&| j d¡ nJ|dv r<| j t¡ n4|dkrR| j t¡ n|dkrh| 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   r1   r6   r   ÚAssertionErrorr/   )r    rd   ry   rz   r{   r4   r5   r!   r!   r"   ÚaddPoint6  s    zTTGlyphPointPen.addPoint)N)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   ÿ   s(       ú
ø)$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