U
    ºmœd•  ã                   @   s„   d dl mZ d dlmZ efdd„ZG dd„ deƒZddd	„Zed
kr€d dl	Z	e
e	jƒdkrtd dlZe	 e ¡ j¡ e	 eƒ ¡ dS )é    )ÚCallable)ÚBasePenc                    s   d  ‡ fdd„| D ƒ¡S )Nú c                 3   s   | ]}ˆ |ƒV  qd S ©N© )Ú.0Úi©Úntosr   úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/fontTools/pens/svgPathPen.pyÚ	<genexpr>   s     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 )Ú
SVGPathPenai  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).

    Note:
        Fonts have a coordinate system where Y grows up, whereas in SVG,
        Y grows down.  As such, rendering path data from this pen in
        SVG typically results in upside-down glyphs.  You can fix this
        by wrapping the data from this pen in an SVG group element with
        transform, or wrap this pen in a transform pen.  For example:

            spen = svgPathPen.SVGPathPen(glyphset)
            pen= TransformPen(spen , (1, 0, 0, -1, 0, 0))
            glyphset[glyphname].draw(pen)
            print(tpen.getCommands())
    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   Ú_handleAnchor0   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   Ú_lineToR   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k	st ‚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   )ÚAssertionErrorr   r   r   r   r   r   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 )zk
        >>> pen = SVGPathPen(None)
        >>> pen.endPath()
        >>> pen._commands
        []
        N)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.   r0   r1   r2   r   r   r   r   r   	   s   B
r   Nc                 C   sŠ  | dkrddl }|jdd… } ddlm} ddl}|jddd�}|jdd	d
d� |jdddd� |jddddd� | | ¡}||jƒ}|j	}i }|j
 ¡ D ].}	|	 d¡}
|
d  ¡ }t|
d ƒ}|||< qš|d }|j|j }}|j|d�}|d  ¡ }d}d}|D ]P}|t|ƒ }|| }t|ƒ}| |¡ | ¡ }|d|||f 7 }||j7 }�qtdƒ td||| f ƒ t|dd� tdƒ dS )z-Generate per-character SVG from font and textNr   é   )ÚTTFontzfonttools pens.svgPathPenzGenerate SVG from text)ÚdescriptionÚfontzfont.ttfz
Font file.)ÚmetavarÚhelpÚtextzText string.z--variationszAXIS=LOCr#   z¼List of space separated locations. A location consist in the name of a variation axis, followed by '=' and a number. E.g.: wght=700 wdth=80. The default is the location of the base master.)r=   Údefaultr>   ú=Úhhea)ÚlocationÚcmapz?<g transform="translate(%d %d) scale(1 -1)"><path d="%s"/></g>
z&<?xml version="1.0" encoding="UTF-8"?>z?<svg width="%d" height="%d" xmlns="http://www.w3.org/2000/svg">)Úendz</svg>)ÚsysÚargvZfontTools.ttLibr:   ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsr<   r?   Z
variationsÚsplitÚstripÚintÚascentÚdescentZgetGlyphSetZgetBestCmapÚordr   Zdrawr2   ÚwidthÚprint)ÚargsrF   r:   rH   ÚparserÚoptionsr<   r?   rC   Ztag_vÚfieldsÚtagÚvrB   rO   rP   ZglyphsetrD   ÚsrR   ÚuÚgZglyphÚpenÚcommandsr   r   r   ÚmainÐ   sh     ÿü	




ý
ÿÿr_   Ú__main__r9   )N)Útypingr   ZfontTools.pens.basePenr   r7   r   r   r_   r3   rF   ÚlenrG   ÚdoctestÚexitÚtestmodÚfailedr   r   r   r   Ú<module>   s    H
F