a
    —Æàg‘  ã                   @   s@   d dl mZ d dlmZ d dlmZ d dlZG dd„ deƒZdS )é    )Úquadratic_to_curves)ÚContourFilterPen)ÚReverseContourPenNc                       s2   e Zd ZdZd
‡ fdd„	Zdd„ Zdd	„ Z‡  ZS )ÚQu2CuPena5  A filter pen to convert quadratic bezier splines to cubic curves
    using the FontTools SegmentPen protocol.

    Args:

        other_pen: another SegmentPen used to draw the transformed outline.
        max_err: maximum approximation error in font units. For optimal results,
            if you know the UPEM of the font, we recommend setting this to a
            value equal, or close to UPEM / 1000.
        reverse_direction: flip the contours' direction but keep starting point.
        stats: a dictionary counting the point numbers of cubic segments.
    FNc                    s.   |rt |ƒ}tƒ  |¡ || _|| _|| _d S )N)r   ÚsuperÚ__init__Ú	all_cubicÚmax_errÚstats)ÚselfZ	other_penr	   r   Zreverse_directionr
   ©Ú	__class__© úP/var/www/sistema_ama/venv/lib/python3.9/site-packages/fontTools/pens/qu2cuPen.pyr   $   s    zQu2CuPen.__init__c                 c   sŽ   t || j| jd�}| jd urN|D ],}tt|ƒd ƒ}| j |d¡d | j|< q |D ]6}t|ƒdkrvd|dd … fV  qRd|dd … fV  qRd S )N)r   é   r   é   é   ZcurveToÚqCurveTo)r   r	   r   r
   ÚstrÚlenÚget)r   ÚqZcurvesZcurveÚnr   r   r   Ú_quadratics_to_curve3   s    
zQu2CuPen._quadratics_to_curvec                 C   s¦  g }d }g }|D ]Š\}}|dkrd| j s>t|ƒdkrd|d d urd|d d u rRtdƒ‚| |f| ¡ n&|r|| |  |¡¡ g }| ||f¡ |r–|d nd }q|r°| |  |¡¡ | j �s¢|}g }|D ]Ü\}}|dk�r’|�r’|d d dk�r’|d d d }|d d d }|d }	|d u�r’t |	d |d  |d |d  ¡�r’t |	d |d  |d |d  ¡�r’|d d d d… | }
||
f|d< qÄ| ||f¡ qÄ|S )Nr   r   éÿÿÿÿz4oncurve-less contours with all_cubic not implementedr   r   éþÿÿÿ)r   r   ÚNotImplementedErrorÚappendÚextendr   ÚmathÚisclose)r   ZcontourZ
quadraticsZ	currentPtZ
newContourÚopÚargsZpt0Zpt1Zpt2ZnewArgsr   r   r   ÚfilterContour?   sT    ÿ
ÿ
ÿÿ"ÿ"þ"ýzQu2CuPen.filterContour)FFN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   Ú__classcell__r   r   r   r   r      s      úr   )ZfontTools.qu2cur   ZfontTools.pens.filterPenr   Z fontTools.pens.reverseContourPenr   r   r   r   r   r   r   Ú<module>   s   