o
    iDD                     @   s\  d Z ddlmZmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZmZ ddlmZmZmZ G dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd de"Z#G dd de"Z$dd Z%G dd de"Z&dd d!d"Z'G d#d$ d$eZ(G d%d& d&Z)d'S )(zGlyphSets returned by a TTFont.    )ABCabstractmethod)Mapping)contextmanager)copydeepcopy)SimpleNamespace)Vector)otRoundfixedToFloat)deprecateFunction)	TransformDecomposedTransform)TransformPenTransformPointPen)DecomposingRecordingPenlerpRecordingsreplayRecordingc                   @   sh   e Zd ZdZddddZedefddZed	d
 Zdd Z	dd Z
dd Zededdd ZdS )_TTGlyphSetzlGeneric dict-like GlyphSet class that pulls metrics from hmtx and
    glyph shape from TrueType or CFF.
    TrecalcBoundsc                C   s   || _ || _d| jv rdd | jd jD ni | _|d ur|ni | _i | _|d ur+|ni | _d| _g | _g | _	|| _
|d j| _t|ddd | _d | _|rrddlm} t|d	d
d | _| jd urt|| jj|d j|| _d S d S d S )Nfvarc                 S   s   i | ]}|j d qS )r   axisTag).0Zaxis r   i/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/fontTools/ttLib/ttGlyphSet.py
<dictcomp>       z(_TTGlyphSet.__init__.<locals>.<dictcomp>r   ZhmtxZvmtxmetricsVarStoreInstancerZHVARtable)r   fontaxesdefaultLocationNormalizedlocationrawLocationoriginalLocationdepthlocationStackrawLocationStackglyphsMappingr   hMetricsgetattrgetvMetrics	hvarTablefontTools.varLib.varStorer!   ZVarStorehvarInstancer)selfr#   r&   r,   r   r!   r   r   r   __init__   s2   


z_TTGlyphSet.__init__resetc                 c   s    | j | j | j| j |r| j | _| j | _n	| j | _i | _| j| | j| zd V  W | j 	 | _| j	 | _d S | j 	 | _| j	 | _w N)
r*   appendr&   r+   r'   r(   r   r%   updatepop)r4   r&   r6   r   r   r   pushLocation5   s    z_TTGlyphSet.pushLocationc              	   c   sB    z| j }|  j d7  _ |V  W |  j d8  _ d S |  j d8  _ w )N   )r)   )r4   r)   r   r   r   	pushDepthH   s   "z_TTGlyphSet.pushDepthc                 C   
   || j v S r7   r,   r4   	glyphNamer   r   r   __contains__Q      
z_TTGlyphSet.__contains__c                 C   s   t | j S r7   )iterr,   keysr4   r   r   r   __iter__T   s   z_TTGlyphSet.__iter__c                 C   s
   t | jS r7   )lenr,   rF   r   r   r   __len__W   rC   z_TTGlyphSet.__len__z#use 'glyphName in glyphSet' instead)categoryc                 C   r>   r7   r?   r@   r   r   r   has_keyZ   s   
z_TTGlyphSet.has_keyN)__name__
__module____qualname____doc__r5   r   boolr;   r=   rB   rG   rI   r   DeprecationWarningrK   r   r   r   r   r      s    
r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )_TTGlyphSetGlyfTc                    s0   |d | _ t j||| j |d |d| _d S )NZglyfr   Zgvar)	glyfTablesuperr5   r/   	gvarTable)r4   r#   r&   r   	__class__r   r   r5   b   s   
z_TTGlyphSetGlyf.__init__c                 C   s   t | || jdS )Nr   )_TTGlyphGlyfr   r@   r   r   r   __getitem__g      z_TTGlyphSetGlyf.__getitem__)TrL   rM   rN   r5   rY   __classcell__r   r   rV   r   rR   a   s    rR   c                       s>   e Zd Z fddZdd Zdd Zedefdd	Z  Z	S )
_TTGlyphSetCFFc                    sJ   d|v rdnd}t || j d j| _t ||| j | | d S )NZCFF2zCFF r   )listZcffvaluesZCharStringscharStringsrT   r5   setLocation)r4   r#   r&   ZtableTagrV   r   r   r5   l   s   z_TTGlyphSetCFF.__init__c                 C   s
   t | |S r7   )_TTGlyphCFFr@   r   r   r   rY   r   rC   z_TTGlyphSetCFF.__getitem__c                 C   s\   d | _ |r)ddlm} t| jdd }|d ur'||j| jd j|}|j| _ d S d S d | _ d S )Nr   r    varStorer   )	blenderr2   r!   r.   r`   Z
otVarStorer#   r$   ZinterpolateFromDeltas)r4   r&   r!   rc   	instancerr   r   r   ra   u   s   
z_TTGlyphSetCFF.setLocationr6   c              
   c   sf    |  | t| ||}z|V  W |  | j n|  | j w W d    d S 1 s,w   Y  d S r7   )ra   r   r;   r&   )r4   r&   r6   valuer   r   r   r;      s   
"z_TTGlyphSetCFF.pushLocation)
rL   rM   rN   r5   rY   ra   r   rP   r;   r\   r   r   rV   r   r]   k   s    r]   c                       s$   e Zd Z fddZdd Z  ZS )_TTGlyphSetVARCc                    s&   || _ t ||| |d j| _d S )NZVARC)glyphSetrT   r5   r"   	varcTable)r4   r#   r&   rh   rV   r   r   r5      s   z_TTGlyphSetVARC.__init__c                 C   s&   | j }||jjvr| j| S t| |S r7   )ri   Coverageglyphsrh   _TTGlyphVARC)r4   rA   varcr   r   r   rY      s   

z_TTGlyphSetVARC.__getitem__r[   r   r   rV   r   rg      s    rg   c                   @   s2   e Zd ZdZddddZedd Zdd	 Zd
S )_TTGlyphaS  Glyph object that supports the Pen protocol, meaning that it has
    .draw() and .drawPoints() methods that take a pen object as their only
    argument. Additionally there are 'width' and 'lsb' attributes, read from
    the 'hmtx' table.

    If the font contains a 'vmtx' table, there will also be 'height' and 'tsb'
    attributes.
    Tr   c                C   s   || _ || _|| _|j| \| _| _|jd ur!|j| \| _| _nd\| _| _|j	rN|j
d urP|j
jd u r;|j|n|j
jj| }|  j|j| 7  _d S d S d S )NNN)rh   namer   r-   widthlsbr0   heighttsbr&   r1   ZAdvWidthMapr#   Z
getGlyphIDmappingr3   )r4   rh   rA   r   Zvaridxr   r   r   r5      s   
z_TTGlyph.__init__c                 C   s   t )dDraw the glyph onto ``pen``. See fontTools.pens.basePen for details
        how that works.
        )NotImplementedErrorr4   penr   r   r   draw   s   z_TTGlyph.drawc                 C   s   ddl m} | || dS )eDraw the glyph onto ``pen``. See fontTools.pens.pointPen for details
        how that works.
        r   )SegmentToPointPenN)ZfontTools.pens.pointPenr|   rz   )r4   ry   r|   r   r   r   
drawPoints   s   z_TTGlyph.drawPointsN)rL   rM   rN   rO   r5   r   rz   r}   r   r   r   r   rn      s    	
rn   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
rX   c                 C   V   |   \}}| j }|rd}||| jj| W d   dS 1 s$w   Y  dS )rv   r   N)_getGlyphAndOffsetrh   r=   rz   rS   r4   ry   glyphoffsetr)   r   r   r   rz         "z_TTGlyphGlyf.drawc                 C   r~   )r{   r   N)r   rh   r=   r}   rS   r   r   r   r   r}      r   z_TTGlyphGlyf.drawPointsc                 C   sN   | j jr| j jd ur|  }n| j j| j }t|dr!| j|j nd}||fS )NxMinr   )	rh   r&   rU   _getGlyphInstancerS   rp   hasattrrr   r   )r4   r   r   r   r   r   r      s
   
z_TTGlyphGlyf._getGlyphAndOffsetc                 C   s@  ddl m} ddlm} ddlm} | j}|j}|jj	| j
 }|j}|j}|| j
||\}	}
d\}}|D ]C}||j|j}|sAq5|j}d |v rp|d u rj|| j
||\}}|d dkr`|d n	ttt|d }||||}|	||| 7 }	q5t|| j
 }t||	|| jd\}}}}|| _|| _|jd u r|| _|| _|S )Nr   )	iup_delta)GlyphCoordinates)supportScalarro   r<   r   )ZfontTools.varLib.iupr   ZfontTools.ttLib.tables._g_l_y_fr   ZfontTools.varLib.modelsr   rh   rS   rU   
variationsrp   r-   r0   Z_getCoordinatesAndControlsr&   r$   coordinatesr^   rangerH   r   _setCoordinatesr   rr   rt   r1   rq   rs   )r4   r   r   r   rh   rS   r   r-   r0   r   _Z
origCoordsZendPtsvarZscalardeltacontrolr   rq   rr   rs   rt   r   r   r   r      sH   &

z_TTGlyphGlyf._getGlyphInstanceN)rL   rM   rN   rz   r}   r   r   r   r   r   r   rX      s
    	rX   c                   @   s   e Zd Zdd ZdS )rb   c                 C   s   | j j| j || j j dS )rv   N)rh   r`   rp   rz   rd   rx   r   r   r   rz     s   z_TTGlyphCFF.drawN)rL   rM   rN   rz   r   r   r   r   rb     s    rb   c                 C   s   | j dkr%| j}|| j}||d}| j}| j}||  ko"|kS   S | j dkr:| j}	|	|| j d 7 }	|	dkS | j dkrQ| jD ]}
t	|
|||sN dS qBdS | j dkrh| jD ]}
t	|
|||re dS qYdS | j dkrvt	| j
||| S dS )	Nr<   r         FT      )ZFormatZ	AxisIndexr   r/   ZFilterRangeMinValueZFilterRangeMaxValueZDefaultValueZVarIdxConditionTable_evaluateConditionZconditionTable)	conditionfvarAxesr&   re   Z	axisIndexr   Z	axisValueZminValueZmaxValuerf   Zsubconditionr   r   r   r     s8   








r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )rl   c                    sf  ddl m}m} | j}|j}|jj| j}|j	j
| }ddlm}	 ddlm}
 |jd j |	|j | jj}|jD ]}|j|j@ rS|jj|j }t| | jj|sSq:i }|jdur|jj|j }t|j}|j|kru|t ||j d7 }t!|t!|ksJ t!|t!|f fdd	t"||D }|j#|kr||j# }t$|}|%| |j&}|j|j'@ }| jj(||p | j(||X | j|j)k}|sz|*|j)|| jj+ W n t,y   d
}Y nw |r|- }|j)| jkr| jn|j}||j) }|rt.||}|/| n
t0||}|1| W d   n	1 sw   Y  W d   n	1 s+w   Y  q:dS )rv   r   )VarComponentFlagsNO_VARIATION_INDEX)MultiVarStoreInstancerr    r   N   c                    s   i | ]
\}} | j |qS r   r   )r   ivr   r   r   r   i  s    z&_TTGlyphVARC._draw.<locals>.<dictcomp>T)2ZfontTools.ttLib.tables.otTablesr   r   rh   ri   rj   rk   indexrp   ZVarCompositeGlyphsZVarCompositeGlyphZfontTools.varLib.multiVarStorer   r2   r!   r#   r$   ZMultiVarStorer&   
componentsflagsZHAVE_CONDITIONZConditionListr   ZconditionIndexr   ZaxisIndicesIndexZAxisIndicesListZItemr	   
axisValuesZaxisValuesVarIndexfi2flrH   zipZtransformVarIndexr   ZapplyTransformDeltas	transformZRESET_UNSPECIFIED_AXESr;   rA   ZaddVarComponentr'   AttributeErrorZtoTransformr   r}   r   rz   )r4   ry   Z
isPointPenr   r   rh   rm   idxr   r   r!   re   compr   r&   ZaxisIndicesr   Zdeltasr   r6   ZshouldDecomposetZcompGlyphSetgZtPenr   r   r   _drawA  s   











z_TTGlyphVARC._drawc                 C      |  |d d S )NFr   rx   r   r   r   rz     rZ   z_TTGlyphVARC.drawc                 C   r   )NTr   rx   r   r   r   r}     rZ   z_TTGlyphVARC.drawPointsN)rL   rM   rN   r   rz   r}   r   r   r   r   rl   @  s    Nrl   Tr   c                C   s8  t |dksJ |d d }|d d }|d d }|d d }tdD ]}|d= q$|  rYt |t | jks9J dd	 | jD | _t|| jD ]\}	}
t|
d
rW|	\|
_|
_qHn| jdkrgt |dksfJ nt |t | j	ksrJ || _	|r|| 
| t|| }t|| }t| j| }t|| j }||||fS )Nr   r   r<   c                 S   s   g | ]}t |qS r   )r   )r   r   r   r   r   
<listcomp>  r   z#_setCoordinates.<locals>.<listcomp>x)rH   r   ZisCompositer   r   r   r   yZnumberOfContoursr   r   r
   r   ZyMax)r   ZcoordrS   r   Z	leftSideXZ
rightSideXZtopSideYZbottomSideYr   pr   ZhorizontalAdvanceWidthZverticalAdvanceWidthZleftSideBearingZtopSideBearingr   r   r   r     s<   


r   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )LerpGlyphSeta+  A glyphset that interpolates between two other glyphsets.

    Factor is typically between 0 and 1. 0 means the first glyphset,
    1 means the second glyphset, and 0.5 means the average of the
    two glyphsets. Other values are possible, and can be useful to
    extrapolate. Defaults to 0.5.
          ?c                 C   s   || _ || _|| _d S r7   )	glyphset1	glyphset2factor)r4   r   r   r   r   r   r   r5     s   
zLerpGlyphSet.__init__c                 C   s&   || j v r|| jv rt|| S t|r7   )r   r   	LerpGlyphKeyErrorr4   	glyphnamer   r   r   rY     s   
zLerpGlyphSet.__getitem__c                 C   s   || j v o	|| jv S r7   )r   r   r   r   r   r   rB     s   zLerpGlyphSet.__contains__c                 C   "   t | j}t | j}t||S r7   )setr   r   rD   intersectionr4   Zset1Zset2r   r   r   rG        

zLerpGlyphSet.__iter__c                 C   r   r7   )r   r   r   rH   r   r   r   r   r   rI     r   zLerpGlyphSet.__len__N)r   )	rL   rM   rN   rO   r5   rY   rB   rG   rI   r   r   r   r   r     s    
r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   || _ || _d S r7   )glyphsetr   )r4   r   r   r   r   r   r5     s   
zLerpGlyph.__init__c                 C   sb   t | jj}| jj| j | t | jj}| jj| j | | jj}tt|j	|j	|| d S r7   )
r   r   r   r   rz   r   r   r   r   rf   )r4   ry   Z
recording1Z
recording2r   r   r   r   rz     s   zLerpGlyph.drawN)rL   rM   rN   r5   rz   r   r   r   r   r     s    r   N)*rO   abcr   r   collections.abcr   
contextlibr   r   r   typesr   ZfontTools.misc.vectorr	   ZfontTools.misc.fixedToolsr
   r   r   ZfontTools.misc.loggingToolsr   ZfontTools.misc.transformr   r   ZfontTools.pens.transformPenr   r   ZfontTools.pens.recordingPenr   r   r   r   rR   r]   rg   rn   rX   rb   r   rl   r   r   r   r   r   r   r   <module>   s0    M
$,M#V&!