
    ]MhŎ                     *   d Z ddlZddl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  ej        d          Zg d	Zd
 Zd Z G d dej                  Z G d d          ZddZedk    rddlZ ej         e                       dS dS )u6  MS VOLT ``.vtp`` to AFDKO ``.fea`` OpenType Layout converter.

Usage
-----

To convert a VTP project file:


.. code-block:: sh

    $ fonttools voltLib.voltToFea input.vtp output.fea

It is also possible convert font files with `TSIV` table (as saved from Volt),
in this case the glyph names used in the Volt project will be mapped to the
actual glyph names in the font files when written to the feature file:

.. code-block:: sh

    $ fonttools voltLib.voltToFea input.ttf output.fea

The ``--quiet`` option can be used to suppress warnings.

The ``--traceback`` can be used to get Python traceback in case of exceptions,
instead of suppressing the traceback.


Limitations
-----------

* Not all VOLT features are supported, the script will error if it it
  encounters something it does not understand. Please report an issue if this
  happens.
* AFDKO feature file syntax for mark positioning is awkward and does not allow
  setting the mark coverage. It also defines mark anchors globally, as a result
  some mark positioning lookups might cover many marks than what was in the VOLT
  file. This should not be an issue in practice, but if it is then the only way
  is to modify the VOLT file or the generated feature file manually to use unique
  mark anchors for each lookup.
* VOLT allows subtable breaks in any lookup type, but AFDKO feature file
  implementations vary in their support; currently AFDKO’s makeOTF supports
  subtable breaks in pair positioning lookups only, while FontTools’ feaLib
  support it for most substitution lookups and only some positioning lookups.
    N)StringIO)TopologicalSorter)ast)TTFont
TTLibError)ParserzfontTools.voltLib.voltToFea)GDEFGSUBGPOSc                 ,   g }t          | t          t          f          r(| D ]$}|                    t	          |                     %nMt          | d          r(|                    t	          | j                             n|                    |            |S )Nenum)
isinstancetuplelistextend_flatten_grouphasattrr   append)groupretitems      [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fontTools/voltLib/voltToFea.pyr   r   =   s    
C%%''  	- 	-DJJ~d++,,,,	-			 

>%*--....

5J    c                     d | D             d | D             }t          |          }fd|                                D             S )Nc                 B    i | ]}|j                                         |S  )namelower.0r   s     r   
<dictcomp>zsort_groups.<locals>.<dictcomp>M   s(    ???u!!##U???r   c                 p    i | ]3}|j                                         d  t          |          D             4S )c                 t    g | ]5}t          |t          j                  |j                                        6S r   )r   VAst	GroupNamer   r   r    xs     r   
<listcomp>z*sort_groups.<locals>.<dictcomp>.<listcomp>O   sD     
 
 
!T^,,
GMMOO
 
 
r   )r   r   r   r   s     r   r!   zsort_groups.<locals>.<dictcomp>N   s\         	
 
 
#E**
 
 
  r   c                      g | ]
}|         S r   r   )r    r   	group_maps     r   r(   zsort_groups.<locals>.<listcomp>W   s    >>>IdO>>>r   )r   static_order)groupsgraphsorterr*   s      @r   sort_groupsr/   L   sk    ?????I    E u%%F>>>>(;(;(=(=>>>>r   c                         e Zd Zd fd	Z xZS )LookupFNc                 \    t                                          |||           g | _        d S N)super__init__chained)selfr   use_extensionlocation	__class__s       r   r5   zLookup.__init__[   s*    }h777r   )FN)__name__
__module____qualname__r5   __classcell__)r:   s   @r   r1   r1   Z   s=                 r   r1   c                       e Zd Z ej        d          Z ej        d          ZddZd Zd Z	ddZ
d	 Zdd
Zd Zd Zd ZddZd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd ZdS )	VoltToFeaz[^A-Za-z_0-9.]z[^A-Za-z_0-9.\-]Nc                 T   t          |t          j                  r|d c| _        | _        nd |c| _        | _        || _        i | _        d | _        i | _        i | _	        i | _
        i | _        t                      | _        i | _        i | _        i | _        i | _        i | _        i | _        d S r3   )r   r$   VoltFile_doc_file_or_path_font
_glyph_map_glyph_order_gdef_glyphclasses	_features_lookupsset_marks
_ligatures_markclasses_anchors	_settings_lookup_names_class_names)r7   file_or_pathfonts      r   r5   zVoltToFea.__init__d   s    lDM22 	?,8$)DIt)),0,)DIt)
 
eer   c                     || j         vr`| j                            d|          }|| j                                         v r |dz  }|| j                                         v  || j         |<   | j         |         S N_)rR   _NOT_LOOKUP_NAME_REsubvaluesr7   r   ress      r   _lookupNamezVoltToFea._lookupName~   s    t)))*..sD99C+224444s
 +224444'*Dt$!$''r   c                     || j         vr`| j                            d|          }|| j                                         v r |dz  }|| j                                         v  || j         |<   | j         |         S rW   )rS   _NOT_CLASS_NAME_RErZ   r[   r\   s      r   
_classNamezVoltToFea._className   s    t((()--c488C*113333s
 *113333&)Dd# &&r   Fc                 h   |j         D ]1}t          |t          j                  r|                     |           2d |j         D             }t          |          D ]}|                     |           |j         D ]}t          |t          j                  rd|v r|                     |           6t          |t          j	                  r| 
                    ||           gt          |t          j        t          j        f          rt          |t          j                  r|                     |           t          |t          j                  st          |          |j         D ]I}t          |t          j                  r-|j        rd|vr(|j        rd|vr4|                     |           Jd S )Nc                 F    g | ]}t          |t          j                  |S r   )r   r$   GroupDefinition)r    ss     r   r(   z0VoltToFea._collectStatements.<locals>.<listcomp>   s*    SSSz!T=Q/R/RS!SSSr   r   r
   )
statementsr   r$   GlyphDefinition_glyphDefinitionr/   _groupDefinitionAnchorDefinition_anchorDefinitionSettingDefinition_settingDefinitionrd   ScriptDefinition_scriptDefinitionLookupDefinitionNotImplementedErrorposrZ   _lookupDefinition)r7   doctablesignore_unsupported_settings	statementr,   r   s          r   _collectStatementszVoltToFea._collectStatements   s    	1 	1I)T%9:: 1%%i000
 TSS^SSS (( 	) 	)E!!%(((( 	5 	5I)T%:;; 
5V##**9555It'=>> 5''	3NOOOOI(<d>R'STT 5It'<== 5&&y1111	4+@AA 5))4445
  	2 	2I)T%:;; 2= V6%9%9= V6%9%9&&y111	2 	2r   c           
      
    t          j                    }|j        } j        rS|                    t          j        d                     |                     j                                                    j        rj|                    t          j        d                     |                    d t           j        
                                          D                         j        rr|                    t          j        d                      j                                        D ]1}|                    |j                   |                    |           2 j                                        }|D ]u}||         }|D ]G}||         }	|	D ]}
 fd|	|
         D             |	|
<   d |	
                                D             ||<   Hd |
                                D             ||<   vd |
                                D             }|r|                    t          j        d	                     |
                                D ]\  }}t          j        |          }t          |d
           }|dk    r7t!          |          dk    r$t"                              d           |d d         }|D ]>}|dk    r,|j                            t          j        |                     t          ||         d           }|dk    r7t!          |          dk    r$t"                              d           |d d         }|D ]}
|dk    rK|
dk    rdnd}|j                            t          j        |
                    d          |                     ||         |
         D ]O} j        |                                         }t          j        |          }|j                            |           P@|                    |            j        rd|v rg }dD ]}| j        v rtd|                                z   }t          j        | j        |                   }|                    |           |                    t          j        |                     |                    d            t          j        d          }|j                            t          j        |            |                    |           |S )Nz# Glyph classesz
# Mark classesc              3   &   K   | ]}|d          V  dS    Nr   )r    cs     r   	<genexpr>z.VoltToFea._buildFeatureFile.<locals>.<genexpr>   s&      NNqadNNNNNNr   z

# Lookupsc                 J    g | ]}|                                 j        v | S r   )r   rK   )r    lr7   s     r   r(   z/VoltToFea._buildFeatureFile.<locals>.<listcomp>   s4     + + +!''))t}:T:T:T:T:Tr   c                     i | ]
\  }}|||S r   r   )r    tr   s      r   r!   z/VoltToFea._buildFeatureFile.<locals>.<dictcomp>   s#    &K&K&K1&Kq!&K&K&Kr   c                     i | ]
\  }}|||S r   r   )r    r   re   s      r   r!   z/VoltToFea._buildFeatureFile.<locals>.<dictcomp>   s#    $K$K$Kda$KQ$K$K$Kr   c                     i | ]
\  }}|||S r   r   )r    r   fs      r   r!   z/VoltToFea._buildFeatureFile.<locals>.<dictcomp>   s#    ;;;TQ;Aq;;;r   z
# Featuresc                     | dk    rdndS )NDFLTr   r|   r   ks    r   <lambda>z-VoltToFea._buildFeatureFile.<locals>.<lambda>   s    fAARS r   )keyaaltr|   zvFEA syntax does not allow script statements in 'aalt' feature, so only lookups from the first script will be included.c                     | dk    rdndS )Ndfltr   r|   r   r   s    r   r   z-VoltToFea._buildFeatureFile.<locals>.<lambda>   s    1;;aaA r   zzFEA syntax does not allow language statements in 'aalt' feature, so only lookups from the first language will be included.r   TF   )include_defaultr	   BASEMARKLIGATURE	COMPONENTGDEF_)r   FeatureFilerf   rI   r   Commentr   r[   rO   sorteditemsrK   r6   rJ   copyFeatureBlocklenlogwarningScriptStatementLanguageStatementljustr   LookupReferenceStatementrH   GlyphClassDefinitionGlyphClassName
TableBlockGlyphClassDefStatement)r7   ru   rt   rf   lookupfeaturesfeature_tagscripts
script_taglangslanguage_tagfeaturescript_tagslanguage_tagsr   r   	lookuprefclasses	classname
glyphclassgdefs   `                    r   _buildFeatureFilezVoltToFea._buildFeatureFile   sq   o^
 	;ck*;<<===d07799::: 	Ock*<==>>>NNF43D3J3J3L3L,M,MNNNNNN= 	*ck-88999-..00 * *!!&.111!!&)))) >&&((# 		L 		LK{+G% L L

+$)  L+ + + +#(#6+ + +E,'' 'L&K&K&K&K
##$K$Kgmmoo$K$K$KH[!!;;X^^%5%5;;; %	+ck,77888(0(8(8 #+ #+$W*;77$W2S2STTT&((S-=-=-A-AKKR   #.bqb/K"- A AJ"f,,*11#2Ej2Q2QRRR$*
+==% % %M #f,,]1C1Ca1G1GX   )6bqb(9(5 A A&&006Bf6L6LddRWO#.55 # 5$0$6$6q$9$94C!" !" !"   %,J$7$E A AD%)]4::<<%@F(+(DV(L(LI#.55i@@@@AA !!'****: 	$&F**GA ) )4:%% '$**,, 6I!$!9)TZPTEU!V!VJ%%j111NN3#5j#A#ABBBBNN4((((>&))DO""3#=w#GHHHd###
r   c                 P   | j         +t          | j                                                  | _         | j         }|t          }| j        | j                                        | _        |                     |||           | 	                    |          }|
                                S r3   )rC   
VoltParserrD   parseTABLESrE   getGlyphOrderrG   rx   r   asFea)r7   ru   rv   rt   feas        r   convertzVoltToFea.convert
  s    9"4#566<<>>DIi>F:! $
 8 8 : :DV-HIII$$V,,yy{{r   c                     	 |j         }n# t          $ r |}Y nw xY wt          j        | j                            ||                    S r3   )glyphAttributeErrorr   	GlyphNamerF   get)r7   r   r   s      r   
_glyphNamezVoltToFea._glyphName  sV    	;DD 	 	 	DDD	}T_00t<<===   
 c                     	 |j         }n# t          $ r |}Y nw xY wt          j        | j        |                                                   S r3   )r   r   r   r   rI   r   )r7   r   r   s      r   
_groupNamezVoltToFea._groupName  sU    	;DD 	 	 	DDD	!$"4TZZ\\"BCCCr   c                 D      fd|                                 D             S )Nc                     g | ]:}t          |t          t          j        f          r                    |          n|;S r   )r   strr$   r   r   r    r'   r7   s     r   r(   z'VoltToFea._glyphSet.<locals>.<listcomp>'  sP     
 
 
 $.a#t~1F#G#GNT__QQ
 
 
r   glyphSet)r7   r   s   ` r   	_glyphSetzVoltToFea._glyphSet&  s6    
 
 
 
]]__
 
 
 	
r   c                    g }|D ]}}t          |t          j                  r)|                    |                     |                     Ft          |t          j                  r)|                    |                     |                     t          |t          j                  r\|                     |j	        d          }|r|
                    |           |                    t          j        |                     t          |t          j                  rW|                     |          }|r|
                    |           G|                    t          j        |                     pt          |          |S NTflatten)r   r$   r   r   r   r%   r   Enum	_coverager   r   r   
GlyphClassRanger   rq   )r7   coverager   r   r   s        r   r   zVoltToFea._coverage,  s[    	0 	0D$// 0T__T223333D$.11 0T__T223333D$),, 0~~di~>> 7LL&&&&LL!5!56666D$*-- 0~~d++ 7LL&&&&LL!5!56666)$///r   c                     g }|D ]^}|                      |d          }t          |          dk    rt          j        |          }n|d         }|                    |           _|S )NTr   r|   r   )r   r   r   r   r   )r7   contextoutr   r   s        r   _contextzVoltToFea._contextC  sp     	! 	!D~~dD~99H8}}q  >(33#A;JJx    
r   c                    |                      |j                  }|                     |j        j        d          }t	          j        |          }t	          j        ||          }|| j        |j                                        <   d S r   )	ra   r   r   r   r   r   r   rI   r   )r7   r   r   glyphsr   classdefs         r   ri   zVoltToFea._groupDefinitionN  sp    uz**
>>^F++
+D*==195:++--...r   c                    	 | j         |j                 | j        |j        <   n# t          $ r Y nw xY w|j        dv rp|j        | j        vr t          j                    | j        |j        <   | j        |j                 j	        
                    |                     |j                             |j        dk    r!| j                            |j                   d S |j        dk    r|j        | j        |j        <   d S d S )Nr   r   r   )rG   idrF   r   	TypeErrortyperH   r   r   r   r   r   rM   add
componentsrN   )r7   r   s     r   rh   zVoltToFea._glyphDefinitionU  s    	*.*;EH*EDOEJ'' 	 	 	D	 :BBBz++),)9)9
5:&Juz")001L1LMMM:KOOEJ'''''Z:%%*/*:DOEJ''' &%s   " 
//c                 \   |j         }|j        D ]}|j         }|j        D ]}d |j        D             }|j         }|| j        vr
i | j        |<   || j        |         vri | j        |         |<   || j        |         |         vsJ |                                | j        |         |         |<   d S )Nc                 F    i | ]}|                     d           d         dS )\r   T)split)r    r   s     r   r!   z/VoltToFea._scriptDefinition.<locals>.<dictcomp>j  s)    KKKa1774==+TKKKr   )tagr   r   lookupsrJ   keys)r7   scriptstaglangltagr   r   ftags           r   ro   zVoltToFea._scriptDefinitione  s    zL 
	B 
	BD8D= B BKK7?KKK{t~--+-DN4(t~d33313DN4(.4>$#7#=====3:<<>>t$T*400B
	B 
	Br   c                     |j                             d          r|j        | j        |j         <   d S |s$t                              d|j                     d S d S )N	COMPILER_zUnsupported setting ignored: )r   
startswithvaluerQ   r   r   )r7   settingignore_unsupporteds      r   rm   zVoltToFea._settingDefinitions  si    <"";// 	H+2=DN7<(((# 	HKKFFFGGGGG	H 	Hr   c                     |\  }}}}}}|r|                                 pd }|r|                                 pd }	|r|                                 pd }
t          j        ||||	|
|          S )N)
xPlacement
yPlacementxAdvance
xPlaDevice
yPlaDevice
xAdvDevice)r   r   ValueRecord)r7   
adjustmentadvdxdyadv_adjust_bydx_adjust_bydy_adjust_by
adv_device	dx_device	dy_devices              r   _adjustmentzVoltToFea._adjustmenty  s    AK>R]L,"<}':':'<'<D
 9\%7%7%9%9AT	 9\%7%7%9%9AT	  !
 
 
 	
r   c                     |\  }}}}}}|rJ |r|                                 pd }|r|                                 pd }	t          j        |pd|pd|pd |	pd           S )Nr   )xDeviceTableyDeviceTable)r   r   Anchor)
r7   r   r  r  r  r  r  r  r  r	  s
             r   _anchorzVoltToFea._anchor  s    AK>R]L,     9\%7%7%9%9AT	 9\%7%7%9%9AT	zG!G!"*d"*d	
 
 
 	
r   c                    |j         }|j        }|                     |j                  }|| j        vr
i | j        |<   |                    d          r(|d d         |dd                                          z   }n|                                }|| j        |         vri | j        |         |<   || j        |         |         |j        <   d S )NMARK_   )r   
glyph_namer  rr   rP   r   r   	component)r7   	anchordef
anchorname	glyphnameanchors        r   rk   zVoltToFea._anchorDefinition  s    ^
(	im,,DM))')DM)$  )) 	,#BQB*QRR.*>*>*@*@@JJ#))++JT]955535DM)$Z0DJi ,Y-@AAAr   c           
      D    |j         }|j        }t          |t          j                  r%|j                                        D ]\  \  }}\  }}|j        |dz
           }	|j        |dz
           }
d}|	|
z   D ]}t          |t          j	                  sd} 
                    |	          } 
                    |
          }                     |          }                     |          }t          |          dk    sJ t          |          dk    sJ |                    t          j        |d         ||d         ||                     
d S t          |t          j                  r|j        D ]w\  }} 
                    |          }                     |          }t          |          dk    sJ |                    t          j        |d         |fgg g d                     xd S t          |t          j                  ri }t)                      }|j        D ]t\  }}                     | d|j                   }t          j        |          }|                                }t)                      }|D ])}|                    |                                           *|                    |          s|                    |           |s|                    |           |D ]U}                     |          } j        |         d|          d         }t          j         |||          } |  j!        ||f<   V|j"        D ]K}!|!                                D ]4}"|"|vrg ||"<   ||f||"         vr||"                             ||f           5LvtG           fd|D                       }#tG           fd	|D                       }$|D ].}"d}%|#r j$        |"         }%d
 tK          |%          D             }||"         D ]}\  }}t          j        |          }tK          d|%dz             D ]P}&|& j        |"         |         v r9 j        |"         |         |&         }||&dz
                               ||f           Q~                     |"          }!|$rt          j&        |!|d                   }n3|#rt          j'        |!|          }nt          j(        |!|d                   }|                    |           0d S t          |t          j)                  r{g }'|j*        D ]3}|D ].}!|!                                D ]}"|'                    |"           /4g }(|j+        D ]3}|D ].}!|!                                D ]}"|(                    |"           /4|'D ]}"                     |"          } j        |"         d         d         })d }*|"|(v rA j        |"         d         d         }*|(,                    |(-                    |"                     |                    t          j.        ||)|*                     |(D ]Y}"                     |"          } j        |"         d         d         }*|                    t          j.        |d |*                     Zd S t_          |          )Nr|   FTr   )
enumerated.r  c              3   *   K   | ]}|j         v V  d S r3   )rN   r    nr7   s     r   r~   z(VoltToFea._gposLookup.<locals>.<genexpr>  s*      DDqa4?2DDDDDDr   c              3   *   K   | ]}|j         v V  d S r3   )rM   r  s     r   r~   z(VoltToFea._gposLookup.<locals>.<genexpr>  s*      <<q!t{*<<<<<<r   c                     g | ]}g S r   r   )r    rX   s     r   r(   z)VoltToFea._gposLookup.<locals>.<listcomp>  s    777777r   entryexit)0rf   rr   r   r$   PositionAdjustPairDefinitionadjust_pairr   coverages_1coverages_2r%   r   r
  r   r   r   PairPosStatementPositionAdjustSingleDefinitionadjust_singleSinglePosStatementPositionAttachDefinitionrL   coverage_tora   r   	MarkClassr   updater   
isdisjointdifference_updater   rP   MarkClassDefinitionrO   r   allrN   rangeMarkMarkPosStatementMarkLigPosStatementMarkBasePosStatementPositionAttachCursiveDefinitioncoverages_entercoverages_exitpopindexCursivePosStatementrq   )+r7   r   	fealookuprf   rr   idx1idx2pos1pos2
coverage_1
coverage_2r  r   glyphs1glyphs2record1record2abr   recordanchorsallmarksr   r  r   	markclassmarksmarkr  r   r  markdefbaser   is_ligatureis_markr   r  enter_coverageexit_coverager!  r"  s+   `                                          r   _gposLookupzVoltToFea._gposLookup  s   )
jc4<== 	+.1o.C.C.E.E  *tltT _TAX6
 _TAX6
 #
&3 * *D%dDN;; *%)
..44..44**400**4007||q((((7||q((((!!(
GWQZZ     # , T@AA h	+)  1**))!,,6{{a''''!!*VAY,?+@"b%PP   	  T:;; `	+GuuH(+ &J &J$* !OOz,I,IFK,I,IJJ	M)44	 (--//
 $ 2 2DLL1111''11 !++H555  ! &&&!& H HI OOI66E!]956Jj6J6JKANF!5iOOG@GD%y)&<==L J JD $ J Jw..,.GDM&	2'$-GG#DM00*i1HIII	JJ DDDDGDDDDDK<<<<G<<<<<G ( (
 7!%!6J77U:%6%6777'.t} M MOD) #i 8 8I%*1j1n%=%= M M	$d(;D(AAA%)]4%8%>y%IF!)a-0778KLLLM
 t,, D3D%(CCDD  D24??DD3D%(CCD!!$'''')( (* TABB 	+N/ 4 4$ 4 4D $ 4 4&--d333344 M. 3 3$ 3 3D $ 3 3%,,T222233 ' O O--d+G4Q7=((=.v6q9D!%%m&9&9$&?&?@@@!!#"9%"M"MNNNN & N N--}T*6215!!#"9%t"L"LMMMMN N
 &c***r   c                 $   |j         }|j        }t          |t          j                  r|j                                        D ]\  \  }	}
\  }}|                     |j        |	dz
                     }|                     |j	        |
dz
                     }t          |          dk    sJ t          |          dk    sJ |d         |d         f}|rt          j        |||fg          }nt          j        |||||g          }|                    |           d S t          |t          j                  rt          j                    g}|j        D ]5\  }}|d                             |                     |d                     6|rt          j        |||fg          }nt          j        ||||g          }|                    |           d S t          |t          j                  rt          j                    g}|j        D ]5\  }}|d                             |                     |d                     6|rt          j        |||fg          }nt          j        ||||g          }|                    |           d S t+          |          )Nr|   r   Tr   )rf   rr   r   r$   r#  r$  r   r   r%  r&  r   r   IgnorePosStatementChainContextPosStatementr   r(  r   r)  r   r+  r,  rq   )r7   r   prefixsuffixignorer=  r6   rf   rr   r>  r?  r@  rA  rD  rE  r   rw   rH  rX   r   s                       r   _gposContextLookupzVoltToFea._gposContextLookup+  s   )
jc4<== (	+.1o.C.C.E.E - -*tltT..)BCC..)BCC7||q((((7||q((((!!*gaj1  # 68P7Q R RII # <'0B! !I !!),,,,- - T@AA 	+n&&'F) B B1q	  4!@!@AAAA 2VVV4L3MNN		8FFWI 	 i(((((T:;; 	+n&&'F" I I!q	  $!G!GHHHH 2VVV4L3MNN		8FFWI 	 i(((((%c***r   c                 	    |j         }|j        }t          |t          j                  ri }|j                                        D ]'\  }}|r|s/|j        \  }}	}
t          	                    | d|	 d|
 d           9 
                    |          } 
                    |          }t          |          dk    sJ t          |d                                         |d                                                   D ]n\  }}|                    t                               |                    g                               t                               |                               o)|                                D ]C\  }}t%          j        g |g t%          j        |                    }|                    |           Dd S |j                                        D ]\  }}|r|s/|j        \  }}	}
t          	                    | d|	 d|
 d           9 
                    |          } 
                    |          }t          |t          j                  rVt          |          dk    sJ t          |          dk    sJ |                    t%          j        ||g g d                     t          |t          j                  rt          |t          j                  rGt          |          dk    sJ |                    t%          j        g |d         g |                     Ot          |t          j                  rst          |          dk    sJ t%          j        g |g |d         d          }t9          d |D                       dk    r	t;          fd|D                       sJ d |D             }fd	|D             }|d                                         }t          |          dk    r|d         gz  }t          |          k    sJ |                    t%          j        d
|                      t          g ||R  D ]I} fd|D             }|                    t%          j        g |d d         g |d         d                     J|                    |           t?          |          d S )N:: Ignoring empty substitutionr|   r   Fc              3   X   K   | ]%}t          |                                          V  &d S r3   r   r   r&   s     r   r~   z(VoltToFea._gsubLookup.<locals>.<genexpr>  s2      ::aAJJLL))::::::r   c              3   b   K   | ])}t          |                                          d fv V  *dS r{   rb  r    r'   r  s     r   r~   z(VoltToFea._gsubLookup.<locals>.<genexpr>  s<      KKqs1::<<00QF:KKKKKKr   c                 6    g | ]}|                                 S r   r   r&   s     r   r(   z)VoltToFea._gsubLookup.<locals>.<listcomp>  s     ;;;qajjll;;;r   c                 R    g | ]#}t          |          d k    r|d         gz  n|$S )r|   r   )r   rd  s     r   r(   z)VoltToFea._gsubLookup.<locals>.<listcomp>  s5    QQQQSVVq[[!vzzaQQQr   # c                 :    g | ]}                     |          S r   )r   r   s     r   r(   z)VoltToFea._gsubLookup.<locals>.<listcomp>  s%    !E!E!E$//!"4"4!E!E!Er   ) rf   rZ   r   r$   SubstitutionAlternateDefinitionmappingr   r9   r   r   r   r   zipr   
setdefaultr   r   r   r   AlternateSubstStatementr   SubstitutionSingleDefinitionSingleSubstStatement+SubstitutionReverseChainingSingleDefinitionSubstitutionMultipleDefinitionMultipleSubstStatementSubstitutionLigatureDefinitionLigatureSubstStatementmaxr2  r   rq   )r7   r   r=  rf   rZ   
alternatesr   valpathlinecolumnr   replacements	src_glyph
repl_glyphr   rw   replacementzippedr  s   `                  @r   _gsubLookupzVoltToFea._gsubLookupY  s\   )
j
 c4?@@ 	JK--//  S # ),&D$KK4 V V$ V V V V VWWW,,#~~c226{{a''''-01I&&((,q/*B*B*D*D. .  )Iz ))#dooi.H.H*I*I2NNUUDOOJ7788    (2'7'7'9'9 - -#|7r3>,#?#? 	 !!),,,,F))++ =	/ =	/HC c %(\"dFtRRdRRVRRRSSS^^C((F>>#..L#t@AA 6/6{{a''''<((A----!!,V\2r5QQ    C!QRR 0/C!DEE -/6{{a''''!!.r6!9b,OO    C!DEE (/<((A----6LOU 	 ::6:::::q55KKKKFKKKKKKKK;;F;;;FQQQQ&QQQF #/q/":":"<"<K;''1,,'21~&6&:{++q0000 %%ck2By2B2B&C&CDDD"%";v";{";";";  !E!E!E!Ef!E!E!E"))6 "F3B3KVBZ     %%i0000)#...{=	/ =	/r   c           	      d   |j         }|j        }t          |t          j                  r|j                                        D ]\  }	}
|	r|
s/|j        \  }}}t          	                    | d| d| d           8| 
                    |	          }| 
                    |
          }|                    t          j        ||||                     g |_        d S t          |t          j        t          j        t          j        t          j        f          st'          t)          |                    g }|j                                        D ]b\  }	}
|	r|
s/|j        \  }}}t          	                    | d| d| d           8|                    | 
                    |	d                     ct-          |          dk    rt          j        |          g}|r-|                    t          j        |||fg                     d S |                    t          j        ||||g                     d S )Nr_  r`  Tr   r|   )rf   rZ   r   r$   rq  rk  r   r9   r   r   r   r   r    ReverseChainSingleSubstStatementr6   ro  rr  rt  rj  rq   r   r   r   r   IgnoreSubstStatementChainContextSubstStatement)r7   r   rZ  r[  r\  r=  r6   rf   rZ   r   rx  ry  rz  r{  r   r|  s                   r   _gsubContextLookupzVoltToFea._gsubContextLookup  sg   )
jc4KLL 	K--//  S # ),&D$KK4 V V$ V V V V VWWW,,#~~c22!!8    
 !#IF1334	
 
 		1 &d3ii000))++ 	= 	=HC c %(\"dFtRRdRRVRRRSSSMM$..d.;;<<<<v;;??nV,,-F 	c68P7QRRSSSSS.vvvyQQ    r   c           	         d }d }d}|j         dk    r|dz  }|j        s|dz  }|j        s|dz  }nVt          |j        t                    r|                     |j                  }n!|j        |                     |j                  }d }|s||t          j        |||          }d}| j	        
                    d          rd}d	|j        v rK|j                            d	          d         }|                                | j        vrut          |                     |          |
          }||j                            |           |j                            t          j        d|j        z                        n~| j        |                                         }|j                            t          j                               |j                            t          j        d|j        z                        || j        |                                <   nft          |                     |j                  |
          }||j                            |           || j        |j                                        <   |j        4|j                            t          j        d|j        z                        g }	|j        D ]}
|                     |
j                  }|                     |
j                  }|
j        dk    }|	                    |||g           |r0t7          |j                  dk    r|	                    g g dg           |	rt          j        |                     |j        dz             |
          }|j                            |           |j        |                     ||           n|j         | !                    ||           |	D ]I\  }}}|j        | "                    ||||||           (|j         | #                    ||||||           Jd S |j        |                     ||           d S |j         | !                    ||           d S d S )Nr   RTLr|         FCOMPILER_USEEXTENSIONLOOKUPSTr   )r8   rg  EXCEPT_CONTEXTz chained)$	directionprocess_baseprocess_marksr   r   r   mark_glyph_setr   LookupFlagStatementrQ   r   r   r   r   rK   r1   r^   rf   r   r   SubtableStatementcommentsr   r   leftrightex_or_inr   LookupBlockr6   rZ   r  rr   rV  r  r]  )r7   r   mark_attachementmark_filteringflagslookupflagsr8   r   r=  contextsr   rZ  r[  r\  r6   s                  r   rs   zVoltToFea._lookupDefinition  s   u$$QJE" 	QJE # 	DQJEE,c22 	D#v/CDD".!__V-BCCN 	$0N4N1' K ><== 	! M6; ;$$T**1-Dzz||4=00"$$T**"/  	 *(//<<<$++CKv{8J,K,KLLLL M$**,,7	$++C,A,C,CDDD$++CKv{8J,K,KLLL*3DM$**,,''  --+  I &$++K8881:DM&+++--.?& ''D6?4J(K(KLLL~ 	1 	1G]]7<00F]]7=11F%)99FOOVVV4555  1#fn--22R000 	4o  z!9::+  G $$W---z%  1111'  111*2  &:)++	7    Z+++	7    z%  33333'  33333 ('r   r3   )F)NF)r;   r<   r=   recompilerY   r`   r5   r^   ra   rx   r   r   r   r   r   r   r   ri   rh   ro   rm   r
  r  rk   rV  r]  r  r  rs   r   r   r   r@   r@   `   s       $"*%677#$788   4( ( (' ' '"2 "2 "2 "2HV V Vp   > > >D D D
 
 
   .	 	 	: : :; ; ; B B BH H H H
 
 
 
 
 
K K KC+ C+ C+J,+ ,+ ,+\]/ ]/ ]/~0 0 0d]4 ]4 ]4 ]4 ]4r   r@   c           
         ddl }ddlm} ddlm} |                    dt          j                  }|                    dd|d	
           |                    dd|d
           |                    dddt          dd           |                    dddd           |                    ddd           |
                    |           } ||j        rdnd           |j        }d}	 t          |          }d|v r.t          |d         j                            d                    }nt"                              d            d!S n# t&          $ r Y nw xY wt)          ||          }	 |                    |j                  }	n# t.          $ r}}
|j        r t3          |
j        d         d"d          }d#|
 d$}|r,|\  }}}t"                              | d%| d%| d&|            nt"                              |           Y d}
~
d!S d}
~
ww xY wt7          |j        d'          5 }|                    |	           ddd           dS # 1 swxY w Y   dS )(z'Convert MS VOLT to AFDKO feature files.r   N)Path)configLoggerzfonttools voltLib.voltToFea)descriptioninputINPUTzinput font/VTP file to process)metavarr   helpfeaturefileOUTPUTzoutput feature filez-tz--tabler   ru   z:List of tables to write, by default all tables are written)actionchoicesdestr  z-qz--quiet
store_truezSuppress non-error messages)r  r  z--tracebacku   Don’t catch exceptionsERRORINFO)levelTSIVzutf-8z6"TSIV" table is missing, font was not saved from VOLT?r|   r9   "z" is not supportedr_  z: w)argparsepathlibr  	fontToolsr  ArgumentParsermain__doc__add_argumentr   
parse_argsquietr  r   r   datadecoder   errorr   r@   r   ru   rq   	tracebackgetattrargsopenr  write)r  r  r  r  parseroptionsrT   rU   	converterr   er9   messagery  rz  r{  feafiles                    r   r  r  J  sQ    OOO&&&&&&$$%4< %  F t2R     xd9N     I     i3P     l1K     %%GL7=<f>>>>=LDl##T>>#DL$5$<$<W$E$EFFLLIINOOO1      ,--I// 
 
 
 	16!9j$77+a+++ 	!)D$II::::v::::;;;;IIgqqqqq
 
g!3	'	' 7c                 s>   )AE 
EE(F 
H
A2HH
"II	I	__main__r3   )r  loggingr  ior   graphlibr   fontTools.feaLibr   fontTools.ttLibr   r   fontTools.voltLibr$   fontTools.voltLib.parserr   r   	getLoggerr   r   r   r/   r  r1   r@   r  r;   sysr"  r   r   r   <module>r     s  + +Z  				       & & & & & &             . . . . . . . . ) ) ) ) ) ) 9 9 9 9 9 9g566	!	!	!	 	 	? ? ?    S_   g4 g4 g4 g4 g4 g4 g4 g4T? ? ? ?D zJJJCHTTVV r   