a
    ZXhDD                     @   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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 | _|rd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   _/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/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__   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)r4   r&   r7   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)   )r4   r)   r   r   r   	pushDepthH   s
    z_TTGlyphSet.pushDepthc                 C   s
   || j v S r8   r,   r4   	glyphNamer   r   r   __contains__Q   s    z_TTGlyphSet.__contains__c                 C   s   t | j S r8   )iterr,   keysr4   r   r   r   __iter__T   s    z_TTGlyphSet.__iter__c                 C   s
   t | jS r8   )lenr,   rE   r   r   r   __len__W   s    z_TTGlyphSet.__len__z#use 'glyphName in glyphSet' instead)categoryc                 C   s
   || j v S r8   r?   r@   r   r   r   has_keyZ   s    z_TTGlyphSet.has_keyN)__name__
__module____qualname____doc__r5   r   boolr<   r>   rB   rF   rH   r   DeprecationWarningrJ   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   s    z_TTGlyphSetGlyf.__getitem__)TrK   rL   rM   r5   rX   __classcell__r   r   rU   r   rQ   a   s   rQ   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 )NZCFF2zCFF r   )listZcffvaluesZCharStringscharStringsrS   r5   setLocation)r4   r#   r&   ZtableTagrU   r   r   r5   l   s    z_TTGlyphSetCFF.__init__c                 C   s
   t | |S r8   )_TTGlyphCFFr@   r   r   r   rX   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   )	blenderr2   r!   r.   r^   Z
otVarStorer#   r$   ZinterpolateFromDeltas)r4   r&   r!   ra   	instancerr   r   r   r_   u   s    
z_TTGlyphSetCFF.setLocationr6   c              
   c   sb   |  | t| ||6}z|V  W |  | j n|  | j 0 W d    n1 sT0    Y  d S r8   )r_   r   r<   r&   )r4   r&   r7   valuer   r   r   r<      s
    
z_TTGlyphSetCFF.pushLocation)
rK   rL   rM   r5   rX   r_   r   rO   r<   rZ   r   r   rU   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)glyphSetrS   r5   r"   	varcTable)r4   r#   r&   rf   rU   r   r   r5      s    z_TTGlyphSetVARC.__init__c                 C   s&   | j }||jjvr| j| S t| |S r8   )rg   Coverageglyphsrf   _TTGlyphVARC)r4   rA   varcr   r   r   rX      s    
z_TTGlyphSetVARC.__getitem__rY   r   r   rU   r   re      s   re   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)rf   namer   r-   widthlsbr0   heighttsbr&   r1   ZAdvWidthMapr#   Z
getGlyphIDmappingr3   )r4   rf   rA   r   Zvaridxr   r   r   r5      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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{   ry   )r4   rx   r{   r   r   r   
drawPoints   s    z_TTGlyph.drawPointsN)rK   rL   rM   rN   r5   r   ry   r|   r   r   r   r   rl      s
   	
rl   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
rW   c                 C   sT   |   \}}| j *}|r d}||| jj| W d   n1 sF0    Y  dS )ru   r   N)_getGlyphAndOffsetrf   r>   ry   rR   r4   rx   glyphoffsetr)   r   r   r   ry      s
    z_TTGlyphGlyf.drawc                 C   sT   |   \}}| j *}|r d}||| jj| W d   n1 sF0    Y  dS )rz   r   N)r}   rf   r>   r|   rR   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   )	rf   r&   rT   _getGlyphInstancerR   rn   hasattrrp   r   )r4   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}|sqj|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)supportScalarrm   r=   r   )ZfontTools.varLib.iupr   ZfontTools.ttLib.tables._g_l_y_fr   ZfontTools.varLib.modelsr   rf   rR   rT   
variationsrn   r-   r0   Z_getCoordinatesAndControlsr&   r$   coordinatesr\   rangerG   r   _setCoordinatesr   rp   rr   r1   ro   rq   )r4   r   r   r   rf   rR   r   r-   r0   r   _Z
origCoordsZendPtsvarZscalardeltacontrolr   ro   rp   rq   rr   r   r   r   r      sH    &
z_TTGlyphGlyf._getGlyphInstanceN)rK   rL   rM   ry   r|   r}   r   r   r   r   r   rW      s   	rW   c                   @   s   e Zd Zdd ZdS )r`   c                 C   s   | j j| j || j j dS rt   )rf   r^   rn   ry   rb   rw   r   r   r   ry     s    z_TTGlyphCFF.drawN)rK   rL   rM   ry   r   r   r   r   r`     s   r`   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 qdS | j dkr| jD ]}
t	|
|||r dS qdS | j dkrt	| j
||| S dS d S )	Nr=   r         FT      )ZFormatZ	AxisIndexr   r/   ZFilterRangeMinValueZFilterRangeMaxValueZDefaultValueZVarIdxConditionTable_evaluateConditionZconditionTable)	conditionfvarAxesr&   rc   Z	axisIndexr   Z	axisValueZminValueZmaxValuerd   Zsubconditionr   r   r   r     s4    








r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )rj   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|sqti }|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}|sz|*|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 )ru   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   rf   rg   rh   ri   indexrn   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fi2flrG   zipZtransformVarIndexr   ZapplyTransformDeltas	transformZRESET_UNSPECIFIED_AXESr<   rA   ZaddVarComponentr'   AttributeErrorZtoTransformr   r|   r   ry   )r4   rx   Z
isPointPenr   r   rf   rk   idxr   r   r!   rc   compr   r&   ZaxisIndicesr   Zdeltasr   r7   ZshouldDecomposetZcompGlyphSetgZtPenr   r   r   _drawA  sv    










z_TTGlyphVARC._drawc                 C   s   |  |d d S )NFr   rw   r   r   r   ry     s    z_TTGlyphVARC.drawc                 C   s   |  |d d S )NTr   rw   r   r   r   r|     s    z_TTGlyphVARC.drawPointsN)rK   rL   rM   r   ry   r|   r   r   r   r   rj   @  s   Nrj   Tr   c                C   s8  t |dksJ |d d }|d d }|d d }|d d }tdD ]
}|d= qH|  rt |t | jksrJ dd	 | jD | _t|| jD ]\}	}
t|
d
r|	\|
_|
_qn8| jdkrt |dksJ nt |t | j	ksJ || _	|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)rG   r   ZisCompositer   r   r   r   yZnumberOfContoursr   r   r
   r   ZyMax)r   ZcoordrR   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 r8   )	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|d S r8   )r   r   	LerpGlyphKeyErrorr4   	glyphnamer   r   r   rX     s    
zLerpGlyphSet.__getitem__c                 C   s   || j v o|| jv S r8   )r   r   r   r   r   r   rB     s    zLerpGlyphSet.__contains__c                 C   s"   t | j}t | j}t||S r8   )setr   r   rC   intersectionr4   Zset1Zset2r   r   r   rF     s    

zLerpGlyphSet.__iter__c                 C   s"   t | j}t | j}t||S r8   )r   r   r   rG   r   r   r   r   r   rH     s    

zLerpGlyphSet.__len__N)r   )	rK   rL   rM   rN   r5   rX   rB   rF   rH   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 r8   )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 r8   )
r   r   r   r   ry   r   r   r   r   rd   )r4   rx   Z
recording1Z
recording2r   r   r   r   ry     s    zLerpGlyph.drawN)rK   rL   rM   r5   ry   r   r   r   r   r     s   r   N)*rN   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   rQ   r[   re   rl   rW   r`   r   rj   r   r   r   r   r   r   r   <module>   s.   M
$,M#V&!