U
    Dvf)  ã                   @   sX   d dl mZ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 )	é    )ÚnoRoundÚotRound)Ú	Transform)Ú	FilterPenÚFilterPointPenÚRoundingPenÚRoundingPointPenc                       sN   e Zd ZdZeef‡ fdd„	Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Z‡  ZS )r   ag  
    Filter pen that rounds point coordinates and component XY offsets to integer. For
    rounding the component transform values, a separate round function can be passed to
    the pen.

    >>> 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ÚtransformRoundFunc©ÚselfZoutPenr   r   ©Ú	__class__© ú>/tmp/pip-unpacked-wheel-qlge9rch/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 r   )r   ÚlineTor   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 r	   ©r   ©Ú.0ÚxÚy©r   r   r   Ú	<genexpr>.   s     z&RoundingPen.curveTo.<locals>.<genexpr>)r   ÚcurveTo©r   Z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 r	   r   r   r!   r   r   r"   3   s     z'RoundingPen.qCurveTo.<locals>.<genexpr>)r   ÚqCurveTor$   r   r!   r   r%   1   s    ÿzRoundingPen.qCurveToc           	      C   sT   |\}}}}}}| j  |t|  |¡|  |¡|  |¡|  |¡|  |¡|  |¡ƒ¡ d S r	   ©r   ÚaddComponentr   r   r   )	r   Z	glyphNameÚtransformationÚxxÚxyÚyxÚyyÚdxÚdyr   r   r   r'   6   s    úþzRoundingPen.addComponent)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r#   r%   r'   Ú__classcell__r   r   r   r   r   	   s   c                       s:   e Zd ZdZeef‡ fdd„	Zd
dd„Zddd	„Z‡  Z	S )r   aŒ  
    Filter point pen that rounds point coordinates and component XY offsets to integer.
    For rounding the component scale values, a separate round function can be passed to
    the pen.

    >>> 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 r	   r
   r   r   r   r   r   c   s    zRoundingPointPen.__init__NFc                 K   s:   | j j|  |d ¡|  |d ¡ff||||dœ|—Ž d S )Nr   r   )ÚsegmentTypeÚsmoothÚnameÚ
identifier)r   ÚaddPointr   )r   r   r4   r5   r6   r7   Úkwargsr   r   r   r8   h   s    ÿûúzRoundingPointPen.addPointc                 K   s`   |\}}}}}	}
| j jf |t|  |¡|  |¡|  |¡|  |¡|  |	¡|  |
¡ƒ|dœ|—Ž d S )N)ÚbaseGlyphNamer(   r7   r&   )r   r:   r(   r7   r9   r)   r*   r+   r,   r-   r.   r   r   r   r'   t   s    úöõzRoundingPointPen.addComponent)NFNN)N)
r/   r0   r1   r2   r   r   r   r8   r'   r3   r   r   r   r   r   E   s          ÿ
N)ZfontTools.misc.roundToolsr   r   ZfontTools.misc.transformr   ZfontTools.pens.filterPenr   r   Ú__all__r   r   r   r   r   r   Ú<module>   s
   <