U
    Dvf                     @   s>   d dl mZ d dlmZ ddgZG dd deZd	ddZdS )
    )pairwise)ContourFilterPenreversedContourReverseContourPenc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )r   a  Filter pen that passes outline data to another pen, 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.
    Fc                    s   t  | || _d S N)super__init__outputImpliedClosingLine)selfZoutPenr	   	__class__ D/tmp/pip-unpacked-wheel-qlge9rch/fontTools/pens/reverseContourPen.pyr      s    zReverseContourPen.__init__c                 C   s   t || jS r   )r   r	   )r
   contourr   r   r   filterContour   s    zReverseContourPen.filterContour)F)__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s   Fc                 c   s  | sdS t | dkstd|  d }|dks4t|dk}| d\}}|dks^td| |d	 }|d
kr|dks~td| rtd|d ftt|dd	  d }| s|dkrd}nd}||fV  n0| d	 \}}|d	 }	|r||fV  ||	kr(d|	ffV  |t|dd	 |f f| d	< t | dkrD| d \}
}n
|| }
}|s|
dkr||kr| d= | r|t|dd	 | f| d	< n*||	ffV  |t|dd	 |f f| d	< t| ddD ]6\\}}\}}|tt|dd	 |d	 f fV  q|r
dnddfV  dS )zGenerator that takes a list of pen's (operator, operands) tuples,
    and yields them with the winding direction reversed.
    N   zinvalid contourr   )endPath	closePathr   )moveToqCurveToz invalid initial segment type: %rr   z)off-curve only paths must end with 'None'z,only one qCurveTo allowed per off-curve pathr   r   FTZlineTo)reverser   r   )lenAssertionErrorpoptuplereversedr   )r   r	   ZcontourTypeclosedZ	firstTypeZfirstPtsZfirstOnCurveZlastTypeZlastPtsZlastOnCurveZ
secondTypeZ	secondPtsZcurTypeZcurPts_ZnextPtsr   r   r   r      sP    
"


(N)F)ZfontTools.misc.arrayToolsr   ZfontTools.pens.filterPenr   __all__r   r   r   r   r   r   <module>   s   