a
    èÝEbô*  ã                   @   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                   @   sr   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)ÚselfZ	other_penr   Úreverse_directionr   r   r   © r   úW/home/ja/django-apps/lartica_env/lib/python3.9/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<   s    
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@   s    
z!Cu2QuPen._check_contour_is_closedc                 C   s"   | j d ur| j | j ¡ d | _ d S ©N)r   r   ÚmoveTor   r   r   r   Ú_add_moveToD   s    
zCu2QuPen._add_moveToc                 C   s&   |   ¡  | | _| _| j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 ¡ n4|dkrP|  ¡  | jj|Ž  |d | _ntd| ƒ‚d S )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rLtt|ƒd ƒ}| j |d¡d | j|< | j|dd … Ž  d S )Nr	   r   r$   )r   r   r   r   Ústrr'   Úgetr(   )r   Zpt1Zpt2Zpt3ÚcurveZ	quadraticr*   r   r   r   Ú_curve_to_quadratica   s    
zCu2QuPen._curve_to_quadraticc                 G   s‚   |   ¡  t|ƒ}|dkr$| j|Ž  nZ|dkrFt|ƒD ]}| j|Ž  q4n8|dkrZ| j|Ž  n$|dkrr|  |d ¡ ntd| ƒ‚d S )Né   r	   r$   r   z%illegal curve segment point count: %d)r   r'   r.   r   r(   r#   r   )r   r)   r*   Úsegmentr   r   r   ÚcurveToi   s    zCu2QuPen.curveToc                 C   s,   |   ¡  | jd u r| j ¡  d  | _| _d S r   )r   r   r   Ú	closePathr   r   r   r   r   r2   y   s    

zCu2QuPen.closePathc                 C   s,   |   ¡  | jd u r| j ¡  d  | _| _d S r   )r   r   r   ÚendPathr   r   r   r   r   r3   €   s    

zCu2QuPen.endPathc                 C   s   |   ¡  | j ||¡ d S r   )r   r   ÚaddComponent)r   Z	glyphNameÚtransformationr   r   r   r4   †   s    zCu2QuPen.addComponent)FNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r   r#   r(   r.   r1   r2   r3   r4   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   Zother_point_penr   r   r   r   r   r   r   ˜   s    
zCu2QuPointPen.__init__c                 C   sb  t |ƒdksJ ‚|d d dk}g }|d d }|d d }|D ]ô\}}|dk�r|  |¡D ]º}|d \}	}
}}|d d |d d  }}||||	g}t|| jƒ}| jd urÔtt |ƒd ƒ}| j |d¡d | j|< dd„ |dd… D ƒ}| |	|
||f¡ | d	|g¡ |d d }q\q@| ||g¡ |d d }q@|�rT|dd … |d d…  }|  |¡ d S )
Nr$   r   Úmover%   r-   r	   c                 S   s   g | ]}|d di f‘qS )FNr   )Ú.0r"   r   r   r   Ú
<listcomp>²   ó    z/Cu2QuPointPen._flushContour.<locals>.<listcomp>Úqcurve)	r'   Ú_split_super_bezier_segmentsr   r   r   r+   r,   ÚappendÚ_drawPoints)r   ÚsegmentsÚclosedÚnew_segmentsZprev_pointsZprev_on_curveÚsegment_typer)   Ú
sub_pointsÚon_curveÚsmoothÚnameÚkwargsZbcp1Zbcp2ZcubicZquadr*   Z
new_pointsr   r   r   Ú_flushContour¢   s0    

zCu2QuPointPen._flushContourc                 C   sÞ   g }t |ƒd }|dkr$| |¡ n¶|dkrÎ|d \}}}}|d }ttdd„ |D ƒƒƒD ]p\}	}
g }|
d d… D ]}| |dd i f¡ qr|	|d krª| ||||f¡ n| |
d dd i f¡ | |¡ qZntd| ƒ‚|S )	Nr$   r	   r%   c                 S   s   g | ]\}}}}|‘qS r   r   )r<   r"   Ú_r   r   r   r=   Ë   s   z>Cu2QuPointPen._split_super_bezier_segments.<locals>.<listcomp>FTz$expected 2 control points, found: %d)r'   rA   Ú	enumerater   r   )r   r)   Zsub_segmentsr*   rH   rI   rJ   rK   Znum_sub_segmentsÚirG   Znew_segmentÚpointr   r   r   r@   À   s*    
ÿÿz*Cu2QuPointPen._split_super_bezier_segmentsc                 C   s^  | j }| ¡  g }t|ƒD �]\}\}}|dv rvt|ƒdksLJ dt|ƒ ƒ‚|d \}}}	}
|j||||	fi |
¤Ž q|dk�rt|ƒdksœJ dt|ƒ ƒ‚|d d… }|rä|dkrº|}n*|D ]$\}}}	}
|j|d ||	fi |
¤Ž q¾|d \}}}	}
|d u rþn|j||||	fi |
¤Ž qtd	| ƒ‚q|D ]&\}}}	}
|j|d ||	fi |
¤Ž �q*| ¡  d S )
N)r;   Úliner$   z$illegal line segment point count: %dr   r?   r	   r&   r%   zunexpected segment type: %r)r   Z	beginPathrN   r'   ZaddPointr   r3   )r   rC   r   Zlast_offcurvesrO   rF   r)   r"   rI   rJ   rK   Z	offcurvesr   r   r   rB   Ü   s<    
ÿ

ÿÿzCu2QuPointPen._drawPointsc                 C   s    | j d u sJ ‚| j ||¡ d S r   )ZcurrentPathr   r4   )r   ZbaseGlyphNamer5   r   r   r   r4     s    zCu2QuPointPen.addComponent)FN)	r6   r7   r8   r9   r   rL   r@   rB   r4   r   r   r   r   r:   ‹   s     ÿ

&r:   N)ZfontTools.cu2qur   ZfontTools.pens.basePenr   r   Z fontTools.pens.reverseContourPenr   ZfontTools.pens.pointPenr   r   r   r:   r   r   r   r   Ú<module>   s   u