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.

Files changed (329) hide show
  1. fontTools/__init__.py +8 -0
  2. fontTools/__main__.py +35 -0
  3. fontTools/afmLib.py +439 -0
  4. fontTools/agl.py +5233 -0
  5. fontTools/cffLib/CFF2ToCFF.py +203 -0
  6. fontTools/cffLib/CFFToCFF2.py +305 -0
  7. fontTools/cffLib/__init__.py +3659 -0
  8. fontTools/cffLib/specializer.py +924 -0
  9. fontTools/cffLib/transforms.py +490 -0
  10. fontTools/cffLib/width.py +210 -0
  11. fontTools/colorLib/__init__.py +0 -0
  12. fontTools/colorLib/builder.py +664 -0
  13. fontTools/colorLib/errors.py +2 -0
  14. fontTools/colorLib/geometry.py +143 -0
  15. fontTools/colorLib/table_builder.py +223 -0
  16. fontTools/colorLib/unbuilder.py +81 -0
  17. fontTools/config/__init__.py +75 -0
  18. fontTools/cu2qu/__init__.py +15 -0
  19. fontTools/cu2qu/__main__.py +6 -0
  20. fontTools/cu2qu/benchmark.py +54 -0
  21. fontTools/cu2qu/cli.py +198 -0
  22. fontTools/cu2qu/cu2qu.c +14829 -0
  23. fontTools/cu2qu/cu2qu.cpython-311-x86_64-linux-musl.so +0 -0
  24. fontTools/cu2qu/cu2qu.py +531 -0
  25. fontTools/cu2qu/errors.py +77 -0
  26. fontTools/cu2qu/ufo.py +349 -0
  27. fontTools/designspaceLib/__init__.py +3338 -0
  28. fontTools/designspaceLib/__main__.py +6 -0
  29. fontTools/designspaceLib/split.py +475 -0
  30. fontTools/designspaceLib/statNames.py +253 -0
  31. fontTools/designspaceLib/types.py +147 -0
  32. fontTools/encodings/MacRoman.py +258 -0
  33. fontTools/encodings/StandardEncoding.py +258 -0
  34. fontTools/encodings/__init__.py +1 -0
  35. fontTools/encodings/codecs.py +135 -0
  36. fontTools/feaLib/__init__.py +4 -0
  37. fontTools/feaLib/__main__.py +78 -0
  38. fontTools/feaLib/ast.py +2134 -0
  39. fontTools/feaLib/builder.py +1747 -0
  40. fontTools/feaLib/error.py +22 -0
  41. fontTools/feaLib/lexer.c +17986 -0
  42. fontTools/feaLib/lexer.cpython-311-x86_64-linux-musl.so +0 -0
  43. fontTools/feaLib/lexer.py +287 -0
  44. fontTools/feaLib/location.py +12 -0
  45. fontTools/feaLib/lookupDebugInfo.py +12 -0
  46. fontTools/feaLib/parser.py +2359 -0
  47. fontTools/feaLib/variableScalar.py +113 -0
  48. fontTools/fontBuilder.py +1008 -0
  49. fontTools/help.py +36 -0
  50. fontTools/merge/__init__.py +248 -0
  51. fontTools/merge/__main__.py +6 -0
  52. fontTools/merge/base.py +81 -0
  53. fontTools/merge/cmap.py +141 -0
  54. fontTools/merge/layout.py +526 -0
  55. fontTools/merge/options.py +85 -0
  56. fontTools/merge/tables.py +341 -0
  57. fontTools/merge/unicode.py +78 -0
  58. fontTools/merge/util.py +143 -0
  59. fontTools/misc/__init__.py +1 -0
  60. fontTools/misc/arrayTools.py +424 -0
  61. fontTools/misc/bezierTools.c +41831 -0
  62. fontTools/misc/bezierTools.cpython-311-x86_64-linux-musl.so +0 -0
  63. fontTools/misc/bezierTools.py +1497 -0
  64. fontTools/misc/classifyTools.py +170 -0
  65. fontTools/misc/cliTools.py +53 -0
  66. fontTools/misc/configTools.py +349 -0
  67. fontTools/misc/cython.py +27 -0
  68. fontTools/misc/dictTools.py +83 -0
  69. fontTools/misc/eexec.py +119 -0
  70. fontTools/misc/encodingTools.py +72 -0
  71. fontTools/misc/etree.py +479 -0
  72. fontTools/misc/filenames.py +245 -0
  73. fontTools/misc/fixedTools.py +253 -0
  74. fontTools/misc/intTools.py +25 -0
  75. fontTools/misc/iterTools.py +12 -0
  76. fontTools/misc/lazyTools.py +42 -0
  77. fontTools/misc/loggingTools.py +543 -0
  78. fontTools/misc/macCreatorType.py +56 -0
  79. fontTools/misc/macRes.py +261 -0
  80. fontTools/misc/plistlib/__init__.py +681 -0
  81. fontTools/misc/plistlib/py.typed +0 -0
  82. fontTools/misc/psCharStrings.py +1496 -0
  83. fontTools/misc/psLib.py +398 -0
  84. fontTools/misc/psOperators.py +572 -0
  85. fontTools/misc/py23.py +96 -0
  86. fontTools/misc/roundTools.py +110 -0
  87. fontTools/misc/sstruct.py +231 -0
  88. fontTools/misc/symfont.py +244 -0
  89. fontTools/misc/testTools.py +229 -0
  90. fontTools/misc/textTools.py +154 -0
  91. fontTools/misc/timeTools.py +88 -0
  92. fontTools/misc/transform.py +516 -0
  93. fontTools/misc/treeTools.py +45 -0
  94. fontTools/misc/vector.py +147 -0
  95. fontTools/misc/visitor.py +142 -0
  96. fontTools/misc/xmlReader.py +188 -0
  97. fontTools/misc/xmlWriter.py +204 -0
  98. fontTools/mtiLib/__init__.py +1402 -0
  99. fontTools/mtiLib/__main__.py +5 -0
  100. fontTools/otlLib/__init__.py +1 -0
  101. fontTools/otlLib/builder.py +3221 -0
  102. fontTools/otlLib/error.py +11 -0
  103. fontTools/otlLib/maxContextCalc.py +96 -0
  104. fontTools/otlLib/optimize/__init__.py +53 -0
  105. fontTools/otlLib/optimize/__main__.py +6 -0
  106. fontTools/otlLib/optimize/gpos.py +453 -0
  107. fontTools/pens/__init__.py +1 -0
  108. fontTools/pens/areaPen.py +52 -0
  109. fontTools/pens/basePen.py +475 -0
  110. fontTools/pens/boundsPen.py +98 -0
  111. fontTools/pens/cairoPen.py +26 -0
  112. fontTools/pens/cocoaPen.py +26 -0
  113. fontTools/pens/cu2quPen.py +325 -0
  114. fontTools/pens/explicitClosingLinePen.py +101 -0
  115. fontTools/pens/filterPen.py +241 -0
  116. fontTools/pens/freetypePen.py +462 -0
  117. fontTools/pens/hashPointPen.py +89 -0
  118. fontTools/pens/momentsPen.c +13448 -0
  119. fontTools/pens/momentsPen.cpython-311-x86_64-linux-musl.so +0 -0
  120. fontTools/pens/momentsPen.py +879 -0
  121. fontTools/pens/perimeterPen.py +69 -0
  122. fontTools/pens/pointInsidePen.py +192 -0
  123. fontTools/pens/pointPen.py +600 -0
  124. fontTools/pens/qtPen.py +29 -0
  125. fontTools/pens/qu2cuPen.py +105 -0
  126. fontTools/pens/quartzPen.py +43 -0
  127. fontTools/pens/recordingPen.py +335 -0
  128. fontTools/pens/reportLabPen.py +79 -0
  129. fontTools/pens/reverseContourPen.py +96 -0
  130. fontTools/pens/roundingPen.py +130 -0
  131. fontTools/pens/statisticsPen.py +312 -0
  132. fontTools/pens/svgPathPen.py +310 -0
  133. fontTools/pens/t2CharStringPen.py +68 -0
  134. fontTools/pens/teePen.py +55 -0
  135. fontTools/pens/transformPen.py +115 -0
  136. fontTools/pens/ttGlyphPen.py +335 -0
  137. fontTools/pens/wxPen.py +29 -0
  138. fontTools/qu2cu/__init__.py +15 -0
  139. fontTools/qu2cu/__main__.py +7 -0
  140. fontTools/qu2cu/benchmark.py +56 -0
  141. fontTools/qu2cu/cli.py +125 -0
  142. fontTools/qu2cu/qu2cu.c +16269 -0
  143. fontTools/qu2cu/qu2cu.cpython-311-x86_64-linux-musl.so +0 -0
  144. fontTools/qu2cu/qu2cu.py +405 -0
  145. fontTools/subset/__init__.py +3838 -0
  146. fontTools/subset/__main__.py +6 -0
  147. fontTools/subset/cff.py +184 -0
  148. fontTools/subset/svg.py +253 -0
  149. fontTools/subset/util.py +25 -0
  150. fontTools/svgLib/__init__.py +3 -0
  151. fontTools/svgLib/path/__init__.py +65 -0
  152. fontTools/svgLib/path/arc.py +154 -0
  153. fontTools/svgLib/path/parser.py +322 -0
  154. fontTools/svgLib/path/shapes.py +183 -0
  155. fontTools/t1Lib/__init__.py +648 -0
  156. fontTools/tfmLib.py +460 -0
  157. fontTools/ttLib/__init__.py +26 -0
  158. fontTools/ttLib/__main__.py +109 -0
  159. fontTools/ttLib/macUtils.py +54 -0
  160. fontTools/ttLib/removeOverlaps.py +393 -0
  161. fontTools/ttLib/reorderGlyphs.py +284 -0
  162. fontTools/ttLib/scaleUpem.py +436 -0
  163. fontTools/ttLib/sfnt.py +662 -0
  164. fontTools/ttLib/standardGlyphOrder.py +271 -0
  165. fontTools/ttLib/tables/B_A_S_E_.py +14 -0
  166. fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
  167. fontTools/ttLib/tables/C_B_D_T_.py +113 -0
  168. fontTools/ttLib/tables/C_B_L_C_.py +19 -0
  169. fontTools/ttLib/tables/C_F_F_.py +61 -0
  170. fontTools/ttLib/tables/C_F_F__2.py +26 -0
  171. fontTools/ttLib/tables/C_O_L_R_.py +165 -0
  172. fontTools/ttLib/tables/C_P_A_L_.py +305 -0
  173. fontTools/ttLib/tables/D_S_I_G_.py +158 -0
  174. fontTools/ttLib/tables/D__e_b_g.py +17 -0
  175. fontTools/ttLib/tables/DefaultTable.py +49 -0
  176. fontTools/ttLib/tables/E_B_D_T_.py +835 -0
  177. fontTools/ttLib/tables/E_B_L_C_.py +718 -0
  178. fontTools/ttLib/tables/F_F_T_M_.py +52 -0
  179. fontTools/ttLib/tables/F__e_a_t.py +149 -0
  180. fontTools/ttLib/tables/G_D_E_F_.py +13 -0
  181. fontTools/ttLib/tables/G_M_A_P_.py +148 -0
  182. fontTools/ttLib/tables/G_P_K_G_.py +133 -0
  183. fontTools/ttLib/tables/G_P_O_S_.py +14 -0
  184. fontTools/ttLib/tables/G_S_U_B_.py +13 -0
  185. fontTools/ttLib/tables/G__l_a_t.py +235 -0
  186. fontTools/ttLib/tables/G__l_o_c.py +85 -0
  187. fontTools/ttLib/tables/H_V_A_R_.py +13 -0
  188. fontTools/ttLib/tables/J_S_T_F_.py +13 -0
  189. fontTools/ttLib/tables/L_T_S_H_.py +58 -0
  190. fontTools/ttLib/tables/M_A_T_H_.py +13 -0
  191. fontTools/ttLib/tables/M_E_T_A_.py +352 -0
  192. fontTools/ttLib/tables/M_V_A_R_.py +13 -0
  193. fontTools/ttLib/tables/O_S_2f_2.py +752 -0
  194. fontTools/ttLib/tables/S_I_N_G_.py +99 -0
  195. fontTools/ttLib/tables/S_T_A_T_.py +15 -0
  196. fontTools/ttLib/tables/S_V_G_.py +223 -0
  197. fontTools/ttLib/tables/S__i_l_f.py +1040 -0
  198. fontTools/ttLib/tables/S__i_l_l.py +92 -0
  199. fontTools/ttLib/tables/T_S_I_B_.py +13 -0
  200. fontTools/ttLib/tables/T_S_I_C_.py +14 -0
  201. fontTools/ttLib/tables/T_S_I_D_.py +13 -0
  202. fontTools/ttLib/tables/T_S_I_J_.py +13 -0
  203. fontTools/ttLib/tables/T_S_I_P_.py +13 -0
  204. fontTools/ttLib/tables/T_S_I_S_.py +13 -0
  205. fontTools/ttLib/tables/T_S_I_V_.py +26 -0
  206. fontTools/ttLib/tables/T_S_I__0.py +59 -0
  207. fontTools/ttLib/tables/T_S_I__1.py +166 -0
  208. fontTools/ttLib/tables/T_S_I__2.py +17 -0
  209. fontTools/ttLib/tables/T_S_I__3.py +22 -0
  210. fontTools/ttLib/tables/T_S_I__5.py +49 -0
  211. fontTools/ttLib/tables/T_T_F_A_.py +14 -0
  212. fontTools/ttLib/tables/TupleVariation.py +884 -0
  213. fontTools/ttLib/tables/V_A_R_C_.py +12 -0
  214. fontTools/ttLib/tables/V_D_M_X_.py +249 -0
  215. fontTools/ttLib/tables/V_O_R_G_.py +165 -0
  216. fontTools/ttLib/tables/V_V_A_R_.py +13 -0
  217. fontTools/ttLib/tables/__init__.py +97 -0
  218. fontTools/ttLib/tables/_a_n_k_r.py +15 -0
  219. fontTools/ttLib/tables/_a_v_a_r.py +191 -0
  220. fontTools/ttLib/tables/_b_s_l_n.py +15 -0
  221. fontTools/ttLib/tables/_c_i_d_g.py +24 -0
  222. fontTools/ttLib/tables/_c_m_a_p.py +1578 -0
  223. fontTools/ttLib/tables/_c_v_a_r.py +94 -0
  224. fontTools/ttLib/tables/_c_v_t.py +55 -0
  225. fontTools/ttLib/tables/_f_e_a_t.py +15 -0
  226. fontTools/ttLib/tables/_f_p_g_m.py +60 -0
  227. fontTools/ttLib/tables/_f_v_a_r.py +261 -0
  228. fontTools/ttLib/tables/_g_a_s_p.py +63 -0
  229. fontTools/ttLib/tables/_g_c_i_d.py +13 -0
  230. fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
  231. fontTools/ttLib/tables/_g_v_a_r.py +292 -0
  232. fontTools/ttLib/tables/_h_d_m_x.py +127 -0
  233. fontTools/ttLib/tables/_h_e_a_d.py +130 -0
  234. fontTools/ttLib/tables/_h_h_e_a.py +147 -0
  235. fontTools/ttLib/tables/_h_m_t_x.py +160 -0
  236. fontTools/ttLib/tables/_k_e_r_n.py +289 -0
  237. fontTools/ttLib/tables/_l_c_a_r.py +13 -0
  238. fontTools/ttLib/tables/_l_o_c_a.py +70 -0
  239. fontTools/ttLib/tables/_l_t_a_g.py +72 -0
  240. fontTools/ttLib/tables/_m_a_x_p.py +147 -0
  241. fontTools/ttLib/tables/_m_e_t_a.py +112 -0
  242. fontTools/ttLib/tables/_m_o_r_t.py +14 -0
  243. fontTools/ttLib/tables/_m_o_r_x.py +15 -0
  244. fontTools/ttLib/tables/_n_a_m_e.py +1237 -0
  245. fontTools/ttLib/tables/_o_p_b_d.py +14 -0
  246. fontTools/ttLib/tables/_p_o_s_t.py +317 -0
  247. fontTools/ttLib/tables/_p_r_e_p.py +16 -0
  248. fontTools/ttLib/tables/_p_r_o_p.py +12 -0
  249. fontTools/ttLib/tables/_s_b_i_x.py +129 -0
  250. fontTools/ttLib/tables/_t_r_a_k.py +332 -0
  251. fontTools/ttLib/tables/_v_h_e_a.py +139 -0
  252. fontTools/ttLib/tables/_v_m_t_x.py +19 -0
  253. fontTools/ttLib/tables/asciiTable.py +20 -0
  254. fontTools/ttLib/tables/grUtils.py +92 -0
  255. fontTools/ttLib/tables/otBase.py +1465 -0
  256. fontTools/ttLib/tables/otConverters.py +2065 -0
  257. fontTools/ttLib/tables/otData.py +6400 -0
  258. fontTools/ttLib/tables/otTables.py +2700 -0
  259. fontTools/ttLib/tables/otTraverse.py +162 -0
  260. fontTools/ttLib/tables/sbixGlyph.py +149 -0
  261. fontTools/ttLib/tables/sbixStrike.py +177 -0
  262. fontTools/ttLib/tables/table_API_readme.txt +91 -0
  263. fontTools/ttLib/tables/ttProgram.py +594 -0
  264. fontTools/ttLib/ttCollection.py +125 -0
  265. fontTools/ttLib/ttFont.py +1155 -0
  266. fontTools/ttLib/ttGlyphSet.py +500 -0
  267. fontTools/ttLib/ttVisitor.py +32 -0
  268. fontTools/ttLib/woff2.py +1683 -0
  269. fontTools/ttx.py +467 -0
  270. fontTools/ufoLib/__init__.py +2477 -0
  271. fontTools/ufoLib/converters.py +334 -0
  272. fontTools/ufoLib/errors.py +22 -0
  273. fontTools/ufoLib/etree.py +6 -0
  274. fontTools/ufoLib/filenames.py +291 -0
  275. fontTools/ufoLib/glifLib.py +2022 -0
  276. fontTools/ufoLib/kerning.py +91 -0
  277. fontTools/ufoLib/plistlib.py +47 -0
  278. fontTools/ufoLib/pointPen.py +6 -0
  279. fontTools/ufoLib/utils.py +76 -0
  280. fontTools/ufoLib/validators.py +1186 -0
  281. fontTools/unicode.py +50 -0
  282. fontTools/unicodedata/Blocks.py +802 -0
  283. fontTools/unicodedata/OTTags.py +50 -0
  284. fontTools/unicodedata/ScriptExtensions.py +806 -0
  285. fontTools/unicodedata/Scripts.py +3618 -0
  286. fontTools/unicodedata/__init__.py +298 -0
  287. fontTools/varLib/__init__.py +1511 -0
  288. fontTools/varLib/__main__.py +6 -0
  289. fontTools/varLib/avar.py +260 -0
  290. fontTools/varLib/avarPlanner.py +1004 -0
  291. fontTools/varLib/builder.py +215 -0
  292. fontTools/varLib/cff.py +631 -0
  293. fontTools/varLib/errors.py +219 -0
  294. fontTools/varLib/featureVars.py +689 -0
  295. fontTools/varLib/instancer/__init__.py +1937 -0
  296. fontTools/varLib/instancer/__main__.py +5 -0
  297. fontTools/varLib/instancer/featureVars.py +190 -0
  298. fontTools/varLib/instancer/names.py +388 -0
  299. fontTools/varLib/instancer/solver.py +309 -0
  300. fontTools/varLib/interpolatable.py +1209 -0
  301. fontTools/varLib/interpolatableHelpers.py +396 -0
  302. fontTools/varLib/interpolatablePlot.py +1269 -0
  303. fontTools/varLib/interpolatableTestContourOrder.py +82 -0
  304. fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
  305. fontTools/varLib/interpolate_layout.py +124 -0
  306. fontTools/varLib/iup.c +19154 -0
  307. fontTools/varLib/iup.cpython-311-x86_64-linux-musl.so +0 -0
  308. fontTools/varLib/iup.py +490 -0
  309. fontTools/varLib/merger.py +1717 -0
  310. fontTools/varLib/models.py +642 -0
  311. fontTools/varLib/multiVarStore.py +253 -0
  312. fontTools/varLib/mutator.py +518 -0
  313. fontTools/varLib/mvar.py +40 -0
  314. fontTools/varLib/plot.py +238 -0
  315. fontTools/varLib/stat.py +149 -0
  316. fontTools/varLib/varStore.py +767 -0
  317. fontTools/voltLib/__init__.py +5 -0
  318. fontTools/voltLib/ast.py +448 -0
  319. fontTools/voltLib/error.py +12 -0
  320. fontTools/voltLib/lexer.py +99 -0
  321. fontTools/voltLib/parser.py +656 -0
  322. fontTools/voltLib/voltToFea.py +730 -0
  323. fonttools-4.55.6.data/data/share/man/man1/ttx.1 +225 -0
  324. fonttools-4.55.6.dist-info/LICENSE +21 -0
  325. fonttools-4.55.6.dist-info/METADATA +3413 -0
  326. fonttools-4.55.6.dist-info/RECORD +329 -0
  327. fonttools-4.55.6.dist-info/WHEEL +5 -0
  328. fonttools-4.55.6.dist-info/entry_points.txt +5 -0
  329. fonttools-4.55.6.dist-info/top_level.txt +1 -0
fontTools/ttx.py ADDED
@@ -0,0 +1,467 @@
1
+ """\
2
+ usage: ttx [options] inputfile1 [... inputfileN]
3
+
4
+ TTX -- From OpenType To XML And Back
5
+
6
+ If an input file is a TrueType or OpenType font file, it will be
7
+ decompiled to a TTX file (an XML-based text format).
8
+ If an input file is a TTX file, it will be compiled to whatever
9
+ format the data is in, a TrueType or OpenType/CFF font file.
10
+ A special input value of - means read from the standard input.
11
+
12
+ Output files are created so they are unique: an existing file is
13
+ never overwritten.
14
+
15
+ General options
16
+ ===============
17
+
18
+ -h Help print this message.
19
+ --version show version and exit.
20
+ -d <outputfolder> Specify a directory where the output files are
21
+ to be created.
22
+ -o <outputfile> Specify a file to write the output to. A special
23
+ value of - would use the standard output.
24
+ -f Overwrite existing output file(s), ie. don't append
25
+ numbers.
26
+ -v Verbose: more messages will be written to stdout
27
+ about what is being done.
28
+ -q Quiet: No messages will be written to stdout about
29
+ what is being done.
30
+ -a allow virtual glyphs ID's on compile or decompile.
31
+
32
+ Dump options
33
+ ============
34
+
35
+ -l List table info: instead of dumping to a TTX file, list
36
+ some minimal info about each table.
37
+ -t <table> Specify a table to dump. Multiple -t options
38
+ are allowed. When no -t option is specified, all tables
39
+ will be dumped.
40
+ -x <table> Specify a table to exclude from the dump. Multiple
41
+ -x options are allowed. -t and -x are mutually exclusive.
42
+ -s Split tables: save the TTX data into separate TTX files per
43
+ table and write one small TTX file that contains references
44
+ to the individual table dumps. This file can be used as
45
+ input to ttx, as long as the table files are in the
46
+ same directory.
47
+ -g Split glyf table: Save the glyf data into separate TTX files
48
+ per glyph and write a small TTX for the glyf table which
49
+ contains references to the individual TTGlyph elements.
50
+ NOTE: specifying -g implies -s (no need for -s together
51
+ with -g)
52
+ -i Do NOT disassemble TT instructions: when this option is
53
+ given, all TrueType programs (glyph programs, the font
54
+ program and the pre-program) will be written to the TTX
55
+ file as hex data instead of assembly. This saves some time
56
+ and makes the TTX file smaller.
57
+ -z <format> Specify a bitmap data export option for EBDT:
58
+ {'raw', 'row', 'bitwise', 'extfile'} or for the CBDT:
59
+ {'raw', 'extfile'} Each option does one of the following:
60
+
61
+ -z raw
62
+ export the bitmap data as a hex dump
63
+ -z row
64
+ export each row as hex data
65
+ -z bitwise
66
+ export each row as binary in an ASCII art style
67
+ -z extfile
68
+ export the data as external files with XML references
69
+
70
+ If no export format is specified 'raw' format is used.
71
+ -e Don't ignore decompilation errors, but show a full traceback
72
+ and abort.
73
+ -y <number> Select font number for TrueType Collection (.ttc/.otc),
74
+ starting from 0.
75
+ --unicodedata <UnicodeData.txt>
76
+ Use custom database file to write character names in the
77
+ comments of the cmap TTX output.
78
+ --newline <value>
79
+ Control how line endings are written in the XML file. It
80
+ can be 'LF', 'CR', or 'CRLF'. If not specified, the
81
+ default platform-specific line endings are used.
82
+
83
+ Compile options
84
+ ===============
85
+
86
+ -m Merge with TrueType-input-file: specify a TrueType or
87
+ OpenType font file to be merged with the TTX file. This
88
+ option is only valid when at most one TTX file is specified.
89
+ -b Don't recalc glyph bounding boxes: use the values in the
90
+ TTX file as-is.
91
+ --recalc-timestamp
92
+ Set font 'modified' timestamp to current time.
93
+ By default, the modification time of the TTX file will be
94
+ used.
95
+ --no-recalc-timestamp
96
+ Keep the original font 'modified' timestamp.
97
+ --flavor <type>
98
+ Specify flavor of output font file. May be 'woff' or 'woff2'.
99
+ Note that WOFF2 requires the Brotli Python extension,
100
+ available at https://github.com/google/brotli
101
+ --with-zopfli
102
+ Use Zopfli instead of Zlib to compress WOFF. The Python
103
+ extension is available at https://pypi.python.org/pypi/zopfli
104
+ """
105
+
106
+ from fontTools.ttLib import TTFont, TTLibError
107
+ from fontTools.misc.macCreatorType import getMacCreatorAndType
108
+ from fontTools.unicode import setUnicodeData
109
+ from fontTools.misc.textTools import Tag, tostr
110
+ from fontTools.misc.timeTools import timestampSinceEpoch
111
+ from fontTools.misc.loggingTools import Timer
112
+ from fontTools.misc.cliTools import makeOutputFileName
113
+ import os
114
+ import sys
115
+ import getopt
116
+ import re
117
+ import logging
118
+
119
+
120
+ log = logging.getLogger("fontTools.ttx")
121
+
122
+ opentypeheaderRE = re.compile("""sfntVersion=['"]OTTO["']""")
123
+
124
+
125
+ class Options(object):
126
+ listTables = False
127
+ outputDir = None
128
+ outputFile = None
129
+ overWrite = False
130
+ verbose = False
131
+ quiet = False
132
+ splitTables = False
133
+ splitGlyphs = False
134
+ disassembleInstructions = True
135
+ mergeFile = None
136
+ recalcBBoxes = True
137
+ ignoreDecompileErrors = True
138
+ bitmapGlyphDataFormat = "raw"
139
+ unicodedata = None
140
+ newlinestr = "\n"
141
+ recalcTimestamp = None
142
+ flavor = None
143
+ useZopfli = False
144
+
145
+ def __init__(self, rawOptions, numFiles):
146
+ self.onlyTables = []
147
+ self.skipTables = []
148
+ self.fontNumber = -1
149
+ for option, value in rawOptions:
150
+ # general options
151
+ if option == "-h":
152
+ print(__doc__)
153
+ sys.exit(0)
154
+ elif option == "--version":
155
+ from fontTools import version
156
+
157
+ print(version)
158
+ sys.exit(0)
159
+ elif option == "-d":
160
+ if not os.path.isdir(value):
161
+ raise getopt.GetoptError(
162
+ "The -d option value must be an existing directory"
163
+ )
164
+ self.outputDir = value
165
+ elif option == "-o":
166
+ self.outputFile = value
167
+ elif option == "-f":
168
+ self.overWrite = True
169
+ elif option == "-v":
170
+ self.verbose = True
171
+ elif option == "-q":
172
+ self.quiet = True
173
+ # dump options
174
+ elif option == "-l":
175
+ self.listTables = True
176
+ elif option == "-t":
177
+ # pad with space if table tag length is less than 4
178
+ value = value.ljust(4)
179
+ self.onlyTables.append(value)
180
+ elif option == "-x":
181
+ # pad with space if table tag length is less than 4
182
+ value = value.ljust(4)
183
+ self.skipTables.append(value)
184
+ elif option == "-s":
185
+ self.splitTables = True
186
+ elif option == "-g":
187
+ # -g implies (and forces) splitTables
188
+ self.splitGlyphs = True
189
+ self.splitTables = True
190
+ elif option == "-i":
191
+ self.disassembleInstructions = False
192
+ elif option == "-z":
193
+ validOptions = ("raw", "row", "bitwise", "extfile")
194
+ if value not in validOptions:
195
+ raise getopt.GetoptError(
196
+ "-z does not allow %s as a format. Use %s"
197
+ % (option, validOptions)
198
+ )
199
+ self.bitmapGlyphDataFormat = value
200
+ elif option == "-y":
201
+ self.fontNumber = int(value)
202
+ # compile options
203
+ elif option == "-m":
204
+ self.mergeFile = value
205
+ elif option == "-b":
206
+ self.recalcBBoxes = False
207
+ elif option == "-e":
208
+ self.ignoreDecompileErrors = False
209
+ elif option == "--unicodedata":
210
+ self.unicodedata = value
211
+ elif option == "--newline":
212
+ validOptions = ("LF", "CR", "CRLF")
213
+ if value == "LF":
214
+ self.newlinestr = "\n"
215
+ elif value == "CR":
216
+ self.newlinestr = "\r"
217
+ elif value == "CRLF":
218
+ self.newlinestr = "\r\n"
219
+ else:
220
+ raise getopt.GetoptError(
221
+ "Invalid choice for --newline: %r (choose from %s)"
222
+ % (value, ", ".join(map(repr, validOptions)))
223
+ )
224
+ elif option == "--recalc-timestamp":
225
+ self.recalcTimestamp = True
226
+ elif option == "--no-recalc-timestamp":
227
+ self.recalcTimestamp = False
228
+ elif option == "--flavor":
229
+ self.flavor = value
230
+ elif option == "--with-zopfli":
231
+ self.useZopfli = True
232
+ if self.verbose and self.quiet:
233
+ raise getopt.GetoptError("-q and -v options are mutually exclusive")
234
+ if self.verbose:
235
+ self.logLevel = logging.DEBUG
236
+ elif self.quiet:
237
+ self.logLevel = logging.WARNING
238
+ else:
239
+ self.logLevel = logging.INFO
240
+ if self.mergeFile and self.flavor:
241
+ raise getopt.GetoptError("-m and --flavor options are mutually exclusive")
242
+ if self.onlyTables and self.skipTables:
243
+ raise getopt.GetoptError("-t and -x options are mutually exclusive")
244
+ if self.mergeFile and numFiles > 1:
245
+ raise getopt.GetoptError(
246
+ "Must specify exactly one TTX source file when using -m"
247
+ )
248
+ if self.flavor != "woff" and self.useZopfli:
249
+ raise getopt.GetoptError("--with-zopfli option requires --flavor 'woff'")
250
+
251
+
252
+ def ttList(input, output, options):
253
+ ttf = TTFont(input, fontNumber=options.fontNumber, lazy=True)
254
+ reader = ttf.reader
255
+ tags = sorted(reader.keys())
256
+ print('Listing table info for "%s":' % input)
257
+ format = " %4s %10s %8s %8s"
258
+ print(format % ("tag ", " checksum", " length", " offset"))
259
+ print(format % ("----", "----------", "--------", "--------"))
260
+ for tag in tags:
261
+ entry = reader.tables[tag]
262
+ if ttf.flavor == "woff2":
263
+ # WOFF2 doesn't store table checksums, so they must be calculated
264
+ from fontTools.ttLib.sfnt import calcChecksum
265
+
266
+ data = entry.loadData(reader.transformBuffer)
267
+ checkSum = calcChecksum(data)
268
+ else:
269
+ checkSum = int(entry.checkSum)
270
+ if checkSum < 0:
271
+ checkSum = checkSum + 0x100000000
272
+ checksum = "0x%08X" % checkSum
273
+ print(format % (tag, checksum, entry.length, entry.offset))
274
+ print()
275
+ ttf.close()
276
+
277
+
278
+ @Timer(log, "Done dumping TTX in %(time).3f seconds")
279
+ def ttDump(input, output, options):
280
+ input_name = input
281
+ if input == "-":
282
+ input, input_name = sys.stdin.buffer, sys.stdin.name
283
+ output_name = output
284
+ if output == "-":
285
+ output, output_name = sys.stdout, sys.stdout.name
286
+ log.info('Dumping "%s" to "%s"...', input_name, output_name)
287
+ if options.unicodedata:
288
+ setUnicodeData(options.unicodedata)
289
+ ttf = TTFont(
290
+ input,
291
+ 0,
292
+ ignoreDecompileErrors=options.ignoreDecompileErrors,
293
+ fontNumber=options.fontNumber,
294
+ )
295
+ ttf.saveXML(
296
+ output,
297
+ tables=options.onlyTables,
298
+ skipTables=options.skipTables,
299
+ splitTables=options.splitTables,
300
+ splitGlyphs=options.splitGlyphs,
301
+ disassembleInstructions=options.disassembleInstructions,
302
+ bitmapGlyphDataFormat=options.bitmapGlyphDataFormat,
303
+ newlinestr=options.newlinestr,
304
+ )
305
+ ttf.close()
306
+
307
+
308
+ @Timer(log, "Done compiling TTX in %(time).3f seconds")
309
+ def ttCompile(input, output, options):
310
+ input_name = input
311
+ if input == "-":
312
+ input, input_name = sys.stdin, sys.stdin.name
313
+ output_name = output
314
+ if output == "-":
315
+ output, output_name = sys.stdout.buffer, sys.stdout.name
316
+ log.info('Compiling "%s" to "%s"...' % (input_name, output))
317
+ if options.useZopfli:
318
+ from fontTools.ttLib import sfnt
319
+
320
+ sfnt.USE_ZOPFLI = True
321
+ ttf = TTFont(
322
+ options.mergeFile,
323
+ flavor=options.flavor,
324
+ recalcBBoxes=options.recalcBBoxes,
325
+ recalcTimestamp=options.recalcTimestamp,
326
+ )
327
+ ttf.importXML(input)
328
+
329
+ if options.recalcTimestamp is None and "head" in ttf and input is not sys.stdin:
330
+ # use TTX file modification time for head "modified" timestamp
331
+ mtime = os.path.getmtime(input)
332
+ ttf["head"].modified = timestampSinceEpoch(mtime)
333
+
334
+ ttf.save(output)
335
+
336
+
337
+ def guessFileType(fileName):
338
+ if fileName == "-":
339
+ header = sys.stdin.buffer.peek(256)
340
+ ext = ""
341
+ else:
342
+ base, ext = os.path.splitext(fileName)
343
+ try:
344
+ with open(fileName, "rb") as f:
345
+ header = f.read(256)
346
+ except IOError:
347
+ return None
348
+
349
+ if header.startswith(b"\xef\xbb\xbf<?xml"):
350
+ header = header.lstrip(b"\xef\xbb\xbf")
351
+ cr, tp = getMacCreatorAndType(fileName)
352
+ if tp in ("sfnt", "FFIL"):
353
+ return "TTF"
354
+ if ext == ".dfont":
355
+ return "TTF"
356
+ head = Tag(header[:4])
357
+ if head == "OTTO":
358
+ return "OTF"
359
+ elif head == "ttcf":
360
+ return "TTC"
361
+ elif head in ("\0\1\0\0", "true"):
362
+ return "TTF"
363
+ elif head == "wOFF":
364
+ return "WOFF"
365
+ elif head == "wOF2":
366
+ return "WOFF2"
367
+ elif head == "<?xm":
368
+ # Use 'latin1' because that can't fail.
369
+ header = tostr(header, "latin1")
370
+ if opentypeheaderRE.search(header):
371
+ return "OTX"
372
+ else:
373
+ return "TTX"
374
+ return None
375
+
376
+
377
+ def parseOptions(args):
378
+ rawOptions, files = getopt.gnu_getopt(
379
+ args,
380
+ "ld:o:fvqht:x:sgim:z:baey:",
381
+ [
382
+ "unicodedata=",
383
+ "recalc-timestamp",
384
+ "no-recalc-timestamp",
385
+ "flavor=",
386
+ "version",
387
+ "with-zopfli",
388
+ "newline=",
389
+ ],
390
+ )
391
+
392
+ options = Options(rawOptions, len(files))
393
+ jobs = []
394
+
395
+ if not files:
396
+ raise getopt.GetoptError("Must specify at least one input file")
397
+
398
+ for input in files:
399
+ if input != "-" and not os.path.isfile(input):
400
+ raise getopt.GetoptError('File not found: "%s"' % input)
401
+ tp = guessFileType(input)
402
+ if tp in ("OTF", "TTF", "TTC", "WOFF", "WOFF2"):
403
+ extension = ".ttx"
404
+ if options.listTables:
405
+ action = ttList
406
+ else:
407
+ action = ttDump
408
+ elif tp == "TTX":
409
+ extension = "." + options.flavor if options.flavor else ".ttf"
410
+ action = ttCompile
411
+ elif tp == "OTX":
412
+ extension = "." + options.flavor if options.flavor else ".otf"
413
+ action = ttCompile
414
+ else:
415
+ raise getopt.GetoptError('Unknown file type: "%s"' % input)
416
+
417
+ if options.outputFile:
418
+ output = options.outputFile
419
+ else:
420
+ if input == "-":
421
+ raise getopt.GetoptError("Must provide -o when reading from stdin")
422
+ output = makeOutputFileName(
423
+ input, options.outputDir, extension, options.overWrite
424
+ )
425
+ # 'touch' output file to avoid race condition in choosing file names
426
+ if action != ttList:
427
+ open(output, "a").close()
428
+ jobs.append((action, input, output))
429
+ return jobs, options
430
+
431
+
432
+ def process(jobs, options):
433
+ for action, input, output in jobs:
434
+ action(input, output, options)
435
+
436
+
437
+ def main(args=None):
438
+ """Convert OpenType fonts to XML and back"""
439
+ from fontTools import configLogger
440
+
441
+ if args is None:
442
+ args = sys.argv[1:]
443
+ try:
444
+ jobs, options = parseOptions(args)
445
+ except getopt.GetoptError as e:
446
+ print("%s\nERROR: %s" % (__doc__, e), file=sys.stderr)
447
+ sys.exit(2)
448
+
449
+ configLogger(level=options.logLevel)
450
+
451
+ try:
452
+ process(jobs, options)
453
+ except KeyboardInterrupt:
454
+ log.error("(Cancelled.)")
455
+ sys.exit(1)
456
+ except SystemExit:
457
+ raise
458
+ except TTLibError as e:
459
+ log.error(e)
460
+ sys.exit(1)
461
+ except:
462
+ log.exception("Unhandled exception has occurred")
463
+ sys.exit(1)
464
+
465
+
466
+ if __name__ == "__main__":
467
+ sys.exit(main())