o
    h                     @   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                       s8   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)self	other_penr	   r   reverse_directionr
   	__class__ k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/pens/qu2cuPen.pyr   $   s   
zQu2CuPen.__init__c                 c   s    t || j| jd}| jd ur(|D ]}tt|d }| j|dd | j|< q|D ]}t|dkr<d|dd  fV  q*d|dd  fV  q*d S )N)r      r         curveToqCurveTo)r   r	   r   r
   strlenget)r   qcurvescurvenr   r   r   _quadratics_to_curve3   s   
zQu2CuPen._quadratics_to_curvec                 C   s  g }d }g }|D ]E\}}|dkr2| j st|dkr2|d d ur2|d d u r)td||f|  n|r>|| | g }|||f |rK|d nd }q|rX|| | | j s|}g }|D ]h\}}|dkr|r|d d dkr|d d d }|d d d }|d }	|d urt|	d |d  |d |d  rt|	d |d  |d |d  r|d d d d | }
||
f|d< qa|||f qa|S )Nr   r   z4oncurve-less contours with all_cubic not implementedr   r   )r   r   NotImplementedErrorappendextendr   mathisclose)r   contour
quadratics	currentPt
newContouropargspt0pt1pt2newArgsr   r   r   filterContour?   sL   ""zQu2CuPen.filterContour)FFN)__name__
__module____qualname____doc__r   r   r0   __classcell__r   r   r   r   r      s    r   )fontTools.qu2cur   fontTools.pens.filterPenr    fontTools.pens.reverseContourPenr   r$   r   r   r   r   r   <module>   s
   