a
    w=ic;                     @   s   d Z ddlZddlmZmZmZ ddlmZmZ g dZ	G dd dZ
G dd	 d	e
ZG d
d deZG dd deZG dd de
ZG dd de
ZdS )a  
=========
PointPens
=========

Where **SegmentPens** have an intuitive approach to drawing
(if you're familiar with postscript anyway), the **PointPen**
is geared towards accessing all the data in the contours of
the glyph. A PointPen has a very simple interface, it just
steps through all the points in a call from glyph.drawPoints().
This allows the caller to provide more data for each point.
For instance, whether or not a point is smooth, and its name.
    N)AnyOptionalTuple)AbstractPenPenError)AbstractPointPenBasePointToSegmentPenPointToSegmentPenSegmentToPointPenGuessSmoothPointPenReverseContourPointPenc                	   @   s   e Zd ZdZdee eddddZddddZde	e
e
f ee eee ee edd
ddZdee	e
e
e
e
e
e
f ee eddddZdS )r   zBaseclass for all PointPens.N)
identifierkwargsreturnc                 K   s   t dS )zStart a new sub path.NNotImplementedErrorselfr   r    r   h/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/fontTools/pens/pointPen.py	beginPath!   s    zAbstractPointPen.beginPath)r   c                 C   s   t dS )zEnd the current sub path.Nr   r   r   r   r   endPath%   s    zAbstractPointPen.endPathF)ptsegmentTypesmoothnamer   r   r   c                 K   s   t dS )z$Add a point to the current sub path.Nr   r   r   r   r   r   r   r   r   r   r   addPoint)   s    
zAbstractPointPen.addPoint)baseGlyphNametransformationr   r   r   c                 K   s   t dS )zAdd a sub glyph.Nr   )r   r   r    r   r   r   r   r   addComponent5   s    zAbstractPointPen.addComponent)N)NFNN)N)__name__
__module____qualname____doc__r   strr   r   r   r   floatboolr   r!   r   r   r   r   r      s0       
 r   c                   @   s<   e Zd ZdZdd ZdddZdd Zd	d
 ZdddZdS )r   a  
	Base class for retrieving the outline in a segment-oriented
	way. The PointPen protocol is simple yet also a little tricky,
	so when you need an outline presented as segments but you have
	as points, do use this base implementation as it properly takes
	care of all the edge cases.
	c                 C   s
   d | _ d S N)currentPathr   r   r   r   __init__I   s    zBasePointToSegmentPen.__init__Nc                 K   s   | j d urtdg | _ d S )NzPath already begun.)r*   r   r   r   r   r   r   L   s    
zBasePointToSegmentPen.beginPathc                 C   s   t dS )a?  Override this method.

		It will be called for each non-empty sub path with a list
		of segments: the 'segments' argument.

		The segments list contains tuples of length 2:
			(segmentType, points)

		segmentType is one of "move", "line", "curve" or "qcurve".
		"move" may only occur as the first segment, and it signifies
		an OPEN path. A CLOSED path does NOT start with a "move", in
		fact it will not contain a "move" at ALL.

		The 'points' field in the 2-tuple is a list of point info
		tuples. The list has 1 or more items, a point tuple has
		four items:
			(point, smooth, name, kwargs)
		'point' is an (x, y) coordinate pair.

		For a closed path, the initial moveTo point is defined as
		the last point of the last segment.

		The 'points' list of "move" and "line" segments always contains
		exactly one point tuple.
		Nr   )r   segmentsr   r   r   _flushContourQ   s    z#BasePointToSegmentPen._flushContourc                 C   sp  | j d u rtd| j }d | _ |s&d S t|dkrf|d \}}}}}d||||fgfg}| | d S g }|d d dkr|d \}}}}}|d||||fgf |d nfd }tt|D ] }	||	 d }|d ur|	} qq|d u r|d n ||d d  |d |d   }g }
|D ]B\}}}}}|
||||f |d u rLq|||
f g }
q| | d S )NzPath not begun.   r   move)NqcurveNNN)r*   r   lenr-   appendpoprange)r   pointsr   r   r   r   r   r,   firstOnCurveiZcurrentSegmentr   r   r   r   m   sB    

 
zBasePointToSegmentPen.endPathFc                 K   s,   | j d u rtd| j |||||f d S NPath not begun)r*   r   r2   r   r   r   r   r      s    
zBasePointToSegmentPen.addPoint)N)NFNN)	r"   r#   r$   r%   r+   r   r-   r   r   r   r   r   r   r   @   s   
0  r   c                   @   s,   e Zd ZdZd
ddZdd Zddd	ZdS )r	   z
	Adapter class that converts the PointPen protocol to the
	(Segment)Pen protocol.

	NOTE: The segment pen does not support and will drop point names, identifiers
	and kwargs.
	Fc                 C   s   t |  || _|| _d S r)   )r   r+   penoutputImpliedClosingLine)r   Z
segmentPenr;   r   r   r   r+      s    
zPointToSegmentPen.__init__c                 C   s  |st d| j}|d d dkrhd}|d d }t|dkrPt dt| |d \}}}}|d= n d}|d \}}|d \}}}}|d u rn
|| | j}t|}	|}
t|	D ]}|| \}}d	d
 |D }|dkr8t|dkrt dt| |d }|d |	ks(|s(|r(||
kr|| |}
q|dkrV|j|  |d }
q|dkrt|j|  |d }
qt d| q|r|	  n|
  d S )NzMust have at least one segment.r   r/   Fr.   z"Illegal move segment point count: Tc                 S   s   g | ]\}}}}|qS r   r   ).0r   _r   r   r   
<listcomp>       z3PointToSegmentPen._flushContour.<locals>.<listcomp>linez"Illegal line segment point count: curver0   zIllegal segmentType: )r   r:   r1   moveTor;   r4   lineTocurveToqCurveTo	closePathr   )r   r,   r:   closedr5   ZmovePtr>   r   r;   Z	nSegmentsZlastPtr7   r   r   r   r   r-      s\    










zPointToSegmentPen._flushContourNc                 K   s   ~~| j || d S r)   )r:   r!   r   	glyphName	transformr   r   r   r   r   r!      s    zPointToSegmentPen.addComponent)F)N)r"   r#   r$   r%   r+   r-   r!   r   r   r   r   r	      s   
Ar	   c                   @   sZ   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S )r
   zT
	Adapter class that converts the (Segment)Pen protocol to the
	PointPen protocol.
	Tc                 C   s    |rt || _n|| _d | _d S r)   )r   r:   contour)r   ZpointPenZguessSmoothr   r   r   r+      s    zSegmentToPointPen.__init__c                 C   s8   | j }|  | jD ]\}}|j||d q|  d S )N)r   )r:   r   rL   r   r   )r   r:   r   r   r   r   r   r-     s
    zSegmentToPointPen._flushContourc                 C   s   g | _ | j |df d S )Nr/   )rL   r2   r   r   r   r   r   rC     s    zSegmentToPointPen.moveToc                 C   s&   | j d u rtd| j |df d S )N'Contour missing required initial moveTorA   )rL   r   r2   rM   r   r   r   rD     s    
zSegmentToPointPen.lineToc                 G   sX   |st d| jd u rtd|d d D ]}| j|d f q*| j|d df d S )NMust pass in at least one pointrN   r<   rB   	TypeErrorrL   r   r2   r   Zptsr   r   r   r   rE     s    
zSegmentToPointPen.curveToc                 G   sx   |st d|d d u r g | _n| jd u r2td|d d D ]}| j|d f q>|d d urt| j|d df d S )NrO   r<   rN   r0   rP   rR   r   r   r   rF     s    
zSegmentToPointPen.qCurveToc                 C   s   | j d u rtdt| j dkrV| j d d | j d d krV| j d | j d< | j d= n$| j d \}}|dkrz|df| j d< |   d | _ d S )NrN   r.   r   r<   r/   rA   )rL   r   r1   r-   )r   r   tpr   r   r   rG   ,  s    
*
zSegmentToPointPen.closePathc                 C   s$   | j d u rtd|   d | _ d S )NrN   )rL   r   r-   r   r   r   r   r   ;  s    
zSegmentToPointPen.endPathc                 C   s$   | j d urtd| j|| d S )N1Components must be added before or after contours)rL   r   r:   r!   )r   rJ   rK   r   r   r   r!   A  s    
zSegmentToPointPen.addComponentN)T)r"   r#   r$   r%   r+   r-   rC   rD   rE   rF   rG   r   r!   r   r   r   r   r
      s   
	r
   c                   @   sH   e Zd ZdZdddZdd Zddd	Zd
d ZdddZdddZ	dS )r   z
	Filtering PointPen that tries to determine whether an on-curve point
	should be "smooth", ie. that it's a "tangent" point or a "curve" point.
	皙?c                 C   s   || _ || _d | _d S r)   )_outPen_error_points)r   ZoutPenerrorr   r   r   r+   M  s    zGuessSmoothPointPen.__init__c                 C   s  | j d u rtd| j }t|}|s(d S |d d dkrHtd|d }n|dkr`td|d }ng }|D ]}|| \}}}}}	|d u rqh|d }
|d }||
 d d ur|| d d urqh|| d }||
 d }|| d }||krh||krh|d |d  |d |d   }}|d |d  |d |d   }}t||}t||}t|| | jk rh||d||	f||< qh|D ]*\}}}}}	| jj	||||fi |	 qvd S )Nr9   r   r.   r/   r<   T)
rX   r   r1   r4   mathatan2absrW   rV   r   )r   r5   ZnPointsindicesr7   r   r   r>   r   r   prevnextZprevPtZnextPtZdx1Zdy1Zdx2Zdy2Za1Za2r   r   r   r   r-   R  s>    

 ""z!GuessSmoothPointPen._flushContourNc                 K   s>   | j d urtdg | _ |d ur(||d< | jjf i | d S )NPath already begunr   )rX   r   rV   r   r   r   r   r   r   z  s    
zGuessSmoothPointPen.beginPathc                 C   s   |    | j  d | _d S r)   )r-   rV   r   rX   r   r   r   r   r     s    
zGuessSmoothPointPen.endPathFc                 K   s<   | j d u rtd|d ur"||d< | j ||d||f d S )Nr9   r   F)rX   r   r2   r   r   r   r   r     s
    
zGuessSmoothPointPen.addPointc                 K   s<   | j d urtd|d ur"||d< | jj||fi | d S NrT   r   )rX   r   rV   r!   )r   rJ   r    r   r   r   r   r   r!     s
    
z GuessSmoothPointPen.addComponent)rU   )N)NFNN)N
r"   r#   r$   r%   r+   r-   r   r   r   r!   r   r   r   r   r   G  s   
(
  
r   c                   @   sF   e Zd ZdZdd Zdd ZdddZd	d
 ZdddZdddZ	dS )r   a  
	This is a PointPen that passes outline data to another PointPen, but
	reversing the winding direction of all contours. Components are simply
	passed through unchanged.

	Closed contours are reversed in such a way that the first point remains
	the first point.
	c                 C   s   || _ d | _d S r)   )r:   currentContour)r   ZoutputPointPenr   r   r   r+     s    zReverseContourPointPen.__init__c                 C   s"  | j }| j}|s*|j| jd |  d S |d d dk}|sDd}nX||d d }tt|D ]}|| d d urd|} qqd|d u rd }n|| d }|	  |s|d d d u r|d q|j| jd |D ]>\}}}	}
}|d ur|}|}nd }|j
|f||	|
d| q|  d S )N)r   r   r.   r/   )r   r   r   )r:   rc   r   currentContourIdentifierr   r2   r3   r4   r1   reverser   )r   r:   rL   rH   ZlastSegmentTyper6   r7   r   ZnextSegmentTyper   r   r   r   r   r   r   r-     s<    z$ReverseContourPointPen._flushContourNc                 K   s(   | j d urtdg | _ || _g | _d S )Nr`   )rc   r   rd   ZonCurver   r   r   r   r     s
    
z ReverseContourPointPen.beginPathc                 C   s$   | j d u rtd|   d | _ d S r8   )rc   r   r-   r   r   r   r   r     s    
zReverseContourPointPen.endPathFc                 K   s<   | j d u rtd|d ur"||d< | j |||||f d S )Nr9   r   )rc   r   r2   r   r   r   r   r     s
    
zReverseContourPointPen.addPointc                 K   s0   | j d urtd| jj||fd|i| d S ra   )rc   r   r:   r!   rI   r   r   r   r!     s    
z#ReverseContourPointPen.addComponent)N)NFNN)Nrb   r   r   r   r   r     s   	0

r   )r%   rZ   typingr   r   r   ZfontTools.pens.basePenr   r   __all__r   r   r	   r
   r   r   r   r   r   r   <module>   s   
"dUNP