U
    Dvf                     @   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__ ;/tmp/pip-unpacked-wheel-qlge9rch/fontTools/pens/qu2cuPen.pyr   $   s    zQu2CuPen.__init__c                 c   s   t || j| jd}| jd k	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 k	rd|d d k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 k	rt|	d |d  |d |d  rt|	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   