o
    h|!                     @   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rBd dl	Z	e
e	jdkr:d dlZe	e j e	e  dS dS )    )Callable)BasePenc                    s   d  fdd| D S )N c                 3   s    | ]} |V  qd S N ).0intosr   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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deegef f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.

    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).

    :Example:
        .. code-block::

            >>> 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'

    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:
        .. code-block:: python

            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)selfglyphSetr
   r   r   r   r   +   s   
zSVGPathPen.__init__c                 C   s   | j dkr| jd dS 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   _handleAnchor3   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}| |}n%|| jkr*d}| |}n| jdkr:d}dt|| j }nd}t|| j}d}|rM||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cmdptsr   r   r   r   _lineToU   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pt2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 )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/   r1   r3   r4   r5   r   r   r   r   r   	   s    !B
r   Nc                    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d |jdddd |jddtdd |jddddd || }|j	durZt
|j	nd}||j|d}|j}|j}	i }
|j D ]}|d}|d  }t|d }||
|< qp|d }|j|j}}|j|
d}|d    |	dur|durtd!|	du rd" fd#d$|D }	|	 }	d}d}|	D ]!}|| }t|}|| | }|d%|||f 7 }||j7 }qt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text?zText string.)r@   nargsrA   z-yz<number>z1Face index into a collection to open. Zero based.z--glyphsz(whitespace-separated list of glyph namesz*Glyphs to show. Exclusive with text option)r@   typerA   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@   defaultrA   )
fontNumber=hhea)locationcmapz)Options --glyphs and --text are exclusiver   c                 3   s    | ]	} t | V  qd S r   )ord)r   urK   r   r   r     s    zmain.<locals>.<genexpr>z?<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.ttLibr=   argparseArgumentParseradd_argumentr:   
parse_argsr&   intr?   rB   glyphs
variationssplitstripr;   ascentdescentgetGlyphSetgetBestCmap
ValueErrorr   r   drawr5   widthprint)argsrP   r=   rS   parseroptionsrG   r?   rB   rX   rJ   tag_vfieldstagvrI   r\   r]   glyphsetsrb   gglyphpencommandsr   rN   r   main   s   
	



rq   __main__r<   r   )typingr   fontTools.pens.basePenr   r:   r   r   rq   r6   rP   lenrQ   doctestexittestmodfailedr   r   r   r   <module>   s     
K[