B
    Ë‹dÛ  ã               @   sT   d dl mZ d dlmZ d dlmZmZ ddgZG dd„ deƒZG dd„ deƒZ	dS )	é    )ÚotRound)Ú	Transform)Ú	FilterPenÚFilterPointPenÚRoundingPenÚRoundingPointPenc                   sL   e Zd ZdZef‡ fdd„	Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
‡  ZS )r   aþ  
    Filter pen that rounds point coordinates and component XY offsets to integer.

    >>> from fontTools.pens.recordingPen import RecordingPen
    >>> recpen = RecordingPen()
    >>> roundpen = RoundingPen(recpen)
    >>> roundpen.moveTo((0.4, 0.6))
    >>> roundpen.lineTo((1.6, 2.5))
    >>> roundpen.qCurveTo((2.4, 4.6), (3.3, 5.7), (4.9, 6.1))
    >>> roundpen.curveTo((6.4, 8.6), (7.3, 9.7), (8.9, 10.1))
    >>> roundpen.addComponent("a", (1.5, 0, 0, 1.5, 10.5, -10.5))
    >>> recpen.value == [
    ...     ('moveTo', ((0, 1),)),
    ...     ('lineTo', ((2, 3),)),
    ...     ('qCurveTo', ((2, 5), (3, 6), (5, 6))),
    ...     ('curveTo', ((6, 9), (7, 10), (9, 10))),
    ...     ('addComponent', ('a', (1.5, 0, 0, 1.5, 11, -10))),
    ... ]
    True
    c                s   t ƒ  |¡ || _d S )N)ÚsuperÚ__init__Ú	roundFunc)ÚselfÚoutPenr
   )Ú	__class__© úg/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/fontTools/pens/roundingPen.pyr	      s    zRoundingPen.__init__c             C   s(   | j  |  |d ¡|  |d ¡f¡ d S )Nr   é   )Ú_outPenÚmoveTor
   )r   Úptr   r   r   r   #   s    zRoundingPen.moveToc             C   s(   | j  |  |d ¡|  |d ¡f¡ d S )Nr   r   )r   ÚlineTor
   )r   r   r   r   r   r   &   s    zRoundingPen.lineToc                s   ˆ j j‡ fdd„|D ƒŽ  d S )Nc             3   s&   | ]\}}ˆ   |¡ˆ   |¡fV  qd S )N)r
   )Ú.0ÚxÚy)r   r   r   ú	<genexpr>+   s    z&RoundingPen.curveTo.<locals>.<genexpr>)r   ÚcurveTo)r   Úpointsr   )r   r   r   )   s    zRoundingPen.curveToc                s   ˆ j j‡ fdd„|D ƒŽ  d S )Nc             3   s&   | ]\}}ˆ   |¡ˆ   |¡fV  qd S )N)r
   )r   r   r   )r   r   r   r   0   s    z'RoundingPen.qCurveTo.<locals>.<genexpr>)r   ÚqCurveTo)r   r   r   )r   r   r   .   s    zRoundingPen.qCurveToc          
   C   s:   | j  |t|d d… |  |d ¡|  |d ¡fžŽ ¡ d S )Né   é   )r   ÚaddComponentr   r
   )r   Z	glyphNameÚtransformationr   r   r   r   3   s    
zRoundingPen.addComponent)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r   r   r   r   Ú__classcell__r   r   )r   r   r   	   s   c                   s6   e Zd ZdZef‡ fdd„	Zd
dd„Zdd	„ Z‡  ZS )r   a'  
    Filter point pen that rounds point coordinates and component XY offsets to integer.

    >>> from fontTools.pens.recordingPen import RecordingPointPen
    >>> recpen = RecordingPointPen()
    >>> roundpen = RoundingPointPen(recpen)
    >>> roundpen.beginPath()
    >>> roundpen.addPoint((0.4, 0.6), 'line')
    >>> roundpen.addPoint((1.6, 2.5), 'line')
    >>> roundpen.addPoint((2.4, 4.6))
    >>> roundpen.addPoint((3.3, 5.7))
    >>> roundpen.addPoint((4.9, 6.1), 'qcurve')
    >>> roundpen.endPath()
    >>> roundpen.addComponent("a", (1.5, 0, 0, 1.5, 10.5, -10.5))
    >>> recpen.value == [
    ...     ('beginPath', (), {}),
    ...     ('addPoint', ((0, 1), 'line', False, None), {}),
    ...     ('addPoint', ((2, 3), 'line', False, None), {}),
    ...     ('addPoint', ((2, 5), None, False, None), {}),
    ...     ('addPoint', ((3, 6), None, False, None), {}),
    ...     ('addPoint', ((5, 6), 'qcurve', False, None), {}),
    ...     ('endPath', (), {}),
    ...     ('addComponent', ('a', (1.5, 0, 0, 1.5, 11, -10)), {}),
    ... ]
    True
    c                s   t ƒ  |¡ || _d S )N)r   r	   r
   )r   r   r
   )r   r   r   r	   Z   s    zRoundingPointPen.__init__NFc             K   s8   | j j|  |d ¡|  |d ¡ff|||dœ|—Ž d S )Nr   r   )ÚsegmentTypeÚsmoothÚname)r   ÚaddPointr
   )r   r   r%   r&   r'   Úkwargsr   r   r   r(   ^   s    zRoundingPointPen.addPointc          	   K   s>   | j j|t|d d… |  |d ¡|  |d ¡fžŽ f|Ž d S )Nr   r   )r   r   r   r
   )r   ZbaseGlyphNamer   r)   r   r   r   r   g   s    
zRoundingPointPen.addComponent)NFN)	r    r!   r"   r#   r   r	   r(   r   r$   r   r   )r   r   r   >   s   
	N)
ZfontTools.misc.roundToolsr   ZfontTools.misc.transformr   ZfontTools.pens.filterPenr   r   Ú__all__r   r   r   r   r   r   Ú<module>   s
   5