
    jke1o                         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m	Z	 ddl
mZ ddlmZ  ej                  d      Zg dZ G d	 d
ej$                        Z G d d      Z G d d      ZddZedk(  rddlZ ej0                   e              yy)u  MS VOLT ``.vtp`` to AFDKO ``.fea`` OpenType Layout converter.

Usage
-----

To convert a VTP project file:


    $ 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:

    $ 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)ast)TTFont
TTLibError)ParserzfontTools.voltLib.voltToFea)GDEFGSUBGPOSc                       e Zd ZddZy)MarkClassDefinitionc                 t    d}t        | dd      s|dz  }|t        j                  j                  | |      z  }|S )N usedF#)getattrr   r   asFea)selfindentress      =/usr/lib/python3/dist-packages/fontTools/voltLib/voltToFea.pyr   zMarkClassDefinition.asFea9   s>    tVU+3JCs&&,,T6::
    N)r   )__name__
__module____qualname__r    r   r   r   r   8   s    r   r   c                       e Zd Zd Zd Zy)Groupc                    |j                   j                         | _         |j                  j                  D cg c]7  }t        |t        j
                        s|j                  j                         9 c}| _        y c c}w N)namelowerenum
isinstanceVAst	GroupNamegroupgroups)r   r&   xs      r   __init__zGroup.__init__C   sQ    JJ$$&	%*ZZ__
 !
1dnn8UAGGMMO
 
s   A=A=c                     | j                   |j                  v ry|j                   | j                  v ry| j                  r|j                  sy| j                  s|j                  ryy y )NTF)r    r'   )r   others     r   __lt__zGroup.__lt__I   sO    99$::$;;u||{{u||  ,{r   N)r   r   r   r)   r,   r   r   r   r   r   B   s    
r   r   c                       e Zd Z ej                  d      Z ej                  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 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                     || _         || _        i | _        d | _        i | _        i | _        i | _        i | _        t               | _	        i | _
        i | _        i | _        i | _        i | _        i | _        y r   )_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__X   ss    )
 
er   c                    || j                   vri| j                  j                  d|      }|| j                   j                         v r"|dz  }|| j                   j                         v r"|| j                   |<   | j                   |   S N_)r>   _NOT_LOOKUP_NAME_REsubvaluesr   r    r   s      r   _lookupNamezVoltToFea._lookupNameo   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 rC   )r?   _NOT_CLASS_NAME_RErF   rG   rH   s      r   
_classNamezVoltToFea._classNamew   s    t((())--c48C**1133s
 **1133&)Dd#  &&r   c                    |j                   D cg c]  }t        |t        j                        s|! }}t	        |d       D ]  }| j                  |        |j                   D ]  }t        |t        j                        r| j                  |       /t        |t        j                        rd|v sN| j                  |       `t        |t        j                        r| j                  |       t        |t        j                        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 )Nc                     t        |       S r   )r   )r(   s    r   <lambda>z.VoltToFea._collectStatements.<locals>.<lambda>   s
    eAh r   keyr
   r	   )
statementsr#   r$   GroupDefinitionsorted_groupDefinitionGlyphDefinition_glyphDefinitionAnchorDefinition_anchorDefinitionSettingDefinition_settingDefinitionScriptDefinition_scriptDefinitionLookupDefinitionNotImplementedErrorposrF   _lookupDefinition)r   doctablessr'   	statements         r   _collectStatementszVoltToFea._collectStatements   sm    !^^Sz!T=Q=Q/R!SS,>? 	-I!!),	-  	5I)T%9%9:%%i0It'<'<=V#**95It'='=>''	2It';';<It'<'<=&&y1	4+@+@A))44	5"  	2I)T%:%:;==V6%9==V6%9&&y1	2+ Ts
   F?F?c           	      P	   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                  rp|j	                  t        j
                  d             | j                  j                         D ]/  }|j                  t        |dg              |j	                  |       1 | 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	|| }}}|rR|j	                  t        j
                  d             |j                         D ]  \  }}t        j                   |      }t        |d       }|D ]  }|j                  j	                  t        j"                  |             t        ||   d	       }|D ]  }
|
d
k(  rdnd}|j                  j	                  t        j$                  |
|             ||   |
   D ]O  }| j                  |j                            }t        j&                  |      }|j                  j	                  |       Q   |j	                  |        | j(                  rd|v rg }dD ]  }|| j(                  v rld|j                         z   }t        j*                  || j(                  |         }|j	                  |       |j	                  t        j,                  |             }|j	                  d         t        j.                  d      }|j                  j	                  t        j0                  |        |j	                  |       |S c c}w c c}}w c c}}w c c}}w )Nz# Glyph classesz
# Mark classesc              3   &   K   | ]	  }|d      yw)   Nr   ).0cs     r   	<genexpr>z.VoltToFea._buildFeatureFile.<locals>.<genexpr>   s     NqadNs   z

# Lookupstargetsz
# Featuresc                     | dk(  rdS dS )NDFLTr   ri   r   ks    r   rO   z-VoltToFea._buildFeatureFile.<locals>.<lambda>   s    1;a A r   rP   c                     | dk(  rdS dS )Ndfltr   ri   r   rp   s    r   rO   z-VoltToFea._buildFeatureFile.<locals>.<lambda>   s    Q&[ VW r   rs   TF)include_defaultr   BASEMARKLIGATURE	COMPONENTGDEF_)r   FeatureFilerR   r5   appendCommentextendrG   r;   rT   itemsr7   r   r6   copyr!   FeatureBlockScriptStatementLanguageStatementLookupReferenceStatementr4   GlyphClassDefinitionGlyphClassName
TableBlockGlyphClassDefStatement)r   rc   rb   rR   lookupfeaturesftagscriptsstaglangsltagltrd   ffeaturestagsltagsrt   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 *!!'&)R"@A!!&)*
 >>&&( 	EDtnG F! YD.3Dk"XQWWY$--=W1"XE$KY27++- E$!Q1A E	F
 07}}Dtq!!adDHTN	E &.^^%5;TQAqD;;ckk,78!)!1 +g**40w,MN! AD&&--c.A.A$.GH"74=6WXE % A26&.$e**1111$X %,DM$$7 AD%)]]4::<%@F(+(D(DV(LI#..55i@AAA !!'*+" ::&F*GA )4::% '$**, 6I!$!9!9)TZZPTEU!VJ%%j1NN3#5#5j#ABNN4() >>&)DOO""3#=#=w#GHd#
O #Y ED;s0   !R
;R

R
%R

RR2
R"=R"c                    t        | j                        j                         }|t        }| j                  | j                  j                         | _        | j                  ||       | j                  |      }|j                         S r   )

VoltParserr0   parseTABLESr1   getGlyphOrderr3   rf   r   r   )r   rc   rb   feas       r   convertzVoltToFea.convert   sp    ++,224>F::! $

 8 8 :DV,$$V,yy{r   c                     	 |j                   }t        j                  | j                  j                  ||            S # t        $ r |}Y <w xY wr   )glyphAttributeErrorr   	GlyphNamer2   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   r5   r!   )r   r&   r    s      r   
_groupNamezVoltToFea._groupName   sJ    	;;D !!$"4"4TZZ\"BCC  	D	s   > AAc                    g }|D ]  }t        |t        j                        r!|j                  | j	                  |             >t        |t        j
                        r!|j                  | j                  |             yt        |t        j                        r!|j                  | j                  |             t        |t        j                        r(|j                  |j                  |j                  f       t        |       |S r   )r#   r$   r   r|   r   r%   r   Enum_enumRangestartendr_   )r   coverager   items       r   	_coveragezVoltToFea._coverage   s     
	0D$/T__T23D$..1T__T23D$)),TZZ-.D$**-djj$((34)$//
	0 r   c                 ^    t        j                  | j                  |j                              S r   )r   
GlyphClassr   r"   )r   r"   s     r   r   zVoltToFea._enum  s    ~~dnnTYY788r   c                     g }|D ]=  }| j                  |      }t        |t        t        f      s|g}|j	                  |       ? |S r   )r   r#   tuplelistr~   )r   contextoutr   r   s        r   _contextzVoltToFea._context  sL     	!D~~d+Hh6$:JJx 		!
 
r   c                     | j                  |j                        }| j                  |j                        }t	        j
                  ||      }|| j                  |j                  j                         <   y r   )rL   r    r   r"   r   r   r5   r!   )r   r&   r    glyphsr   s        r   rU   zVoltToFea._groupDefinition  sU    uzz*EJJ'--dF;
1;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)Nru   rw   rx   )r3   idr2   r    	TypeErrortyper4   r   r   r   r|   r   r9   add
componentsr:   )r   r   s     r   rW   zVoltToFea._glyphDefinition  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splitr6   keys)	r   scriptr   langr   r   r   r   r   s	            r   r]   zVoltToFea._scriptDefinition.  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 t        j                  d|j                           y )N	COMPILER_zUnsupported setting ignored: )r    
startswithvaluer=   logwarning)r   settings     r   r[   zVoltToFea._settingDefinition<  sB    <<"";/+2==DNN7<<(KK7~FGr   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._adjustmentB  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._anchorR  s|    AK>R]L,    9\%7%7%9AT	 9\%7%7%9AT	zzG!G!"*d"*d	
 	
r   c                 8   |j                   }|j                  }| j                  |j                        }|j	                  d      rwdj                  |j                  d      dd        }t        j                  | j                  |            }| j                  |      }t        |||      }|| j                  ||f<   y || j                  vri | j                  |<   || j                  |   vri | j                  |   |<   || j                  |   |   |j                  <   y )NMARK_rD   ri   )r    
glyph_namer   r`   r   joinr   r   	MarkClassrL   r   r   r;   r<   	component)	r   	anchordef
anchorname	glyphnameanchorr    	markclassr   markdefs	            r   rY   zVoltToFea._anchorDefinition`  s    ^^
((	imm,  )88J,,S1!"56Ddood&;<IOOI.E))VUCG9@Dy*56-+-i(y!9979i(4HNDMM)$Z01D1DEr   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&                        ri }|j(                  D ]  \  }}|D ]2  }|j+                         D ]  }|d|z   f}d| j,                  |   _         4 t        j0                  | j3                  |            }|j4                  D ]<  }|j+                         D ]'  }||vrg ||<   |||   vs||   j                  |       ) >  |D ]Q  }d}|| j6                  v r| j6                  |   }g }||   D ]  }t        j0                  | j3                  |            }t9        d|dz         D ]e  }t        |      |k  r|j                  g        d }|| j:                  |   |   v r| j:                  |   |   |   }||dz
     j                  ||f       g  | j=                  |      }|| j>                  v rt        j@                  ||d         }n>|| j6                  v rt        jB                  ||      }nt        jD                  ||d         }|j                  |       T y t        |t        jF                        rbg } |jH                  D ]/  }!|!D ](  }|j+                         D ]  }| j                  |        * 1 g }"|jJ                  D ]/  }!|!D ](  }|j+                         D ]  }|"j                  |        * 1 | D ]  }| j=                  |      }#| j:                  |   d   d   }$d }%||"v r5| j:                  |   d   d   }%|"jM                  |"jO                  |             |j                  t        jP                  |#|$|%              |"D ]N  }| j=                  |      }#| j:                  |   d   d   }%|j                  t        jP                  |#d |%             P y tS        |      )	Nri   FTr   )
enumeratedr   entryexit)*rR   r`   r#   r$   PositionAdjustPairDefinitionadjust_pairr   coverages_1coverages_2r%   r   r   lenr|   r   PairPosStatementPositionAdjustSingleDefinitionadjust_singleSinglePosStatementPositionAttachDefinitioncoverage_toglyphSetr;   r   r   rL   r   r:   ranger<   r   r9   MarkMarkPosStatementMarkLigPosStatementMarkBasePosStatementPositionAttachCursiveDefinitioncoverages_entercoverages_exitpopindexCursivePosStatementr_   )&r   r   	fealookuprR   r`   idx1idx2pos1pos2
coverage_1
coverage_2r   r   glyphs1glyphs2record1record2abr   recordanchorsmarksr   markr    rQ   r   baser   r   r   enter_coverager   exit_coverager   r   r   s&                                         r   _gposLookupzVoltToFea._gposLookupr  s   ))
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$'OO < y! ;D
 !% ;#Wy%896:))#.3;;  MM$//)*DE	LL <D $ <w.,.GDM$GDM9#DM00;	<<<"   (
4??*!%!6J#DM ID #dood.C DI%*1j1n%= I	u:	1!LL,!%$d(;D(AA%)]]4%8%>y%IFi!m,33VY4GHII t,4;;&33D%(CDT__,224?D33D%(CD!!$'/(0 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**r   c                    |j                   }|j                  r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||f}t        j                  ||||      }|j                  |        y t        |t        j                         rt        j"                         g}|j$                  D ]*  \  }}| j                  |      }|d   j'                  |       , |rt        j                  |||fg      }nt        j                  ||||g      }|j                  |       y t        |t        j(                        rt        j"                         g}|j*                  D ](  \  }}|d   j'                  | j                  |             * |rt        j                  |||fg      }nt        j                  ||||g      }|j                  |       y t-        |      )Nri   r   )rR   reversalr`   r#   r$   r   r   r   r   r   r   r   r   IgnorePosStatementChainContextPosStatementr|   r  r   r  r~   r  r  r_   )r   r   prefixsuffixignorer  targetlookuprR   r`   r  r  r  r  r  r  r   re   r   r  r  r   r   rD   s                          r   _gposContextLookupzVoltToFea._gposContextLookup  sd    ))
??""jjc4<<=.1oo.C.C.E -*tltT..)BC..)BC7|q(((7|q(((!!*gaj1 # 6 68P7Q RI+\:G # < <!I !!),- T@@Ann&'F)) (1q)q	  '( 22VVV4L3MN	88FF\N	 i(T::;nn&'F" ;!q	  !9:; 22VVV4L3MN	88FF\N	 i(%c**r   c           	      
   |j                   }|j                  }|j                  j                         D ]  \  }	}
|	r|
s/|j                  \  }}}t
        j                  | d| d| d       :d }| j                  |	      }| j                  |
      }|r|||f}t        j                  |g      }n@t        |t        j                        r:t        |      dk(  sJ t        |      dk(  sJ t        j                  |||||      }nt        |t        j                        r9t        |      dk(  sJ t        |      dk(  sJ t        j                   ||||      }nt        |t        j"                        r-t        |      dk(  sJ t        j$                  ||d   |||      }nRt        |t        j&                        r-t        |      dk(  sJ t        j(                  ||||d   |      }nt+        |      |j-                  |        y )N:z: Ignoring empty substitutionri   r   )rR   rF   mappingr   locationr   r   r   r   IgnoreSubstStatementr#   r$   SubstitutionSingleDefinitionr   SingleSubstStatement+SubstitutionReverseChainingSingleDefinition ReverseChainSingleSubstStatementSubstitutionMultipleDefinitionMultipleSubstStatementSubstitutionLigatureDefinitionLigatureSubstStatementr_   r|   )r   r   r*  r+  r,  chainr  rR   rF   rQ   valpathlinecolumnre   r   replacementschain_contexts                     r   _gsubLookupzVoltToFea._gsubLookup  s   ))
jj))+ #	)HCc%(\\"dFtfAdV1VH4QRSI^^C(F>>#.L!' 844m_E	C!B!BC6{a'''<(A---44L&&%	 C!Q!QR6{a'''<(A---@@FFL	 C!D!DE6{a'''66F1Iv|U	 C!D!DE<(A---66FFLOU	 *#..i(G#	)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                  v rZ|j                  j                  d      d   }|j                         | j                  vr}t        j                  | 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                         <   nrt        j                  | j                  |j                              }||j                  j!                  |       || j                  |j                  j                         <   |j&                  ;|j                  j!                  t        j"                  d|j&                  z                g }|j(                  r|j(                  D ]  }	| j+                  |	j,                        }
| j+                  |	j.                        }|	j0                  dk(  }|j!                  |
||d	g       |s`t3        |j(                        dk(  sy|j!                  g g d	d
g        n|j!                  g g d	d	g       d }|D ]   \  }
}}}|j4                  | j7                  ||
||||       |j8                  8| j:                  j=                  d      rd
|_        |
s|s|s|r|st|r| j                  |j                  dz         }t        j                  |      }tA        |dg       |_!        |jB                  j!                  |       | jE                  ||       | jG                  ||
||||       | jE                  ||        y )Nr   RTLri         r   z# EXCEPT_CONTEXTFTCOMPILER_USEEXTENSIONLOOKUPSz targetrm   )$	directionprocess_baseprocess_marksr#   strr   mark_glyph_setr   LookupFlagStatementr    r   r!   r7   LookupBlockrI   rR   r|   r}   SubtableStatementcommentsr   r   leftrightex_or_inr   rF   rC  r`   r=   r   use_extensionr   rm   r%  r.  )r   r   mark_attachementmark_filteringflagslookupflagsr    r  contextsr   r*  r+  r,  r-  r<  
targetnames                   r   ra   zVoltToFea._lookupDefinition=  s   u$QJE""QJE ##QJE,,c2#v/C/CD"".!__V-B-BCN$0N4N11'K 6;; ;;$$T*1-Dzz|4==0OOD,<,<T,BC	*((//<$$++CKKv{{8J,KL MM$**,7	$$++C,A,A,CD$$++CKKv{{8J,KL*3DMM$**,'(8(8(EFI&$$++K81:DMM&++++-.??&  ''D6??4J(KL>>!>> ;w||4w}}5 ))-== ?@ c&..1Q6OORUD$9:; OORUE23-5 	8)FFFEzz%  	Rzz%>>%%&DE.2I+Vu!l&:%)%5%5fkkI6M%N
'*z'B,3Iy",M	)!))00>((>++	< $$VY7%	8r   r   )r   r   r   recompilerE   rK   r)   rI   rL   rf   r   r   r   r   r   r   r   rU   rW   r]   r[   r   r   rY   r%  r.  rC  ra   r   r   r   r.   r.   T   s    $"**%67#$78.('2B@D
>D9<; BH
 
O$l+\2+h')RQ8r   r.   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|   rc   z:List of tables to write, by default all tables are written)actionchoicesdestrf  z-qz--quiet
store_truezSuppress non-error messages)ri  rf  z--tracebacku   Don’t catch exceptionsERRORINFO)levelTSIVzutf-8z6"TSIV" table is missing, font was not saved from VOLT?ri   r2  "z" is not supportedr0  z: w)argparsepathlibr`  	fontToolsra  ArgumentParsermain__doc__add_argumentr   
parse_argsquietrc  r   r   datadecoder   errorr   r.   r   rc   r_   	tracebackr   argsopenrg  write)r  rs  r`  ra  parseroptionsr@   rA   	converterr   er2  messager>  r?  r@  feafiles                    r   rw  rw    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   )rx  loggingr]  ior   fontTools.feaLibr   fontTools.ttLibr   r   fontTools.voltLibr$   fontTools.voltLib.parserr   r   	getLoggerr   r   r   r   r.   rw  r   sysr   r   r   r   <module>r     s   'R  	    . ) 9g56	!#11  $z8 z8z?D zCHHTV r   