U
    Dvf                     @   sH  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 ]4Zed Zedd eeeD d Zee qe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rDe$ Z-e-.d$ e-/d% e-/d& e-0d'd(d) e-/d* e-1  e2e-j3 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   :/tmp/pip-unpacked-wheel-qlge9rch/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      s     r   c                 c   s   | ]}t |d d V  qd S )Nr   )tuple)r   itemr   r   r   r      s     c                 #   s,   | ]$\ }t  fd dt|D V  qdS )c                 3   s.   | ]&\}}|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   !   s     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   '   s     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   s     z0_BezierFuncsLazy.__missing__.<locals>.<listcomp>r	   r   )
r'   r-   r/   BezierCurver
   	gcd_termscollectr#   r   Zlambdify)r0   r   argsr,   r   r   r   __missing__8   s    z_BezierFuncsLazy.__missing__N)__name__
__module____qualname__r1   r8   r   r   r   r   r.   3   s   r.   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kr t|| j|< | j| S r   )str_BezierFuncsr.   )ZcelffuncZfuncstrr   r   r   _getGreenBezierFuncsB   s    
zGreenPen._getGreenBezierFuncsNc                 C   s"   t | | | || _d| _d S )Nr   )r   r1   r@   _funcsvalue)r0   r?   Zglyphsetr   r   r   r1   I   s    zGreenPen.__init__c                 C   s
   || _ d S r   )_GreenPen__startPointr0   p0r   r   r   _moveToN   s    zGreenPen._moveToc                 C   s"   |   }|| jkr| | j d S r   )_getCurrentPointrC   _lineTorD   r   r   r   
_closePathQ   s    
zGreenPen._closePathc                 C   s   |   }|| jkrtd S r   )rG   rC   NotImplementedErrorrD   r   r   r   _endPathV   s    
zGreenPen._endPathc                 C   s&   |   }|  j| jd ||7  _d S )Nr	   rG   rB   rA   )r0   p1rE   r   r   r   rH   \   s    zGreenPen._lineToc                 C   s(   |   }|  j| jd |||7  _d S )Nr&   rL   )r0   rM   p2rE   r   r   r   _qCurveToOne`   s    zGreenPen._qCurveToOnec                 C   s*   |   }|  j| jd ||||7  _d S )Nr   rL   )r0   rM   rN   Zp3rE   r   r   r   _curveToOned   s    zGreenPen._curveToOne)N)r9   r:   r;   r>   classmethodr@   r1   rF   rI   rK   rH   rO   rP   r   r   r   r   r<   ?   s   

r<   )r?   c           
         s  |d k	rt d|  t d| | f |d |D ]\}}t d| |d q,t dd|d dD ]8 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 qЈ dkrt d|d n. dkrt d|d n dkr0t d|d |D ]\}}	t d||	f |d q4t |d tdd |D |D ]\}}	t d||	f |d qrqXt 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 = 0a  
	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:
			# Green theorem is not defined on open contours.
			raise OpenContourError(
							"Green theorem is not defined on open contours."
			)
 )endrR   )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
     
  
 z!printGreenPen.<locals>.<dictcomp>r	   c                    s   g | ]\}}t |t  qS r   )r-   r4   )r   namer,   r   r   r   r3      s     z!printGreenPen.<locals>.<listcomp>c              	   S   s"   g | ]}t |ttd qS )r   )r
   r5   r6   r#   r   r   r,   r   r   r   r3      s     c                    s   g | ]}|  qS r   r*   rY   rZ   r   r   r3      s     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   rY   r   r   r   r3      s     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penNamefuncsrR   Z	docstringrX   r,   ZgreensZdefsexprsrB   r   )r   r*   r   printGreenPent   sr    




	

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   rU   rV   r]   r   r(   ZBinomialCoefficientr'   r   r   lenthisappendr   ZBernsteinPolynomialr4   ZBezierCurveCr-   dictr.   r<   ZAreaPenZ
MomentXPenZ
MomentYPenZMomentXXPenZMomentYYPenZMomentXYPenstdoutr`   r9   ZpenZmoveToZlineToZcurveToZ	closePathr\   rB   r   r   r   r   <module>   s\   -|




