a
    ×¶îa  ã                   @   s`   d dl mZ d dlmZ efdd„ZG dd„ deƒZedkr\d dlZd dl	Z	e 
e	 ¡ j¡ dS )	é    )ÚCallable)ÚBasePenc                    s   d  ‡ fdd„| D ƒ¡S )Nú c                 3   s   | ]}ˆ |ƒV  qd S ©N© )Ú.0Úi©Úntosr   úi/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/fontTools/pens/svgPathPen.pyÚ	<genexpr>   ó    z pointToString.<locals>.<genexpr>)Újoin)Úptr
   r   r	   r   ÚpointToString   s    r   c                   @   sl   e Zd ZdZefeegef 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 )Ú
SVGPathPena>   Pen to draw SVG path d commands.

    Example::
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen.lineTo((1, 1))
        >>> pen.curveTo((2, 2), (3, 3), (4, 4))
        >>> pen.closePath()
        >>> pen.getCommands()
        'M0 0 1 1C2 2 3 3 4 4Z'

    Args:
        glyphSet: a dictionary of drawable glyph objects keyed by name
            used to resolve component references in composite glyphs.
        ntos: a callable that takes a number and returns a string, to
            customize how numbers are formatted (default: str).
    r	   c                 C   s.   t  | |¡ g | _d | _d | _d | _|| _d S r   )r   Ú__init__Ú	_commandsÚ_lastCommandÚ_lastXÚ_lastYÚ_ntos)ÚselfZglyphSetr
   r   r   r   r      s    zSVGPathPen.__init__c                 C   s   | j dkr| j d¡ dS )z™
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen.moveTo((10, 10))
        >>> pen._commands
        ['M10 10']
        ÚMéÿÿÿÿN)r   r   Úpop©r   r   r   r   Ú_handleAnchor#   s    
zSVGPathPen._handleAnchorc                 C   s:   |   ¡  dt|| jƒ }| j |¡ d| _|\| _| _dS )aV  
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen._commands
        ['M0 0']

        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 0))
        >>> pen._commands
        ['M10 0']

        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 10))
        >>> pen._commands
        ['M0 10']
        zM%sr   N)r   r   r   r   Úappendr   r   r   )r   r   Útr   r   r   Ú_moveTo.   s
    zSVGPathPen._moveToc                 C   s¾   |\}}|| j kr || jkr dS || j kr:d}|  |¡}nJ|| jkrTd}|  |¡}n0| jdkrtd}dt|| jƒ }nd}t|| jƒ}d}|rš||7 }|| _||7 }| j |¡ |\| _ | _dS )aU  
        # duplicate point
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((10, 10))
        >>> pen._commands
        ['M10 10']

        # vertical line
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((10, 0))
        >>> pen._commands
        ['M10 10', 'V0']

        # horizontal line
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((0, 10))
        >>> pen._commands
        ['M10 10', 'H0']

        # basic
        >>> pen = SVGPathPen(None)
        >>> pen.lineTo((70, 80))
        >>> pen._commands
        ['L70 80']

        # basic following a moveto
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen.lineTo((10, 10))
        >>> pen._commands
        ['M0 0', ' 10 10']
        NÚVÚHr   r   ÚLÚ )r   r   r   r   r   r   r   )r   r   ÚxÚyÚcmdZptsr   r   r   r   Ú_lineToE   s*    $


zSVGPathPen._lineToc                 C   s^   d}|t || jƒd 7 }|t || jƒd 7 }|t || jƒ7 }| j |¡ d| _|\| _| _dS )z›
        >>> pen = SVGPathPen(None)
        >>> pen.curveTo((10, 20), (30, 40), (50, 60))
        >>> pen._commands
        ['C10 20 30 40 50 60']
        ÚCr   N©r   r   r   r   r   r   r   )r   Úpt1Úpt2Zpt3r   r   r   r   Ú_curveToOne‡   s    zSVGPathPen._curveToOnec                 C   sV   |dusJ ‚d}|t || jƒd 7 }|t || jƒ7 }| j |¡ d| _|\| _| _dS )aw  
        >>> pen = SVGPathPen(None)
        >>> pen.qCurveTo((10, 20), (30, 40))
        >>> pen._commands
        ['Q10 20 30 40']
        >>> from fontTools.misc.roundTools import otRound
        >>> pen = SVGPathPen(None, ntos=lambda v: str(otRound(v)))
        >>> pen.qCurveTo((3, 3), (7, 5), (11, 4))
        >>> pen._commands
        ['Q3 3 5 4', 'Q7 5 11 4']
        NÚQr   r*   )r   r+   r,   r   r   r   r   Ú_qCurveToOne–   s    zSVGPathPen._qCurveToOnec                 C   s"   | j  d¡ d| _d | _| _dS )zp
        >>> pen = SVGPathPen(None)
        >>> pen.closePath()
        >>> pen._commands
        ['Z']
        ÚZN)r   r   r   r   r   r   r   r   r   Ú
_closePathª   s    zSVGPathPen._closePathc                 C   s   |   ¡  d| _d | _| _dS )zn
        >>> pen = SVGPathPen(None)
        >>> pen.endPath()
        >>> pen._commands
        ['Z']
        N)r1   r   r   r   r   r   r   r   Ú_endPathµ   s    zSVGPathPen._endPathc                 C   s   d  | j¡S )Nr$   )r   r   r   r   r   r   ÚgetCommandsÀ   s    zSVGPathPen.getCommandsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   Úfloatr   r   r    r(   r-   r/   r1   r2   r3   r   r   r   r   r   	   s   Br   Ú__main__N)Útypingr   ZfontTools.pens.basePenr   r8   r   r   r4   ÚsysÚdoctestÚexitÚtestmodÚfailedr   r   r   r   Ú<module>   s    <