o
    tBh*                     @   sd   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	 G dd deZ
G dd	 d	eZd
S )    )curve_to_quadratic)AbstractPendecomposeSuperBezierSegment)ReverseContourPen)BasePointToSegmentPen)ReverseContourPointPenc                   @   sv   e Zd ZdZ		dddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )Cu2QuPena   A filter pen to convert cubic bezier curves to quadratic b-splines
    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 quadratic segments.
        ignore_single_points: don't emit contours containing only a single point

    NOTE: The "ignore_single_points" argument is deprecated since v1.3.0,
    which dropped Robofab subpport. It's no longer needed to special-case
    UFO2-style anchors (aka "named points") when using ufoLib >= 2.0,
    as these are no longer drawn onto pens as single-point contours,
    but are handled separately as anchors.
    FNc                 C   sT   |rt || _n|| _|| _|| _|rdd l}|jdtdd || _d | _d | _	d S )Nr   zIignore_single_points is deprecated and will be removed in future versions   )
stacklevel)
r   penmax_errstatswarningswarnUserWarningignore_single_pointsstart_pt
current_pt)self	other_penr   reverse_directionr   r   r    r   n/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/fontTools/pens/cu2quPen.py__init__+   s   
zCu2QuPen.__init__c                 C   s   | j d u r	tdd S )NzmoveTo is requiredr   AssertionErrorr   r   r   r   _check_contour_is_open<      
zCu2QuPen._check_contour_is_openc                 C   s   | j d ur	tdd S )Nz closePath or endPath is requiredr   r   r   r   r   _check_contour_is_closed@   r   z!Cu2QuPen._check_contour_is_closedc                 C   s&   | j d ur| j| j  d | _ d S d S N)r   r   moveTor   r   r   r   _add_moveToD   s   

zCu2QuPen._add_moveToc                 C   s*   |    | | _| _| js|   d S d S r    )r   r   r   r   r"   r   ptr   r   r   r!   I   s
   zCu2QuPen.moveToc                 C   s&   |    |   | j| || _d S r    )r   r"   r   lineTor   r#   r   r   r   r%   O   s   
zCu2QuPen.lineToc                 G   s`   |    t|}|dkr| |d  d S |dkr*|   | jj|  |d | _d S td| )N   r   &illegal qcurve segment point count: %d)r   lenr%   r"   r   qCurveTor   r   )r   pointsnr   r   r   r*   U   s   zCu2QuPen.qCurveToc                 C   sb   | j |||f}t|| j}| jd ur&tt|d }| j|dd | j|< | j|dd    d S )Nr	   r   r&   )r   r   r   r   strr)   getr*   )r   pt1pt2pt3curve	quadraticr,   r   r   r   _curve_to_quadratica   s   
zCu2QuPen._curve_to_quadraticc                 G   s   |    t|}|dkr| j|  d S |dkr%t|D ]}| j|  qd S |dkr0| j|  d S |dkr=| |d  d S td| )N   r	   r&   r   z%illegal curve segment point count: %d)r   r)   r4   r   r*   r%   r   )r   r+   r,   segmentr   r   r   curveToi   s   zCu2QuPen.curveToc                 C   ,   |    | jd u r| j  d  | _| _d S r    )r   r   r   	closePathr   r   r   r   r   r9   y   s   

zCu2QuPen.closePathc                 C   r8   r    )r   r   r   endPathr   r   r   r   r   r:      s   

zCu2QuPen.endPathc                 C   s   |    | j|| d S r    )r   r   addComponent)r   	glyphNametransformationr   r   r   r;      s   zCu2QuPen.addComponent)FNF)__name__
__module____qualname____doc__r   r   r   r"   r!   r%   r*   r4   r7   r9   r:   r;   r   r   r   r   r      s     
r   c                   @   s>   e Zd ZdZ		dddZdd Zdd	 Zd
d Zdd ZdS )Cu2QuPointPena4   A filter pen to convert cubic bezier curves to quadratic b-splines
    using the RoboFab PointPen protocol.

    Args:
        other_point_pen: another PointPen 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: reverse the winding direction of all contours.
        stats: a dictionary counting the point numbers of quadratic segments.
    FNc                 C   s0   t |  |rt|| _n|| _|| _|| _d S r    )r   r   r   r   r   r   )r   other_point_penr   r   r   r   r   r   r      s   

zCu2QuPointPen.__init__c                 C   s^  t |dksJ |d d dk}g }|d d }|d d }|D ]y\}}|dkr| |D ]]}|d \}	}
}}|d d |d d }}||||	g}t|| j}| jd uritt |d }| j|dd | j|< dd |dd D }||	|
||f |d	|g |d d }q-q |||g |d d }q |r|dd  |d d  }| | d S )
Nr&   r   mover'   r2   r	   c                 S   s   g | ]}|d di fqS FNr   ).0r$   r   r   r   
<listcomp>   s    z/Cu2QuPointPen._flushContour.<locals>.<listcomp>qcurve)	r)   _split_super_bezier_segmentsr   r   r   r-   r.   append_drawPoints)r   segmentsclosednew_segmentsprev_pointsprev_on_curvesegment_typer+   
sub_pointson_curvesmoothnamekwargsbcp1bcp2cubicquadr,   
new_pointsr   r   r   _flushContour   s2   
zCu2QuPointPen._flushContourc                 C   s   g }t |d }|dkr|| |S |dkri|d \}}}}|d }ttdd |D D ]8\}	}
g }|
d d D ]}||dd i f q:|	|d krV|||||f n||
d dd i f || q.|S td| )	Nr&   r	   r'   c                 S   s   g | ]\}}}}|qS r   r   )rF   r$   _r   r   r   rG      s    z>Cu2QuPointPen._split_super_bezier_segments.<locals>.<listcomp>FTz$expected 2 control points, found: %d)r)   rJ   	enumerater   r   )r   r+   sub_segmentsr,   rS   rT   rU   rV   num_sub_segmentsirR   new_segmentpointr   r   r   rI      s,   

z*Cu2QuPointPen._split_super_bezier_segmentsc                 C   sV  | j }|  g }t|D ]\}\}}|dv r:t|dks%J dt| |d \}}}	}
|j||||	fi |
 q|dkrt|dksLJ dt| |d d }|rp|dkr[|}n|D ]\}}}	}
|j|d ||	fi |
 q]|d \}}}	}
|d u r}q|j||||	fi |
 qtd	| |D ]\}}}	}
|j|d ||	fi |
 q|  d S )
N)rD   liner&   z$illegal line segment point count: %dr   rH   r	   r(   r'   zunexpected segment type: %r)r   	beginPathr^   r)   addPointr   r:   )r   rL   r   last_offcurvesra   rQ   r+   r$   rT   rU   rV   	offcurvesr   r   r   rK      s<   

zCu2QuPointPen._drawPointsc                 C   s    | j d u sJ | j|| d S r    )currentPathr   r;   )r   baseGlyphNamer=   r   r   r   r;     s   zCu2QuPointPen.addComponentrE   )	r>   r?   r@   rA   r   r\   rI   rK   r;   r   r   r   r   rB      s    

&rB   N)fontTools.cu2qur   fontTools.pens.basePenr   r    fontTools.pens.reverseContourPenr   fontTools.pens.pointPenr   r   r   rB   r   r   r   r   <module>   s   u