a
    —ÆàgL(  ã                @   @   sÐ  d Z dZddl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mZmZmZmZmZ d
Zeegef ee eee  dœdd„Zeeedœdd„ZG dd„ de	ƒZedd�G dd„ deƒƒZedd�G dd„ deƒƒZejdfeƒ gejdfedd�gej dfedd�gej!dfedd d!�gej dfeƒ gej"dfed"d�gej#dfed#d$d%�ed&d'd%�gej$dfed#d$d%�ed(d)d%�gej%dfed*d+d%�ed,d-d%�gej&dfed.d�gej&dfeƒ gej&d/feƒ gej'dfed0d�gej'dfeƒ gej'd/fed1d2�ed3d2�ed4d2�gej(dfed5d�gej(dfeƒ gej(d/feƒ gej)dfed6d�gej)dfeƒ gej)d/fed1d2�ed3d2�ed4d2�gej*dfed7d�ed1d2�ed4d2�gej+dfed8d�gej,dfed9d�gej-dfeƒ gej.dfed:d2�gej/dfed;d�gej0dfed<d=d%�gej1dfed>d?d%�gej2dfed@dAd%�edBdCd%�giZ3eej4j5dDf Z6ej4eee6 dEœdFdG„Z7eee6 ee6 gdf Z8ej4ee8ee6 dHœdIdJ„Z9ej:ee dKœdLdM„Z;dS )NzReorder glyphs in a font.zRod Sheeteré    )ÚttLib)ÚotBase)ÚotTables)ÚABCÚabstractmethod)Ú	dataclass)Údeque)ÚOptionalÚAnyÚCallableÚDequeÚIterableÚListÚTupleZCoverage)Úget_glyph_idÚglyphsÚparallel_listc                    sd   |rHt dd„ t||ƒD ƒ‡ fdd„d�}ttt|Ž ƒ\}}||d d …< nt |ˆ d�}||d d …< d S )Nc                 s   s   | ]\}}||fV  qd S ©N© )Ú.0ÚgÚer   r   úV/var/www/sistema_ama/venv/lib/python3.9/site-packages/fontTools/ttLib/reorderGlyphs.pyÚ	<genexpr>$   ó    z_sort_by_gid.<locals>.<genexpr>c                    s   ˆ | d ƒS )Nr   r   )Út©r   r   r   Ú<lambda>%   r   z_sort_by_gid.<locals>.<lambda>©Úkey)ÚsortedÚzipÚmapÚlist)r   r   r   Z	reorderedZsorted_glyphsZsorted_parallel_listr   r   r   Ú_sort_by_gid   s    
þr$   )ÚvalueÚdotted_attrÚreturnc                 C   s0   |  d¡}|sJ ‚|r,| d¡}t| |ƒ} q| S )NÚ.r   )ÚsplitÚpopÚgetattr)r%   r&   Z
attr_namesÚ	attr_namer   r   r   Ú_get_dotted_attr/   s    

r-   c                   @   s*   e Zd ZdZeejejddœdd„ƒZ	dS )ÚReorderRulezEA rule to reorder something in a font to match the fonts glyph order.N©Úfontr%   r'   c                 C   s   d S r   r   )Úselfr0   r%   r   r   r   Úapply<   s    zReorderRule.apply)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚTTFontr   Ú	BaseTabler2   r   r   r   r   r.   9   s   r.   T)Úfrozenc                   @   sD   e Zd ZU dZdZee ed< eZ	eed< e
jejddœdd„ZdS )ÚReorderCoveragezNReorder a Coverage table, and optionally a list that is sorted parallel to it.NÚparallel_list_attrÚcoverage_attrr/   c                 C   s¨   t || jƒ}t|ƒturvd }| jrdt || jƒ}t|ƒtu sJJ | j› d�ƒ‚t|ƒt|jƒksdJ dƒ‚t|j|j|ƒ n.| jrŠJ d| › �ƒ‚|D ]}t|j|jd ƒ qŽd S )Nú should be a listzNothing makes sensez2Can't have multiple coverage AND a parallel list; )	r-   r<   Útyper#   r;   Úlenr   r$   Ú
getGlyphID)r1   r0   r%   Zcoverager   Zcoverage_entryr   r   r   r2   H   s"    
ÿ
þÿþzReorderCoverage.apply)r3   r4   r5   r6   r;   r	   ÚstrÚ__annotations__Ú_COVERAGE_ATTRr<   r   r7   r   r8   r2   r   r   r   r   r:   @   s   
r:   c                   @   s8   e Zd ZU dZeed< eed< ejej	ddœdd„Z
dS )ÚReorderLista7  Reorder the items within a list to match the updated glyph order.

    Useful when a list ordered by coverage itself contains something ordered by a gid.
    For example, the PairSet table of https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable.
    Ú	list_attrr   Nr/   c                    s@   t |ˆjƒ}t|tƒs&J ˆj› d�ƒ‚|j‡ ‡fdd„d� d S )Nr=   c                    s   ˆ   t| ˆjƒ¡S r   )r@   r+   r   )Úv©r0   r1   r   r   r   n   r   z#ReorderList.apply.<locals>.<lambda>r   )r-   rE   Ú
isinstancer#   Úsort)r1   r0   r%   Úlstr   rG   r   r2   k   s    zReorderList.apply)r3   r4   r5   r6   rA   rB   r   r7   r   r8   r2   r   r   r   r   rD   `   s   
rD   é   é   ÚValue)r;   ÚPairSetNZPairValueRecordZSecondGlyphr   ZEntryExitRecordZMarkCoveragezMarkArray.MarkRecord)r<   r;   ZBaseCoveragezBaseArray.BaseRecordZLigatureCoveragezLigatureArray.LigatureAttachZMark1CoveragezMark1Array.MarkRecordZMark2CoveragezMark2Array.Mark2RecordZ
PosRuleSeté   ZChainPosRuleSetZBacktrackCoverage)r<   ZInputCoverageZLookAheadCoverageZ
SubRuleSetZChainSubRuleSetZ
SubstituteZAttachPointZLigGlyphZExtendedShapeCoverageZItalicsCorrectionZTopAccentCoverageZTopAccentAttachmentZMathKernCoverageZMathKernInfoRecordsZVertGlyphCoverageZVertGlyphConstructionZHorizGlyphCoverageZHorizGlyphConstruction.)ÚrootÚroot_accessorr'   c                 c   s   t | |dd„ ƒE d H  d S )Nc                 S   s
   |   |¡S r   )Úextend)ÚfrontierÚnewr   r   r   r   ×   r   z!_bfs_base_table.<locals>.<lambda>)Ú_traverse_ot_data)rP   rQ   r   r   r   Ú_bfs_base_tableÓ   s    
ÿrV   )rP   rQ   Úadd_to_frontier_fnr'   c                 c   sj   t ƒ }| tj || ¡f¡ |rf| ¡ }|d j}|V  g }| ¡ D ]}| ||f ¡ qD|||ƒ qd S )Néÿÿÿÿ)r   Úappendr   r8   ÚSubTableEntryÚpopleftr%   ZiterSubTables)rP   rQ   rW   rS   ÚpathÚcurrentZnew_entriesZsubtable_entryr   r   r   rU   ß   s    
rU   )r0   Únew_glyph_orderc                    s|  ˆ  ¡ }t|ƒt|ƒkr6tdt|ƒ› dt|ƒ› d�ƒ‚t|ƒt|ƒkrrtdt|ƒt|ƒ › dt|ƒt|ƒ › �ƒ‚ˆ ¡  t‡fdd„ˆ ¡ D ƒƒ}|r¦td|› �ƒ‚ˆ |¡ h d	£}|D ]l}|ˆ ¡ v r¼tˆ| j	d
|› d�ƒD ]B}|d j
}t|ƒt|dd ƒf}t |g ¡D ]}	|	 ˆ|¡ �qqäq¼dˆv �rxˆd }
|
jjd jj‰ ||
jjd _‡ fdd„|D ƒ|
jjd j_d S )NzNew glyph order contains z glyphs, but font has z glyphszTNew glyph order does not contain the same set of glyphs as the font:
* only in new: z
* only in old: c                 3   s   | ]}ˆ   |¡s|V  qd S r   )ZisLoaded)r   r   )r0   r   r   r     r   z reorderGlyphs.<locals>.<genexpr>z/Everything should be loaded, following aren't: >   ZGDEFZMATHZGSUBZGPOSzfont["z"]rX   ZFormatzCFF r   c                    s   i | ]}|ˆ   |¡“qS r   )Úget)r   Úk)Úcharstringsr   r   Ú
<dictcomp>  s   z!reorderGlyphs.<locals>.<dictcomp>)ZgetGlyphOrderr?   Ú
ValueErrorÚsetZensureDecompiledr    ÚkeysZsetGlyphOrderrV   Útabler%   r>   r+   Ú_REORDER_RULESr_   r2   ZcffZtopDictIndexZCharStringsZcharStringsÚcharset)r0   r^   Zold_glyph_orderZ
not_loadedZcoverage_containersÚtagr\   r%   Zreorder_keyZreorderZ	cff_tabler   )ra   r0   r   ÚreorderGlyphsô   sF    ÿÿÿþÿ	



ÿrj   )<r6   Ú
__author__Z	fontToolsr   ZfontTools.ttLib.tablesr   r   ZotÚabcr   r   Zdataclassesr   Úcollectionsr   Útypingr	   r
   r   r   r   r   r   rC   rA   Úintr$   r-   r.   r:   rD   Z	SinglePosZPairPosrN   Z
CursivePosZMarkBasePosZ
MarkLigPosZMarkMarkPosZ
ContextPosZChainContextPosZContextSubstZChainContextSubstZReverseChainSingleSubstZ
AttachListZLigCaretListZMarkGlyphSetsDefZMathGlyphInfoZMathItalicsCorrectionInfoZMathTopAccentAttachmentZMathKernInfoZMathVariantsrg   r8   rZ   ZSubTablePathrV   ZAddToFrontierFnrU   r7   rj   r   r   r   r   Ú<module>   sà   $
ý
ÿÿüÿþü	ÿÿüýýýÿÿÿÿÿþþû²]þ	þ