a
    ¥Q•h½E  ã                   @   sl  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#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edœ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rV|ni | _d| _g | _g | _	|| _
|d j| _t| d¡dd ƒ| _d | _|ràddlm} t| d	¡d
d ƒ| _| jd urà|| jj|d j|ƒ| _d S )NÚfvarc                 S   s   i | ]}|j d “qS )r   ©ÚaxisTag)Ú.0Zaxis© r   úS/var/www/sistema_ama/venv/lib/python3.9/site-packages/fontTools/ttLib/ttGlyphSet.pyÚ
<dictcomp>   ó    z(_TTGlyphSet.__init__.<locals>.<dictcomp>r   Ú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__   s.    ÿý
ÿz_TTGlyphSet.__init__©Úresetc                 c   s¦   | j  | j¡ | j | j¡ |r:| j ¡ | _| j ¡ | _n| j ¡ | _i | _| j |¡ | j |¡ z"d V  W | j  	¡ | _| j 	¡ | _n| j  	¡ | _| j 	¡ | _0 d S ©N)
r+   Úappendr'   r,   r(   r)   r   r&   ÚupdateÚpop)r5   r'   r8   r   r   r   ÚpushLocation5   s    ÿz_TTGlyphSet.pushLocationc              	   c   sB   z,| j }|  j d7  _ |V  W |  j d8  _ n|  j d8  _ 0 d S )Né   )r*   )r5   r*   r   r   r   Ú	pushDepthH   s
    z_TTGlyphSet.pushDepthc                 C   s
   || j v S r9   ©r-   ©r5   Ú	glyphNamer   r   r   Ú__contains__Q   s    z_TTGlyphSet.__contains__c                 C   s   t | j ¡ ƒS r9   )Úiterr-   Úkeys©r5   r   r   r   Ú__iter__T   s    z_TTGlyphSet.__iter__c                 C   s
   t | jƒS r9   )Úlenr-   rF   r   r   r   Ú__len__W   s    z_TTGlyphSet.__len__z#use 'glyphName in glyphSet' instead)Úcategoryc                 C   s
   || j v S r9   r@   rA   r   r   r   Úhas_keyZ   s    z_TTGlyphSet.has_keyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r6   r   Úboolr=   r?   rC   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 ©NÚglyfr   Zgvar©Ú	glyfTableÚsuperr6   r0   Ú	gvarTable©r5   r$   r'   r   ©Ú	__class__r   r   r6   b   s    
ú_TTGlyphSetGlyf.__init__c                 C   s   t | || jd�S ©Nr   ©Ú_TTGlyphGlyfr   rA   r   r   r   Ú__getitem__g   s    ú_TTGlyphSetGlyf.__getitem__)T©rL   rM   rN   r6   r`   Ú__classcell__r   r   rZ   r   rR   a   s   rR   c                       s&   e Zd Zd‡ fdd„	Zdd„ Z‡  ZS )rR   Tc                    s0   |d | _ tƒ j||| j |d� | d¡| _d S rS   rU   rY   rZ   r   r   r6   l   s    
r\   c                 C   s   t | || jd�S r]   r^   rA   r   r   r   r`   q   s    ra   )Trb   r   r   rZ   r   rR   k   s   c                       s>   e Zd Z‡ fdd„Zdd„ Zdd„ Zeedœdd	„ƒZ‡  Z	S )
Ú_TTGlyphSetCFFc                    sJ   d|v rdnd}t || j ¡ ƒd j| _tƒ  ||| j¡ |  |¡ d S )NÚCFF2zCFF r   )ÚlistÚcffÚvaluesZCharStringsÚcharStringsrW   r6   ÚsetLocation)r5   r$   r'   ZtableTagrZ   r   r   r6   v   s    z_TTGlyphSetCFF.__init__c                 C   s
   t | |ƒS r9   )Ú_TTGlyphCFFrA   r   r   r   r`   |   s    z_TTGlyphSetCFF.__getitem__c                 C   sV   d | _ |rLddlm} t| jdd ƒ}|d urR||j| jd j|ƒ}|j| _ nd | _ d S )Nr   r!   ÚvarStorer   )	Úblenderr3   r"   r/   ri   Z
otVarStorer$   r%   ZinterpolateFromDeltas)r5   r'   r"   rl   Ú	instancerr   r   r   rj      s    ÿ
z_TTGlyphSetCFF.setLocationr7   c              
   c   sb   |   |¡ t | ||¡�6}z|V  W |   | j¡ n|   | j¡ 0 W d   ƒ n1 sT0    Y  d S r9   )rj   r   r=   r'   )r5   r'   r8   Úvaluer   r   r   r=   �   s
    
z_TTGlyphSetCFF.pushLocation)
rL   rM   rN   r6   r`   rj   r   rP   r=   rc   r   r   rZ   r   rd   u   s
   rd   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )Ú_TTGlyphSetVARCc                    s&   || _ tƒ  |||¡ |d j| _d S )NÚVARC)ÚglyphSetrW   r6   r#   Ú	varcTable)r5   r$   r'   rr   rZ   r   r   r6   š   s    z_TTGlyphSetVARC.__init__c                 C   s&   | j }||jjvr| j| S t| |ƒS r9   )rs   ÚCoverageÚglyphsrr   Ú_TTGlyphVARC)r5   rB   Úvarcr   r   r   r`   Ÿ   s    
z_TTGlyphSetVARC.__getitem__rb   r   r   rZ   r   rp   ™   s   rp   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rB|j| \| _| _nd\| _| _|j	r˜|j
d ur˜|j
jd u rv|j |¡n|j
jj| }|  j|j| 7  _d S )N©NN)rr   Únamer   r.   ÚwidthÚlsbr1   ÚheightÚtsbr'   r2   ZAdvWidthMapr$   Ú
getGlyphIDÚmappingr4   )r5   rr   rB   r   Zvaridxr   r   r   r6   °   s    

ÿýz_TTGlyph.__init__c                 C   s   t ‚dS ©údDraw the glyph onto ``pen``. See fontTools.pens.basePen for details
        how that works.
        N)ÚNotImplementedError©r5   Ú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ˆ   r†   )r5   r…   rˆ   r   r   r   Ú
drawPointsÉ   s    z_TTGlyph.drawPointsN)rL   rM   rN   rO   r6   r   r†   r‰   r   r   r   r   rx   ¦   s
   	
rx   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
r_   c                 C   sT   |   ¡ \}}| j ¡ �*}|r d}| || jj|¡ W d  ƒ n1 sF0    Y  dS )r‚   r   N)Ú_getGlyphAndOffsetrr   r?   r†   rV   ©r5   r…   ÚglyphÚoffsetr*   r   r   r   r†   Ó   s
    z_TTGlyphGlyf.drawc                 C   sT   |   ¡ \}}| j ¡ �*}|r d}| || jj|¡ W d  ƒ n1 sF0    Y  dS )r‡   r   N)rŠ   rr   r?   r‰   rV   r‹   r   r   r   r‰   ß   s
    z_TTGlyphGlyf.drawPointsc                 C   sN   | j jr| j jd ur|  ¡ }n| j j| j }t|dƒrB| j|j nd}||fS )NÚxMinr   )	rr   r'   rX   Ú_getGlyphInstancerV   rz   Úhasattrr|   rŽ   )r5   rŒ   r�   r   r   r   rŠ   ë   s
    
z_TTGlyphGlyf._getGlyphAndOffsetc                 C   sB  ddl m} ddlm} ddlm} | j}|j}|jj	| j
 }|j}|j}| | j
||¡\}	}
d\}}|D ]†}||j|jƒ}|s‚qj|j}d |v rà|d u rÔ| | j
||¡\}}|d dkrÀ|d nttt|d ƒƒƒ}||||ƒ}|	||ƒ| 7 }	qjt|| j
 ƒ}t||	|| jd�\}}}}|| _|| _|jd u �r>|| _|| _|S )Nr   )Ú	iup_delta)ÚGlyphCoordinates)ÚsupportScalarry   r>   r   )ZfontTools.varLib.iupr‘   ZfontTools.ttLib.tables._g_l_y_fr’   ÚfontTools.varLib.modelsr“   rr   rV   rX   Ú
variationsrz   r.   r1   Z_getCoordinatesAndControlsr'   r%   Úcoordinatesrf   ÚrangerH   r   Ú_setCoordinatesr   r|   r~   r2   r{   r}   )r5   r‘   r’   r“   rr   rV   r•   r.   r1   r–   Ú_Z
origCoordsZendPtsÚvarÚscalarÚdeltaZcontrolrŒ   r{   r|   r}   r~   r   r   r   r�   ô   sH    ÿÿ&ÿ
ÿz_TTGlyphGlyf._getGlyphInstanceN)rL   rM   rN   r†   r‰   rŠ   r�   r   r   r   r   r_   Ò   s   	r_   c                   @   s   e Zd Zdd„ ZdS )rk   c                 C   s   | j j| j  || j j¡ dS r�   )rr   ri   rz   r†   rm   r„   r   r   r   r†      s    z_TTGlyphCFF.drawN)rL   rM   rN   r†   r   r   r   r   rk     s   rk   c                 C   sô   | j dkrJ| j}|| j}| |d¡}| j}| j}||  koD|kS   S | j dkrt| j}	|	|| j d 7 }	|	dkS | j dkr¢| jD ]}
t	|
|||ƒs„ dS q„dS | j dkrÐ| jD ]}
t	|
|||ƒr² dS q²dS | j dkrìt	| j
|||ƒ S dS d S )	Nr>   r   é   é   FTé   é   )ÚFormatZ	AxisIndexr   r0   ZFilterRangeMinValueZFilterRangeMaxValueZDefaultValueZVarIdxÚConditionTableÚ_evaluateConditionZconditionTable)Ú	conditionÚfvarAxesr'   rn   Z	axisIndexr   Z	axisValueZminValueZmaxValuero   Zsubconditionr   r   r   r£   '  s4    








ÿr£   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )rv   c                    st  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@ r¨|jj|j }t|ˆ | jj|ƒs¨qti }|jdu�r,|jj|j }t|jƒ}|j|krî|t ||j dƒ7 }t!|ƒt!|ƒk�sJ t!|ƒt!|ƒfƒ‚‡ fdd	„t"||ƒD ƒ}|j#|k�rT||j# }t$|ƒ}| %|¡ |j&}|j|j'@ }| jj (||¡�æ | j (||¡�¶ | j|j)k}|�sÌz| *|j)|| jj+¡ W n t,�yÊ   d
}Y n0 |�r.| -¡ }|j)| jk�rî| jn|j}||j) }|�rt.||ƒ}| /|¡ nt0||ƒ}| 1|¡ W d  ƒ n1 �sD0    Y  W d  ƒ qt1 �sd0    Y  qtdS )r‚   r   )ÚVarComponentFlagsÚNO_VARIATION_INDEX)ÚMultiVarStoreInstancerr!   r   Né   c                    s   i | ]\}}ˆ | j |“qS r   r   )r   ÚiÚv©r¥   r   r   r   s  s   z&_TTGlyphVARC._draw.<locals>.<dictcomp>T)2ZfontTools.ttLib.tables.otTablesr¦   r§   rr   rs   rt   ru   Úindexrz   ZVarCompositeGlyphsZVarCompositeGlyphZfontTools.varLib.multiVarStorer¨   r3   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=   rB   ZaddVarComponentr(   ÚAttributeErrorZtoTransformr   r‰   r   r†   )r5   r…   Z
isPointPenr¦   r§   rr   rw   ÚidxrŒ   r¨   r"   rn   Úcompr¤   r'   ZaxisIndicesr°   Zdeltasr³   r8   ZshouldDecomposeÚtZcompGlyphSetÚgZtPenr   r¬   r   Ú_drawK  sv    ÿÿ

þ
ÿ

ÿ

ÿ
ý


z_TTGlyphVARC._drawc                 C   s   |   |d¡ d S )NF©r¹   r„   r   r   r   r†   ™  s    z_TTGlyphVARC.drawc                 C   s   |   |d¡ d S )NTrº   r„   r   r   r   r‰   œ  s    z_TTGlyphVARC.drawPointsN)rL   rM   rN   r¹   r†   r‰   r   r   r   r   rv   J  s   Nrv   Tr   c                C   s8  t |ƒdksJ ‚|d d }|d d }|d d }|d d }tdƒD ]
}|d= qH|  ¡ r²t |ƒt | jƒksrJ ‚dd	„ | jD ƒ| _t|| jƒD ]\}	}
t|
d
ƒr�|	\|
_|
_q�n8| jdkrÎt |ƒdksêJ ‚nt |ƒt | j	ƒksäJ ‚|| _	|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Œ   ÚcoordrV   r   Z	leftSideXZ
rightSideXZtopSideYZbottomSideYr™   Úpr¶   ZhorizontalAdvanceWidthZverticalAdvanceWidthZleftSideBearingZtopSideBearingr   r   r   r˜      s8    


ü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 r9   )Ú	glyphset1Ú	glyphset2Úfactor)r5   rÆ   rÇ   rÈ   r   r   r   r6   Ï  s    zLerpGlyphSet.__init__c                 C   s*   || j v r|| jv rt|| ƒS t|ƒ‚d S r9   )rÆ   rÇ   Ú	LerpGlyphÚKeyError©r5   Ú	glyphnamer   r   r   r`   Ô  s    
zLerpGlyphSet.__getitem__c                 C   s   || j v o|| jv S r9   )rÆ   rÇ   rË   r   r   r   rC   Ù  s    zLerpGlyphSet.__contains__c                 C   s"   t | jƒ}t | jƒ}t| |¡ƒS r9   )ÚsetrÆ   rÇ   rD   Úintersection©r5   Zset1Zset2r   r   r   rG   Ü  s    

zLerpGlyphSet.__iter__c                 C   s"   t | jƒ}t | jƒ}t| |¡ƒS r9   )rÍ   rÆ   rÇ   rH   rÎ   rÏ   r   r   r   rI   á  s    

zLerpGlyphSet.__len__N)rÅ   )	rL   rM   rN   rO   r6   r`   rC   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 r9   )ÚglyphsetrÌ   )r5   rÌ   rÐ   r   r   r   r6   è  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 r9   )
r   rÐ   rÆ   rÌ   r†   rÇ   rÈ   r   r   ro   )r5   r…   Z
recording1Z
recording2rÈ   r   r   r   r†   ì  s    zLerpGlyph.drawN)rL   rM   rN   r6   r†   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±   ÚfontTools.misc.loggingToolsr   ZfontTools.misc.transformr   r   ZfontTools.pens.transformPenr   r   ZfontTools.pens.recordingPenr   r   r   r   rR   rd   rp   rx   r_   rk   r£   rv   r˜   rÄ   rÉ   r   r   r   r   Ú<module>   s0   M

$,M#V&!