fonttools 4.55.6__cp39-cp39-manylinux_2_17_x86_64.manylinux2014_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-39-x86_64-linux-gnu.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-39-x86_64-linux-gnu.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-39-x86_64-linux-gnu.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-39-x86_64-linux-gnu.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-39-x86_64-linux-gnu.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-39-x86_64-linux-gnu.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 +6 -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
@@ -0,0 +1,11 @@
1
+ class OpenTypeLibError(Exception):
2
+ def __init__(self, message, location):
3
+ Exception.__init__(self, message)
4
+ self.location = location
5
+
6
+ def __str__(self):
7
+ message = Exception.__str__(self)
8
+ if self.location:
9
+ return f"{self.location}: {message}"
10
+ else:
11
+ return message
@@ -0,0 +1,96 @@
1
+ __all__ = ["maxCtxFont"]
2
+
3
+
4
+ def maxCtxFont(font):
5
+ """Calculate the usMaxContext value for an entire font."""
6
+
7
+ maxCtx = 0
8
+ for tag in ("GSUB", "GPOS"):
9
+ if tag not in font:
10
+ continue
11
+ table = font[tag].table
12
+ if not table.LookupList:
13
+ continue
14
+ for lookup in table.LookupList.Lookup:
15
+ for st in lookup.SubTable:
16
+ maxCtx = maxCtxSubtable(maxCtx, tag, lookup.LookupType, st)
17
+ return maxCtx
18
+
19
+
20
+ def maxCtxSubtable(maxCtx, tag, lookupType, st):
21
+ """Calculate usMaxContext based on a single lookup table (and an existing
22
+ max value).
23
+ """
24
+
25
+ # single positioning, single / multiple substitution
26
+ if (tag == "GPOS" and lookupType == 1) or (
27
+ tag == "GSUB" and lookupType in (1, 2, 3)
28
+ ):
29
+ maxCtx = max(maxCtx, 1)
30
+
31
+ # pair positioning
32
+ elif tag == "GPOS" and lookupType == 2:
33
+ maxCtx = max(maxCtx, 2)
34
+
35
+ # ligatures
36
+ elif tag == "GSUB" and lookupType == 4:
37
+ for ligatures in st.ligatures.values():
38
+ for ligature in ligatures:
39
+ maxCtx = max(maxCtx, ligature.CompCount)
40
+
41
+ # context
42
+ elif (tag == "GPOS" and lookupType == 7) or (tag == "GSUB" and lookupType == 5):
43
+ maxCtx = maxCtxContextualSubtable(maxCtx, st, "Pos" if tag == "GPOS" else "Sub")
44
+
45
+ # chained context
46
+ elif (tag == "GPOS" and lookupType == 8) or (tag == "GSUB" and lookupType == 6):
47
+ maxCtx = maxCtxContextualSubtable(
48
+ maxCtx, st, "Pos" if tag == "GPOS" else "Sub", "Chain"
49
+ )
50
+
51
+ # extensions
52
+ elif (tag == "GPOS" and lookupType == 9) or (tag == "GSUB" and lookupType == 7):
53
+ maxCtx = maxCtxSubtable(maxCtx, tag, st.ExtensionLookupType, st.ExtSubTable)
54
+
55
+ # reverse-chained context
56
+ elif tag == "GSUB" and lookupType == 8:
57
+ maxCtx = maxCtxContextualRule(maxCtx, st, "Reverse")
58
+
59
+ return maxCtx
60
+
61
+
62
+ def maxCtxContextualSubtable(maxCtx, st, ruleType, chain=""):
63
+ """Calculate usMaxContext based on a contextual feature subtable."""
64
+
65
+ if st.Format == 1:
66
+ for ruleset in getattr(st, "%s%sRuleSet" % (chain, ruleType)):
67
+ if ruleset is None:
68
+ continue
69
+ for rule in getattr(ruleset, "%s%sRule" % (chain, ruleType)):
70
+ if rule is None:
71
+ continue
72
+ maxCtx = maxCtxContextualRule(maxCtx, rule, chain)
73
+
74
+ elif st.Format == 2:
75
+ for ruleset in getattr(st, "%s%sClassSet" % (chain, ruleType)):
76
+ if ruleset is None:
77
+ continue
78
+ for rule in getattr(ruleset, "%s%sClassRule" % (chain, ruleType)):
79
+ if rule is None:
80
+ continue
81
+ maxCtx = maxCtxContextualRule(maxCtx, rule, chain)
82
+
83
+ elif st.Format == 3:
84
+ maxCtx = maxCtxContextualRule(maxCtx, st, chain)
85
+
86
+ return maxCtx
87
+
88
+
89
+ def maxCtxContextualRule(maxCtx, st, chain):
90
+ """Calculate usMaxContext based on a contextual feature rule."""
91
+
92
+ if not chain:
93
+ return max(maxCtx, st.GlyphCount)
94
+ elif chain == "Reverse":
95
+ return max(maxCtx, 1 + st.LookAheadGlyphCount)
96
+ return max(maxCtx, st.InputGlyphCount + st.LookAheadGlyphCount)
@@ -0,0 +1,53 @@
1
+ from argparse import RawTextHelpFormatter
2
+ from fontTools.otlLib.optimize.gpos import COMPRESSION_LEVEL, compact
3
+ from fontTools.ttLib import TTFont
4
+
5
+
6
+ def main(args=None):
7
+ """Optimize the layout tables of an existing font"""
8
+ from argparse import ArgumentParser
9
+
10
+ from fontTools import configLogger
11
+
12
+ parser = ArgumentParser(
13
+ prog="otlLib.optimize",
14
+ description=main.__doc__,
15
+ formatter_class=RawTextHelpFormatter,
16
+ )
17
+ parser.add_argument("font")
18
+ parser.add_argument(
19
+ "-o", metavar="OUTPUTFILE", dest="outfile", default=None, help="output file"
20
+ )
21
+ parser.add_argument(
22
+ "--gpos-compression-level",
23
+ help=COMPRESSION_LEVEL.help,
24
+ default=COMPRESSION_LEVEL.default,
25
+ choices=list(range(10)),
26
+ type=int,
27
+ )
28
+ logging_group = parser.add_mutually_exclusive_group(required=False)
29
+ logging_group.add_argument(
30
+ "-v", "--verbose", action="store_true", help="Run more verbosely."
31
+ )
32
+ logging_group.add_argument(
33
+ "-q", "--quiet", action="store_true", help="Turn verbosity off."
34
+ )
35
+ options = parser.parse_args(args)
36
+
37
+ configLogger(
38
+ level=("DEBUG" if options.verbose else "ERROR" if options.quiet else "INFO")
39
+ )
40
+
41
+ font = TTFont(options.font)
42
+ compact(font, options.gpos_compression_level)
43
+ font.save(options.outfile or options.font)
44
+
45
+
46
+ if __name__ == "__main__":
47
+ import sys
48
+
49
+ if len(sys.argv) > 1:
50
+ sys.exit(main())
51
+ import doctest
52
+
53
+ sys.exit(doctest.testmod().failed)
@@ -0,0 +1,6 @@
1
+ import sys
2
+ from fontTools.otlLib.optimize import main
3
+
4
+
5
+ if __name__ == "__main__":
6
+ sys.exit(main())
@@ -0,0 +1,453 @@
1
+ import logging
2
+ import os
3
+ from collections import defaultdict, namedtuple
4
+ from functools import reduce
5
+ from itertools import chain
6
+ from math import log2
7
+ from typing import DefaultDict, Dict, Iterable, List, Sequence, Tuple
8
+
9
+ from fontTools.config import OPTIONS
10
+ from fontTools.misc.intTools import bit_count, bit_indices
11
+ from fontTools.ttLib import TTFont
12
+ from fontTools.ttLib.tables import otBase, otTables
13
+
14
+ log = logging.getLogger(__name__)
15
+
16
+ COMPRESSION_LEVEL = OPTIONS[f"{__name__}:COMPRESSION_LEVEL"]
17
+
18
+ # Kept because ufo2ft depends on it, to be removed once ufo2ft uses the config instead
19
+ # https://github.com/fonttools/fonttools/issues/2592
20
+ GPOS_COMPACT_MODE_ENV_KEY = "FONTTOOLS_GPOS_COMPACT_MODE"
21
+ GPOS_COMPACT_MODE_DEFAULT = str(COMPRESSION_LEVEL.default)
22
+
23
+
24
+ def _compression_level_from_env() -> int:
25
+ env_level = GPOS_COMPACT_MODE_DEFAULT
26
+ if GPOS_COMPACT_MODE_ENV_KEY in os.environ:
27
+ import warnings
28
+
29
+ warnings.warn(
30
+ f"'{GPOS_COMPACT_MODE_ENV_KEY}' environment variable is deprecated. "
31
+ "Please set the 'fontTools.otlLib.optimize.gpos:COMPRESSION_LEVEL' option "
32
+ "in TTFont.cfg.",
33
+ DeprecationWarning,
34
+ )
35
+
36
+ env_level = os.environ[GPOS_COMPACT_MODE_ENV_KEY]
37
+ if len(env_level) == 1 and env_level in "0123456789":
38
+ return int(env_level)
39
+ raise ValueError(f"Bad {GPOS_COMPACT_MODE_ENV_KEY}={env_level}")
40
+
41
+
42
+ def compact(font: TTFont, level: int) -> TTFont:
43
+ # Ideal plan:
44
+ # 1. Find lookups of Lookup Type 2: Pair Adjustment Positioning Subtable
45
+ # https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable
46
+ # 2. Extract glyph-glyph kerning and class-kerning from all present subtables
47
+ # 3. Regroup into different subtable arrangements
48
+ # 4. Put back into the lookup
49
+ #
50
+ # Actual implementation:
51
+ # 2. Only class kerning is optimized currently
52
+ # 3. If the input kerning is already in several subtables, the subtables
53
+ # are not grouped together first; instead each subtable is treated
54
+ # independently, so currently this step is:
55
+ # Split existing subtables into more smaller subtables
56
+ gpos = font["GPOS"]
57
+ for lookup in gpos.table.LookupList.Lookup:
58
+ if lookup.LookupType == 2:
59
+ compact_lookup(font, level, lookup)
60
+ elif lookup.LookupType == 9 and lookup.SubTable[0].ExtensionLookupType == 2:
61
+ compact_ext_lookup(font, level, lookup)
62
+ return font
63
+
64
+
65
+ def compact_lookup(font: TTFont, level: int, lookup: otTables.Lookup) -> None:
66
+ new_subtables = compact_pair_pos(font, level, lookup.SubTable)
67
+ lookup.SubTable = new_subtables
68
+ lookup.SubTableCount = len(new_subtables)
69
+
70
+
71
+ def compact_ext_lookup(font: TTFont, level: int, lookup: otTables.Lookup) -> None:
72
+ new_subtables = compact_pair_pos(
73
+ font, level, [ext_subtable.ExtSubTable for ext_subtable in lookup.SubTable]
74
+ )
75
+ new_ext_subtables = []
76
+ for subtable in new_subtables:
77
+ ext_subtable = otTables.ExtensionPos()
78
+ ext_subtable.Format = 1
79
+ ext_subtable.ExtSubTable = subtable
80
+ new_ext_subtables.append(ext_subtable)
81
+ lookup.SubTable = new_ext_subtables
82
+ lookup.SubTableCount = len(new_ext_subtables)
83
+
84
+
85
+ def compact_pair_pos(
86
+ font: TTFont, level: int, subtables: Sequence[otTables.PairPos]
87
+ ) -> Sequence[otTables.PairPos]:
88
+ new_subtables = []
89
+ for subtable in subtables:
90
+ if subtable.Format == 1:
91
+ # Not doing anything to Format 1 (yet?)
92
+ new_subtables.append(subtable)
93
+ elif subtable.Format == 2:
94
+ new_subtables.extend(compact_class_pairs(font, level, subtable))
95
+ return new_subtables
96
+
97
+
98
+ def compact_class_pairs(
99
+ font: TTFont, level: int, subtable: otTables.PairPos
100
+ ) -> List[otTables.PairPos]:
101
+ from fontTools.otlLib.builder import buildPairPosClassesSubtable
102
+
103
+ subtables = []
104
+ classes1: DefaultDict[int, List[str]] = defaultdict(list)
105
+ for g in subtable.Coverage.glyphs:
106
+ classes1[subtable.ClassDef1.classDefs.get(g, 0)].append(g)
107
+ classes2: DefaultDict[int, List[str]] = defaultdict(list)
108
+ for g, i in subtable.ClassDef2.classDefs.items():
109
+ classes2[i].append(g)
110
+ all_pairs = {}
111
+ for i, class1 in enumerate(subtable.Class1Record):
112
+ for j, class2 in enumerate(class1.Class2Record):
113
+ if is_really_zero(class2):
114
+ continue
115
+ all_pairs[(tuple(sorted(classes1[i])), tuple(sorted(classes2[j])))] = (
116
+ getattr(class2, "Value1", None),
117
+ getattr(class2, "Value2", None),
118
+ )
119
+ grouped_pairs = cluster_pairs_by_class2_coverage_custom_cost(font, all_pairs, level)
120
+ for pairs in grouped_pairs:
121
+ subtables.append(buildPairPosClassesSubtable(pairs, font.getReverseGlyphMap()))
122
+ return subtables
123
+
124
+
125
+ def is_really_zero(class2: otTables.Class2Record) -> bool:
126
+ v1 = getattr(class2, "Value1", None)
127
+ v2 = getattr(class2, "Value2", None)
128
+ return (v1 is None or v1.getEffectiveFormat() == 0) and (
129
+ v2 is None or v2.getEffectiveFormat() == 0
130
+ )
131
+
132
+
133
+ Pairs = Dict[
134
+ Tuple[Tuple[str, ...], Tuple[str, ...]],
135
+ Tuple[otBase.ValueRecord, otBase.ValueRecord],
136
+ ]
137
+
138
+
139
+ # Adapted from https://github.com/fonttools/fonttools/blob/f64f0b42f2d1163b2d85194e0979def539f5dca3/Lib/fontTools/ttLib/tables/otTables.py#L935-L958
140
+ def _getClassRanges(glyphIDs: Iterable[int]):
141
+ glyphIDs = sorted(glyphIDs)
142
+ last = glyphIDs[0]
143
+ ranges = [[last]]
144
+ for glyphID in glyphIDs[1:]:
145
+ if glyphID != last + 1:
146
+ ranges[-1].append(last)
147
+ ranges.append([glyphID])
148
+ last = glyphID
149
+ ranges[-1].append(last)
150
+ return ranges, glyphIDs[0], glyphIDs[-1]
151
+
152
+
153
+ # Adapted from https://github.com/fonttools/fonttools/blob/f64f0b42f2d1163b2d85194e0979def539f5dca3/Lib/fontTools/ttLib/tables/otTables.py#L960-L989
154
+ def _classDef_bytes(
155
+ class_data: List[Tuple[List[Tuple[int, int]], int, int]],
156
+ class_ids: List[int],
157
+ coverage=False,
158
+ ):
159
+ if not class_ids:
160
+ return 0
161
+ first_ranges, min_glyph_id, max_glyph_id = class_data[class_ids[0]]
162
+ range_count = len(first_ranges)
163
+ for i in class_ids[1:]:
164
+ data = class_data[i]
165
+ range_count += len(data[0])
166
+ min_glyph_id = min(min_glyph_id, data[1])
167
+ max_glyph_id = max(max_glyph_id, data[2])
168
+ glyphCount = max_glyph_id - min_glyph_id + 1
169
+ # https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table-format-1
170
+ format1_bytes = 6 + glyphCount * 2
171
+ # https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table-format-2
172
+ format2_bytes = 4 + range_count * 6
173
+ return min(format1_bytes, format2_bytes)
174
+
175
+
176
+ ClusteringContext = namedtuple(
177
+ "ClusteringContext",
178
+ [
179
+ "lines",
180
+ "all_class1",
181
+ "all_class1_data",
182
+ "all_class2_data",
183
+ "valueFormat1_bytes",
184
+ "valueFormat2_bytes",
185
+ ],
186
+ )
187
+
188
+
189
+ class Cluster:
190
+ # TODO(Python 3.7): Turn this into a dataclass
191
+ # ctx: ClusteringContext
192
+ # indices: int
193
+ # Caches
194
+ # TODO(Python 3.8): use functools.cached_property instead of the
195
+ # manually cached properties, and remove the cache fields listed below.
196
+ # _indices: Optional[List[int]] = None
197
+ # _column_indices: Optional[List[int]] = None
198
+ # _cost: Optional[int] = None
199
+
200
+ __slots__ = "ctx", "indices_bitmask", "_indices", "_column_indices", "_cost"
201
+
202
+ def __init__(self, ctx: ClusteringContext, indices_bitmask: int):
203
+ self.ctx = ctx
204
+ self.indices_bitmask = indices_bitmask
205
+ self._indices = None
206
+ self._column_indices = None
207
+ self._cost = None
208
+
209
+ @property
210
+ def indices(self):
211
+ if self._indices is None:
212
+ self._indices = bit_indices(self.indices_bitmask)
213
+ return self._indices
214
+
215
+ @property
216
+ def column_indices(self):
217
+ if self._column_indices is None:
218
+ # Indices of columns that have a 1 in at least 1 line
219
+ # => binary OR all the lines
220
+ bitmask = reduce(int.__or__, (self.ctx.lines[i] for i in self.indices))
221
+ self._column_indices = bit_indices(bitmask)
222
+ return self._column_indices
223
+
224
+ @property
225
+ def width(self):
226
+ # Add 1 because Class2=0 cannot be used but needs to be encoded.
227
+ return len(self.column_indices) + 1
228
+
229
+ @property
230
+ def cost(self):
231
+ if self._cost is None:
232
+ self._cost = (
233
+ # 2 bytes to store the offset to this subtable in the Lookup table above
234
+ 2
235
+ # Contents of the subtable
236
+ # From: https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#pair-adjustment-positioning-format-2-class-pair-adjustment
237
+ # uint16 posFormat Format identifier: format = 2
238
+ + 2
239
+ # Offset16 coverageOffset Offset to Coverage table, from beginning of PairPos subtable.
240
+ + 2
241
+ + self.coverage_bytes
242
+ # uint16 valueFormat1 ValueRecord definition — for the first glyph of the pair (may be zero).
243
+ + 2
244
+ # uint16 valueFormat2 ValueRecord definition — for the second glyph of the pair (may be zero).
245
+ + 2
246
+ # Offset16 classDef1Offset Offset to ClassDef table, from beginning of PairPos subtable — for the first glyph of the pair.
247
+ + 2
248
+ + self.classDef1_bytes
249
+ # Offset16 classDef2Offset Offset to ClassDef table, from beginning of PairPos subtable — for the second glyph of the pair.
250
+ + 2
251
+ + self.classDef2_bytes
252
+ # uint16 class1Count Number of classes in classDef1 table — includes Class 0.
253
+ + 2
254
+ # uint16 class2Count Number of classes in classDef2 table — includes Class 0.
255
+ + 2
256
+ # Class1Record class1Records[class1Count] Array of Class1 records, ordered by classes in classDef1.
257
+ + (self.ctx.valueFormat1_bytes + self.ctx.valueFormat2_bytes)
258
+ * len(self.indices)
259
+ * self.width
260
+ )
261
+ return self._cost
262
+
263
+ @property
264
+ def coverage_bytes(self):
265
+ format1_bytes = (
266
+ # From https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-format-1
267
+ # uint16 coverageFormat Format identifier — format = 1
268
+ # uint16 glyphCount Number of glyphs in the glyph array
269
+ 4
270
+ # uint16 glyphArray[glyphCount] Array of glyph IDs — in numerical order
271
+ + sum(len(self.ctx.all_class1[i]) for i in self.indices) * 2
272
+ )
273
+ ranges = sorted(
274
+ chain.from_iterable(self.ctx.all_class1_data[i][0] for i in self.indices)
275
+ )
276
+ merged_range_count = 0
277
+ last = None
278
+ for start, end in ranges:
279
+ if last is not None and start != last + 1:
280
+ merged_range_count += 1
281
+ last = end
282
+ format2_bytes = (
283
+ # From https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-format-2
284
+ # uint16 coverageFormat Format identifier — format = 2
285
+ # uint16 rangeCount Number of RangeRecords
286
+ 4
287
+ # RangeRecord rangeRecords[rangeCount] Array of glyph ranges — ordered by startGlyphID.
288
+ # uint16 startGlyphID First glyph ID in the range
289
+ # uint16 endGlyphID Last glyph ID in the range
290
+ # uint16 startCoverageIndex Coverage Index of first glyph ID in range
291
+ + merged_range_count * 6
292
+ )
293
+ return min(format1_bytes, format2_bytes)
294
+
295
+ @property
296
+ def classDef1_bytes(self):
297
+ # We can skip encoding one of the Class1 definitions, and use
298
+ # Class1=0 to represent it instead, because Class1 is gated by the
299
+ # Coverage definition. Use Class1=0 for the highest byte savings.
300
+ # Going through all options takes too long, pick the biggest class
301
+ # = what happens in otlLib.builder.ClassDefBuilder.classes()
302
+ biggest_index = max(self.indices, key=lambda i: len(self.ctx.all_class1[i]))
303
+ return _classDef_bytes(
304
+ self.ctx.all_class1_data, [i for i in self.indices if i != biggest_index]
305
+ )
306
+
307
+ @property
308
+ def classDef2_bytes(self):
309
+ # All Class2 need to be encoded because we can't use Class2=0
310
+ return _classDef_bytes(self.ctx.all_class2_data, self.column_indices)
311
+
312
+
313
+ def cluster_pairs_by_class2_coverage_custom_cost(
314
+ font: TTFont,
315
+ pairs: Pairs,
316
+ compression: int = 5,
317
+ ) -> List[Pairs]:
318
+ if not pairs:
319
+ # The subtable was actually empty?
320
+ return [pairs]
321
+
322
+ # Sorted for reproducibility/determinism
323
+ all_class1 = sorted(set(pair[0] for pair in pairs))
324
+ all_class2 = sorted(set(pair[1] for pair in pairs))
325
+
326
+ # Use Python's big ints for binary vectors representing each line
327
+ lines = [
328
+ sum(
329
+ 1 << i if (class1, class2) in pairs else 0
330
+ for i, class2 in enumerate(all_class2)
331
+ )
332
+ for class1 in all_class1
333
+ ]
334
+
335
+ # Map glyph names to ids and work with ints throughout for ClassDef formats
336
+ name_to_id = font.getReverseGlyphMap()
337
+ # Each entry in the arrays below is (range_count, min_glyph_id, max_glyph_id)
338
+ all_class1_data = [
339
+ _getClassRanges(name_to_id[name] for name in cls) for cls in all_class1
340
+ ]
341
+ all_class2_data = [
342
+ _getClassRanges(name_to_id[name] for name in cls) for cls in all_class2
343
+ ]
344
+
345
+ format1 = 0
346
+ format2 = 0
347
+ for pair, value in pairs.items():
348
+ format1 |= value[0].getEffectiveFormat() if value[0] else 0
349
+ format2 |= value[1].getEffectiveFormat() if value[1] else 0
350
+ valueFormat1_bytes = bit_count(format1) * 2
351
+ valueFormat2_bytes = bit_count(format2) * 2
352
+
353
+ ctx = ClusteringContext(
354
+ lines,
355
+ all_class1,
356
+ all_class1_data,
357
+ all_class2_data,
358
+ valueFormat1_bytes,
359
+ valueFormat2_bytes,
360
+ )
361
+
362
+ cluster_cache: Dict[int, Cluster] = {}
363
+
364
+ def make_cluster(indices: int) -> Cluster:
365
+ cluster = cluster_cache.get(indices, None)
366
+ if cluster is not None:
367
+ return cluster
368
+ cluster = Cluster(ctx, indices)
369
+ cluster_cache[indices] = cluster
370
+ return cluster
371
+
372
+ def merge(cluster: Cluster, other: Cluster) -> Cluster:
373
+ return make_cluster(cluster.indices_bitmask | other.indices_bitmask)
374
+
375
+ # Agglomerative clustering by hand, checking the cost gain of the new
376
+ # cluster against the previously separate clusters
377
+ # Start with 1 cluster per line
378
+ # cluster = set of lines = new subtable
379
+ clusters = [make_cluster(1 << i) for i in range(len(lines))]
380
+
381
+ # Cost of 1 cluster with everything
382
+ # `(1 << len) - 1` gives a bitmask full of 1's of length `len`
383
+ cost_before_splitting = make_cluster((1 << len(lines)) - 1).cost
384
+ log.debug(f" len(clusters) = {len(clusters)}")
385
+
386
+ while len(clusters) > 1:
387
+ lowest_cost_change = None
388
+ best_cluster_index = None
389
+ best_other_index = None
390
+ best_merged = None
391
+ for i, cluster in enumerate(clusters):
392
+ for j, other in enumerate(clusters[i + 1 :]):
393
+ merged = merge(cluster, other)
394
+ cost_change = merged.cost - cluster.cost - other.cost
395
+ if lowest_cost_change is None or cost_change < lowest_cost_change:
396
+ lowest_cost_change = cost_change
397
+ best_cluster_index = i
398
+ best_other_index = i + 1 + j
399
+ best_merged = merged
400
+ assert lowest_cost_change is not None
401
+ assert best_cluster_index is not None
402
+ assert best_other_index is not None
403
+ assert best_merged is not None
404
+
405
+ # If the best merge we found is still taking down the file size, then
406
+ # there's no question: we must do it, because it's beneficial in both
407
+ # ways (lower file size and lower number of subtables). However, if the
408
+ # best merge we found is not reducing file size anymore, then we need to
409
+ # look at the other stop criteria = the compression factor.
410
+ if lowest_cost_change > 0:
411
+ # Stop critera: check whether we should keep merging.
412
+ # Compute size reduction brought by splitting
413
+ cost_after_splitting = sum(c.cost for c in clusters)
414
+ # size_reduction so that after = before * (1 - size_reduction)
415
+ # E.g. before = 1000, after = 800, 1 - 800/1000 = 0.2
416
+ size_reduction = 1 - cost_after_splitting / cost_before_splitting
417
+
418
+ # Force more merging by taking into account the compression number.
419
+ # Target behaviour: compression number = 1 to 9, default 5 like gzip
420
+ # - 1 = accept to add 1 subtable to reduce size by 50%
421
+ # - 5 = accept to add 5 subtables to reduce size by 50%
422
+ # See https://github.com/harfbuzz/packtab/blob/master/Lib/packTab/__init__.py#L690-L691
423
+ # Given the size reduction we have achieved so far, compute how many
424
+ # new subtables are acceptable.
425
+ max_new_subtables = -log2(1 - size_reduction) * compression
426
+ log.debug(
427
+ f" len(clusters) = {len(clusters):3d} size_reduction={size_reduction:5.2f} max_new_subtables={max_new_subtables}",
428
+ )
429
+ if compression == 9:
430
+ # Override level 9 to mean: create any number of subtables
431
+ max_new_subtables = len(clusters)
432
+
433
+ # If we have managed to take the number of new subtables below the
434
+ # threshold, then we can stop.
435
+ if len(clusters) <= max_new_subtables + 1:
436
+ break
437
+
438
+ # No reason to stop yet, do the merge and move on to the next.
439
+ del clusters[best_other_index]
440
+ clusters[best_cluster_index] = best_merged
441
+
442
+ # All clusters are final; turn bitmasks back into the "Pairs" format
443
+ pairs_by_class1: Dict[Tuple[str, ...], Pairs] = defaultdict(dict)
444
+ for pair, values in pairs.items():
445
+ pairs_by_class1[pair[0]][pair] = values
446
+ pairs_groups: List[Pairs] = []
447
+ for cluster in clusters:
448
+ pairs_group: Pairs = dict()
449
+ for i in cluster.indices:
450
+ class1 = all_class1[i]
451
+ pairs_group.update(pairs_by_class1[class1])
452
+ pairs_groups.append(pairs_group)
453
+ return pairs_groups
@@ -0,0 +1 @@
1
+ """Empty __init__.py file to signal Python this directory is a package."""
@@ -0,0 +1,52 @@
1
+ """Calculate the area of a glyph."""
2
+
3
+ from fontTools.pens.basePen import BasePen
4
+
5
+
6
+ __all__ = ["AreaPen"]
7
+
8
+
9
+ class AreaPen(BasePen):
10
+ def __init__(self, glyphset=None):
11
+ BasePen.__init__(self, glyphset)
12
+ self.value = 0
13
+
14
+ def _moveTo(self, p0):
15
+ self._p0 = self._startPoint = p0
16
+
17
+ def _lineTo(self, p1):
18
+ x0, y0 = self._p0
19
+ x1, y1 = p1
20
+ self.value -= (x1 - x0) * (y1 + y0) * 0.5
21
+ self._p0 = p1
22
+
23
+ def _qCurveToOne(self, p1, p2):
24
+ # https://github.com/Pomax/bezierinfo/issues/44
25
+ p0 = self._p0
26
+ x0, y0 = p0[0], p0[1]
27
+ x1, y1 = p1[0] - x0, p1[1] - y0
28
+ x2, y2 = p2[0] - x0, p2[1] - y0
29
+ self.value -= (x2 * y1 - x1 * y2) / 3
30
+ self._lineTo(p2)
31
+ self._p0 = p2
32
+
33
+ def _curveToOne(self, p1, p2, p3):
34
+ # https://github.com/Pomax/bezierinfo/issues/44
35
+ p0 = self._p0
36
+ x0, y0 = p0[0], p0[1]
37
+ x1, y1 = p1[0] - x0, p1[1] - y0
38
+ x2, y2 = p2[0] - x0, p2[1] - y0
39
+ x3, y3 = p3[0] - x0, p3[1] - y0
40
+ self.value -= (x1 * (-y2 - y3) + x2 * (y1 - 2 * y3) + x3 * (y1 + 2 * y2)) * 0.15
41
+ self._lineTo(p3)
42
+ self._p0 = p3
43
+
44
+ def _closePath(self):
45
+ self._lineTo(self._startPoint)
46
+ del self._p0, self._startPoint
47
+
48
+ def _endPath(self):
49
+ if self._p0 != self._startPoint:
50
+ # Area is not defined for open contours.
51
+ raise NotImplementedError
52
+ del self._p0, self._startPoint