
    }f'                        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mZmZ d
Zdeegef         dee         deee                  fdZdededefdZ G d de	          Z ed           G d de                      Z ed           G d de                      Z i ej!        df e            gej!        df ed          gej"        df ed          gej#        d f e d!d"#          gej"        df e            gej$        df ed$          gej%        df ed%d&'           ed(d)'          gej&        df ed%d&'           ed*d+'          gej'        df ed,d-'           ed.d/'          gej(        df ed0          gej(        df e            gej(        d1f e            gej)        df ed2          gej)        df e            gej)        d1f ed34           ed54           ed64          gej*        df ed7          gej*        df e            gej*        d1f e            gej+        df ed8          gej+        df e            gej+        d1f ed34           ed54           ed64          gej,        df ed9           ed34           ed64          gej-        d f ed:          gej.        d f ed;          gej/        d f e            gej0        d f ed<4          gej1        d f ed=          gej2        d f ed>d?'          gej3        d f ed@dA'          gej4        d f edBdC'           edDdE'          giZ5eej6        j7        dFf         Z8dGej6        dHedee8         fdIZ9eee8         ee8         gd f         Z:dGej6        dHedJe:dee8         fdKZ;dLej<        dMee         fdNZ=d S )OzReorder glyphs in a font.zRod Sheeter    )ttLib)otBase)otTables)ABCabstractmethod)	dataclass)deque)	OptionalAnyCallableDequeIterableList
NamedTupleTupleUnionCoverageget_glyph_idglyphsparallel_listc                      |rSt          d t          ||          D              fd          }t          t          t          |           \  }}||d d <   nt          |           }||d d <   d S )Nc              3   $   K   | ]\  }}||fV  d S N ).0ges      V/var/www/rtfcompare/venv/lib/python3.11/site-packages/fontTools/ttLib/reorderGlyphs.py	<genexpr>z_sort_by_gid.<locals>.<genexpr>&   s*      ;;1aV;;;;;;    c                 &     | d                   S )Nr   r   )tr   s    r   <lambda>z_sort_by_gid.<locals>.<lambda>'   s    ,,qt,, r    key)sortedzipmaplist)r   r   r   	reorderedsorted_glyphssorted_parallel_lists   `     r   _sort_by_gidr-      s    
  9;;FM : :;;;,,,,
 
 
	 /2$Y.H.H++/aaav<888F111IIIr    valuedotted_attrreturnc                     |                     d          }|sJ |r'|                    d          }t          | |          } |'| S )N.r   )splitpopgetattr)r.   r/   
attr_names	attr_names       r   _get_dotted_attrr8   1   sZ    ""3''J
 *NN1%%	y))  * Lr    c                   J    e Zd ZdZedej        dej        ddfd            Z	dS )ReorderRulezEA rule to reorder something in a font to match the fonts glyph order.fontr.   r0   Nc                     d S r   r   )selfr;   r.   s      r   applyzReorderRule.apply>   s    JM#r    )
__name__
__module____qualname____doc__r   r   TTFontr   	BaseTabler>   r   r    r   r:   r:   ;   s@        OOM%,Mv/?MDMMM ^MMMr    r:   T)frozenc                   d    e Zd ZU dZdZee         ed<   eZ	eed<   de
j        dej        ddfdZdS )	ReorderCoveragezNReorder a Coverage table, and optionally a list that is sorted parallel to it.Nparallel_list_attrcoverage_attrr;   r.   r0   c                    t          || j                  }t          |          t          urd }| j        rlt          || j                  }t          |          t          u sJ | j         d            t          |          t          |j                  k    s
J d            t          |j        |j        |           d S | j        rJ d|              |D ]}t          |j        |j        d            d S )N should be a listzNothing makes sensez2Can't have multiple coverage AND a parallel list; )	r8   rI   typer)   rH   lenr   r-   
getGlyphID)r=   r;   r.   coverager   coverage_entrys         r   r>   zReorderCoverage.applyJ   s*   #E4+=>>>>%% M& Y 08O P P''4///-@@@ 0//=))S-A-AAAACXAAA(/=IIIII
 +K KJDJJK K K #+ K KT_n.CTJJJJK Kr    )r?   r@   rA   rB   rH   r
   str__annotations___COVERAGE_ATTRrI   r   rC   r   rD   r>   r   r    r   rG   rG   B   sz         XX )-,,,'M3'''K%, Kv/? KD K K K K K Kr    rG   c                   P    e Zd ZU dZeed<   eed<   dej        dej	        ddf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%   r;   r.   r0   Nc                      t          | j                  }t          |t                    sJ  j         d            |                     fd           d S )NrK   c                 T                         t          | j                            S r   )rN   r5   r%   )vr;   r=   s    r   r#   z#ReorderList.apply.<locals>.<lambda>p   s    twq$(/C/CDD r    r$   )r8   rV   
isinstancer)   sort)r=   r;   r.   lsts   ``  r   r>   zReorderList.applym   se    udn55#t$$JJ&J&J&JJJJDDDDDEEEEEr    )r?   r@   rA   rB   rQ   rR   r   rC   r   rD   r>   r   r    r   rU   rU   b   sk           NNN	HHHF%, Fv/? FD F F F F F Fr    rU         Value)rH   PairSetNPairValueRecordSecondGlyphr$   EntryExitRecordMarkCoveragezMarkArray.MarkRecord)rI   rH   BaseCoveragezBaseArray.BaseRecordLigatureCoveragezLigatureArray.LigatureAttachMark1CoveragezMark1Array.MarkRecordMark2CoveragezMark2Array.Mark2Record
PosRuleSet   ChainPosRuleSetBacktrackCoverage)rI   InputCoverageLookAheadCoverage
SubRuleSetChainSubRuleSet
SubstituteAttachPointLigGlyphExtendedShapeCoverageItalicsCorrectionTopAccentCoverageTopAccentAttachmentMathKernCoverageMathKernInfoRecordsVertGlyphCoverageVertGlyphConstructionHorizGlyphCoverageHorizGlyphConstruction.rootroot_accessorc              #   :   K   t          | |d           E d {V  d S )Nc                 ,    |                      |          S r   )extend)frontiernews     r   r#   z!_bfs_base_table.<locals>.<lambda>   s    8??33G3G r    )_traverse_ot_data)r~   r   s     r   _bfs_base_tabler      sM       !mGG          r    add_to_frontier_fnc              #   `  K   t                      }|                    t          j                            ||           f           |rg|                                }|d         j        }|V  g }|                                D ]}|                    ||fz               |||           |ed S d S )N)r	   appendr   rD   SubTableEntrypopleftr.   iterSubTables)r~   r   r   r   pathcurrentnew_entriessubtable_entrys           r   r   r      s      
 %*GGHOOV%33M4HHJKKK
 2!!r(.


%3355 	9 	9Nt~&7788888[111  2 2 2 2 2r    r;   new_glyph_orderc           	                                            }t          |          t          |          k    r0t          dt          |           dt          |           d          t          |          t          |          k    rOt          dt          |          t          |          z
   dt          |          t          |          z
                                               t           fd                                 D                       }|rt          d|                                |           h d}|D ]}|                                 v rt           |         j	        d	| d
          D ]c}|d         j
        }t          |          t          |dd           f}t                              |g           D ]}	|	                     |           dd 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   F   K   | ]}                     |          |V  d S r   )isLoaded)r   r"   r;   s     r   r   z reorderGlyphs.<locals>.<genexpr>	  s4      GGadmmA6F6FGGGGGGGr    z/Everything should be loaded, following aren't: >   GDEFGPOSGSUBMATHzfont["z"]r   Format)getGlyphOrderrM   
ValueErrorsetensureDecompiledr&   keyssetGlyphOrderr   tabler.   rL   r5   _REORDER_RULESgetr>   )
r;   r   old_glyph_order
not_loadedcoverage_containerstagr   r.   reorder_keyreorders
   `         r   reorderGlyphsr      s)   ((**O
?s?3333:O(<(< : :00: : :
 
 	

 ?s?3333L!/22S5I5IIL L!/22S5I5IIL L
 
 	
 	GGGG499;;GGGGGJ YW:WWXXX''':::" / /$))++'S	9I#9I9I9IJJ / /R#E{{GE8T,J,JK-11+rBB / /GMM$....// /r    )>rB   
__author__	fontToolsr   fontTools.ttLib.tablesr   r   otabcr   r   dataclassesr   collectionsr	   typingr
   r   r   r   r   r   r   r   r   rS   rQ   intr-   r8   r:   rG   rU   	SinglePosPairPosr`   
CursivePosMarkBasePos
MarkLigPosMarkMarkPos
ContextPosChainContextPosContextSubstChainContextSubstReverseChainSingleSubst
AttachListLigCaretListMarkGlyphSetsDefMathGlyphInfoMathItalicsCorrectionInfoMathTopAccentAttachmentMathKernInfoMathVariantsr   rD   r   SubTablePathr   AddToFrontierFnr   rC   r   r   r    r   <module>r      s     
       ) ) ) ) ) ) 1 1 1 1 1 1 # # # # # # # # ! ! ! ! ! !      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C5#:&I DI&   $C c c    N N N N N# N N N $K K K K Kk K K K> $F F F F F+ F F F$X\1))*X \17CCCDX ZOooCCCD	X
 Z%6MJJJKX ZOoo''(X ]A<MNNNOX ^Q(=S	
 	
 	
 	(=S	
 	
 	
	X  ]A(=S	
 	
 	
 	,=	
 	
 	
	!X2 ^Q)>U	
 	
 	
 	)>V	
 	
 	
	3XB ]ALIIIJCXD ]A**+EXF ]A**+GXH ooARSSSTIXJ oo//0KXL &9:::o666&9:::MXX _a??lKKKLYXZ _a??,,-[X\ _a??,,-1CT U U UV1 1 121&9:::o666&9::: 
 #<888&9:::&9:::& ]DOO}MMMN_dooLLLM$//"3"3!4t=TUUUV!4(+>???+ &-BW	
 	
 	
)
 _d,AV	
 	
 	

 _d-6	
 	
 	
 	.7	
 	
 	
	]X Xz V%3S89

+.l    E,/l1CDdJK2

2+.2DS2l2 2 2 2* /  /tCy  /  /  /  /  /  /r    