
    khŎ                     $   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j8                   e              yy)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 ]  }|j                  t	        |              |S t        | d      r&|j                  t	        | j                               |S |j                  |        |S )Nenum)
isinstancetuplelistextend_flatten_grouphasattrr   append)groupretitems      m/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/fontTools/voltLib/voltToFea.pyr   r   =   sw    
C%%' 	-DJJ~d+,	- J	 
	

>%**-. J 	

5J    c                    | D ci c]  }|j                   j                         | }}| D ci c]f  }|j                   j                         t        |      D cg c]6  }t        |t        j
                        r|j                  j                         8 c}h }}}t        |      }|j                         D cg c]  }||   	 c}S c c}w c c}w c c}}w c c}w N)	namelowerr   r   VAst	GroupNamer   r   static_order)groupsr   	group_mapxgraphsorterr   s          r   sort_groupsr&   L   s    8>?u!!#U*?I?   	

#E*
!T^^, GGMMO
 	
E  u%F(.(;(;(=>IdO>> @
 ?s"   "C+C;CC9CCc                         e Zd Zd fd	Z xZS )Lookupc                 6    t         |   |||       g | _        y r   )super__init__chained)selfr   use_extensionlocation	__class__s       r   r+   zLookup.__init__[   s    }h7r   )FN)__name__
__module____qualname__r+   __classcell__)r0   s   @r   r(   r(   Z   s     r   r(   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y)	VoltToFeaz[^A-Za-z_0-9.]z[^A-Za-z_0-9.\-]Nc                 J   t        |t        j                        r|d c| _        | _        nd |c| _        | _        || _        i | _        d | _        i | _        i | _	        i | _
        i | _        t               | _        i | _        i | _        i | _        i | _        i | _        i | _        y r   )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)r-   file_or_pathfonts      r   r+   zVoltToFea.__init__d   s    lDMM2,8$)DIt),0,)DIt)
 
er   c                    || j                   vri| j                  j                  d|      }|| j                   j                         v r"|dz  }|| j                   j                         v r"|| j                   |<   | j                   |   S N_)rH   _NOT_LOOKUP_NAME_REsubvaluesr-   r   ress      r   _lookupNamezVoltToFea._lookupName~   s    t)))**..sD9C++2244s
 ++2244'*Dt$!!$''r   c                    || j                   vri| j                  j                  d|      }|| j                   j                         v r"|dz  }|| j                   j                         v r"|| j                   |<   | j                   |   S rM   )rI   _NOT_CLASS_NAME_RErP   rQ   rR   s      r   
_classNamezVoltToFea._className   s    t((())--c48C**1133s
 **1133&)Dd#  &&r   c                    |j                   D ].  }t        |t        j                        s| j	                  |       0 |j                   D cg c]  }t        |t        j
                        s|! }}t        |      D ]  }| j                  |        |j                   D ]  }t        |t        j                        rd|v s"| j                  |       4t        |t        j                        r| j                  ||       at        |t        j                  t        j
                  f      rt        |t        j                        r| j                  |       t        |t        j                        rt        |       |j                   D ]P  }t        |t        j                        s|j                   rd|vr/|j"                  rd|vr@| j%                  |       R y c c}w )Nr   r
   )
statementsr   r   GlyphDefinition_glyphDefinitionGroupDefinitionr&   _groupDefinitionAnchorDefinition_anchorDefinitionSettingDefinition_settingDefinitionScriptDefinition_scriptDefinitionLookupDefinitionNotImplementedErrorposrP   _lookupDefinition)r-   doctablesignore_unsupported_settings	statementsr!   r   s           r   _collectStatementszVoltToFea._collectStatements   s    	1I)T%9%9:%%i0	1 !^^Sz!T=Q=Q/R!SS ( 	)E!!%(	)  	5I)T%:%:;V#**95It'='=>''	3NOI(<(<d>R>R'STIt'<'<=&&y1	4+@+@A))44	5  	2I)T%:%:;==V6%9==V6%9&&y1	2' Ts   G,Gc           
      8
   t        j                         }|j                  }| j                  rM|j	                  t        j
                  d             |j                  | j                  j                                | j                  r]|j	                  t        j
                  d             |j                  d t        | j                  j                               D               | j                  ro|j	                  t        j
                  d             | j                  j                         D ].  }|j                  |j                         |j	                  |       0 | j                  j                         }|D ]  }||   }|D ]k  }||   }	|	D ]5  }
|	|
   D cg c]!  }|j                         | j                  v s |# c}|	|
<   7 |	j                         D ci c]  \  }}|s	|| c}}||<   m |j                         D ci c]  \  }}|s	|| c}}||<    |j                         D ci c]  \  }}|s	|| }}}|r|j	                  t        j
                  d             |j                         D ]  \  }}t        j                   |      }t        |d       }|dk(  r(t#        |      d	kD  rt$        j'                  d
       |d d	 }|D ]"  }|dk7  r.|j                  j	                  t        j(                  |             t        ||   d       }|dk(  r(t#        |      d	kD  rt$        j'                  d       |d d	 }|D ]  }
|dk7  rH|
dk(  rdnd}|j                  j	                  t        j*                  |
j-                  d      |             ||   |
   D ]O  }| j                  |j                            }t        j.                  |      }|j                  j	                  |       Q  % |j	                  |        | j0                  rd|v rg }dD ]  }|| j0                  v rld|j                         z   }t        j2                  || j0                  |         }|j	                  |       |j	                  t        j4                  |             }|j	                  d         t        j6                  d      }|j                  j	                  t        j8                  |        |j	                  |       |S c c}w c c}}w c c}}w c c}}w )Nz# Glyph classesz
# Mark classesc              3   &   K   | ]	  }|d      yw   N ).0cs     r   	<genexpr>z.VoltToFea._buildFeatureFile.<locals>.<genexpr>   s     NqadNs   z

# Lookupsz
# Featuresc                     | dk(  rdS dS )NDFLTr   rq   rr   ks    r   <lambda>z-VoltToFea._buildFeatureFile.<locals>.<lambda>   s    fA RS r   )keyaaltrq   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S dS )Ndfltr   rq   rr   rx   s    r   rz   z-VoltToFea._buildFeatureFile.<locals>.<lambda>   s    1;a A 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   FeatureFilerY   r?   r   Commentr   rQ   rE   sorteditemsrA   r,   r@   copyr   FeatureBlocklenlogwarningScriptStatementLanguageStatementljustLookupReferenceStatementr>   GlyphClassDefinitionGlyphClassName
TableBlockGlyphClassDefStatement)r-   ri   rh   rY   lookupfeaturesfeature_tagscripts
script_taglangslanguage_tagltrl   ffeaturescript_tagslanguage_tagsr   r   	lookuprefclasses	classname
glyphclassgdefs                            r   _buildFeatureFilezVoltToFea._buildFeatureFile   s   oo^^
ckk*;<=d00779:ckk*<=>NF43D3D3J3J3L,MNN==ckk-89--..0 *!!&..1!!&)*
 >>&&(# 		LK{+G% L

+$) L#(#6+!'')t}}:T+E,' 9>&K1q!t&K
#L 7>mmo$KdaQT$KH[!		L &.^^%5;TQAqD;;ckk,78(0(8 #+$W**;7$W2ST&(S-=-AKKR #.bq/K"- AJ"f,**11#2E2Ej2QR$*
+=%M #f,]1Ca1GX )6bq(9(5 A&&06Bf6LdRWO#..55 # 5 5$0$6$6q$94C!" %,J$7$E AD%)]]4::<%@F(+(D(DV(LI#..55i@AAA4 !!'*G#+J ::&F*GA )4::% '$**, 6I!$!9!9)TZZPTEU!VJ%%j1NN3#5#5j#ABNN4() >>&)DOO""3#=#=w#GHd#
{+ 'L$K;s0   !T
:T

T

$T


TT1
T<Tc                 P   | j                   (t        | j                        j                         | _         | j                   }|t        }| j
                  | j
                  j                         | _        | j                  |||       | j                  |      }|j                         S r   )r9   
VoltParserr:   parseTABLESr;   getGlyphOrderr=   rm   r   asFea)r-   ri   rj   rh   feas        r   convertzVoltToFea.convert
  s    99"4#5#56<<>DIii>F::! $

 8 8 :DV-HI$$V,yy{r   c                     	 |j                   }t        j                  | j                  j                  ||            S # t        $ r |}Y <w xY wr   )glyphAttributeErrorr   	GlyphNamer<   get)r-   r   r   s      r   
_glyphNamezVoltToFea._glyphName  sH    	;;D }}T__00t<==  	D	s   = A
Ac                     	 |j                   }t        j                  | j                  |j                                  S # t        $ r |}Y =w xY wr   )r   r   r   r   r?   r   )r-   r   r   s      r   
_groupNamezVoltToFea._groupName  sJ    	;;D !!$"4"4TZZ\"BCC  	D	s   > AAc                     |j                         D cg c]5  }t        |t        t        j                  f      r| j                  |      n|7 c}S c c}w r   )glyphSetr   strr   r   r   )r-   r   r#   s      r   	_glyphSetzVoltToFea._glyphSet&  sJ     ]]_
 $.a#t~~1F#GT__QQN
 	
 
s   :Ac                    g }|D ]X  }t        |t        j                        r!|j                  | j	                  |             ?t        |t        j
                        r!|j                  | j                  |             zt        |t        j                        rV| j                  |j                  d      }|r|j                  |       |j                  t        j                  |             t        |t        j                        rL| j                  |      }|r|j                  |       *|j                  t        j                  |             Pt        |       |S NTflatten)r   r   r   r   r   r   r   Enum	_coverager   r   r   
GlyphClassRanger   re   )r-   coverager   r   r   s        r   r   zVoltToFea._coverage,  s     	0D$/T__T23D$..1T__T23D$)),~~dii~>LL&LL!56D$**-~~d+LL&LL!56)$//%	0& r   c                     g }|D ]O  }| j                  |d      }t        |      dkD  rt        j                  |      }n|d   }|j	                  |       Q |S )NTr   rq   r   )r   r   r   r   r   )r-   contextoutr   r   s        r   _contextzVoltToFea._contextC  s^     	!D~~dD~9H8}q >>(3#A;JJx 	! 
r   c                 ,   | j                  |j                        }| j                  |j                  j                  d      }t	        j
                  |      }t	        j                  ||      }|| j                  |j                  j                         <   y r   )	rW   r   r   r   r   r   r   r?   r   )r-   r   r   glyphsr   classdefs         r   r]   zVoltToFea._groupDefinitionN  sk    uzz*

>^^F+
++D*=195::++-.r   c                    	 | j                   |j                     | j                  |j                  <   |j
                  dv r|j
                  | j                  vr+t        j                         | j                  |j
                  <   | j                  |j
                     j                  j                  | j                  |j                               |j
                  dk(  r&| j                  j                  |j                         y |j
                  dk(  r$|j                  | j                  |j                  <   y y # t        $ r Y w xY w)Nr   r   r   )r=   idr<   r   	TypeErrortyper>   r   r   r   r   r   rC   add
componentsrD   )r-   r   s     r   r[   zVoltToFea._glyphDefinitionU  s    	*.*;*;EHH*EDOOEJJ' ::BBzz+),)9

5::&JJuzz"))001LM::KKOOEJJ'ZZ:%*/*:*:DOOEJJ' &  		s   0D7 7	EEc                    |j                   }|j                  D ]  }|j                   }|j                  D ]  }|j                  D ci c]  }|j	                  d      d   d }}|j                   }|| j
                  vri | j
                  |<   || j
                  |   vri | j
                  |   |<   || j
                  |   |   vsJ |j                         | j
                  |   |   |<     y c c}w )N\r   T)tagr   r   lookupssplitr@   keys)	r-   scriptstaglangltagr   r   r   ftags	            r   rc   zVoltToFea._scriptDefinitione  s    zzLL 
	BD88D== B;B??Ka1774=+T1KK{{t~~-+-DNN4(t~~d3313DNN4(.4>>$#7#====3:<<>t$T*40B
	B Ls   C-c                     |j                   j                  d      r$|j                  | j                  |j                   <   y |s#t        j                  d|j                           y y )N	COMPILER_zUnsupported setting ignored: )r   
startswithvaluerG   r   r   )r-   settingignore_unsupporteds      r   ra   zVoltToFea._settingDefinitions  sJ    <<"";/+2==DNN7<<(#KK7~FG $r   c                     |\  }}}}}}|xr |j                         xs d }|xr |j                         xs d }	|xr |j                         xs d }
t        j                  ||||	|
|      S )N)
xPlacement
yPlacementxAdvance
xPlaDevice
yPlaDevice
xAdvDevice)r   r   ValueRecord)r-   
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AT	 9\%7%7%9AT	  !
 	
r   c                     |\  }}}}}}|rJ |xr |j                         xs d }|xr |j                         xs d }	t        j                  |xs d|xs d|xs d |	xs d       S )Nr   )xDeviceTableyDeviceTable)r   r   Anchor)
r-   r   r   r   r   r   r   r   r   r   s
             r   _anchorzVoltToFea._anchor  s|    AK>R]L,    9\%7%7%9AT	 9\%7%7%9AT	zzG!G!"*d"*d	
 	
r   c                    |j                   }|j                  }| j                  |j                        }|| j                  vri | j                  |<   |j                  d      r|d d |dd  j                         z   }n|j                         }|| j                  |   vri | j                  |   |<   || j                  |   |   |j                  <   y )NMARK_   )r   
glyph_namer   rf   rF   r   r   	component)r-   	anchordef
anchorname	glyphnameanchors        r   r_   zVoltToFea._anchorDefinition  s    ^^
((	imm,DMM)')DMM)$  )#BQ*QR.*>*>*@@J#))+JT]]95535DMM)$Z0DJi ,Y-@-@Ar   c           
      \    |j                   }|j                  }t        |t        j                        r	|j
                  j                         D ]  \  \  }}\  }}|j                  |dz
     }	|j                  |dz
     }
d}|	|
z   D ]  }t        |t        j                        rd}!  j                  |	      } j                  |
      } j                  |      } j                  |      }t        |      dk(  sJ t        |      dk(  sJ |j                  t        j                  |d   ||d   ||              y t        |t        j                         rt|j"                  D ]d  \  }} j                  |      } j                  |      }t        |      dk(  sJ |j                  t        j$                  |d   |fgg g d             f y t        |t        j&                        ri }t)               }|j*                  D ]X  \  }} j-                  | d|j.                         }t        j0                  |      }|j3                         }t)               }|D ]!  }|j5                  |j7                                # |j9                  |      s|j;                  |       |s|j5                  |       |D ]S  } j=                  |      } j>                  |   d|    d   }t        j@                  |||      } |  jB                  ||f<   U |jD                  D ]@  }!|!j7                         D ]+  }"|"|vrg ||"<   ||f||"   vs||"   j                  ||f       - B [ tG         fd|D              }#tG         fd	|D              }$|D ]  }"d}%|#r jH                  |"   }%tK        |%      D &cg c]  }&g  }}&||"   D ]q  \  }}t        j0                  |      }tK        d|%dz         D ]E  }'|' j>                  |"   |   v s j>                  |"   |   |'   }||'dz
     j                  ||f       G s  j=                  |"      }!|$rt        jL                  |!|d         }n2|#rt        jN                  |!|      }nt        jP                  |!|d         }|j                  |        y t        |t        jR                        rbg }(|jT                  D ]/  }|D ](  }!|!j7                         D ]  }"|(j                  |"        * 1 g })|jV                  D ]/  }|D ](  }!|!j7                         D ]  }"|)j                  |"        * 1 |(D ]  }" j=                  |"      } j>                  |"   d
   d   }*d }+|"|)v r5 j>                  |"   d   d   }+|)jY                  |)j[                  |"             |j                  t        j\                  ||*|+              |)D ]N  }" j=                  |"      } j>                  |"   d   d   }+|j                  t        j\                  |d |+             P y t_        |      c c}&w )Nrq   FTr   )
enumerated.r   c              3   :   K   | ]  }|j                   v   y wr   )rD   rs   nr-   s     r   ru   z(VoltToFea._gposLookup.<locals>.<genexpr>  s     Dqa4??2D   c              3   :   K   | ]  }|j                   v   y wr   )rC   r  s     r   ru   z(VoltToFea._gposLookup.<locals>.<genexpr>  s     <q!t{{*<r  entryexit)0rY   rf   r   r   PositionAdjustPairDefinitionadjust_pairr   coverages_1coverages_2r   r   r   r   r   r   PairPosStatementPositionAdjustSingleDefinitionadjust_singleSinglePosStatementPositionAttachDefinitionrB   coverage_torW   r   	MarkClassr   updater   
isdisjointdifference_updater   rF   MarkClassDefinitionrE   r   allrD   rangeMarkMarkPosStatementMarkLigPosStatementMarkBasePosStatementPositionAttachCursiveDefinitioncoverages_entercoverages_exitpopindexCursivePosStatementre   ),r-   r   	fealookuprY   rf   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   rN   r  enter_coverageexit_coverager  r  s,   `                                           r   _gposLookupzVoltToFea._gposLookup  sP   ))
jjc4<<=.1oo.C.C.E *tltT __TAX6
 __TAX6
 #
&3 *D%dDNN;%)
* ..4..4**40**407|q(((7|q(((!!((
GWQZZ#, T@@A)) 1*))!,6{a'''!!**VAY,?+@"b%P	 T::;GuH(+ &J$* !OOzl!FKK=,IJ	MM)4	 (--/
 $ 2DLL12''1++H5  &!& HI OOI6E!]]95j\6JKANF!55iOG@GD%%y)&<=	H  LL JD $ Jw.,.GDM&	2'$-G#DM00*i1HI	JJC&JP DGDDK<G<<G (
!%!6J%*:%6777'.t} MOD) #i 8I%*1j1n%= M	$d(;D(AA%)]]4%8%>y%IF!)a-0778KLMM t,33D%(CD 224?D33D%(CD!!$')(* TAABN// 4$ 4D $ 4&--d3444 M.. 3$ 3D $ 3%,,T2333 ' O-d+G4Q7=(==.v6q9D!%%m&9&9$&?@!!#"9"9%"MNO & N-}}T*6215!!#"9"9%t"LMN
 &c**] 8s   )	X)c                    |j                   }|j                  }t        |t        j                        r|j
                  j                         D ]  \  \  }	}
\  }}| j                  |j                  |	dz
           }| j                  |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      }|j                  |        y t        |t        j                        rt        j                          g}|j"                  D ]*  \  }}|d   j%                  | j                  |d             , |rt        j                  |||fg      }nt        j                  ||||g      }|j                  |       y t        |t        j&                        rt        j                          g}|j(                  D ]*  \  }}|d   j%                  | j                  |d             , |rt        j                  |||fg      }nt        j                  ||||g      }|j                  |       y t+        |      )Nrq   r   Tr   )rY   rf   r   r   r  r  r   r   r  r  r   r   IgnorePosStatementChainContextPosStatementr   r  r   r  r   r  r  re   )r-   r   prefixsuffixignorer+  r,   rY   rf   r,  r-  r.  r/  r2  r3  r   rk   r6  rN   r   s                       r   _gposContextLookupzVoltToFea._gposContextLookup+  sW   ))
jjc4<<=.1oo.C.C.E -*tltT..)BC..)BC7|q(((7|q(((!!*gaj1 # 6 68P7Q RI # < <'0B!I !!),- T@@Ann&'F)) B1q	  4!@AB 22VVV4L3MN	88FFWI	 i(T::;nn&'F" I!q	  $!GHI 22VVV4L3MN	88FFWI	 i(%c**r   c                 	   |j                   }|j                  }t        |t        j                        rei }|j
                  j                         D ]  \  }}|r|s/|j                  \  }}	}
t        j                  | d|	 d|
 d       9| j                  |      }| j                  |      }t        |      dk(  sJ t        |d   j                         |d   j                               D ]V  \  }}|j                  t        | j!                  |            g       j#                  t        | j!                  |                   X  |j                         D ]A  \  }}t%        j&                  g |g t%        j(                  |            }|j#                  |       C y |j
                  j                         D ]  \  }}|r|s/|j                  \  }}	}
t        j                  | d|	 d|
 d       :| j                  |      }| j                  |      }t        |t        j*                        rIt        |      dk(  sJ t        |      dk(  sJ |j#                  t%        j,                  ||g g d             t        |t        j.                        rt        |t        j0                        r<t        |      dk(  sJ |j#                  t%        j2                  g |d   g |             0t        |t        j4                        rqt        |      dk(  sJ t%        j6                  g |g |d   d      }t9        d |D              dkD  rt;        fd|D              sJ |D cg c]  }|j                          }}|D cg c]  }t        |      dk(  r	|d   gz  n| }}|d   j                         }t        |      dk(  r	|d   gz  }t        |      k\  sJ |j#                  t%        j<                  d|              t        g || D ]N  }|D cg c]  }| j!                  |       }}|j#                  t%        j6                  g |d d	 g |d	   d             P |j#                  |       t?        |       y c c}w c c}w c c}w )
N:: Ignoring empty substitutionrq   r   Fc              3   N   K   | ]  }t        |j                                 y wr   r   r   )rs   r#   s     r   ru   z(VoltToFea._gsubLookup.<locals>.<genexpr>  s     :aAJJL):s   #%c              3   X   K   | ]!  }t        |j                               d fv  # ywrp   rP  )rs   r#   r  s     r   ru   z(VoltToFea._gsubLookup.<locals>.<genexpr>  s%     Kqs1::<0QF:Ks   '*# ) rY   rP   r   r   SubstitutionAlternateDefinitionmappingr   r/   r   r   r   r   zipr   
setdefaultr   r   r   r   AlternateSubstStatementr   SubstitutionSingleDefinitionSingleSubstStatement+SubstitutionReverseChainingSingleDefinitionSubstitutionMultipleDefinitionMultipleSubstStatementSubstitutionLigatureDefinitionLigatureSubstStatementmaxr   r   re   )r-   r   r+  rY   rP   
alternatesr{   valpathlinecolumnr   replacements	src_glyph
repl_glyphr   rk   r#   replacementzippedr  s                       @r   _gsubLookupzVoltToFea._gsubLookupY  sW   ))
jj
 c4??@JKK--/ S#),&D$KK4&$q8U VW,#~~c26{a'''-01I&&(,q/*B*B*D. )Iz ))#dooi.H*I2NUUDOOJ78 (2'7'7'9 -#|77r3>>,#?	 !!),	-
 ))+ =	/HCc%(\\"dFtfAdV1VH4QRS^^C(F>>#.L#t@@A6{a'''<(A---!!,,V\2r5Q C!Q!QRC!D!DE6{a'''!!..r6!9b,O C!D!DE<(A---66LOU	 :6::q5KFKKKK4:;qajjl;F;JPQQSVq[!vza?QFQ #/q/":":"<K;'1,'21~&6&:{+q000 %%ckkByk2B&CD"%";v";{"; >D!E$//!"4!E!E"))66 "F3BKVBZ %%i0)#..{=	/F <Q  "Fs   Q=: RRc           	      L   |j                   }|j                  }t        |t        j                        r|j
                  j                         D ]  \  }	}
|	r|
s/|j                  \  }}}t        j                  | d| d| d       9| j                  |	      }| j                  |
      }|j                  t        j                  ||||              g |_        y t        |t        j                  t        j                   t        j"                  t        j$                  f      st'        t)        |            g }|j
                  j                         D ]Z  \  }	}
|	r|
s/|j                  \  }}}t        j                  | d| d| d       9|j+                  | j                  |	d             \ t-        |      dkD  rt        j.                  |      g}|r)|j                  t        j0                  |||fg             y |j                  t        j2                  ||||g             y )NrM  rN  Tr   rq   )rY   rP   r   r   r[  rU  r   r/   r   r   r   r   r    ReverseChainSingleSubstStatementr,   rY  r\  r^  rT  re   r   r   r   r   IgnoreSubstStatementChainContextSubstStatement)r-   r   rH  rI  rJ  r+  r,   rY   rP   r{   rb  rc  rd  re  r   rf  s                   r   _gsubContextLookupzVoltToFea._gsubContextLookup  s   ))
jjc4KKLKK--/ S#),&D$KK4&$q8U VW,#~~c2!!88 !#I11333344	
 &d3i00))+ 	=HCc%(\\"dFtfAdV1VH4QRSMM$..d.;<	= v;?nnV,-Fc668P7QRS..vvvyQr   c           	      J	   d }d }d}|j                   dk(  r|dz  }|j                  s|dz  }|j                  s|dz  }n]t        |j                  t              r| j                  |j                        }n'|j                  | j                  |j                        }d }|s||t        j                  |||      }d}| j                  j                  d      rd}d	|j                  v rR|j                  j                  d	      d   }|j                         | j                  vrut        | j!                  |      |
      }||j"                  j%                  |       |j"                  j%                  t        j&                  d|j                  z                n| j                  |j                            }|j"                  j%                  t        j(                                |j"                  j%                  t        j&                  d|j                  z                || j                  |j                         <   njt        | j!                  |j                        |
      }||j"                  j%                  |       || j                  |j                  j                         <   |j*                  ;|j"                  j%                  t        j&                  d|j*                  z                g }	|j,                  D ]  }
| j/                  |
j0                        }| j/                  |
j2                        }|
j4                  dk(  }|	j%                  |||g       |s_t7        |j,                        dk(  sx|	j%                  g g dg        |	rt        j8                  | j!                  |j                  dz         |
      }|j:                  j%                  |       |j<                  | j?                  ||       n|j@                  | jC                  ||       |	D ]L  \  }}}|j<                  | jE                  ||||||       *|j@                  7| jG                  ||||||       N y |j<                  | j?                  ||       y |j@                  | jC                  ||       y y )Nr   RTLrq         FCOMPILER_USEEXTENSIONLOOKUPSTr   )r.   rR  EXCEPT_CONTEXTz chained)$	directionprocess_baseprocess_marksr   r   r   mark_glyph_setr   LookupFlagStatementrG   r   r   r   r   rA   r(   rT   rY   r   r   SubtableStatementcommentsr   r   leftrightex_or_inr   LookupBlockr,   rP   rk  rf   rD  rp  rK  )r-   r   mark_attachementmark_filteringflagslookupflagsr.   r   r+  contextsr   rH  rI  rJ  r,   s                  r   rg   zVoltToFea._lookupDefinition  s    u$QJE""QJE ##QJE,,c2#v/C/CD"".!__V-B-BCN$0N4N11'K >><= M6;; ;;$$T*1-Dzz|4==0"$$T*"/	 *((//<$$++CKKv{{8J,KL MM$**,7	$$++C,A,A,CD$$++CKKv{{8J,KL*3DMM$**,'  -+I &$$++K81:DMM&++++-.??&  ''D6??4J(KL~~ 	1G]]7<<0F]]7==1F%%)99FOOVVV45 #fnn-2R0	1 oo  z!9:+G $$W-zz%  1'  1*2 &::)++	7 ZZ+++	7 zz%  3'  3 (r   r   )F)NF)r1   r2   r3   recompilerO   rV   r+   rT   rW   rm   r   r   r   r   r   r   r   r]   r[   rc   ra   r   r   r_   rD  rK  rk  rp  rg   rr   r   r   r6   r6   `   s    $"**%67#$784('"2HVp>D
.	:; BH
 
KC+J,+\]/~0d]4r   r6   c           
      4   ddl }ddlm} ddlm} |j                  dt        j                        }|j                  dd|d	
       |j                  dd|d
       |j                  dddt        dd       |j                  dddd       |j                  ddd       |j                  |       } ||j                  rdnd       |j                  }d}	 t        |      }d|v r(t        |d   j                  j!                  d            }nt"        j%                  d        y!	 t)        ||      }	 |j+                  |j,                        }	t7        |j8                  d'      5 }|j;                  |	       ddd       y# t&        $ r Y dw xY w# t.        $ ru}
|j0                  r t3        |
j4                  d   d"d      }d#|
 d$}|r'|\  }}}t"        j%                  | d%| d%| d&|        nt"        j%                  |       Y d}
~
y!d}
~
ww xY w# 1 sw Y   yxY w)(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   ri   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?rq   r/   "z" is not supportedrM  z: w)argparsepathlibr  	fontToolsr  ArgumentParsermain__doc__add_argumentr   
parse_argsquietr  r   r   datadecoder   errorr   r6   r   ri   re   	tracebackgetattrargsopenr  write)r  r  r  r  parseroptionsrJ   rK   	converterr   er/   messagerc  rd  re  feafiles                    r   r  r  J  s>    &$$%4<< % F t2R   xd9N   I   i3P   l1K   %G7==f>==LDl#T>#DL$5$5$<$<W$EFLIINO  ,-I/ 
g!!3	' 7c #    
166!9j$7aS*+!)D$IIavQvhb	:;IIg
 s8   AE> 2F #H>	F
	F
	HA+HHH__main__r   )r  loggingr  ior   graphlibr   fontTools.feaLibr   fontTools.ttLibr   r   fontTools.voltLibr   fontTools.voltLib.parserr   r   	getLoggerr   r   r   r&   r  r(   r6   r  r1   sysr  rr   r   r   <module>r     s   +Z  	  &   . ) 9g56	!	?S__ g4 g4T?D zCHHTV r   