fonttools 4.60.2__cp311-cp311-win32.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.
Files changed (353) 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/annotations.py +30 -0
  6. fontTools/cffLib/CFF2ToCFF.py +258 -0
  7. fontTools/cffLib/CFFToCFF2.py +305 -0
  8. fontTools/cffLib/__init__.py +3694 -0
  9. fontTools/cffLib/specializer.py +927 -0
  10. fontTools/cffLib/transforms.py +495 -0
  11. fontTools/cffLib/width.py +210 -0
  12. fontTools/colorLib/__init__.py +0 -0
  13. fontTools/colorLib/builder.py +664 -0
  14. fontTools/colorLib/errors.py +2 -0
  15. fontTools/colorLib/geometry.py +143 -0
  16. fontTools/colorLib/table_builder.py +223 -0
  17. fontTools/colorLib/unbuilder.py +81 -0
  18. fontTools/config/__init__.py +90 -0
  19. fontTools/cu2qu/__init__.py +15 -0
  20. fontTools/cu2qu/__main__.py +6 -0
  21. fontTools/cu2qu/benchmark.py +54 -0
  22. fontTools/cu2qu/cli.py +198 -0
  23. fontTools/cu2qu/cu2qu.c +15817 -0
  24. fontTools/cu2qu/cu2qu.cp311-win32.pyd +0 -0
  25. fontTools/cu2qu/cu2qu.py +563 -0
  26. fontTools/cu2qu/errors.py +77 -0
  27. fontTools/cu2qu/ufo.py +363 -0
  28. fontTools/designspaceLib/__init__.py +3343 -0
  29. fontTools/designspaceLib/__main__.py +6 -0
  30. fontTools/designspaceLib/split.py +475 -0
  31. fontTools/designspaceLib/statNames.py +260 -0
  32. fontTools/designspaceLib/types.py +147 -0
  33. fontTools/encodings/MacRoman.py +258 -0
  34. fontTools/encodings/StandardEncoding.py +258 -0
  35. fontTools/encodings/__init__.py +1 -0
  36. fontTools/encodings/codecs.py +135 -0
  37. fontTools/feaLib/__init__.py +4 -0
  38. fontTools/feaLib/__main__.py +78 -0
  39. fontTools/feaLib/ast.py +2143 -0
  40. fontTools/feaLib/builder.py +1814 -0
  41. fontTools/feaLib/error.py +22 -0
  42. fontTools/feaLib/lexer.c +17029 -0
  43. fontTools/feaLib/lexer.cp311-win32.pyd +0 -0
  44. fontTools/feaLib/lexer.py +287 -0
  45. fontTools/feaLib/location.py +12 -0
  46. fontTools/feaLib/lookupDebugInfo.py +12 -0
  47. fontTools/feaLib/parser.py +2394 -0
  48. fontTools/feaLib/variableScalar.py +118 -0
  49. fontTools/fontBuilder.py +1014 -0
  50. fontTools/help.py +36 -0
  51. fontTools/merge/__init__.py +248 -0
  52. fontTools/merge/__main__.py +6 -0
  53. fontTools/merge/base.py +81 -0
  54. fontTools/merge/cmap.py +173 -0
  55. fontTools/merge/layout.py +526 -0
  56. fontTools/merge/options.py +85 -0
  57. fontTools/merge/tables.py +352 -0
  58. fontTools/merge/unicode.py +78 -0
  59. fontTools/merge/util.py +143 -0
  60. fontTools/misc/__init__.py +1 -0
  61. fontTools/misc/arrayTools.py +424 -0
  62. fontTools/misc/bezierTools.c +39731 -0
  63. fontTools/misc/bezierTools.cp311-win32.pyd +0 -0
  64. fontTools/misc/bezierTools.py +1500 -0
  65. fontTools/misc/classifyTools.py +170 -0
  66. fontTools/misc/cliTools.py +53 -0
  67. fontTools/misc/configTools.py +349 -0
  68. fontTools/misc/cython.py +27 -0
  69. fontTools/misc/dictTools.py +83 -0
  70. fontTools/misc/eexec.py +119 -0
  71. fontTools/misc/encodingTools.py +72 -0
  72. fontTools/misc/enumTools.py +23 -0
  73. fontTools/misc/etree.py +456 -0
  74. fontTools/misc/filenames.py +245 -0
  75. fontTools/misc/filesystem/__init__.py +68 -0
  76. fontTools/misc/filesystem/_base.py +134 -0
  77. fontTools/misc/filesystem/_copy.py +45 -0
  78. fontTools/misc/filesystem/_errors.py +54 -0
  79. fontTools/misc/filesystem/_info.py +75 -0
  80. fontTools/misc/filesystem/_osfs.py +164 -0
  81. fontTools/misc/filesystem/_path.py +67 -0
  82. fontTools/misc/filesystem/_subfs.py +92 -0
  83. fontTools/misc/filesystem/_tempfs.py +34 -0
  84. fontTools/misc/filesystem/_tools.py +34 -0
  85. fontTools/misc/filesystem/_walk.py +55 -0
  86. fontTools/misc/filesystem/_zipfs.py +204 -0
  87. fontTools/misc/fixedTools.py +253 -0
  88. fontTools/misc/intTools.py +25 -0
  89. fontTools/misc/iterTools.py +12 -0
  90. fontTools/misc/lazyTools.py +42 -0
  91. fontTools/misc/loggingTools.py +543 -0
  92. fontTools/misc/macCreatorType.py +56 -0
  93. fontTools/misc/macRes.py +261 -0
  94. fontTools/misc/plistlib/__init__.py +681 -0
  95. fontTools/misc/plistlib/py.typed +0 -0
  96. fontTools/misc/psCharStrings.py +1511 -0
  97. fontTools/misc/psLib.py +398 -0
  98. fontTools/misc/psOperators.py +572 -0
  99. fontTools/misc/py23.py +96 -0
  100. fontTools/misc/roundTools.py +110 -0
  101. fontTools/misc/sstruct.py +227 -0
  102. fontTools/misc/symfont.py +242 -0
  103. fontTools/misc/testTools.py +233 -0
  104. fontTools/misc/textTools.py +156 -0
  105. fontTools/misc/timeTools.py +88 -0
  106. fontTools/misc/transform.py +516 -0
  107. fontTools/misc/treeTools.py +45 -0
  108. fontTools/misc/vector.py +147 -0
  109. fontTools/misc/visitor.py +158 -0
  110. fontTools/misc/xmlReader.py +188 -0
  111. fontTools/misc/xmlWriter.py +231 -0
  112. fontTools/mtiLib/__init__.py +1400 -0
  113. fontTools/mtiLib/__main__.py +5 -0
  114. fontTools/otlLib/__init__.py +1 -0
  115. fontTools/otlLib/builder.py +3465 -0
  116. fontTools/otlLib/error.py +11 -0
  117. fontTools/otlLib/maxContextCalc.py +96 -0
  118. fontTools/otlLib/optimize/__init__.py +53 -0
  119. fontTools/otlLib/optimize/__main__.py +6 -0
  120. fontTools/otlLib/optimize/gpos.py +439 -0
  121. fontTools/pens/__init__.py +1 -0
  122. fontTools/pens/areaPen.py +52 -0
  123. fontTools/pens/basePen.py +475 -0
  124. fontTools/pens/boundsPen.py +98 -0
  125. fontTools/pens/cairoPen.py +26 -0
  126. fontTools/pens/cocoaPen.py +26 -0
  127. fontTools/pens/cu2quPen.py +325 -0
  128. fontTools/pens/explicitClosingLinePen.py +101 -0
  129. fontTools/pens/filterPen.py +433 -0
  130. fontTools/pens/freetypePen.py +462 -0
  131. fontTools/pens/hashPointPen.py +89 -0
  132. fontTools/pens/momentsPen.c +13378 -0
  133. fontTools/pens/momentsPen.cp311-win32.pyd +0 -0
  134. fontTools/pens/momentsPen.py +879 -0
  135. fontTools/pens/perimeterPen.py +69 -0
  136. fontTools/pens/pointInsidePen.py +192 -0
  137. fontTools/pens/pointPen.py +643 -0
  138. fontTools/pens/qtPen.py +29 -0
  139. fontTools/pens/qu2cuPen.py +105 -0
  140. fontTools/pens/quartzPen.py +43 -0
  141. fontTools/pens/recordingPen.py +335 -0
  142. fontTools/pens/reportLabPen.py +79 -0
  143. fontTools/pens/reverseContourPen.py +96 -0
  144. fontTools/pens/roundingPen.py +130 -0
  145. fontTools/pens/statisticsPen.py +312 -0
  146. fontTools/pens/svgPathPen.py +310 -0
  147. fontTools/pens/t2CharStringPen.py +88 -0
  148. fontTools/pens/teePen.py +55 -0
  149. fontTools/pens/transformPen.py +115 -0
  150. fontTools/pens/ttGlyphPen.py +335 -0
  151. fontTools/pens/wxPen.py +29 -0
  152. fontTools/qu2cu/__init__.py +15 -0
  153. fontTools/qu2cu/__main__.py +7 -0
  154. fontTools/qu2cu/benchmark.py +56 -0
  155. fontTools/qu2cu/cli.py +125 -0
  156. fontTools/qu2cu/qu2cu.c +16682 -0
  157. fontTools/qu2cu/qu2cu.cp311-win32.pyd +0 -0
  158. fontTools/qu2cu/qu2cu.py +405 -0
  159. fontTools/subset/__init__.py +4096 -0
  160. fontTools/subset/__main__.py +6 -0
  161. fontTools/subset/cff.py +184 -0
  162. fontTools/subset/svg.py +253 -0
  163. fontTools/subset/util.py +25 -0
  164. fontTools/svgLib/__init__.py +3 -0
  165. fontTools/svgLib/path/__init__.py +65 -0
  166. fontTools/svgLib/path/arc.py +154 -0
  167. fontTools/svgLib/path/parser.py +322 -0
  168. fontTools/svgLib/path/shapes.py +183 -0
  169. fontTools/t1Lib/__init__.py +648 -0
  170. fontTools/tfmLib.py +460 -0
  171. fontTools/ttLib/__init__.py +30 -0
  172. fontTools/ttLib/__main__.py +148 -0
  173. fontTools/ttLib/macUtils.py +54 -0
  174. fontTools/ttLib/removeOverlaps.py +395 -0
  175. fontTools/ttLib/reorderGlyphs.py +285 -0
  176. fontTools/ttLib/scaleUpem.py +436 -0
  177. fontTools/ttLib/sfnt.py +661 -0
  178. fontTools/ttLib/standardGlyphOrder.py +271 -0
  179. fontTools/ttLib/tables/B_A_S_E_.py +14 -0
  180. fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
  181. fontTools/ttLib/tables/C_B_D_T_.py +113 -0
  182. fontTools/ttLib/tables/C_B_L_C_.py +19 -0
  183. fontTools/ttLib/tables/C_F_F_.py +61 -0
  184. fontTools/ttLib/tables/C_F_F__2.py +26 -0
  185. fontTools/ttLib/tables/C_O_L_R_.py +165 -0
  186. fontTools/ttLib/tables/C_P_A_L_.py +305 -0
  187. fontTools/ttLib/tables/D_S_I_G_.py +158 -0
  188. fontTools/ttLib/tables/D__e_b_g.py +35 -0
  189. fontTools/ttLib/tables/DefaultTable.py +49 -0
  190. fontTools/ttLib/tables/E_B_D_T_.py +835 -0
  191. fontTools/ttLib/tables/E_B_L_C_.py +718 -0
  192. fontTools/ttLib/tables/F_F_T_M_.py +52 -0
  193. fontTools/ttLib/tables/F__e_a_t.py +149 -0
  194. fontTools/ttLib/tables/G_D_E_F_.py +13 -0
  195. fontTools/ttLib/tables/G_M_A_P_.py +148 -0
  196. fontTools/ttLib/tables/G_P_K_G_.py +133 -0
  197. fontTools/ttLib/tables/G_P_O_S_.py +14 -0
  198. fontTools/ttLib/tables/G_S_U_B_.py +13 -0
  199. fontTools/ttLib/tables/G_V_A_R_.py +5 -0
  200. fontTools/ttLib/tables/G__l_a_t.py +235 -0
  201. fontTools/ttLib/tables/G__l_o_c.py +85 -0
  202. fontTools/ttLib/tables/H_V_A_R_.py +13 -0
  203. fontTools/ttLib/tables/J_S_T_F_.py +13 -0
  204. fontTools/ttLib/tables/L_T_S_H_.py +58 -0
  205. fontTools/ttLib/tables/M_A_T_H_.py +13 -0
  206. fontTools/ttLib/tables/M_E_T_A_.py +352 -0
  207. fontTools/ttLib/tables/M_V_A_R_.py +13 -0
  208. fontTools/ttLib/tables/O_S_2f_2.py +752 -0
  209. fontTools/ttLib/tables/S_I_N_G_.py +99 -0
  210. fontTools/ttLib/tables/S_T_A_T_.py +15 -0
  211. fontTools/ttLib/tables/S_V_G_.py +223 -0
  212. fontTools/ttLib/tables/S__i_l_f.py +1040 -0
  213. fontTools/ttLib/tables/S__i_l_l.py +92 -0
  214. fontTools/ttLib/tables/T_S_I_B_.py +13 -0
  215. fontTools/ttLib/tables/T_S_I_C_.py +14 -0
  216. fontTools/ttLib/tables/T_S_I_D_.py +13 -0
  217. fontTools/ttLib/tables/T_S_I_J_.py +13 -0
  218. fontTools/ttLib/tables/T_S_I_P_.py +13 -0
  219. fontTools/ttLib/tables/T_S_I_S_.py +13 -0
  220. fontTools/ttLib/tables/T_S_I_V_.py +26 -0
  221. fontTools/ttLib/tables/T_S_I__0.py +70 -0
  222. fontTools/ttLib/tables/T_S_I__1.py +163 -0
  223. fontTools/ttLib/tables/T_S_I__2.py +17 -0
  224. fontTools/ttLib/tables/T_S_I__3.py +22 -0
  225. fontTools/ttLib/tables/T_S_I__5.py +60 -0
  226. fontTools/ttLib/tables/T_T_F_A_.py +14 -0
  227. fontTools/ttLib/tables/TupleVariation.py +884 -0
  228. fontTools/ttLib/tables/V_A_R_C_.py +12 -0
  229. fontTools/ttLib/tables/V_D_M_X_.py +249 -0
  230. fontTools/ttLib/tables/V_O_R_G_.py +165 -0
  231. fontTools/ttLib/tables/V_V_A_R_.py +13 -0
  232. fontTools/ttLib/tables/__init__.py +98 -0
  233. fontTools/ttLib/tables/_a_n_k_r.py +15 -0
  234. fontTools/ttLib/tables/_a_v_a_r.py +193 -0
  235. fontTools/ttLib/tables/_b_s_l_n.py +15 -0
  236. fontTools/ttLib/tables/_c_i_d_g.py +24 -0
  237. fontTools/ttLib/tables/_c_m_a_p.py +1591 -0
  238. fontTools/ttLib/tables/_c_v_a_r.py +94 -0
  239. fontTools/ttLib/tables/_c_v_t.py +56 -0
  240. fontTools/ttLib/tables/_f_e_a_t.py +15 -0
  241. fontTools/ttLib/tables/_f_p_g_m.py +62 -0
  242. fontTools/ttLib/tables/_f_v_a_r.py +261 -0
  243. fontTools/ttLib/tables/_g_a_s_p.py +63 -0
  244. fontTools/ttLib/tables/_g_c_i_d.py +13 -0
  245. fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
  246. fontTools/ttLib/tables/_g_v_a_r.py +340 -0
  247. fontTools/ttLib/tables/_h_d_m_x.py +127 -0
  248. fontTools/ttLib/tables/_h_e_a_d.py +130 -0
  249. fontTools/ttLib/tables/_h_h_e_a.py +147 -0
  250. fontTools/ttLib/tables/_h_m_t_x.py +164 -0
  251. fontTools/ttLib/tables/_k_e_r_n.py +289 -0
  252. fontTools/ttLib/tables/_l_c_a_r.py +13 -0
  253. fontTools/ttLib/tables/_l_o_c_a.py +70 -0
  254. fontTools/ttLib/tables/_l_t_a_g.py +72 -0
  255. fontTools/ttLib/tables/_m_a_x_p.py +147 -0
  256. fontTools/ttLib/tables/_m_e_t_a.py +112 -0
  257. fontTools/ttLib/tables/_m_o_r_t.py +14 -0
  258. fontTools/ttLib/tables/_m_o_r_x.py +15 -0
  259. fontTools/ttLib/tables/_n_a_m_e.py +1242 -0
  260. fontTools/ttLib/tables/_o_p_b_d.py +14 -0
  261. fontTools/ttLib/tables/_p_o_s_t.py +319 -0
  262. fontTools/ttLib/tables/_p_r_e_p.py +16 -0
  263. fontTools/ttLib/tables/_p_r_o_p.py +12 -0
  264. fontTools/ttLib/tables/_s_b_i_x.py +129 -0
  265. fontTools/ttLib/tables/_t_r_a_k.py +332 -0
  266. fontTools/ttLib/tables/_v_h_e_a.py +139 -0
  267. fontTools/ttLib/tables/_v_m_t_x.py +19 -0
  268. fontTools/ttLib/tables/asciiTable.py +20 -0
  269. fontTools/ttLib/tables/grUtils.py +92 -0
  270. fontTools/ttLib/tables/otBase.py +1458 -0
  271. fontTools/ttLib/tables/otConverters.py +2068 -0
  272. fontTools/ttLib/tables/otData.py +6400 -0
  273. fontTools/ttLib/tables/otTables.py +2703 -0
  274. fontTools/ttLib/tables/otTraverse.py +163 -0
  275. fontTools/ttLib/tables/sbixGlyph.py +149 -0
  276. fontTools/ttLib/tables/sbixStrike.py +177 -0
  277. fontTools/ttLib/tables/table_API_readme.txt +91 -0
  278. fontTools/ttLib/tables/ttProgram.py +594 -0
  279. fontTools/ttLib/ttCollection.py +125 -0
  280. fontTools/ttLib/ttFont.py +1148 -0
  281. fontTools/ttLib/ttGlyphSet.py +490 -0
  282. fontTools/ttLib/ttVisitor.py +32 -0
  283. fontTools/ttLib/woff2.py +1680 -0
  284. fontTools/ttx.py +479 -0
  285. fontTools/ufoLib/__init__.py +2575 -0
  286. fontTools/ufoLib/converters.py +407 -0
  287. fontTools/ufoLib/errors.py +30 -0
  288. fontTools/ufoLib/etree.py +6 -0
  289. fontTools/ufoLib/filenames.py +356 -0
  290. fontTools/ufoLib/glifLib.py +2120 -0
  291. fontTools/ufoLib/kerning.py +141 -0
  292. fontTools/ufoLib/plistlib.py +47 -0
  293. fontTools/ufoLib/pointPen.py +6 -0
  294. fontTools/ufoLib/utils.py +107 -0
  295. fontTools/ufoLib/validators.py +1208 -0
  296. fontTools/unicode.py +50 -0
  297. fontTools/unicodedata/Blocks.py +817 -0
  298. fontTools/unicodedata/Mirrored.py +446 -0
  299. fontTools/unicodedata/OTTags.py +50 -0
  300. fontTools/unicodedata/ScriptExtensions.py +832 -0
  301. fontTools/unicodedata/Scripts.py +3639 -0
  302. fontTools/unicodedata/__init__.py +306 -0
  303. fontTools/varLib/__init__.py +1600 -0
  304. fontTools/varLib/__main__.py +6 -0
  305. fontTools/varLib/avar/__init__.py +0 -0
  306. fontTools/varLib/avar/__main__.py +72 -0
  307. fontTools/varLib/avar/build.py +79 -0
  308. fontTools/varLib/avar/map.py +108 -0
  309. fontTools/varLib/avar/plan.py +1004 -0
  310. fontTools/varLib/avar/unbuild.py +271 -0
  311. fontTools/varLib/avarPlanner.py +8 -0
  312. fontTools/varLib/builder.py +215 -0
  313. fontTools/varLib/cff.py +631 -0
  314. fontTools/varLib/errors.py +219 -0
  315. fontTools/varLib/featureVars.py +703 -0
  316. fontTools/varLib/hvar.py +113 -0
  317. fontTools/varLib/instancer/__init__.py +2052 -0
  318. fontTools/varLib/instancer/__main__.py +5 -0
  319. fontTools/varLib/instancer/featureVars.py +190 -0
  320. fontTools/varLib/instancer/names.py +388 -0
  321. fontTools/varLib/instancer/solver.py +309 -0
  322. fontTools/varLib/interpolatable.py +1209 -0
  323. fontTools/varLib/interpolatableHelpers.py +399 -0
  324. fontTools/varLib/interpolatablePlot.py +1269 -0
  325. fontTools/varLib/interpolatableTestContourOrder.py +82 -0
  326. fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
  327. fontTools/varLib/interpolate_layout.py +124 -0
  328. fontTools/varLib/iup.c +19815 -0
  329. fontTools/varLib/iup.cp311-win32.pyd +0 -0
  330. fontTools/varLib/iup.py +490 -0
  331. fontTools/varLib/merger.py +1717 -0
  332. fontTools/varLib/models.py +642 -0
  333. fontTools/varLib/multiVarStore.py +253 -0
  334. fontTools/varLib/mutator.py +529 -0
  335. fontTools/varLib/mvar.py +40 -0
  336. fontTools/varLib/plot.py +238 -0
  337. fontTools/varLib/stat.py +149 -0
  338. fontTools/varLib/varStore.py +739 -0
  339. fontTools/voltLib/__init__.py +5 -0
  340. fontTools/voltLib/__main__.py +206 -0
  341. fontTools/voltLib/ast.py +452 -0
  342. fontTools/voltLib/error.py +12 -0
  343. fontTools/voltLib/lexer.py +99 -0
  344. fontTools/voltLib/parser.py +664 -0
  345. fontTools/voltLib/voltToFea.py +911 -0
  346. fonttools-4.60.2.data/data/share/man/man1/ttx.1 +225 -0
  347. fonttools-4.60.2.dist-info/METADATA +2250 -0
  348. fonttools-4.60.2.dist-info/RECORD +353 -0
  349. fonttools-4.60.2.dist-info/WHEEL +5 -0
  350. fonttools-4.60.2.dist-info/entry_points.txt +5 -0
  351. fonttools-4.60.2.dist-info/licenses/LICENSE +21 -0
  352. fonttools-4.60.2.dist-info/licenses/LICENSE.external +388 -0
  353. fonttools-4.60.2.dist-info/top_level.txt +1 -0
Binary file
@@ -0,0 +1,490 @@
1
+ try:
2
+ import cython
3
+ except (AttributeError, ImportError):
4
+ # if cython not installed, use mock module with no-op decorators and types
5
+ from fontTools.misc import cython
6
+ COMPILED = cython.compiled
7
+
8
+ from typing import (
9
+ Sequence,
10
+ Tuple,
11
+ Union,
12
+ )
13
+ from numbers import Integral, Real
14
+
15
+
16
+ _Point = Tuple[Real, Real]
17
+ _Delta = Tuple[Real, Real]
18
+ _PointSegment = Sequence[_Point]
19
+ _DeltaSegment = Sequence[_Delta]
20
+ _DeltaOrNone = Union[_Delta, None]
21
+ _DeltaOrNoneSegment = Sequence[_DeltaOrNone]
22
+ _Endpoints = Sequence[Integral]
23
+
24
+
25
+ MAX_LOOKBACK = 8
26
+
27
+
28
+ @cython.cfunc
29
+ @cython.locals(
30
+ j=cython.int,
31
+ n=cython.int,
32
+ x1=cython.double,
33
+ x2=cython.double,
34
+ d1=cython.double,
35
+ d2=cython.double,
36
+ scale=cython.double,
37
+ x=cython.double,
38
+ d=cython.double,
39
+ )
40
+ def iup_segment(
41
+ coords: _PointSegment, rc1: _Point, rd1: _Delta, rc2: _Point, rd2: _Delta
42
+ ): # -> _DeltaSegment:
43
+ """Given two reference coordinates `rc1` & `rc2` and their respective
44
+ delta vectors `rd1` & `rd2`, returns interpolated deltas for the set of
45
+ coordinates `coords`."""
46
+
47
+ # rc1 = reference coord 1
48
+ # rd1 = reference delta 1
49
+ out_arrays = [None, None]
50
+ for j in 0, 1:
51
+ out_arrays[j] = out = []
52
+ x1, x2, d1, d2 = rc1[j], rc2[j], rd1[j], rd2[j]
53
+
54
+ if x1 == x2:
55
+ n = len(coords)
56
+ if d1 == d2:
57
+ out.extend([d1] * n)
58
+ else:
59
+ out.extend([0] * n)
60
+ continue
61
+
62
+ if x1 > x2:
63
+ x1, x2 = x2, x1
64
+ d1, d2 = d2, d1
65
+
66
+ # x1 < x2
67
+ scale = (d2 - d1) / (x2 - x1)
68
+ for pair in coords:
69
+ x = pair[j]
70
+
71
+ if x <= x1:
72
+ d = d1
73
+ elif x >= x2:
74
+ d = d2
75
+ else:
76
+ # Interpolate
77
+ #
78
+ # NOTE: we assign an explicit intermediate variable here in
79
+ # order to disable a fused mul-add optimization. See:
80
+ #
81
+ # - https://godbolt.org/z/YsP4T3TqK,
82
+ # - https://github.com/fonttools/fonttools/issues/3703
83
+ nudge = (x - x1) * scale
84
+ d = d1 + nudge
85
+
86
+ out.append(d)
87
+
88
+ return zip(*out_arrays)
89
+
90
+
91
+ def iup_contour(deltas: _DeltaOrNoneSegment, coords: _PointSegment) -> _DeltaSegment:
92
+ """For the contour given in `coords`, interpolate any missing
93
+ delta values in delta vector `deltas`.
94
+
95
+ Returns fully filled-out delta vector."""
96
+
97
+ assert len(deltas) == len(coords)
98
+ if None not in deltas:
99
+ return deltas
100
+
101
+ n = len(deltas)
102
+ # indices of points with explicit deltas
103
+ indices = [i for i, v in enumerate(deltas) if v is not None]
104
+ if not indices:
105
+ # All deltas are None. Return 0,0 for all.
106
+ return [(0, 0)] * n
107
+
108
+ out = []
109
+ it = iter(indices)
110
+ start = next(it)
111
+ if start != 0:
112
+ # Initial segment that wraps around
113
+ i1, i2, ri1, ri2 = 0, start, start, indices[-1]
114
+ out.extend(
115
+ iup_segment(
116
+ coords[i1:i2], coords[ri1], deltas[ri1], coords[ri2], deltas[ri2]
117
+ )
118
+ )
119
+ out.append(deltas[start])
120
+ for end in it:
121
+ if end - start > 1:
122
+ i1, i2, ri1, ri2 = start + 1, end, start, end
123
+ out.extend(
124
+ iup_segment(
125
+ coords[i1:i2], coords[ri1], deltas[ri1], coords[ri2], deltas[ri2]
126
+ )
127
+ )
128
+ out.append(deltas[end])
129
+ start = end
130
+ if start != n - 1:
131
+ # Final segment that wraps around
132
+ i1, i2, ri1, ri2 = start + 1, n, start, indices[0]
133
+ out.extend(
134
+ iup_segment(
135
+ coords[i1:i2], coords[ri1], deltas[ri1], coords[ri2], deltas[ri2]
136
+ )
137
+ )
138
+
139
+ assert len(deltas) == len(out), (len(deltas), len(out))
140
+ return out
141
+
142
+
143
+ def iup_delta(
144
+ deltas: _DeltaOrNoneSegment, coords: _PointSegment, ends: _Endpoints
145
+ ) -> _DeltaSegment:
146
+ """For the outline given in `coords`, with contour endpoints given
147
+ in sorted increasing order in `ends`, interpolate any missing
148
+ delta values in delta vector `deltas`.
149
+
150
+ Returns fully filled-out delta vector."""
151
+
152
+ assert sorted(ends) == ends and len(coords) == (ends[-1] + 1 if ends else 0) + 4
153
+ n = len(coords)
154
+ ends = ends + [n - 4, n - 3, n - 2, n - 1]
155
+ out = []
156
+ start = 0
157
+ for end in ends:
158
+ end += 1
159
+ contour = iup_contour(deltas[start:end], coords[start:end])
160
+ out.extend(contour)
161
+ start = end
162
+
163
+ return out
164
+
165
+
166
+ # Optimizer
167
+
168
+
169
+ @cython.cfunc
170
+ @cython.inline
171
+ @cython.locals(
172
+ i=cython.int,
173
+ j=cython.int,
174
+ # tolerance=cython.double, # https://github.com/fonttools/fonttools/issues/3282
175
+ x=cython.double,
176
+ y=cython.double,
177
+ p=cython.double,
178
+ q=cython.double,
179
+ )
180
+ @cython.returns(int)
181
+ def can_iup_in_between(
182
+ deltas: _DeltaSegment,
183
+ coords: _PointSegment,
184
+ i: Integral,
185
+ j: Integral,
186
+ tolerance: Real,
187
+ ): # -> bool:
188
+ """Return true if the deltas for points at `i` and `j` (`i < j`) can be
189
+ successfully used to interpolate deltas for points in between them within
190
+ provided error tolerance."""
191
+
192
+ assert j - i >= 2
193
+ interp = iup_segment(coords[i + 1 : j], coords[i], deltas[i], coords[j], deltas[j])
194
+ deltas = deltas[i + 1 : j]
195
+
196
+ return all(
197
+ abs(complex(x - p, y - q)) <= tolerance
198
+ for (x, y), (p, q) in zip(deltas, interp)
199
+ )
200
+
201
+
202
+ @cython.locals(
203
+ cj=cython.double,
204
+ dj=cython.double,
205
+ lcj=cython.double,
206
+ ldj=cython.double,
207
+ ncj=cython.double,
208
+ ndj=cython.double,
209
+ force=cython.int,
210
+ forced=set,
211
+ )
212
+ def _iup_contour_bound_forced_set(
213
+ deltas: _DeltaSegment, coords: _PointSegment, tolerance: Real = 0
214
+ ) -> set:
215
+ """The forced set is a conservative set of points on the contour that must be encoded
216
+ explicitly (ie. cannot be interpolated). Calculating this set allows for significantly
217
+ speeding up the dynamic-programming, as well as resolve circularity in DP.
218
+
219
+ The set is precise; that is, if an index is in the returned set, then there is no way
220
+ that IUP can generate delta for that point, given `coords` and `deltas`.
221
+ """
222
+ assert len(deltas) == len(coords)
223
+
224
+ n = len(deltas)
225
+ forced = set()
226
+ # Track "last" and "next" points on the contour as we sweep.
227
+ for i in range(len(deltas) - 1, -1, -1):
228
+ ld, lc = deltas[i - 1], coords[i - 1]
229
+ d, c = deltas[i], coords[i]
230
+ nd, nc = deltas[i - n + 1], coords[i - n + 1]
231
+
232
+ for j in (0, 1): # For X and for Y
233
+ cj = c[j]
234
+ dj = d[j]
235
+ lcj = lc[j]
236
+ ldj = ld[j]
237
+ ncj = nc[j]
238
+ ndj = nd[j]
239
+
240
+ if lcj <= ncj:
241
+ c1, c2 = lcj, ncj
242
+ d1, d2 = ldj, ndj
243
+ else:
244
+ c1, c2 = ncj, lcj
245
+ d1, d2 = ndj, ldj
246
+
247
+ force = False
248
+
249
+ # If the two coordinates are the same, then the interpolation
250
+ # algorithm produces the same delta if both deltas are equal,
251
+ # and zero if they differ.
252
+ #
253
+ # This test has to be before the next one.
254
+ if c1 == c2:
255
+ if abs(d1 - d2) > tolerance and abs(dj) > tolerance:
256
+ force = True
257
+
258
+ # If coordinate for current point is between coordinate of adjacent
259
+ # points on the two sides, but the delta for current point is NOT
260
+ # between delta for those adjacent points (considering tolerance
261
+ # allowance), then there is no way that current point can be IUP-ed.
262
+ # Mark it forced.
263
+ elif c1 <= cj <= c2: # and c1 != c2
264
+ if not (min(d1, d2) - tolerance <= dj <= max(d1, d2) + tolerance):
265
+ force = True
266
+
267
+ # Otherwise, the delta should either match the closest, or have the
268
+ # same sign as the interpolation of the two deltas.
269
+ else: # cj < c1 or c2 < cj
270
+ if d1 != d2:
271
+ if cj < c1:
272
+ if (
273
+ abs(dj) > tolerance
274
+ and abs(dj - d1) > tolerance
275
+ and ((dj - tolerance < d1) != (d1 < d2))
276
+ ):
277
+ force = True
278
+ else: # c2 < cj
279
+ if (
280
+ abs(dj) > tolerance
281
+ and abs(dj - d2) > tolerance
282
+ and ((d2 < dj + tolerance) != (d1 < d2))
283
+ ):
284
+ force = True
285
+
286
+ if force:
287
+ forced.add(i)
288
+ break
289
+
290
+ return forced
291
+
292
+
293
+ @cython.locals(
294
+ i=cython.int,
295
+ j=cython.int,
296
+ best_cost=cython.double,
297
+ best_j=cython.int,
298
+ cost=cython.double,
299
+ forced=set,
300
+ tolerance=cython.double,
301
+ )
302
+ def _iup_contour_optimize_dp(
303
+ deltas: _DeltaSegment,
304
+ coords: _PointSegment,
305
+ forced=set(),
306
+ tolerance: Real = 0,
307
+ lookback: Integral = None,
308
+ ):
309
+ """Straightforward Dynamic-Programming. For each index i, find least-costly encoding of
310
+ points 0 to i where i is explicitly encoded. We find this by considering all previous
311
+ explicit points j and check whether interpolation can fill points between j and i.
312
+
313
+ Note that solution always encodes last point explicitly. Higher-level is responsible
314
+ for removing that restriction.
315
+
316
+ As major speedup, we stop looking further whenever we see a "forced" point."""
317
+
318
+ n = len(deltas)
319
+ if lookback is None:
320
+ lookback = n
321
+ lookback = min(lookback, MAX_LOOKBACK)
322
+ costs = {-1: 0}
323
+ chain = {-1: None}
324
+ for i in range(0, n):
325
+ best_cost = costs[i - 1] + 1
326
+
327
+ costs[i] = best_cost
328
+ chain[i] = i - 1
329
+
330
+ if i - 1 in forced:
331
+ continue
332
+
333
+ for j in range(i - 2, max(i - lookback, -2), -1):
334
+ cost = costs[j] + 1
335
+
336
+ if cost < best_cost and can_iup_in_between(deltas, coords, j, i, tolerance):
337
+ costs[i] = best_cost = cost
338
+ chain[i] = j
339
+
340
+ if j in forced:
341
+ break
342
+
343
+ return chain, costs
344
+
345
+
346
+ def _rot_list(l: list, k: int):
347
+ """Rotate list by k items forward. Ie. item at position 0 will be
348
+ at position k in returned list. Negative k is allowed."""
349
+ n = len(l)
350
+ k %= n
351
+ if not k:
352
+ return l
353
+ return l[n - k :] + l[: n - k]
354
+
355
+
356
+ def _rot_set(s: set, k: int, n: int):
357
+ k %= n
358
+ if not k:
359
+ return s
360
+ return {(v + k) % n for v in s}
361
+
362
+
363
+ def iup_contour_optimize(
364
+ deltas: _DeltaSegment, coords: _PointSegment, tolerance: Real = 0.0
365
+ ) -> _DeltaOrNoneSegment:
366
+ """For contour with coordinates `coords`, optimize a set of delta
367
+ values `deltas` within error `tolerance`.
368
+
369
+ Returns delta vector that has most number of None items instead of
370
+ the input delta.
371
+ """
372
+
373
+ n = len(deltas)
374
+
375
+ # Get the easy cases out of the way:
376
+
377
+ # If all are within tolerance distance of 0, encode nothing:
378
+ if all(abs(complex(*p)) <= tolerance for p in deltas):
379
+ return [None] * n
380
+
381
+ # If there's exactly one point, return it:
382
+ if n == 1:
383
+ return deltas
384
+
385
+ # If all deltas are exactly the same, return just one (the first one):
386
+ d0 = deltas[0]
387
+ if all(d0 == d for d in deltas):
388
+ return [d0] + [None] * (n - 1)
389
+
390
+ # Else, solve the general problem using Dynamic Programming.
391
+
392
+ forced = _iup_contour_bound_forced_set(deltas, coords, tolerance)
393
+ # The _iup_contour_optimize_dp() routine returns the optimal encoding
394
+ # solution given the constraint that the last point is always encoded.
395
+ # To remove this constraint, we use two different methods, depending on
396
+ # whether forced set is non-empty or not:
397
+
398
+ # Debugging: Make the next if always take the second branch and observe
399
+ # if the font size changes (reduced); that would mean the forced-set
400
+ # has members it should not have.
401
+ if forced:
402
+ # Forced set is non-empty: rotate the contour start point
403
+ # such that the last point in the list is a forced point.
404
+ k = (n - 1) - max(forced)
405
+ assert k >= 0
406
+
407
+ deltas = _rot_list(deltas, k)
408
+ coords = _rot_list(coords, k)
409
+ forced = _rot_set(forced, k, n)
410
+
411
+ # Debugging: Pass a set() instead of forced variable to the next call
412
+ # to exercise forced-set computation for under-counting.
413
+ chain, costs = _iup_contour_optimize_dp(deltas, coords, forced, tolerance)
414
+
415
+ # Assemble solution.
416
+ solution = set()
417
+ i = n - 1
418
+ while i is not None:
419
+ solution.add(i)
420
+ i = chain[i]
421
+ solution.remove(-1)
422
+
423
+ # if not forced <= solution:
424
+ # print("coord", coords)
425
+ # print("deltas", deltas)
426
+ # print("len", len(deltas))
427
+ assert forced <= solution, (forced, solution)
428
+
429
+ deltas = [deltas[i] if i in solution else None for i in range(n)]
430
+
431
+ deltas = _rot_list(deltas, -k)
432
+ else:
433
+ # Repeat the contour an extra time, solve the new case, then look for solutions of the
434
+ # circular n-length problem in the solution for new linear case. I cannot prove that
435
+ # this always produces the optimal solution...
436
+ chain, costs = _iup_contour_optimize_dp(
437
+ deltas + deltas, coords + coords, forced, tolerance, n
438
+ )
439
+ best_sol, best_cost = None, n + 1
440
+
441
+ for start in range(n - 1, len(costs) - 1):
442
+ # Assemble solution.
443
+ solution = set()
444
+ i = start
445
+ while i > start - n:
446
+ solution.add(i % n)
447
+ i = chain[i]
448
+ if i == start - n:
449
+ cost = costs[start] - costs[start - n]
450
+ if cost <= best_cost:
451
+ best_sol, best_cost = solution, cost
452
+
453
+ # if not forced <= best_sol:
454
+ # print("coord", coords)
455
+ # print("deltas", deltas)
456
+ # print("len", len(deltas))
457
+ assert forced <= best_sol, (forced, best_sol)
458
+
459
+ deltas = [deltas[i] if i in best_sol else None for i in range(n)]
460
+
461
+ return deltas
462
+
463
+
464
+ def iup_delta_optimize(
465
+ deltas: _DeltaSegment,
466
+ coords: _PointSegment,
467
+ ends: _Endpoints,
468
+ tolerance: Real = 0.0,
469
+ ) -> _DeltaOrNoneSegment:
470
+ """For the outline given in `coords`, with contour endpoints given
471
+ in sorted increasing order in `ends`, optimize a set of delta
472
+ values `deltas` within error `tolerance`.
473
+
474
+ Returns delta vector that has most number of None items instead of
475
+ the input delta.
476
+ """
477
+ assert sorted(ends) == ends and len(coords) == (ends[-1] + 1 if ends else 0) + 4
478
+ n = len(coords)
479
+ ends = ends + [n - 4, n - 3, n - 2, n - 1]
480
+ out = []
481
+ start = 0
482
+ for end in ends:
483
+ contour = iup_contour_optimize(
484
+ deltas[start : end + 1], coords[start : end + 1], tolerance
485
+ )
486
+ assert len(contour) == end - start + 1
487
+ out.extend(contour)
488
+ start = end + 1
489
+
490
+ return out