fonttools 4.55.6__cp311-cp311-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fonttools might be problematic. Click here for more details.
- fontTools/__init__.py +8 -0
- fontTools/__main__.py +35 -0
- fontTools/afmLib.py +439 -0
- fontTools/agl.py +5233 -0
- fontTools/cffLib/CFF2ToCFF.py +203 -0
- fontTools/cffLib/CFFToCFF2.py +305 -0
- fontTools/cffLib/__init__.py +3659 -0
- fontTools/cffLib/specializer.py +924 -0
- fontTools/cffLib/transforms.py +490 -0
- fontTools/cffLib/width.py +210 -0
- fontTools/colorLib/__init__.py +0 -0
- fontTools/colorLib/builder.py +664 -0
- fontTools/colorLib/errors.py +2 -0
- fontTools/colorLib/geometry.py +143 -0
- fontTools/colorLib/table_builder.py +223 -0
- fontTools/colorLib/unbuilder.py +81 -0
- fontTools/config/__init__.py +75 -0
- fontTools/cu2qu/__init__.py +15 -0
- fontTools/cu2qu/__main__.py +6 -0
- fontTools/cu2qu/benchmark.py +54 -0
- fontTools/cu2qu/cli.py +198 -0
- fontTools/cu2qu/cu2qu.c +14829 -0
- fontTools/cu2qu/cu2qu.cpython-311-x86_64-linux-musl.so +0 -0
- fontTools/cu2qu/cu2qu.py +531 -0
- fontTools/cu2qu/errors.py +77 -0
- fontTools/cu2qu/ufo.py +349 -0
- fontTools/designspaceLib/__init__.py +3338 -0
- fontTools/designspaceLib/__main__.py +6 -0
- fontTools/designspaceLib/split.py +475 -0
- fontTools/designspaceLib/statNames.py +253 -0
- fontTools/designspaceLib/types.py +147 -0
- fontTools/encodings/MacRoman.py +258 -0
- fontTools/encodings/StandardEncoding.py +258 -0
- fontTools/encodings/__init__.py +1 -0
- fontTools/encodings/codecs.py +135 -0
- fontTools/feaLib/__init__.py +4 -0
- fontTools/feaLib/__main__.py +78 -0
- fontTools/feaLib/ast.py +2134 -0
- fontTools/feaLib/builder.py +1747 -0
- fontTools/feaLib/error.py +22 -0
- fontTools/feaLib/lexer.c +17986 -0
- fontTools/feaLib/lexer.cpython-311-x86_64-linux-musl.so +0 -0
- fontTools/feaLib/lexer.py +287 -0
- fontTools/feaLib/location.py +12 -0
- fontTools/feaLib/lookupDebugInfo.py +12 -0
- fontTools/feaLib/parser.py +2359 -0
- fontTools/feaLib/variableScalar.py +113 -0
- fontTools/fontBuilder.py +1008 -0
- fontTools/help.py +36 -0
- fontTools/merge/__init__.py +248 -0
- fontTools/merge/__main__.py +6 -0
- fontTools/merge/base.py +81 -0
- fontTools/merge/cmap.py +141 -0
- fontTools/merge/layout.py +526 -0
- fontTools/merge/options.py +85 -0
- fontTools/merge/tables.py +341 -0
- fontTools/merge/unicode.py +78 -0
- fontTools/merge/util.py +143 -0
- fontTools/misc/__init__.py +1 -0
- fontTools/misc/arrayTools.py +424 -0
- fontTools/misc/bezierTools.c +41831 -0
- fontTools/misc/bezierTools.cpython-311-x86_64-linux-musl.so +0 -0
- fontTools/misc/bezierTools.py +1497 -0
- fontTools/misc/classifyTools.py +170 -0
- fontTools/misc/cliTools.py +53 -0
- fontTools/misc/configTools.py +349 -0
- fontTools/misc/cython.py +27 -0
- fontTools/misc/dictTools.py +83 -0
- fontTools/misc/eexec.py +119 -0
- fontTools/misc/encodingTools.py +72 -0
- fontTools/misc/etree.py +479 -0
- fontTools/misc/filenames.py +245 -0
- fontTools/misc/fixedTools.py +253 -0
- fontTools/misc/intTools.py +25 -0
- fontTools/misc/iterTools.py +12 -0
- fontTools/misc/lazyTools.py +42 -0
- fontTools/misc/loggingTools.py +543 -0
- fontTools/misc/macCreatorType.py +56 -0
- fontTools/misc/macRes.py +261 -0
- fontTools/misc/plistlib/__init__.py +681 -0
- fontTools/misc/plistlib/py.typed +0 -0
- fontTools/misc/psCharStrings.py +1496 -0
- fontTools/misc/psLib.py +398 -0
- fontTools/misc/psOperators.py +572 -0
- fontTools/misc/py23.py +96 -0
- fontTools/misc/roundTools.py +110 -0
- fontTools/misc/sstruct.py +231 -0
- fontTools/misc/symfont.py +244 -0
- fontTools/misc/testTools.py +229 -0
- fontTools/misc/textTools.py +154 -0
- fontTools/misc/timeTools.py +88 -0
- fontTools/misc/transform.py +516 -0
- fontTools/misc/treeTools.py +45 -0
- fontTools/misc/vector.py +147 -0
- fontTools/misc/visitor.py +142 -0
- fontTools/misc/xmlReader.py +188 -0
- fontTools/misc/xmlWriter.py +204 -0
- fontTools/mtiLib/__init__.py +1402 -0
- fontTools/mtiLib/__main__.py +5 -0
- fontTools/otlLib/__init__.py +1 -0
- fontTools/otlLib/builder.py +3221 -0
- fontTools/otlLib/error.py +11 -0
- fontTools/otlLib/maxContextCalc.py +96 -0
- fontTools/otlLib/optimize/__init__.py +53 -0
- fontTools/otlLib/optimize/__main__.py +6 -0
- fontTools/otlLib/optimize/gpos.py +453 -0
- fontTools/pens/__init__.py +1 -0
- fontTools/pens/areaPen.py +52 -0
- fontTools/pens/basePen.py +475 -0
- fontTools/pens/boundsPen.py +98 -0
- fontTools/pens/cairoPen.py +26 -0
- fontTools/pens/cocoaPen.py +26 -0
- fontTools/pens/cu2quPen.py +325 -0
- fontTools/pens/explicitClosingLinePen.py +101 -0
- fontTools/pens/filterPen.py +241 -0
- fontTools/pens/freetypePen.py +462 -0
- fontTools/pens/hashPointPen.py +89 -0
- fontTools/pens/momentsPen.c +13448 -0
- fontTools/pens/momentsPen.cpython-311-x86_64-linux-musl.so +0 -0
- fontTools/pens/momentsPen.py +879 -0
- fontTools/pens/perimeterPen.py +69 -0
- fontTools/pens/pointInsidePen.py +192 -0
- fontTools/pens/pointPen.py +600 -0
- fontTools/pens/qtPen.py +29 -0
- fontTools/pens/qu2cuPen.py +105 -0
- fontTools/pens/quartzPen.py +43 -0
- fontTools/pens/recordingPen.py +335 -0
- fontTools/pens/reportLabPen.py +79 -0
- fontTools/pens/reverseContourPen.py +96 -0
- fontTools/pens/roundingPen.py +130 -0
- fontTools/pens/statisticsPen.py +312 -0
- fontTools/pens/svgPathPen.py +310 -0
- fontTools/pens/t2CharStringPen.py +68 -0
- fontTools/pens/teePen.py +55 -0
- fontTools/pens/transformPen.py +115 -0
- fontTools/pens/ttGlyphPen.py +335 -0
- fontTools/pens/wxPen.py +29 -0
- fontTools/qu2cu/__init__.py +15 -0
- fontTools/qu2cu/__main__.py +7 -0
- fontTools/qu2cu/benchmark.py +56 -0
- fontTools/qu2cu/cli.py +125 -0
- fontTools/qu2cu/qu2cu.c +16269 -0
- fontTools/qu2cu/qu2cu.cpython-311-x86_64-linux-musl.so +0 -0
- fontTools/qu2cu/qu2cu.py +405 -0
- fontTools/subset/__init__.py +3838 -0
- fontTools/subset/__main__.py +6 -0
- fontTools/subset/cff.py +184 -0
- fontTools/subset/svg.py +253 -0
- fontTools/subset/util.py +25 -0
- fontTools/svgLib/__init__.py +3 -0
- fontTools/svgLib/path/__init__.py +65 -0
- fontTools/svgLib/path/arc.py +154 -0
- fontTools/svgLib/path/parser.py +322 -0
- fontTools/svgLib/path/shapes.py +183 -0
- fontTools/t1Lib/__init__.py +648 -0
- fontTools/tfmLib.py +460 -0
- fontTools/ttLib/__init__.py +26 -0
- fontTools/ttLib/__main__.py +109 -0
- fontTools/ttLib/macUtils.py +54 -0
- fontTools/ttLib/removeOverlaps.py +393 -0
- fontTools/ttLib/reorderGlyphs.py +284 -0
- fontTools/ttLib/scaleUpem.py +436 -0
- fontTools/ttLib/sfnt.py +662 -0
- fontTools/ttLib/standardGlyphOrder.py +271 -0
- fontTools/ttLib/tables/B_A_S_E_.py +14 -0
- fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
- fontTools/ttLib/tables/C_B_D_T_.py +113 -0
- fontTools/ttLib/tables/C_B_L_C_.py +19 -0
- fontTools/ttLib/tables/C_F_F_.py +61 -0
- fontTools/ttLib/tables/C_F_F__2.py +26 -0
- fontTools/ttLib/tables/C_O_L_R_.py +165 -0
- fontTools/ttLib/tables/C_P_A_L_.py +305 -0
- fontTools/ttLib/tables/D_S_I_G_.py +158 -0
- fontTools/ttLib/tables/D__e_b_g.py +17 -0
- fontTools/ttLib/tables/DefaultTable.py +49 -0
- fontTools/ttLib/tables/E_B_D_T_.py +835 -0
- fontTools/ttLib/tables/E_B_L_C_.py +718 -0
- fontTools/ttLib/tables/F_F_T_M_.py +52 -0
- fontTools/ttLib/tables/F__e_a_t.py +149 -0
- fontTools/ttLib/tables/G_D_E_F_.py +13 -0
- fontTools/ttLib/tables/G_M_A_P_.py +148 -0
- fontTools/ttLib/tables/G_P_K_G_.py +133 -0
- fontTools/ttLib/tables/G_P_O_S_.py +14 -0
- fontTools/ttLib/tables/G_S_U_B_.py +13 -0
- fontTools/ttLib/tables/G__l_a_t.py +235 -0
- fontTools/ttLib/tables/G__l_o_c.py +85 -0
- fontTools/ttLib/tables/H_V_A_R_.py +13 -0
- fontTools/ttLib/tables/J_S_T_F_.py +13 -0
- fontTools/ttLib/tables/L_T_S_H_.py +58 -0
- fontTools/ttLib/tables/M_A_T_H_.py +13 -0
- fontTools/ttLib/tables/M_E_T_A_.py +352 -0
- fontTools/ttLib/tables/M_V_A_R_.py +13 -0
- fontTools/ttLib/tables/O_S_2f_2.py +752 -0
- fontTools/ttLib/tables/S_I_N_G_.py +99 -0
- fontTools/ttLib/tables/S_T_A_T_.py +15 -0
- fontTools/ttLib/tables/S_V_G_.py +223 -0
- fontTools/ttLib/tables/S__i_l_f.py +1040 -0
- fontTools/ttLib/tables/S__i_l_l.py +92 -0
- fontTools/ttLib/tables/T_S_I_B_.py +13 -0
- fontTools/ttLib/tables/T_S_I_C_.py +14 -0
- fontTools/ttLib/tables/T_S_I_D_.py +13 -0
- fontTools/ttLib/tables/T_S_I_J_.py +13 -0
- fontTools/ttLib/tables/T_S_I_P_.py +13 -0
- fontTools/ttLib/tables/T_S_I_S_.py +13 -0
- fontTools/ttLib/tables/T_S_I_V_.py +26 -0
- fontTools/ttLib/tables/T_S_I__0.py +59 -0
- fontTools/ttLib/tables/T_S_I__1.py +166 -0
- fontTools/ttLib/tables/T_S_I__2.py +17 -0
- fontTools/ttLib/tables/T_S_I__3.py +22 -0
- fontTools/ttLib/tables/T_S_I__5.py +49 -0
- fontTools/ttLib/tables/T_T_F_A_.py +14 -0
- fontTools/ttLib/tables/TupleVariation.py +884 -0
- fontTools/ttLib/tables/V_A_R_C_.py +12 -0
- fontTools/ttLib/tables/V_D_M_X_.py +249 -0
- fontTools/ttLib/tables/V_O_R_G_.py +165 -0
- fontTools/ttLib/tables/V_V_A_R_.py +13 -0
- fontTools/ttLib/tables/__init__.py +97 -0
- fontTools/ttLib/tables/_a_n_k_r.py +15 -0
- fontTools/ttLib/tables/_a_v_a_r.py +191 -0
- fontTools/ttLib/tables/_b_s_l_n.py +15 -0
- fontTools/ttLib/tables/_c_i_d_g.py +24 -0
- fontTools/ttLib/tables/_c_m_a_p.py +1578 -0
- fontTools/ttLib/tables/_c_v_a_r.py +94 -0
- fontTools/ttLib/tables/_c_v_t.py +55 -0
- fontTools/ttLib/tables/_f_e_a_t.py +15 -0
- fontTools/ttLib/tables/_f_p_g_m.py +60 -0
- fontTools/ttLib/tables/_f_v_a_r.py +261 -0
- fontTools/ttLib/tables/_g_a_s_p.py +63 -0
- fontTools/ttLib/tables/_g_c_i_d.py +13 -0
- fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
- fontTools/ttLib/tables/_g_v_a_r.py +292 -0
- fontTools/ttLib/tables/_h_d_m_x.py +127 -0
- fontTools/ttLib/tables/_h_e_a_d.py +130 -0
- fontTools/ttLib/tables/_h_h_e_a.py +147 -0
- fontTools/ttLib/tables/_h_m_t_x.py +160 -0
- fontTools/ttLib/tables/_k_e_r_n.py +289 -0
- fontTools/ttLib/tables/_l_c_a_r.py +13 -0
- fontTools/ttLib/tables/_l_o_c_a.py +70 -0
- fontTools/ttLib/tables/_l_t_a_g.py +72 -0
- fontTools/ttLib/tables/_m_a_x_p.py +147 -0
- fontTools/ttLib/tables/_m_e_t_a.py +112 -0
- fontTools/ttLib/tables/_m_o_r_t.py +14 -0
- fontTools/ttLib/tables/_m_o_r_x.py +15 -0
- fontTools/ttLib/tables/_n_a_m_e.py +1237 -0
- fontTools/ttLib/tables/_o_p_b_d.py +14 -0
- fontTools/ttLib/tables/_p_o_s_t.py +317 -0
- fontTools/ttLib/tables/_p_r_e_p.py +16 -0
- fontTools/ttLib/tables/_p_r_o_p.py +12 -0
- fontTools/ttLib/tables/_s_b_i_x.py +129 -0
- fontTools/ttLib/tables/_t_r_a_k.py +332 -0
- fontTools/ttLib/tables/_v_h_e_a.py +139 -0
- fontTools/ttLib/tables/_v_m_t_x.py +19 -0
- fontTools/ttLib/tables/asciiTable.py +20 -0
- fontTools/ttLib/tables/grUtils.py +92 -0
- fontTools/ttLib/tables/otBase.py +1465 -0
- fontTools/ttLib/tables/otConverters.py +2065 -0
- fontTools/ttLib/tables/otData.py +6400 -0
- fontTools/ttLib/tables/otTables.py +2700 -0
- fontTools/ttLib/tables/otTraverse.py +162 -0
- fontTools/ttLib/tables/sbixGlyph.py +149 -0
- fontTools/ttLib/tables/sbixStrike.py +177 -0
- fontTools/ttLib/tables/table_API_readme.txt +91 -0
- fontTools/ttLib/tables/ttProgram.py +594 -0
- fontTools/ttLib/ttCollection.py +125 -0
- fontTools/ttLib/ttFont.py +1155 -0
- fontTools/ttLib/ttGlyphSet.py +500 -0
- fontTools/ttLib/ttVisitor.py +32 -0
- fontTools/ttLib/woff2.py +1683 -0
- fontTools/ttx.py +467 -0
- fontTools/ufoLib/__init__.py +2477 -0
- fontTools/ufoLib/converters.py +334 -0
- fontTools/ufoLib/errors.py +22 -0
- fontTools/ufoLib/etree.py +6 -0
- fontTools/ufoLib/filenames.py +291 -0
- fontTools/ufoLib/glifLib.py +2022 -0
- fontTools/ufoLib/kerning.py +91 -0
- fontTools/ufoLib/plistlib.py +47 -0
- fontTools/ufoLib/pointPen.py +6 -0
- fontTools/ufoLib/utils.py +76 -0
- fontTools/ufoLib/validators.py +1186 -0
- fontTools/unicode.py +50 -0
- fontTools/unicodedata/Blocks.py +802 -0
- fontTools/unicodedata/OTTags.py +50 -0
- fontTools/unicodedata/ScriptExtensions.py +806 -0
- fontTools/unicodedata/Scripts.py +3618 -0
- fontTools/unicodedata/__init__.py +298 -0
- fontTools/varLib/__init__.py +1511 -0
- fontTools/varLib/__main__.py +6 -0
- fontTools/varLib/avar.py +260 -0
- fontTools/varLib/avarPlanner.py +1004 -0
- fontTools/varLib/builder.py +215 -0
- fontTools/varLib/cff.py +631 -0
- fontTools/varLib/errors.py +219 -0
- fontTools/varLib/featureVars.py +689 -0
- fontTools/varLib/instancer/__init__.py +1937 -0
- fontTools/varLib/instancer/__main__.py +5 -0
- fontTools/varLib/instancer/featureVars.py +190 -0
- fontTools/varLib/instancer/names.py +388 -0
- fontTools/varLib/instancer/solver.py +309 -0
- fontTools/varLib/interpolatable.py +1209 -0
- fontTools/varLib/interpolatableHelpers.py +396 -0
- fontTools/varLib/interpolatablePlot.py +1269 -0
- fontTools/varLib/interpolatableTestContourOrder.py +82 -0
- fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
- fontTools/varLib/interpolate_layout.py +124 -0
- fontTools/varLib/iup.c +19154 -0
- fontTools/varLib/iup.cpython-311-x86_64-linux-musl.so +0 -0
- fontTools/varLib/iup.py +490 -0
- fontTools/varLib/merger.py +1717 -0
- fontTools/varLib/models.py +642 -0
- fontTools/varLib/multiVarStore.py +253 -0
- fontTools/varLib/mutator.py +518 -0
- fontTools/varLib/mvar.py +40 -0
- fontTools/varLib/plot.py +238 -0
- fontTools/varLib/stat.py +149 -0
- fontTools/varLib/varStore.py +767 -0
- fontTools/voltLib/__init__.py +5 -0
- fontTools/voltLib/ast.py +448 -0
- fontTools/voltLib/error.py +12 -0
- fontTools/voltLib/lexer.py +99 -0
- fontTools/voltLib/parser.py +656 -0
- fontTools/voltLib/voltToFea.py +730 -0
- fonttools-4.55.6.data/data/share/man/man1/ttx.1 +225 -0
- fonttools-4.55.6.dist-info/LICENSE +21 -0
- fonttools-4.55.6.dist-info/METADATA +3413 -0
- fonttools-4.55.6.dist-info/RECORD +329 -0
- fonttools-4.55.6.dist-info/WHEEL +5 -0
- fonttools-4.55.6.dist-info/entry_points.txt +5 -0
- fonttools-4.55.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
"""\
|
|
2
|
+
MS VOLT ``.vtp`` to AFDKO ``.fea`` OpenType Layout converter.
|
|
3
|
+
|
|
4
|
+
Usage
|
|
5
|
+
-----
|
|
6
|
+
|
|
7
|
+
To convert a VTP project file:
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
.. code-block:: sh
|
|
11
|
+
|
|
12
|
+
$ fonttools voltLib.voltToFea input.vtp output.fea
|
|
13
|
+
|
|
14
|
+
It is also possible convert font files with `TSIV` table (as saved from Volt),
|
|
15
|
+
in this case the glyph names used in the Volt project will be mapped to the
|
|
16
|
+
actual glyph names in the font files when written to the feature file:
|
|
17
|
+
|
|
18
|
+
.. code-block:: sh
|
|
19
|
+
|
|
20
|
+
$ fonttools voltLib.voltToFea input.ttf output.fea
|
|
21
|
+
|
|
22
|
+
The ``--quiet`` option can be used to suppress warnings.
|
|
23
|
+
|
|
24
|
+
The ``--traceback`` can be used to get Python traceback in case of exceptions,
|
|
25
|
+
instead of suppressing the traceback.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Limitations
|
|
29
|
+
-----------
|
|
30
|
+
|
|
31
|
+
* Not all VOLT features are supported, the script will error if it it
|
|
32
|
+
encounters something it does not understand. Please report an issue if this
|
|
33
|
+
happens.
|
|
34
|
+
* AFDKO feature file syntax for mark positioning is awkward and does not allow
|
|
35
|
+
setting the mark coverage. It also defines mark anchors globally, as a result
|
|
36
|
+
some mark positioning lookups might cover many marks than what was in the VOLT
|
|
37
|
+
file. This should not be an issue in practice, but if it is then the only way
|
|
38
|
+
is to modify the VOLT file or the generated feature file manually to use unique
|
|
39
|
+
mark anchors for each lookup.
|
|
40
|
+
* VOLT allows subtable breaks in any lookup type, but AFDKO feature file
|
|
41
|
+
implementations vary in their support; currently AFDKO’s makeOTF supports
|
|
42
|
+
subtable breaks in pair positioning lookups only, while FontTools’ feaLib
|
|
43
|
+
support it for most substitution lookups and only some positioning lookups.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
import logging
|
|
47
|
+
import re
|
|
48
|
+
from io import StringIO
|
|
49
|
+
|
|
50
|
+
from fontTools.feaLib import ast
|
|
51
|
+
from fontTools.ttLib import TTFont, TTLibError
|
|
52
|
+
from fontTools.voltLib import ast as VAst
|
|
53
|
+
from fontTools.voltLib.parser import Parser as VoltParser
|
|
54
|
+
|
|
55
|
+
log = logging.getLogger("fontTools.voltLib.voltToFea")
|
|
56
|
+
|
|
57
|
+
TABLES = ["GDEF", "GSUB", "GPOS"]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class MarkClassDefinition(ast.MarkClassDefinition):
|
|
61
|
+
def asFea(self, indent=""):
|
|
62
|
+
res = ""
|
|
63
|
+
if not getattr(self, "used", False):
|
|
64
|
+
res += "#"
|
|
65
|
+
res += ast.MarkClassDefinition.asFea(self, indent)
|
|
66
|
+
return res
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# For sorting voltLib.ast.GlyphDefinition, see its use below.
|
|
70
|
+
class Group:
|
|
71
|
+
def __init__(self, group):
|
|
72
|
+
self.name = group.name.lower()
|
|
73
|
+
self.groups = [
|
|
74
|
+
x.group.lower() for x in group.enum.enum if isinstance(x, VAst.GroupName)
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
def __lt__(self, other):
|
|
78
|
+
if self.name in other.groups:
|
|
79
|
+
return True
|
|
80
|
+
if other.name in self.groups:
|
|
81
|
+
return False
|
|
82
|
+
if self.groups and not other.groups:
|
|
83
|
+
return False
|
|
84
|
+
if not self.groups and other.groups:
|
|
85
|
+
return True
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class VoltToFea:
|
|
89
|
+
_NOT_LOOKUP_NAME_RE = re.compile(r"[^A-Za-z_0-9.]")
|
|
90
|
+
_NOT_CLASS_NAME_RE = re.compile(r"[^A-Za-z_0-9.\-]")
|
|
91
|
+
|
|
92
|
+
def __init__(self, file_or_path, font=None):
|
|
93
|
+
self._file_or_path = file_or_path
|
|
94
|
+
self._font = font
|
|
95
|
+
|
|
96
|
+
self._glyph_map = {}
|
|
97
|
+
self._glyph_order = None
|
|
98
|
+
|
|
99
|
+
self._gdef = {}
|
|
100
|
+
self._glyphclasses = {}
|
|
101
|
+
self._features = {}
|
|
102
|
+
self._lookups = {}
|
|
103
|
+
|
|
104
|
+
self._marks = set()
|
|
105
|
+
self._ligatures = {}
|
|
106
|
+
|
|
107
|
+
self._markclasses = {}
|
|
108
|
+
self._anchors = {}
|
|
109
|
+
|
|
110
|
+
self._settings = {}
|
|
111
|
+
|
|
112
|
+
self._lookup_names = {}
|
|
113
|
+
self._class_names = {}
|
|
114
|
+
|
|
115
|
+
def _lookupName(self, name):
|
|
116
|
+
if name not in self._lookup_names:
|
|
117
|
+
res = self._NOT_LOOKUP_NAME_RE.sub("_", name)
|
|
118
|
+
while res in self._lookup_names.values():
|
|
119
|
+
res += "_"
|
|
120
|
+
self._lookup_names[name] = res
|
|
121
|
+
return self._lookup_names[name]
|
|
122
|
+
|
|
123
|
+
def _className(self, name):
|
|
124
|
+
if name not in self._class_names:
|
|
125
|
+
res = self._NOT_CLASS_NAME_RE.sub("_", name)
|
|
126
|
+
while res in self._class_names.values():
|
|
127
|
+
res += "_"
|
|
128
|
+
self._class_names[name] = res
|
|
129
|
+
return self._class_names[name]
|
|
130
|
+
|
|
131
|
+
def _collectStatements(self, doc, tables):
|
|
132
|
+
# Collect and sort group definitions first, to make sure a group
|
|
133
|
+
# definition that references other groups comes after them since VOLT
|
|
134
|
+
# does not enforce such ordering, and feature file require it.
|
|
135
|
+
groups = [s for s in doc.statements if isinstance(s, VAst.GroupDefinition)]
|
|
136
|
+
for statement in sorted(groups, key=lambda x: Group(x)):
|
|
137
|
+
self._groupDefinition(statement)
|
|
138
|
+
|
|
139
|
+
for statement in doc.statements:
|
|
140
|
+
if isinstance(statement, VAst.GlyphDefinition):
|
|
141
|
+
self._glyphDefinition(statement)
|
|
142
|
+
elif isinstance(statement, VAst.AnchorDefinition):
|
|
143
|
+
if "GPOS" in tables:
|
|
144
|
+
self._anchorDefinition(statement)
|
|
145
|
+
elif isinstance(statement, VAst.SettingDefinition):
|
|
146
|
+
self._settingDefinition(statement)
|
|
147
|
+
elif isinstance(statement, VAst.GroupDefinition):
|
|
148
|
+
pass # Handled above
|
|
149
|
+
elif isinstance(statement, VAst.ScriptDefinition):
|
|
150
|
+
self._scriptDefinition(statement)
|
|
151
|
+
elif not isinstance(statement, VAst.LookupDefinition):
|
|
152
|
+
raise NotImplementedError(statement)
|
|
153
|
+
|
|
154
|
+
# Lookup definitions need to be handled last as they reference glyph
|
|
155
|
+
# and mark classes that might be defined after them.
|
|
156
|
+
for statement in doc.statements:
|
|
157
|
+
if isinstance(statement, VAst.LookupDefinition):
|
|
158
|
+
if statement.pos and "GPOS" not in tables:
|
|
159
|
+
continue
|
|
160
|
+
if statement.sub and "GSUB" not in tables:
|
|
161
|
+
continue
|
|
162
|
+
self._lookupDefinition(statement)
|
|
163
|
+
|
|
164
|
+
def _buildFeatureFile(self, tables):
|
|
165
|
+
doc = ast.FeatureFile()
|
|
166
|
+
statements = doc.statements
|
|
167
|
+
|
|
168
|
+
if self._glyphclasses:
|
|
169
|
+
statements.append(ast.Comment("# Glyph classes"))
|
|
170
|
+
statements.extend(self._glyphclasses.values())
|
|
171
|
+
|
|
172
|
+
if self._markclasses:
|
|
173
|
+
statements.append(ast.Comment("\n# Mark classes"))
|
|
174
|
+
statements.extend(c[1] for c in sorted(self._markclasses.items()))
|
|
175
|
+
|
|
176
|
+
if self._lookups:
|
|
177
|
+
statements.append(ast.Comment("\n# Lookups"))
|
|
178
|
+
for lookup in self._lookups.values():
|
|
179
|
+
statements.extend(getattr(lookup, "targets", []))
|
|
180
|
+
statements.append(lookup)
|
|
181
|
+
|
|
182
|
+
# Prune features
|
|
183
|
+
features = self._features.copy()
|
|
184
|
+
for ftag in features:
|
|
185
|
+
scripts = features[ftag]
|
|
186
|
+
for stag in scripts:
|
|
187
|
+
langs = scripts[stag]
|
|
188
|
+
for ltag in langs:
|
|
189
|
+
langs[ltag] = [l for l in langs[ltag] if l.lower() in self._lookups]
|
|
190
|
+
scripts[stag] = {t: l for t, l in langs.items() if l}
|
|
191
|
+
features[ftag] = {t: s for t, s in scripts.items() if s}
|
|
192
|
+
features = {t: f for t, f in features.items() if f}
|
|
193
|
+
|
|
194
|
+
if features:
|
|
195
|
+
statements.append(ast.Comment("# Features"))
|
|
196
|
+
for ftag, scripts in features.items():
|
|
197
|
+
feature = ast.FeatureBlock(ftag)
|
|
198
|
+
stags = sorted(scripts, key=lambda k: 0 if k == "DFLT" else 1)
|
|
199
|
+
for stag in stags:
|
|
200
|
+
feature.statements.append(ast.ScriptStatement(stag))
|
|
201
|
+
ltags = sorted(scripts[stag], key=lambda k: 0 if k == "dflt" else 1)
|
|
202
|
+
for ltag in ltags:
|
|
203
|
+
include_default = True if ltag == "dflt" else False
|
|
204
|
+
feature.statements.append(
|
|
205
|
+
ast.LanguageStatement(ltag, include_default=include_default)
|
|
206
|
+
)
|
|
207
|
+
for name in scripts[stag][ltag]:
|
|
208
|
+
lookup = self._lookups[name.lower()]
|
|
209
|
+
lookupref = ast.LookupReferenceStatement(lookup)
|
|
210
|
+
feature.statements.append(lookupref)
|
|
211
|
+
statements.append(feature)
|
|
212
|
+
|
|
213
|
+
if self._gdef and "GDEF" in tables:
|
|
214
|
+
classes = []
|
|
215
|
+
for name in ("BASE", "MARK", "LIGATURE", "COMPONENT"):
|
|
216
|
+
if name in self._gdef:
|
|
217
|
+
classname = "GDEF_" + name.lower()
|
|
218
|
+
glyphclass = ast.GlyphClassDefinition(classname, self._gdef[name])
|
|
219
|
+
statements.append(glyphclass)
|
|
220
|
+
classes.append(ast.GlyphClassName(glyphclass))
|
|
221
|
+
else:
|
|
222
|
+
classes.append(None)
|
|
223
|
+
|
|
224
|
+
gdef = ast.TableBlock("GDEF")
|
|
225
|
+
gdef.statements.append(ast.GlyphClassDefStatement(*classes))
|
|
226
|
+
statements.append(gdef)
|
|
227
|
+
|
|
228
|
+
return doc
|
|
229
|
+
|
|
230
|
+
def convert(self, tables=None):
|
|
231
|
+
doc = VoltParser(self._file_or_path).parse()
|
|
232
|
+
|
|
233
|
+
if tables is None:
|
|
234
|
+
tables = TABLES
|
|
235
|
+
if self._font is not None:
|
|
236
|
+
self._glyph_order = self._font.getGlyphOrder()
|
|
237
|
+
|
|
238
|
+
self._collectStatements(doc, tables)
|
|
239
|
+
fea = self._buildFeatureFile(tables)
|
|
240
|
+
return fea.asFea()
|
|
241
|
+
|
|
242
|
+
def _glyphName(self, glyph):
|
|
243
|
+
try:
|
|
244
|
+
name = glyph.glyph
|
|
245
|
+
except AttributeError:
|
|
246
|
+
name = glyph
|
|
247
|
+
return ast.GlyphName(self._glyph_map.get(name, name))
|
|
248
|
+
|
|
249
|
+
def _groupName(self, group):
|
|
250
|
+
try:
|
|
251
|
+
name = group.group
|
|
252
|
+
except AttributeError:
|
|
253
|
+
name = group
|
|
254
|
+
return ast.GlyphClassName(self._glyphclasses[name.lower()])
|
|
255
|
+
|
|
256
|
+
def _coverage(self, coverage):
|
|
257
|
+
items = []
|
|
258
|
+
for item in coverage:
|
|
259
|
+
if isinstance(item, VAst.GlyphName):
|
|
260
|
+
items.append(self._glyphName(item))
|
|
261
|
+
elif isinstance(item, VAst.GroupName):
|
|
262
|
+
items.append(self._groupName(item))
|
|
263
|
+
elif isinstance(item, VAst.Enum):
|
|
264
|
+
items.append(self._enum(item))
|
|
265
|
+
elif isinstance(item, VAst.Range):
|
|
266
|
+
items.append((item.start, item.end))
|
|
267
|
+
else:
|
|
268
|
+
raise NotImplementedError(item)
|
|
269
|
+
return items
|
|
270
|
+
|
|
271
|
+
def _enum(self, enum):
|
|
272
|
+
return ast.GlyphClass(self._coverage(enum.enum))
|
|
273
|
+
|
|
274
|
+
def _context(self, context):
|
|
275
|
+
out = []
|
|
276
|
+
for item in context:
|
|
277
|
+
coverage = self._coverage(item)
|
|
278
|
+
if not isinstance(coverage, (tuple, list)):
|
|
279
|
+
coverage = [coverage]
|
|
280
|
+
out.extend(coverage)
|
|
281
|
+
return out
|
|
282
|
+
|
|
283
|
+
def _groupDefinition(self, group):
|
|
284
|
+
name = self._className(group.name)
|
|
285
|
+
glyphs = self._enum(group.enum)
|
|
286
|
+
glyphclass = ast.GlyphClassDefinition(name, glyphs)
|
|
287
|
+
|
|
288
|
+
self._glyphclasses[group.name.lower()] = glyphclass
|
|
289
|
+
|
|
290
|
+
def _glyphDefinition(self, glyph):
|
|
291
|
+
try:
|
|
292
|
+
self._glyph_map[glyph.name] = self._glyph_order[glyph.id]
|
|
293
|
+
except TypeError:
|
|
294
|
+
pass
|
|
295
|
+
|
|
296
|
+
if glyph.type in ("BASE", "MARK", "LIGATURE", "COMPONENT"):
|
|
297
|
+
if glyph.type not in self._gdef:
|
|
298
|
+
self._gdef[glyph.type] = ast.GlyphClass()
|
|
299
|
+
self._gdef[glyph.type].glyphs.append(self._glyphName(glyph.name))
|
|
300
|
+
|
|
301
|
+
if glyph.type == "MARK":
|
|
302
|
+
self._marks.add(glyph.name)
|
|
303
|
+
elif glyph.type == "LIGATURE":
|
|
304
|
+
self._ligatures[glyph.name] = glyph.components
|
|
305
|
+
|
|
306
|
+
def _scriptDefinition(self, script):
|
|
307
|
+
stag = script.tag
|
|
308
|
+
for lang in script.langs:
|
|
309
|
+
ltag = lang.tag
|
|
310
|
+
for feature in lang.features:
|
|
311
|
+
lookups = {l.split("\\")[0]: True for l in feature.lookups}
|
|
312
|
+
ftag = feature.tag
|
|
313
|
+
if ftag not in self._features:
|
|
314
|
+
self._features[ftag] = {}
|
|
315
|
+
if stag not in self._features[ftag]:
|
|
316
|
+
self._features[ftag][stag] = {}
|
|
317
|
+
assert ltag not in self._features[ftag][stag]
|
|
318
|
+
self._features[ftag][stag][ltag] = lookups.keys()
|
|
319
|
+
|
|
320
|
+
def _settingDefinition(self, setting):
|
|
321
|
+
if setting.name.startswith("COMPILER_"):
|
|
322
|
+
self._settings[setting.name] = setting.value
|
|
323
|
+
else:
|
|
324
|
+
log.warning(f"Unsupported setting ignored: {setting.name}")
|
|
325
|
+
|
|
326
|
+
def _adjustment(self, adjustment):
|
|
327
|
+
adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = adjustment
|
|
328
|
+
|
|
329
|
+
adv_device = adv_adjust_by and adv_adjust_by.items() or None
|
|
330
|
+
dx_device = dx_adjust_by and dx_adjust_by.items() or None
|
|
331
|
+
dy_device = dy_adjust_by and dy_adjust_by.items() or None
|
|
332
|
+
|
|
333
|
+
return ast.ValueRecord(
|
|
334
|
+
xPlacement=dx,
|
|
335
|
+
yPlacement=dy,
|
|
336
|
+
xAdvance=adv,
|
|
337
|
+
xPlaDevice=dx_device,
|
|
338
|
+
yPlaDevice=dy_device,
|
|
339
|
+
xAdvDevice=adv_device,
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
def _anchor(self, adjustment):
|
|
343
|
+
adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = adjustment
|
|
344
|
+
|
|
345
|
+
assert not adv_adjust_by
|
|
346
|
+
dx_device = dx_adjust_by and dx_adjust_by.items() or None
|
|
347
|
+
dy_device = dy_adjust_by and dy_adjust_by.items() or None
|
|
348
|
+
|
|
349
|
+
return ast.Anchor(
|
|
350
|
+
dx or 0,
|
|
351
|
+
dy or 0,
|
|
352
|
+
xDeviceTable=dx_device or None,
|
|
353
|
+
yDeviceTable=dy_device or None,
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
def _anchorDefinition(self, anchordef):
|
|
357
|
+
anchorname = anchordef.name
|
|
358
|
+
glyphname = anchordef.glyph_name
|
|
359
|
+
anchor = self._anchor(anchordef.pos)
|
|
360
|
+
|
|
361
|
+
if anchorname.startswith("MARK_"):
|
|
362
|
+
name = "_".join(anchorname.split("_")[1:])
|
|
363
|
+
markclass = ast.MarkClass(self._className(name))
|
|
364
|
+
glyph = self._glyphName(glyphname)
|
|
365
|
+
markdef = MarkClassDefinition(markclass, anchor, glyph)
|
|
366
|
+
self._markclasses[(glyphname, anchorname)] = markdef
|
|
367
|
+
else:
|
|
368
|
+
if glyphname not in self._anchors:
|
|
369
|
+
self._anchors[glyphname] = {}
|
|
370
|
+
if anchorname not in self._anchors[glyphname]:
|
|
371
|
+
self._anchors[glyphname][anchorname] = {}
|
|
372
|
+
self._anchors[glyphname][anchorname][anchordef.component] = anchor
|
|
373
|
+
|
|
374
|
+
def _gposLookup(self, lookup, fealookup):
|
|
375
|
+
statements = fealookup.statements
|
|
376
|
+
|
|
377
|
+
pos = lookup.pos
|
|
378
|
+
if isinstance(pos, VAst.PositionAdjustPairDefinition):
|
|
379
|
+
for (idx1, idx2), (pos1, pos2) in pos.adjust_pair.items():
|
|
380
|
+
coverage_1 = pos.coverages_1[idx1 - 1]
|
|
381
|
+
coverage_2 = pos.coverages_2[idx2 - 1]
|
|
382
|
+
|
|
383
|
+
# If not both are groups, use “enum pos” otherwise makeotf will
|
|
384
|
+
# fail.
|
|
385
|
+
enumerated = False
|
|
386
|
+
for item in coverage_1 + coverage_2:
|
|
387
|
+
if not isinstance(item, VAst.GroupName):
|
|
388
|
+
enumerated = True
|
|
389
|
+
|
|
390
|
+
glyphs1 = self._coverage(coverage_1)
|
|
391
|
+
glyphs2 = self._coverage(coverage_2)
|
|
392
|
+
record1 = self._adjustment(pos1)
|
|
393
|
+
record2 = self._adjustment(pos2)
|
|
394
|
+
assert len(glyphs1) == 1
|
|
395
|
+
assert len(glyphs2) == 1
|
|
396
|
+
statements.append(
|
|
397
|
+
ast.PairPosStatement(
|
|
398
|
+
glyphs1[0], record1, glyphs2[0], record2, enumerated=enumerated
|
|
399
|
+
)
|
|
400
|
+
)
|
|
401
|
+
elif isinstance(pos, VAst.PositionAdjustSingleDefinition):
|
|
402
|
+
for a, b in pos.adjust_single:
|
|
403
|
+
glyphs = self._coverage(a)
|
|
404
|
+
record = self._adjustment(b)
|
|
405
|
+
assert len(glyphs) == 1
|
|
406
|
+
statements.append(
|
|
407
|
+
ast.SinglePosStatement([(glyphs[0], record)], [], [], False)
|
|
408
|
+
)
|
|
409
|
+
elif isinstance(pos, VAst.PositionAttachDefinition):
|
|
410
|
+
anchors = {}
|
|
411
|
+
for marks, classname in pos.coverage_to:
|
|
412
|
+
for mark in marks:
|
|
413
|
+
# Set actually used mark classes. Basically a hack to get
|
|
414
|
+
# around the feature file syntax limitation of making mark
|
|
415
|
+
# classes global and not allowing mark positioning to
|
|
416
|
+
# specify mark coverage.
|
|
417
|
+
for name in mark.glyphSet():
|
|
418
|
+
key = (name, "MARK_" + classname)
|
|
419
|
+
self._markclasses[key].used = True
|
|
420
|
+
markclass = ast.MarkClass(self._className(classname))
|
|
421
|
+
for base in pos.coverage:
|
|
422
|
+
for name in base.glyphSet():
|
|
423
|
+
if name not in anchors:
|
|
424
|
+
anchors[name] = []
|
|
425
|
+
if classname not in anchors[name]:
|
|
426
|
+
anchors[name].append(classname)
|
|
427
|
+
|
|
428
|
+
for name in anchors:
|
|
429
|
+
components = 1
|
|
430
|
+
if name in self._ligatures:
|
|
431
|
+
components = self._ligatures[name]
|
|
432
|
+
|
|
433
|
+
marks = []
|
|
434
|
+
for mark in anchors[name]:
|
|
435
|
+
markclass = ast.MarkClass(self._className(mark))
|
|
436
|
+
for component in range(1, components + 1):
|
|
437
|
+
if len(marks) < component:
|
|
438
|
+
marks.append([])
|
|
439
|
+
anchor = None
|
|
440
|
+
if component in self._anchors[name][mark]:
|
|
441
|
+
anchor = self._anchors[name][mark][component]
|
|
442
|
+
marks[component - 1].append((anchor, markclass))
|
|
443
|
+
|
|
444
|
+
base = self._glyphName(name)
|
|
445
|
+
if name in self._marks:
|
|
446
|
+
mark = ast.MarkMarkPosStatement(base, marks[0])
|
|
447
|
+
elif name in self._ligatures:
|
|
448
|
+
mark = ast.MarkLigPosStatement(base, marks)
|
|
449
|
+
else:
|
|
450
|
+
mark = ast.MarkBasePosStatement(base, marks[0])
|
|
451
|
+
statements.append(mark)
|
|
452
|
+
elif isinstance(pos, VAst.PositionAttachCursiveDefinition):
|
|
453
|
+
# Collect enter and exit glyphs
|
|
454
|
+
enter_coverage = []
|
|
455
|
+
for coverage in pos.coverages_enter:
|
|
456
|
+
for base in coverage:
|
|
457
|
+
for name in base.glyphSet():
|
|
458
|
+
enter_coverage.append(name)
|
|
459
|
+
exit_coverage = []
|
|
460
|
+
for coverage in pos.coverages_exit:
|
|
461
|
+
for base in coverage:
|
|
462
|
+
for name in base.glyphSet():
|
|
463
|
+
exit_coverage.append(name)
|
|
464
|
+
|
|
465
|
+
# Write enter anchors, also check if the glyph has exit anchor and
|
|
466
|
+
# write it, too.
|
|
467
|
+
for name in enter_coverage:
|
|
468
|
+
glyph = self._glyphName(name)
|
|
469
|
+
entry = self._anchors[name]["entry"][1]
|
|
470
|
+
exit = None
|
|
471
|
+
if name in exit_coverage:
|
|
472
|
+
exit = self._anchors[name]["exit"][1]
|
|
473
|
+
exit_coverage.pop(exit_coverage.index(name))
|
|
474
|
+
statements.append(ast.CursivePosStatement(glyph, entry, exit))
|
|
475
|
+
|
|
476
|
+
# Write any remaining exit anchors.
|
|
477
|
+
for name in exit_coverage:
|
|
478
|
+
glyph = self._glyphName(name)
|
|
479
|
+
exit = self._anchors[name]["exit"][1]
|
|
480
|
+
statements.append(ast.CursivePosStatement(glyph, None, exit))
|
|
481
|
+
else:
|
|
482
|
+
raise NotImplementedError(pos)
|
|
483
|
+
|
|
484
|
+
def _gposContextLookup(
|
|
485
|
+
self, lookup, prefix, suffix, ignore, fealookup, targetlookup
|
|
486
|
+
):
|
|
487
|
+
statements = fealookup.statements
|
|
488
|
+
|
|
489
|
+
assert not lookup.reversal
|
|
490
|
+
|
|
491
|
+
pos = lookup.pos
|
|
492
|
+
if isinstance(pos, VAst.PositionAdjustPairDefinition):
|
|
493
|
+
for (idx1, idx2), (pos1, pos2) in pos.adjust_pair.items():
|
|
494
|
+
glyphs1 = self._coverage(pos.coverages_1[idx1 - 1])
|
|
495
|
+
glyphs2 = self._coverage(pos.coverages_2[idx2 - 1])
|
|
496
|
+
assert len(glyphs1) == 1
|
|
497
|
+
assert len(glyphs2) == 1
|
|
498
|
+
glyphs = (glyphs1[0], glyphs2[0])
|
|
499
|
+
|
|
500
|
+
if ignore:
|
|
501
|
+
statement = ast.IgnorePosStatement([(prefix, glyphs, suffix)])
|
|
502
|
+
else:
|
|
503
|
+
lookups = (targetlookup, targetlookup)
|
|
504
|
+
statement = ast.ChainContextPosStatement(
|
|
505
|
+
prefix, glyphs, suffix, lookups
|
|
506
|
+
)
|
|
507
|
+
statements.append(statement)
|
|
508
|
+
elif isinstance(pos, VAst.PositionAdjustSingleDefinition):
|
|
509
|
+
glyphs = [ast.GlyphClass()]
|
|
510
|
+
for a, b in pos.adjust_single:
|
|
511
|
+
glyph = self._coverage(a)
|
|
512
|
+
glyphs[0].extend(glyph)
|
|
513
|
+
|
|
514
|
+
if ignore:
|
|
515
|
+
statement = ast.IgnorePosStatement([(prefix, glyphs, suffix)])
|
|
516
|
+
else:
|
|
517
|
+
statement = ast.ChainContextPosStatement(
|
|
518
|
+
prefix, glyphs, suffix, [targetlookup]
|
|
519
|
+
)
|
|
520
|
+
statements.append(statement)
|
|
521
|
+
elif isinstance(pos, VAst.PositionAttachDefinition):
|
|
522
|
+
glyphs = [ast.GlyphClass()]
|
|
523
|
+
for coverage, _ in pos.coverage_to:
|
|
524
|
+
glyphs[0].extend(self._coverage(coverage))
|
|
525
|
+
|
|
526
|
+
if ignore:
|
|
527
|
+
statement = ast.IgnorePosStatement([(prefix, glyphs, suffix)])
|
|
528
|
+
else:
|
|
529
|
+
statement = ast.ChainContextPosStatement(
|
|
530
|
+
prefix, glyphs, suffix, [targetlookup]
|
|
531
|
+
)
|
|
532
|
+
statements.append(statement)
|
|
533
|
+
else:
|
|
534
|
+
raise NotImplementedError(pos)
|
|
535
|
+
|
|
536
|
+
def _gsubLookup(self, lookup, prefix, suffix, ignore, chain, fealookup):
|
|
537
|
+
statements = fealookup.statements
|
|
538
|
+
|
|
539
|
+
sub = lookup.sub
|
|
540
|
+
for key, val in sub.mapping.items():
|
|
541
|
+
if not key or not val:
|
|
542
|
+
path, line, column = sub.location
|
|
543
|
+
log.warning(f"{path}:{line}:{column}: Ignoring empty substitution")
|
|
544
|
+
continue
|
|
545
|
+
statement = None
|
|
546
|
+
glyphs = self._coverage(key)
|
|
547
|
+
replacements = self._coverage(val)
|
|
548
|
+
if ignore:
|
|
549
|
+
chain_context = (prefix, glyphs, suffix)
|
|
550
|
+
statement = ast.IgnoreSubstStatement([chain_context])
|
|
551
|
+
elif isinstance(sub, VAst.SubstitutionSingleDefinition):
|
|
552
|
+
assert len(glyphs) == 1
|
|
553
|
+
assert len(replacements) == 1
|
|
554
|
+
statement = ast.SingleSubstStatement(
|
|
555
|
+
glyphs, replacements, prefix, suffix, chain
|
|
556
|
+
)
|
|
557
|
+
elif isinstance(sub, VAst.SubstitutionReverseChainingSingleDefinition):
|
|
558
|
+
assert len(glyphs) == 1
|
|
559
|
+
assert len(replacements) == 1
|
|
560
|
+
statement = ast.ReverseChainSingleSubstStatement(
|
|
561
|
+
prefix, suffix, glyphs, replacements
|
|
562
|
+
)
|
|
563
|
+
elif isinstance(sub, VAst.SubstitutionMultipleDefinition):
|
|
564
|
+
assert len(glyphs) == 1
|
|
565
|
+
statement = ast.MultipleSubstStatement(
|
|
566
|
+
prefix, glyphs[0], suffix, replacements, chain
|
|
567
|
+
)
|
|
568
|
+
elif isinstance(sub, VAst.SubstitutionLigatureDefinition):
|
|
569
|
+
assert len(replacements) == 1
|
|
570
|
+
statement = ast.LigatureSubstStatement(
|
|
571
|
+
prefix, glyphs, suffix, replacements[0], chain
|
|
572
|
+
)
|
|
573
|
+
else:
|
|
574
|
+
raise NotImplementedError(sub)
|
|
575
|
+
statements.append(statement)
|
|
576
|
+
|
|
577
|
+
def _lookupDefinition(self, lookup):
|
|
578
|
+
mark_attachement = None
|
|
579
|
+
mark_filtering = None
|
|
580
|
+
|
|
581
|
+
flags = 0
|
|
582
|
+
if lookup.direction == "RTL":
|
|
583
|
+
flags |= 1
|
|
584
|
+
if not lookup.process_base:
|
|
585
|
+
flags |= 2
|
|
586
|
+
# FIXME: Does VOLT support this?
|
|
587
|
+
# if not lookup.process_ligatures:
|
|
588
|
+
# flags |= 4
|
|
589
|
+
if not lookup.process_marks:
|
|
590
|
+
flags |= 8
|
|
591
|
+
elif isinstance(lookup.process_marks, str):
|
|
592
|
+
mark_attachement = self._groupName(lookup.process_marks)
|
|
593
|
+
elif lookup.mark_glyph_set is not None:
|
|
594
|
+
mark_filtering = self._groupName(lookup.mark_glyph_set)
|
|
595
|
+
|
|
596
|
+
lookupflags = None
|
|
597
|
+
if flags or mark_attachement is not None or mark_filtering is not None:
|
|
598
|
+
lookupflags = ast.LookupFlagStatement(
|
|
599
|
+
flags, mark_attachement, mark_filtering
|
|
600
|
+
)
|
|
601
|
+
if "\\" in lookup.name:
|
|
602
|
+
# Merge sub lookups as subtables (lookups named “base\sub”),
|
|
603
|
+
# makeotf/feaLib will issue a warning and ignore the subtable
|
|
604
|
+
# statement if it is not a pairpos lookup, though.
|
|
605
|
+
name = lookup.name.split("\\")[0]
|
|
606
|
+
if name.lower() not in self._lookups:
|
|
607
|
+
fealookup = ast.LookupBlock(self._lookupName(name))
|
|
608
|
+
if lookupflags is not None:
|
|
609
|
+
fealookup.statements.append(lookupflags)
|
|
610
|
+
fealookup.statements.append(ast.Comment("# " + lookup.name))
|
|
611
|
+
else:
|
|
612
|
+
fealookup = self._lookups[name.lower()]
|
|
613
|
+
fealookup.statements.append(ast.SubtableStatement())
|
|
614
|
+
fealookup.statements.append(ast.Comment("# " + lookup.name))
|
|
615
|
+
self._lookups[name.lower()] = fealookup
|
|
616
|
+
else:
|
|
617
|
+
fealookup = ast.LookupBlock(self._lookupName(lookup.name))
|
|
618
|
+
if lookupflags is not None:
|
|
619
|
+
fealookup.statements.append(lookupflags)
|
|
620
|
+
self._lookups[lookup.name.lower()] = fealookup
|
|
621
|
+
|
|
622
|
+
if lookup.comments is not None:
|
|
623
|
+
fealookup.statements.append(ast.Comment("# " + lookup.comments))
|
|
624
|
+
|
|
625
|
+
contexts = []
|
|
626
|
+
if lookup.context:
|
|
627
|
+
for context in lookup.context:
|
|
628
|
+
prefix = self._context(context.left)
|
|
629
|
+
suffix = self._context(context.right)
|
|
630
|
+
ignore = context.ex_or_in == "EXCEPT_CONTEXT"
|
|
631
|
+
contexts.append([prefix, suffix, ignore, False])
|
|
632
|
+
# It seems that VOLT will create contextual substitution using
|
|
633
|
+
# only the input if there is no other contexts in this lookup.
|
|
634
|
+
if ignore and len(lookup.context) == 1:
|
|
635
|
+
contexts.append([[], [], False, True])
|
|
636
|
+
else:
|
|
637
|
+
contexts.append([[], [], False, False])
|
|
638
|
+
|
|
639
|
+
targetlookup = None
|
|
640
|
+
for prefix, suffix, ignore, chain in contexts:
|
|
641
|
+
if lookup.sub is not None:
|
|
642
|
+
self._gsubLookup(lookup, prefix, suffix, ignore, chain, fealookup)
|
|
643
|
+
|
|
644
|
+
if lookup.pos is not None:
|
|
645
|
+
if self._settings.get("COMPILER_USEEXTENSIONLOOKUPS"):
|
|
646
|
+
fealookup.use_extension = True
|
|
647
|
+
if prefix or suffix or chain or ignore:
|
|
648
|
+
if not ignore and targetlookup is None:
|
|
649
|
+
targetname = self._lookupName(lookup.name + " target")
|
|
650
|
+
targetlookup = ast.LookupBlock(targetname)
|
|
651
|
+
fealookup.targets = getattr(fealookup, "targets", [])
|
|
652
|
+
fealookup.targets.append(targetlookup)
|
|
653
|
+
self._gposLookup(lookup, targetlookup)
|
|
654
|
+
self._gposContextLookup(
|
|
655
|
+
lookup, prefix, suffix, ignore, fealookup, targetlookup
|
|
656
|
+
)
|
|
657
|
+
else:
|
|
658
|
+
self._gposLookup(lookup, fealookup)
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def main(args=None):
|
|
662
|
+
"""Convert MS VOLT to AFDKO feature files."""
|
|
663
|
+
|
|
664
|
+
import argparse
|
|
665
|
+
from pathlib import Path
|
|
666
|
+
|
|
667
|
+
from fontTools import configLogger
|
|
668
|
+
|
|
669
|
+
parser = argparse.ArgumentParser(
|
|
670
|
+
"fonttools voltLib.voltToFea", description=main.__doc__
|
|
671
|
+
)
|
|
672
|
+
parser.add_argument(
|
|
673
|
+
"input", metavar="INPUT", type=Path, help="input font/VTP file to process"
|
|
674
|
+
)
|
|
675
|
+
parser.add_argument(
|
|
676
|
+
"featurefile", metavar="OUTPUT", type=Path, help="output feature file"
|
|
677
|
+
)
|
|
678
|
+
parser.add_argument(
|
|
679
|
+
"-t",
|
|
680
|
+
"--table",
|
|
681
|
+
action="append",
|
|
682
|
+
choices=TABLES,
|
|
683
|
+
dest="tables",
|
|
684
|
+
help="List of tables to write, by default all tables are written",
|
|
685
|
+
)
|
|
686
|
+
parser.add_argument(
|
|
687
|
+
"-q", "--quiet", action="store_true", help="Suppress non-error messages"
|
|
688
|
+
)
|
|
689
|
+
parser.add_argument(
|
|
690
|
+
"--traceback", action="store_true", help="Don’t catch exceptions"
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
options = parser.parse_args(args)
|
|
694
|
+
|
|
695
|
+
configLogger(level=("ERROR" if options.quiet else "INFO"))
|
|
696
|
+
|
|
697
|
+
file_or_path = options.input
|
|
698
|
+
font = None
|
|
699
|
+
try:
|
|
700
|
+
font = TTFont(file_or_path)
|
|
701
|
+
if "TSIV" in font:
|
|
702
|
+
file_or_path = StringIO(font["TSIV"].data.decode("utf-8"))
|
|
703
|
+
else:
|
|
704
|
+
log.error('"TSIV" table is missing, font was not saved from VOLT?')
|
|
705
|
+
return 1
|
|
706
|
+
except TTLibError:
|
|
707
|
+
pass
|
|
708
|
+
|
|
709
|
+
converter = VoltToFea(file_or_path, font)
|
|
710
|
+
try:
|
|
711
|
+
fea = converter.convert(options.tables)
|
|
712
|
+
except NotImplementedError as e:
|
|
713
|
+
if options.traceback:
|
|
714
|
+
raise
|
|
715
|
+
location = getattr(e.args[0], "location", None)
|
|
716
|
+
message = f'"{e}" is not supported'
|
|
717
|
+
if location:
|
|
718
|
+
path, line, column = location
|
|
719
|
+
log.error(f"{path}:{line}:{column}: {message}")
|
|
720
|
+
else:
|
|
721
|
+
log.error(message)
|
|
722
|
+
return 1
|
|
723
|
+
with open(options.featurefile, "w") as feafile:
|
|
724
|
+
feafile.write(fea)
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
if __name__ == "__main__":
|
|
728
|
+
import sys
|
|
729
|
+
|
|
730
|
+
sys.exit(main())
|