
    jkez                        d dl mZ d dlmZ efdZ G d de      Zd
dZedk(  r`d dl	Z	 e
e	j                        d	k(  r/d dlZ e	j                   ej                         j                          e	j                   e              yy)    )Callable)BasePenc                 8    dj                  fd| D              S )N c              3   .   K   | ]  } |        y wN ).0intoss     ;/usr/lib/python3/dist-packages/fontTools/pens/svgPathPen.py	<genexpr>z pointToString.<locals>.<genexpr>   s     (DG(s   )join)ptr   s    `r   pointToStringr      s    88(R(((    c                   \    e Zd ZdZefdeegef   fdZd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zy)
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                 v    t        j                  | |       g | _        d | _        d | _        d | _        || _        y r   )r   __init__	_commands_lastCommand_lastX_lastY_ntos)selfglyphSetr   s      r   r   zSVGPathPen.__init__(   s6    x( 
r   c                 Z    | j                   dk(  r| j                  j                  d       yy)z
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen.moveTo((10, 10))
        >>> pen._commands
        ['M10 10']
        MN)r   r   popr   s    r   _handleAnchorzSVGPathPen._handleAnchor0   s)     #NNr" $r   c                     | j                          dt        || j                        z  }| j                  j	                  |       d| _        |\  | _        | _        y)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   ts      r   _moveTozSVGPathPen._moveTo;   sM    " 	]2tzz23a #% T[r   c                    |\  }}|| j                   k(  r|| j                  k(  ry|| j                   k(  rd}| j                  |      }nf|| j                  k(  rd}| j                  |      }nC| j                  dk(  rd}dt	        || j                        z   }nd}t	        || j                        }d}|r||z  }|| _        ||z  }| j
                  j                  |       |\  | _         | _        y)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cmdptsr&   s          r   _lineTozSVGPathPen._lineToR   s    H 1T[[ 0$++C**Q-C$++C**Q-C#%Cb$**55C CDJJ/CHA #D	Sa #% T[r   c                    d}|t        || j                        dz   z  }|t        || j                        dz   z  }|t        || j                        z  }| j                  j                  |       d| _        |\  | _        | _        y)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pt2pt3r&   s        r   _curveToOnezSVGPathPen._curveToOne   sz     	]3

+c11	]3

+c11	]3

++a #& T[r   c                     |J d}|t        || j                        dz   z  }|t        || j                        z  }| j                  j                  |       d| _        |\  | _        | _        y)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   r4   )r   r5   r6   r&   s       r   _qCurveToOnezSVGPathPen._qCurveToOne   sj     	]3

+c11	]3

++a #& T[r   c                 d    | j                   j                  d       d| _        dx| _        | _        y)zp
        >>> pen = SVGPathPen(None)
        >>> pen.closePath()
        >>> pen._commands
        ['Z']
        ZN)r   r%   r   r   r   r"   s    r   
_closePathzSVGPathPen._closePath   s,     	c"$((dkr   c                 .    d| _         dx| _        | _        y)zk
        >>> pen = SVGPathPen(None)
        >>> pen.endPath()
        >>> pen._commands
        []
        N)r   r   r   r"   s    r   _endPathzSVGPathPen._endPath   s     !$((dkr   c                 8    dj                  | j                        S )Nr,   )r   r   r"   s    r   getCommandszSVGPathPen.getCommands   s    wwt~~&&r   N)__name__
__module____qualname____doc__strr   floatr   r#   r'   r1   r8   r;   r>   r@   rB   r	   r   r   r   r   	   sO    < AD x'= 	#&.@&D''(	))'r   r   Nc                    | ddl }|j                  dd } ddlm} ddl}|j                  dd      }|j                  dd	d
       |j                  ddd       |j                  ddd       |j                  dddd       |j                  |       }|j                  t        |j                        nd} ||j                  |      }|j                  }i }	|j                  j                         D ]9  }
|
j                  d      }|d   j                         }t        |d         }||	|<   ; |d   }|j                   |j"                  }}|j%                  |	      }|d   j'                         }d}d}|D ][  }|t)        |         }||   }t+        |      }|j-                  |       |j/                         }|d|||fz  z  }||j0                  z  }] t3        d       t3        d|||z
  fz         t3        |d       t3        d       y) 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-yz<number>z1Face index into a collection to open. Zero based.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.)rN   defaultrO   )
fontNumber=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argvfontTools.ttLibrK   argparseArgumentParseradd_argument
parse_argsr.   intrM   rP   
variationssplitstriprH   ascentdescentgetGlyphSetgetBestCmapordr   drawrB   widthprint)argsrX   rK   r[   parseroptionsrR   rM   rP   rU   tag_vfieldstagvrT   rc   rd   glyphsetrV   sri   ugglyphpencommandss                             r   mainry      s@    |xx|&$$#1I % F 
F
^D
@  
 L	   %G#*99#8WYYaJ',,:6D<<DH##))+ S!Qioo&)	 <Dkk4<<GF2H<##%D
AE QL"

3??$	OS
 
 	
 	  

23	I&7"
#	$ 
!	(Or   __main__rJ   r   )typingr   fontTools.pens.basePenr   rG   r   r   ry   rC   rX   lenrY   doctestexittestmodfailedr	   r   r   <module>r      s}     *  )D' D'NJZ z
388}"))*CHHTV r   