a
    w=ic_                     @   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rd 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   j/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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 )
SVGPathPenaj   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']
        MN)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   _lineToQ   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   Nc                 C   s  | du 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$   zList 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drawr3   widthprint)argsrG   r;   rI   parseroptionsr=   r@   rD   Ztag_vfieldstagvrC   rP   rQ   ZglyphsetrE   srS   ugZglyphpencommandsr   r   r   main   sZ    




r`   __main__r:   )N)typingr   ZfontTools.pens.basePenr   r8   r   r   r`   r4   rG   lenrH   doctestexittestmodfailedr   r   r   r   <module>   s    H
<