o
    ÐùaÛ  ã                   @   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                    ó   t ƒ  |¡ || _d S ©N©ÚsuperÚ__init__Ú	roundFunc©ÚselfZoutPenr   ©Ú	__class__© ú</usr/lib/python3/dist-packages/fontTools/pens/roundingPen.pyr      ó   
zRoundingPen.__init__c                 C   ó(   | j  |  |d ¡|  |d ¡f¡ d S ©Nr   é   )Ú_outPenÚmoveTor   ©r   Úptr   r   r   r   #   ó   (zRoundingPen.moveToc                 C   r   r   )r   ÚlineTor   r   r   r   r   r   &   r   zRoundingPen.lineToc                    ó   ˆ j j‡ fdd„|D ƒŽ  d S )Nc                 3   ó(    | ]\}}ˆ   |¡ˆ   |¡fV  qd S r	   ©r   ©Ú.0ÚxÚy©r   r   r   Ú	<genexpr>+   ó   €& z&RoundingPen.curveTo.<locals>.<genexpr>)r   ÚcurveTo©r   Zpointsr   r%   r   r(   )   ó   ÿzRoundingPen.curveToc                    r   )Nc                 3   r   r	   r    r!   r%   r   r   r&   0   r'   z'RoundingPen.qCurveTo.<locals>.<genexpr>)r   ÚqCurveTor)   r   r%   r   r+   .   r*   zRoundingPen.qCurveToc              	   C   s@   | j  |tg |d d… ¢|  |d ¡‘|  |d ¡‘R Ž ¡ d S ©Né   é   ©r   ÚaddComponentr   r   )r   Z	glyphNameÚtransformationr   r   r   r0   3   s   
ÿþýþzRoundingPen.addComponent)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r(   r+   r0   Ú__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                    r   r	   r
   r   r   r   r   r   Z   r   zRoundingPointPen.__init__NFc                 K   s8   | j j|  |d ¡|  |d ¡ff|||dœ|¤Ž d S )Nr   r   )ÚsegmentTypeÚsmoothÚname)r   ÚaddPointr   )r   r   r7   r8   r9   Úkwargsr   r   r   r:   ^   s   ÿü
ûzRoundingPointPen.addPointc                 K   sH   | j j|tg |d d… ¢|  |d ¡‘|  |d ¡‘R Ž fi |¤Ž d S r,   r/   )r   ZbaseGlyphNamer1   r;   r   r   r   r0   g   s   
ÿþýþ
ùzRoundingPointPen.addComponent)NFN)	r2   r3   r4   r5   r   r   r:   r0   r6   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