U
    Q»{jL(  ã                @   @   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   ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/fontTools/ttLib/reorderGlyphs.pyÚ	<genexpr>$   s     z_sort_by_gid.<locals>.<genexpr>c                    s   ˆ | d ƒS )Nr   r   )Út©r   r   r   Ú<lambda>%   ó    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t‚|r,| d¡}t| |ƒ} q| S )NÚ.r   )ÚsplitÚAssertionErrorÚ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   )Úselfr1   r%   r   r   r   Úapply<   s    zReorderRule.apply)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚTTFontr   Ú	BaseTabler3   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_attrr0   c                 C   s¨   t || jƒ}t|ƒtk	rvd }| jrdt || jƒ}t|ƒtksJt| j› d�ƒ‚t|ƒt|jƒksdtdƒ‚t|j	|j|ƒ n.| jrŠt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<   r*   Úlenr   r$   Ú
getGlyphID)r2   r1   r%   Zcoverager   Zcoverage_entryr   r   r   r3   H   s"    
ÿ
þÿþzReorderCoverage.apply)r4   r5   r6   r7   r<   r	   ÚstrÚ__annotations__Ú_COVERAGE_ATTRr=   r   r8   r   r9   r3   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   Nr0   c                    s@   t |ˆjƒ}t|tƒs&tˆj› d�ƒ‚|j‡ ‡fdd„d� d S )Nr>   c                    s   ˆ   t| ˆjƒ¡S r   )rA   r,   r   )Úv©r1   r2   r   r   r   n   r   z#ReorderList.apply.<locals>.<lambda>r   )r.   rF   Ú
isinstancer#   r*   Úsort)r2   r1   r%   Úlstr   rH   r   r3   k   s    zReorderList.apply)r4   r5   r6   r7   rB   rC   r   r8   r   r9   r3   r   r   r   r   rE   `   s   
rE   é   é   Ú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)rQ   rR   r   r   r   Ú_bfs_base_tableÓ   s
      ÿrW   )rQ   rR   Ú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   r9   ÚSubTableEntryÚpopleftr%   ZiterSubTables)rQ   rR   rX   rT   ÚpathÚcurrentZnew_entriesZsubtable_entryr   r   r   rV   ß   s    
rV   )r1   Ú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|› �ƒ‚ˆ |¡ d	d
ddh}|D ]l}|ˆ ¡ krÀtˆ| j	d|› d�ƒD ]B}|d j
}t|ƒt|dd ƒf}t |g ¡D ]}	|	 ˆ|¡ �qqèqÀdˆk�r|ˆ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   )r1   r   r   r     s     
 z reorderGlyphs.<locals>.<genexpr>z/Everything should be loaded, following aren't: ZGDEFZGPOSZGSUBZMATHzfont["z"]rY   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setGlyphOrderrW   Útabler%   r?   r,   Ú_REORDER_RULESr`   r3   ZcffZtopDictIndexZCharStringsZcharStringsÚcharset)r1   r_   Zold_glyph_orderZ
not_loadedZcoverage_containersÚtagr]   r%   Zreorder_keyZreorderZ	cff_tabler   )rb   r1   r   ÚreorderGlyphsô   s:    ÿ&ÿ	



ÿrk   )<r7   Ú
__author__Z	fontToolsr   ZfontTools.ttLib.tablesr   r   ZotÚabcr   r   Údataclassesr   Úcollectionsr   Útypingr	   r
   r   r   r   r   r   rD   rB   Úintr$   r.   r/   r;   rE   Z	SinglePosZPairPosrO   Z
CursivePosZMarkBasePosZ
MarkLigPosZMarkMarkPosZ
ContextPosZChainContextPosZContextSubstZChainContextSubstZReverseChainSingleSubstZ
AttachListZLigCaretListZMarkGlyphSetsDefZMathGlyphInfoZMathItalicsCorrectionInfoZMathTopAccentAttachmentZMathKernInfoZMathVariantsrh   r9   r[   ZSubTablePathrW   ZAddToFrontierFnrV   r8   rk   r   r   r   r   Ú<module>   s  $
ý
  
 
   
 ÿ ÿü ÿþü	 ÿ ÿü 
   
 ý 
   
 ýý 
 
  
ÿ ÿÿ ÿÿþþû²] þ	  þ