o
    l^Ufd                     @   sL  d dl mZ d dlmZ d dlmZ d dlZd dlZdZ	ej
ddd\ZZZej
d	d
dZeej
de	d  ddZeej
de	d  ddZeedd dD  Zeej
de	d  d
dZdgZede	d D ]Zed Zedd eeeD d Zee qiedd eD Z[[edd eeD Zedd eeD Zedd eeD Zdd Z G dd de!Z"G dd deZ#ee#dd Z$ee#ed Z%ee#ed Z&ee#ee d Z'ee#ee d Z(ee#ee d Z)ej*dfd!d"Z+e,d#kr$e$ Z-e-.d$ e-/d% e-/d& e-0d'd(d) e-/d* e-1  e2e-j3 dS dS )+    )BasePen)partial)countN   zt x yTrealcFzx:%d   zy:%dc                 c   s*    | ]}t jd td |f ddV  qdS )zp:%d[%s]r	   Tr   N)spsymbolsn).0w r   6lib/python3.10/site-packages/fontTools/misc/symfont.py	<genexpr>   s   ( r   Z01zc:%d)r	   r   c                 c   s$    | ]}t |d   t |  V  qdS r	   N)last)r   jr   r   r   r         " r   c                 c   s     | ]}t |d d V  qd S )Nr   )tuple)r   itemr   r   r   r          c                 #   s.    | ]\ }t  fd dt|D V  qdS )c                 3   s0    | ]\}}|t |  d t   |   V  qdS r   )t)r   ir   r   r   r   r      s   . <genexpr>.<genexpr>N)r   	enumerate)r   Zcoeffsr   r   r   r      s
    
c                 #   s.    | ]\} t  fd dtdD V  qdS )c                 3   s*    | ] t  fd dtD V  qdS )c                 3   s$    | ]\}}t |   | V  qd S N)Pr   r   Z	bernsteinr   r   r   r   !   r   z<genexpr>.<genexpr>.<genexpr>Nsumr   )r   
bernsteinsr#   r   r       s
    
r      N)r   range)r   r   r   r&   r   r      s    
c                 c   s*    | ]\}}t d d t|D V  qdS )c                 s   s     | ]\}}t | | V  qd S r    )Cr"   r   r   r   r   '   r   r   Nr$   )r   r   r'   r   r   r   r   &   s
    
c                 C   sT   t t | t } | t|d t|d i} t | t |d t tddf} | S )Nr   r	   )r
   Z	integrateZsympifyysubsxZdiffr   )fZcurveXYr   r   r   green,   s   "r/   c                   @   s   e Zd Zdd Zdd ZdS )_BezierFuncsLazyc                 C   s   || _ i | _d S r    )_symfuncZ	_bezfuncs)selfZsymfuncr   r   r   __init__4   s   
z_BezierFuncsLazy.__init__c                 C   sH   dd t |d D }t| jt| }t|ttd}t	||S )Nc                 S   s   g | ]}d | qS )zp%dr   )r   dr   r   r   
<listcomp>9       z0_BezierFuncsLazy.__missing__.<locals>.<listcomp>r	   r   )
r)   r/   r1   BezierCurver
   	gcd_termscollectr%   r!   Zlambdify)r2   r   argsr.   r   r   r   __missing__8   s   z_BezierFuncsLazy.__missing__N)__name__
__module____qualname__r3   r;   r   r   r   r   r0   3   s    r0   c                   @   sV   e Zd Zi Zedd ZdddZdd Zdd	 Zd
d Z	dd Z
dd Zdd ZdS )GreenPenc                 C   s*   t |}|| jvrt|| j|< | j| S r    )str_BezierFuncsr0   )ZcelffuncZfuncstrr   r   r   _getGreenBezierFuncsB   s   

zGreenPen._getGreenBezierFuncsNc                 C   s"   t | | | || _d| _d S )Nr   )r   r3   rC   _funcsvalue)r2   rB   Zglyphsetr   r   r   r3   I   s   
zGreenPen.__init__c                 C   s
   || _ d S r    )_startPointr2   p0r   r   r   _moveToN   s   
zGreenPen._moveToc                 C   s&   |   }|| jkr| | j d S d S r    )_getCurrentPointrF   _lineTorG   r   r   r   
_closePathQ   s   
zGreenPen._closePathc                 C   s   |   }|| jkrtd S r    )rJ   rF   NotImplementedErrorrG   r   r   r   _endPathV   s   
zGreenPen._endPathc                 C   s&   |   }|  j| jd ||7  _d S )Nr	   rJ   rE   rD   )r2   p1rH   r   r   r   rK   \   s   zGreenPen._lineToc                 C   s(   |   }|  j| jd |||7  _d S )Nr(   rO   )r2   rP   p2rH   r   r   r   _qCurveToOne`   s    zGreenPen._qCurveToOnec                 C   s*   |   }|  j| jd ||||7  _d S )Nr   rO   )r2   rP   rQ   Zp3rH   r   r   r   _curveToOned   s   "zGreenPen._curveToOner    )r<   r=   r>   rA   classmethodrC   r3   rI   rL   rN   rK   rR   rS   r   r   r   r   r?   ?   s    

r?   )rB   c           
         s  |d ur
t d|  t d| | f |d |D ]\}}t d| |d qt dd|d dD ] d	d
 t d D  fdd|D }dd |D }fdd|D }tj|ddd t D d\}}t   |D ]\}}	t d| |d qg dkrt d|d n dkrt d|d n
 dkrt d|d |D ]\}}	t d||	f |d qt |d tdd |D |D ]\}}	t d||	f |d qq,t d|  |d |D ]\}}t d|t|f |d qt d|d d S ) Nz"""%s"""a  from fontTools.pens.basePen import BasePen, OpenContourError
try:
	import cython

	COMPILED = cython.compiled
except (AttributeError, ImportError):
	# if cython not installed, use mock module with no-op decorators and types
	from fontTools.misc import cython

	COMPILED = False


__all__ = ["%s"]

class %s(BasePen):

	def __init__(self, glyphset=None):
		BasePen.__init__(self, glyphset)
)filez		self.%s = 0aT  
	def _moveTo(self, p0):
		self._startPoint = p0

	def _closePath(self):
		p0 = self._getCurrentPoint()
		if p0 != self._startPoint:
			self._lineTo(self._startPoint)

	def _endPath(self):
		p0 = self._getCurrentPoint()
		if p0 != self._startPoint:
			raise OpenContourError(
							"Glyph statistics is not defined on open contours."
			)
 )endrU   )r	   r(   r   c                 S   s4   i | ]}t d D ]}t| | ttg| | qqS )r(   )r)   r!   XY)r   r   r   r   r   r   
<dictcomp>   s   4 z!printGreenPen.<locals>.<dictcomp>r	   c                    s   g | ]\}}t |t  qS r   )r/   r7   )r   namer.   r   r   r   r5      s    z!printGreenPen.<locals>.<listcomp>c              	   S   s"   g | ]}t |ttd qS )r   )r
   r8   r9   r%   r!   r   r.   r   r   r   r5      s   " c                    s   g | ]}|  qS r   r,   r\   r]   r   r   r5      s    Zbasicc                 s   s    | ]
}t d | V  qdS )zr%dN)r
   ZSymbol)r   r   r   r   r   r      s    z printGreenPen.<locals>.<genexpr>)Zoptimizationsr   z!	@cython.locals(%s=cython.double)z	@cython.locals(x0=cython.double, y0=cython.double)
	@cython.locals(x1=cython.double, y1=cython.double)
	def _lineTo(self, p1):
		x0,y0 = self._getCurrentPoint()
		x1,y1 = p1
r(   z	@cython.locals(x0=cython.double, y0=cython.double)
	@cython.locals(x1=cython.double, y1=cython.double)
	@cython.locals(x2=cython.double, y2=cython.double)
	def _qCurveToOne(self, p1, p2):
		x0,y0 = self._getCurrentPoint()
		x1,y1 = p1
		x2,y2 = p2
r   a=  	@cython.locals(x0=cython.double, y0=cython.double)
	@cython.locals(x1=cython.double, y1=cython.double)
	@cython.locals(x2=cython.double, y2=cython.double)
	@cython.locals(x3=cython.double, y3=cython.double)
	def _curveToOne(self, p1, p2, p3):
		x0,y0 = self._getCurrentPoint()
		x1,y1 = p1
		x2,y2 = p2
		x3,y3 = p3
z			%s = %sc                 S   s   g | ]}|d  qS r   r   r\   r   r   r   r5      r6   z		self.%s += %szj
if __name__ == '__main__':
	from fontTools.misc.symfont import x, y, printGreenPen
	printGreenPen('%s', [z		      ('%s', %s),z			     ]))printr)   r
   Zcser   zipr@   )
ZpenNameZfuncsrU   Z	docstringr[   r.   ZgreensZdefsZexprsrE   r   )r   r,   r   printGreenPent   st   

	
r`   __main__)d   rb   )rb      )rc   rc   )rc      ),  re   )rd   i^  )rc   rb   )4ZfontTools.pens.basePenr   	functoolsr   	itertoolsr   Zsympyr
   sysr   r   r   r-   r+   r   r   rX   rY   r_   r!   r*   ZBinomialCoefficientr)   r   r   lenthisappendr   ZBernsteinPolynomialr7   ZBezierCurveCr/   dictr0   r?   ZAreaPenZ
MomentXPenZ
MomentYPenZMomentXXPenZMomentYYPenZMomentXYPenstdoutr`   r<   ZpenZmoveToZlineToZcurveToZ	closePathr^   rE   r   r   r   r   <module>   s`    -
{



