fonttools 4.58.3__cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.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 (334) 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 +3694 -0
  8. fontTools/cffLib/specializer.py +927 -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 +90 -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 +15545 -0
  23. fontTools/cu2qu/cu2qu.cpython-312-aarch64-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 +260 -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 +2142 -0
  39. fontTools/feaLib/builder.py +1796 -0
  40. fontTools/feaLib/error.py +22 -0
  41. fontTools/feaLib/lexer.c +17336 -0
  42. fontTools/feaLib/lexer.cpython-312-aarch64-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 +2379 -0
  47. fontTools/feaLib/variableScalar.py +113 -0
  48. fontTools/fontBuilder.py +1014 -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 +173 -0
  54. fontTools/merge/layout.py +526 -0
  55. fontTools/merge/options.py +85 -0
  56. fontTools/merge/tables.py +352 -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 +40136 -0
  62. fontTools/misc/bezierTools.cpython-312-aarch64-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 +456 -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 +242 -0
  89. fontTools/misc/testTools.py +233 -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 +1400 -0
  99. fontTools/mtiLib/__main__.py +5 -0
  100. fontTools/otlLib/__init__.py +1 -0
  101. fontTools/otlLib/builder.py +3435 -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 +439 -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 +13459 -0
  119. fontTools/pens/momentsPen.cpython-312-aarch64-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 +609 -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 +88 -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 +16738 -0
  143. fontTools/qu2cu/qu2cu.cpython-312-aarch64-linux-gnu.so +0 -0
  144. fontTools/qu2cu/qu2cu.py +405 -0
  145. fontTools/subset/__init__.py +3929 -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 +30 -0
  158. fontTools/ttLib/__main__.py +148 -0
  159. fontTools/ttLib/macUtils.py +54 -0
  160. fontTools/ttLib/removeOverlaps.py +393 -0
  161. fontTools/ttLib/reorderGlyphs.py +285 -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 +35 -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_V_A_R_.py +5 -0
  186. fontTools/ttLib/tables/G__l_a_t.py +235 -0
  187. fontTools/ttLib/tables/G__l_o_c.py +85 -0
  188. fontTools/ttLib/tables/H_V_A_R_.py +13 -0
  189. fontTools/ttLib/tables/J_S_T_F_.py +13 -0
  190. fontTools/ttLib/tables/L_T_S_H_.py +58 -0
  191. fontTools/ttLib/tables/M_A_T_H_.py +13 -0
  192. fontTools/ttLib/tables/M_E_T_A_.py +352 -0
  193. fontTools/ttLib/tables/M_V_A_R_.py +13 -0
  194. fontTools/ttLib/tables/O_S_2f_2.py +752 -0
  195. fontTools/ttLib/tables/S_I_N_G_.py +99 -0
  196. fontTools/ttLib/tables/S_T_A_T_.py +15 -0
  197. fontTools/ttLib/tables/S_V_G_.py +223 -0
  198. fontTools/ttLib/tables/S__i_l_f.py +1040 -0
  199. fontTools/ttLib/tables/S__i_l_l.py +92 -0
  200. fontTools/ttLib/tables/T_S_I_B_.py +13 -0
  201. fontTools/ttLib/tables/T_S_I_C_.py +14 -0
  202. fontTools/ttLib/tables/T_S_I_D_.py +13 -0
  203. fontTools/ttLib/tables/T_S_I_J_.py +13 -0
  204. fontTools/ttLib/tables/T_S_I_P_.py +13 -0
  205. fontTools/ttLib/tables/T_S_I_S_.py +13 -0
  206. fontTools/ttLib/tables/T_S_I_V_.py +26 -0
  207. fontTools/ttLib/tables/T_S_I__0.py +70 -0
  208. fontTools/ttLib/tables/T_S_I__1.py +166 -0
  209. fontTools/ttLib/tables/T_S_I__2.py +17 -0
  210. fontTools/ttLib/tables/T_S_I__3.py +22 -0
  211. fontTools/ttLib/tables/T_S_I__5.py +60 -0
  212. fontTools/ttLib/tables/T_T_F_A_.py +14 -0
  213. fontTools/ttLib/tables/TupleVariation.py +884 -0
  214. fontTools/ttLib/tables/V_A_R_C_.py +12 -0
  215. fontTools/ttLib/tables/V_D_M_X_.py +249 -0
  216. fontTools/ttLib/tables/V_O_R_G_.py +165 -0
  217. fontTools/ttLib/tables/V_V_A_R_.py +13 -0
  218. fontTools/ttLib/tables/__init__.py +98 -0
  219. fontTools/ttLib/tables/_a_n_k_r.py +15 -0
  220. fontTools/ttLib/tables/_a_v_a_r.py +191 -0
  221. fontTools/ttLib/tables/_b_s_l_n.py +15 -0
  222. fontTools/ttLib/tables/_c_i_d_g.py +24 -0
  223. fontTools/ttLib/tables/_c_m_a_p.py +1591 -0
  224. fontTools/ttLib/tables/_c_v_a_r.py +94 -0
  225. fontTools/ttLib/tables/_c_v_t.py +57 -0
  226. fontTools/ttLib/tables/_f_e_a_t.py +15 -0
  227. fontTools/ttLib/tables/_f_p_g_m.py +62 -0
  228. fontTools/ttLib/tables/_f_v_a_r.py +261 -0
  229. fontTools/ttLib/tables/_g_a_s_p.py +63 -0
  230. fontTools/ttLib/tables/_g_c_i_d.py +13 -0
  231. fontTools/ttLib/tables/_g_l_y_f.py +2312 -0
  232. fontTools/ttLib/tables/_g_v_a_r.py +337 -0
  233. fontTools/ttLib/tables/_h_d_m_x.py +127 -0
  234. fontTools/ttLib/tables/_h_e_a_d.py +130 -0
  235. fontTools/ttLib/tables/_h_h_e_a.py +147 -0
  236. fontTools/ttLib/tables/_h_m_t_x.py +160 -0
  237. fontTools/ttLib/tables/_k_e_r_n.py +289 -0
  238. fontTools/ttLib/tables/_l_c_a_r.py +13 -0
  239. fontTools/ttLib/tables/_l_o_c_a.py +70 -0
  240. fontTools/ttLib/tables/_l_t_a_g.py +72 -0
  241. fontTools/ttLib/tables/_m_a_x_p.py +147 -0
  242. fontTools/ttLib/tables/_m_e_t_a.py +112 -0
  243. fontTools/ttLib/tables/_m_o_r_t.py +14 -0
  244. fontTools/ttLib/tables/_m_o_r_x.py +15 -0
  245. fontTools/ttLib/tables/_n_a_m_e.py +1237 -0
  246. fontTools/ttLib/tables/_o_p_b_d.py +14 -0
  247. fontTools/ttLib/tables/_p_o_s_t.py +320 -0
  248. fontTools/ttLib/tables/_p_r_e_p.py +16 -0
  249. fontTools/ttLib/tables/_p_r_o_p.py +12 -0
  250. fontTools/ttLib/tables/_s_b_i_x.py +129 -0
  251. fontTools/ttLib/tables/_t_r_a_k.py +332 -0
  252. fontTools/ttLib/tables/_v_h_e_a.py +139 -0
  253. fontTools/ttLib/tables/_v_m_t_x.py +19 -0
  254. fontTools/ttLib/tables/asciiTable.py +20 -0
  255. fontTools/ttLib/tables/grUtils.py +92 -0
  256. fontTools/ttLib/tables/otBase.py +1466 -0
  257. fontTools/ttLib/tables/otConverters.py +2068 -0
  258. fontTools/ttLib/tables/otData.py +6400 -0
  259. fontTools/ttLib/tables/otTables.py +2708 -0
  260. fontTools/ttLib/tables/otTraverse.py +163 -0
  261. fontTools/ttLib/tables/sbixGlyph.py +149 -0
  262. fontTools/ttLib/tables/sbixStrike.py +177 -0
  263. fontTools/ttLib/tables/table_API_readme.txt +91 -0
  264. fontTools/ttLib/tables/ttProgram.py +594 -0
  265. fontTools/ttLib/ttCollection.py +125 -0
  266. fontTools/ttLib/ttFont.py +1157 -0
  267. fontTools/ttLib/ttGlyphSet.py +490 -0
  268. fontTools/ttLib/ttVisitor.py +32 -0
  269. fontTools/ttLib/woff2.py +1683 -0
  270. fontTools/ttx.py +479 -0
  271. fontTools/ufoLib/__init__.py +2477 -0
  272. fontTools/ufoLib/converters.py +398 -0
  273. fontTools/ufoLib/errors.py +30 -0
  274. fontTools/ufoLib/etree.py +6 -0
  275. fontTools/ufoLib/filenames.py +346 -0
  276. fontTools/ufoLib/glifLib.py +2029 -0
  277. fontTools/ufoLib/kerning.py +121 -0
  278. fontTools/ufoLib/plistlib.py +47 -0
  279. fontTools/ufoLib/pointPen.py +6 -0
  280. fontTools/ufoLib/utils.py +79 -0
  281. fontTools/ufoLib/validators.py +1186 -0
  282. fontTools/unicode.py +50 -0
  283. fontTools/unicodedata/Blocks.py +801 -0
  284. fontTools/unicodedata/Mirrored.py +446 -0
  285. fontTools/unicodedata/OTTags.py +50 -0
  286. fontTools/unicodedata/ScriptExtensions.py +826 -0
  287. fontTools/unicodedata/Scripts.py +3617 -0
  288. fontTools/unicodedata/__init__.py +302 -0
  289. fontTools/varLib/__init__.py +1517 -0
  290. fontTools/varLib/__main__.py +6 -0
  291. fontTools/varLib/avar.py +260 -0
  292. fontTools/varLib/avarPlanner.py +1004 -0
  293. fontTools/varLib/builder.py +215 -0
  294. fontTools/varLib/cff.py +631 -0
  295. fontTools/varLib/errors.py +219 -0
  296. fontTools/varLib/featureVars.py +695 -0
  297. fontTools/varLib/hvar.py +113 -0
  298. fontTools/varLib/instancer/__init__.py +1946 -0
  299. fontTools/varLib/instancer/__main__.py +5 -0
  300. fontTools/varLib/instancer/featureVars.py +190 -0
  301. fontTools/varLib/instancer/names.py +388 -0
  302. fontTools/varLib/instancer/solver.py +309 -0
  303. fontTools/varLib/interpolatable.py +1209 -0
  304. fontTools/varLib/interpolatableHelpers.py +396 -0
  305. fontTools/varLib/interpolatablePlot.py +1269 -0
  306. fontTools/varLib/interpolatableTestContourOrder.py +82 -0
  307. fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
  308. fontTools/varLib/interpolate_layout.py +124 -0
  309. fontTools/varLib/iup.c +19830 -0
  310. fontTools/varLib/iup.cpython-312-aarch64-linux-gnu.so +0 -0
  311. fontTools/varLib/iup.py +490 -0
  312. fontTools/varLib/merger.py +1717 -0
  313. fontTools/varLib/models.py +642 -0
  314. fontTools/varLib/multiVarStore.py +253 -0
  315. fontTools/varLib/mutator.py +518 -0
  316. fontTools/varLib/mvar.py +40 -0
  317. fontTools/varLib/plot.py +238 -0
  318. fontTools/varLib/stat.py +149 -0
  319. fontTools/varLib/varStore.py +739 -0
  320. fontTools/voltLib/__init__.py +5 -0
  321. fontTools/voltLib/__main__.py +206 -0
  322. fontTools/voltLib/ast.py +452 -0
  323. fontTools/voltLib/error.py +12 -0
  324. fontTools/voltLib/lexer.py +99 -0
  325. fontTools/voltLib/parser.py +664 -0
  326. fontTools/voltLib/voltToFea.py +911 -0
  327. fonttools-4.58.3.data/data/share/man/man1/ttx.1 +225 -0
  328. fonttools-4.58.3.dist-info/METADATA +2133 -0
  329. fonttools-4.58.3.dist-info/RECORD +334 -0
  330. fonttools-4.58.3.dist-info/WHEEL +7 -0
  331. fonttools-4.58.3.dist-info/entry_points.txt +5 -0
  332. fonttools-4.58.3.dist-info/licenses/LICENSE +21 -0
  333. fonttools-4.58.3.dist-info/licenses/LICENSE.external +359 -0
  334. fonttools-4.58.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1496 @@
1
+ """psCharStrings.py -- module implementing various kinds of CharStrings:
2
+ CFF dictionary data and Type1/Type2 CharStrings.
3
+ """
4
+
5
+ from fontTools.misc.fixedTools import (
6
+ fixedToFloat,
7
+ floatToFixed,
8
+ floatToFixedToStr,
9
+ strToFixedToFloat,
10
+ )
11
+ from fontTools.misc.textTools import bytechr, byteord, bytesjoin, strjoin
12
+ from fontTools.pens.boundsPen import BoundsPen
13
+ import struct
14
+ import logging
15
+
16
+
17
+ log = logging.getLogger(__name__)
18
+
19
+
20
+ def read_operator(self, b0, data, index):
21
+ if b0 == 12:
22
+ op = (b0, byteord(data[index]))
23
+ index = index + 1
24
+ else:
25
+ op = b0
26
+ try:
27
+ operator = self.operators[op]
28
+ except KeyError:
29
+ return None, index
30
+ value = self.handle_operator(operator)
31
+ return value, index
32
+
33
+
34
+ def read_byte(self, b0, data, index):
35
+ return b0 - 139, index
36
+
37
+
38
+ def read_smallInt1(self, b0, data, index):
39
+ b1 = byteord(data[index])
40
+ return (b0 - 247) * 256 + b1 + 108, index + 1
41
+
42
+
43
+ def read_smallInt2(self, b0, data, index):
44
+ b1 = byteord(data[index])
45
+ return -(b0 - 251) * 256 - b1 - 108, index + 1
46
+
47
+
48
+ def read_shortInt(self, b0, data, index):
49
+ (value,) = struct.unpack(">h", data[index : index + 2])
50
+ return value, index + 2
51
+
52
+
53
+ def read_longInt(self, b0, data, index):
54
+ (value,) = struct.unpack(">l", data[index : index + 4])
55
+ return value, index + 4
56
+
57
+
58
+ def read_fixed1616(self, b0, data, index):
59
+ (value,) = struct.unpack(">l", data[index : index + 4])
60
+ return fixedToFloat(value, precisionBits=16), index + 4
61
+
62
+
63
+ def read_reserved(self, b0, data, index):
64
+ assert NotImplementedError
65
+ return NotImplemented, index
66
+
67
+
68
+ def read_realNumber(self, b0, data, index):
69
+ number = ""
70
+ while True:
71
+ b = byteord(data[index])
72
+ index = index + 1
73
+ nibble0 = (b & 0xF0) >> 4
74
+ nibble1 = b & 0x0F
75
+ if nibble0 == 0xF:
76
+ break
77
+ number = number + realNibbles[nibble0]
78
+ if nibble1 == 0xF:
79
+ break
80
+ number = number + realNibbles[nibble1]
81
+ return float(number), index
82
+
83
+
84
+ t1OperandEncoding = [None] * 256
85
+ t1OperandEncoding[0:32] = (32) * [read_operator]
86
+ t1OperandEncoding[32:247] = (247 - 32) * [read_byte]
87
+ t1OperandEncoding[247:251] = (251 - 247) * [read_smallInt1]
88
+ t1OperandEncoding[251:255] = (255 - 251) * [read_smallInt2]
89
+ t1OperandEncoding[255] = read_longInt
90
+ assert len(t1OperandEncoding) == 256
91
+
92
+ t2OperandEncoding = t1OperandEncoding[:]
93
+ t2OperandEncoding[28] = read_shortInt
94
+ t2OperandEncoding[255] = read_fixed1616
95
+
96
+ cffDictOperandEncoding = t2OperandEncoding[:]
97
+ cffDictOperandEncoding[29] = read_longInt
98
+ cffDictOperandEncoding[30] = read_realNumber
99
+ cffDictOperandEncoding[255] = read_reserved
100
+
101
+
102
+ realNibbles = [
103
+ "0",
104
+ "1",
105
+ "2",
106
+ "3",
107
+ "4",
108
+ "5",
109
+ "6",
110
+ "7",
111
+ "8",
112
+ "9",
113
+ ".",
114
+ "E",
115
+ "E-",
116
+ None,
117
+ "-",
118
+ ]
119
+ realNibblesDict = {v: i for i, v in enumerate(realNibbles)}
120
+
121
+ maxOpStack = 193
122
+
123
+
124
+ def buildOperatorDict(operatorList):
125
+ oper = {}
126
+ opc = {}
127
+ for item in operatorList:
128
+ if len(item) == 2:
129
+ oper[item[0]] = item[1]
130
+ else:
131
+ oper[item[0]] = item[1:]
132
+ if isinstance(item[0], tuple):
133
+ opc[item[1]] = item[0]
134
+ else:
135
+ opc[item[1]] = (item[0],)
136
+ return oper, opc
137
+
138
+
139
+ t2Operators = [
140
+ # opcode name
141
+ (1, "hstem"),
142
+ (3, "vstem"),
143
+ (4, "vmoveto"),
144
+ (5, "rlineto"),
145
+ (6, "hlineto"),
146
+ (7, "vlineto"),
147
+ (8, "rrcurveto"),
148
+ (10, "callsubr"),
149
+ (11, "return"),
150
+ (14, "endchar"),
151
+ (15, "vsindex"),
152
+ (16, "blend"),
153
+ (18, "hstemhm"),
154
+ (19, "hintmask"),
155
+ (20, "cntrmask"),
156
+ (21, "rmoveto"),
157
+ (22, "hmoveto"),
158
+ (23, "vstemhm"),
159
+ (24, "rcurveline"),
160
+ (25, "rlinecurve"),
161
+ (26, "vvcurveto"),
162
+ (27, "hhcurveto"),
163
+ # (28, 'shortint'), # not really an operator
164
+ (29, "callgsubr"),
165
+ (30, "vhcurveto"),
166
+ (31, "hvcurveto"),
167
+ ((12, 0), "ignore"), # dotsection. Yes, there a few very early OTF/CFF
168
+ # fonts with this deprecated operator. Just ignore it.
169
+ ((12, 3), "and"),
170
+ ((12, 4), "or"),
171
+ ((12, 5), "not"),
172
+ ((12, 8), "store"),
173
+ ((12, 9), "abs"),
174
+ ((12, 10), "add"),
175
+ ((12, 11), "sub"),
176
+ ((12, 12), "div"),
177
+ ((12, 13), "load"),
178
+ ((12, 14), "neg"),
179
+ ((12, 15), "eq"),
180
+ ((12, 18), "drop"),
181
+ ((12, 20), "put"),
182
+ ((12, 21), "get"),
183
+ ((12, 22), "ifelse"),
184
+ ((12, 23), "random"),
185
+ ((12, 24), "mul"),
186
+ ((12, 26), "sqrt"),
187
+ ((12, 27), "dup"),
188
+ ((12, 28), "exch"),
189
+ ((12, 29), "index"),
190
+ ((12, 30), "roll"),
191
+ ((12, 34), "hflex"),
192
+ ((12, 35), "flex"),
193
+ ((12, 36), "hflex1"),
194
+ ((12, 37), "flex1"),
195
+ ]
196
+
197
+
198
+ def getIntEncoder(format):
199
+ if format == "cff":
200
+ twoByteOp = bytechr(28)
201
+ fourByteOp = bytechr(29)
202
+ elif format == "t1":
203
+ twoByteOp = None
204
+ fourByteOp = bytechr(255)
205
+ else:
206
+ assert format == "t2"
207
+ twoByteOp = bytechr(28)
208
+ fourByteOp = None
209
+
210
+ def encodeInt(
211
+ value,
212
+ fourByteOp=fourByteOp,
213
+ bytechr=bytechr,
214
+ pack=struct.pack,
215
+ unpack=struct.unpack,
216
+ twoByteOp=twoByteOp,
217
+ ):
218
+ if -107 <= value <= 107:
219
+ code = bytechr(value + 139)
220
+ elif 108 <= value <= 1131:
221
+ value = value - 108
222
+ code = bytechr((value >> 8) + 247) + bytechr(value & 0xFF)
223
+ elif -1131 <= value <= -108:
224
+ value = -value - 108
225
+ code = bytechr((value >> 8) + 251) + bytechr(value & 0xFF)
226
+ elif twoByteOp is not None and -32768 <= value <= 32767:
227
+ code = twoByteOp + pack(">h", value)
228
+ elif fourByteOp is None:
229
+ # Backwards compatible hack: due to a previous bug in FontTools,
230
+ # 16.16 fixed numbers were written out as 4-byte ints. When
231
+ # these numbers were small, they were wrongly written back as
232
+ # small ints instead of 4-byte ints, breaking round-tripping.
233
+ # This here workaround doesn't do it any better, since we can't
234
+ # distinguish anymore between small ints that were supposed to
235
+ # be small fixed numbers and small ints that were just small
236
+ # ints. Hence the warning.
237
+ log.warning(
238
+ "4-byte T2 number got passed to the "
239
+ "IntType handler. This should happen only when reading in "
240
+ "old XML files.\n"
241
+ )
242
+ code = bytechr(255) + pack(">l", value)
243
+ else:
244
+ code = fourByteOp + pack(">l", value)
245
+ return code
246
+
247
+ return encodeInt
248
+
249
+
250
+ encodeIntCFF = getIntEncoder("cff")
251
+ encodeIntT1 = getIntEncoder("t1")
252
+ encodeIntT2 = getIntEncoder("t2")
253
+
254
+
255
+ def encodeFixed(f, pack=struct.pack):
256
+ """For T2 only"""
257
+ value = floatToFixed(f, precisionBits=16)
258
+ if value & 0xFFFF == 0: # check if the fractional part is zero
259
+ return encodeIntT2(value >> 16) # encode only the integer part
260
+ else:
261
+ return b"\xff" + pack(">l", value) # encode the entire fixed point value
262
+
263
+
264
+ realZeroBytes = bytechr(30) + bytechr(0xF)
265
+
266
+
267
+ def encodeFloat(f):
268
+ # For CFF only, used in cffLib
269
+ if f == 0.0: # 0.0 == +0.0 == -0.0
270
+ return realZeroBytes
271
+ # Note: 14 decimal digits seems to be the limitation for CFF real numbers
272
+ # in macOS. However, we use 8 here to match the implementation of AFDKO.
273
+ s = "%.8G" % f
274
+ if s[:2] == "0.":
275
+ s = s[1:]
276
+ elif s[:3] == "-0.":
277
+ s = "-" + s[2:]
278
+ elif s.endswith("000"):
279
+ significantDigits = s.rstrip("0")
280
+ s = "%sE%d" % (significantDigits, len(s) - len(significantDigits))
281
+ else:
282
+ dotIndex = s.find(".")
283
+ eIndex = s.find("E")
284
+ if dotIndex != -1 and eIndex != -1:
285
+ integerPart = s[:dotIndex]
286
+ fractionalPart = s[dotIndex + 1 : eIndex]
287
+ exponent = int(s[eIndex + 1 :])
288
+ newExponent = exponent - len(fractionalPart)
289
+ if newExponent == 1:
290
+ s = "%s%s0" % (integerPart, fractionalPart)
291
+ else:
292
+ s = "%s%sE%d" % (integerPart, fractionalPart, newExponent)
293
+ if s.startswith((".0", "-.0")):
294
+ sign, s = s.split(".", 1)
295
+ s = "%s%sE-%d" % (sign, s.lstrip("0"), len(s))
296
+ nibbles = []
297
+ while s:
298
+ c = s[0]
299
+ s = s[1:]
300
+ if c == "E":
301
+ c2 = s[:1]
302
+ if c2 == "-":
303
+ s = s[1:]
304
+ c = "E-"
305
+ elif c2 == "+":
306
+ s = s[1:]
307
+ if s.startswith("0"):
308
+ s = s[1:]
309
+ nibbles.append(realNibblesDict[c])
310
+ nibbles.append(0xF)
311
+ if len(nibbles) % 2:
312
+ nibbles.append(0xF)
313
+ d = bytechr(30)
314
+ for i in range(0, len(nibbles), 2):
315
+ d = d + bytechr(nibbles[i] << 4 | nibbles[i + 1])
316
+ return d
317
+
318
+
319
+ class CharStringCompileError(Exception):
320
+ pass
321
+
322
+
323
+ class SimpleT2Decompiler(object):
324
+ def __init__(self, localSubrs, globalSubrs, private=None, blender=None):
325
+ self.localSubrs = localSubrs
326
+ self.localBias = calcSubrBias(localSubrs)
327
+ self.globalSubrs = globalSubrs
328
+ self.globalBias = calcSubrBias(globalSubrs)
329
+ self.private = private
330
+ self.blender = blender
331
+ self.reset()
332
+
333
+ def reset(self):
334
+ self.callingStack = []
335
+ self.operandStack = []
336
+ self.hintCount = 0
337
+ self.hintMaskBytes = 0
338
+ self.numRegions = 0
339
+ self.vsIndex = 0
340
+
341
+ def execute(self, charString):
342
+ self.callingStack.append(charString)
343
+ needsDecompilation = charString.needsDecompilation()
344
+ if needsDecompilation:
345
+ program = []
346
+ pushToProgram = program.append
347
+ else:
348
+ pushToProgram = lambda x: None
349
+ pushToStack = self.operandStack.append
350
+ index = 0
351
+ while True:
352
+ token, isOperator, index = charString.getToken(index)
353
+ if token is None:
354
+ break # we're done!
355
+ pushToProgram(token)
356
+ if isOperator:
357
+ handlerName = "op_" + token
358
+ handler = getattr(self, handlerName, None)
359
+ if handler is not None:
360
+ rv = handler(index)
361
+ if rv:
362
+ hintMaskBytes, index = rv
363
+ pushToProgram(hintMaskBytes)
364
+ else:
365
+ self.popall()
366
+ else:
367
+ pushToStack(token)
368
+ if needsDecompilation:
369
+ charString.setProgram(program)
370
+ del self.callingStack[-1]
371
+
372
+ def pop(self):
373
+ value = self.operandStack[-1]
374
+ del self.operandStack[-1]
375
+ return value
376
+
377
+ def popall(self):
378
+ stack = self.operandStack[:]
379
+ self.operandStack[:] = []
380
+ return stack
381
+
382
+ def push(self, value):
383
+ self.operandStack.append(value)
384
+
385
+ def op_return(self, index):
386
+ if self.operandStack:
387
+ pass
388
+
389
+ def op_endchar(self, index):
390
+ pass
391
+
392
+ def op_ignore(self, index):
393
+ pass
394
+
395
+ def op_callsubr(self, index):
396
+ subrIndex = self.pop()
397
+ subr = self.localSubrs[subrIndex + self.localBias]
398
+ self.execute(subr)
399
+
400
+ def op_callgsubr(self, index):
401
+ subrIndex = self.pop()
402
+ subr = self.globalSubrs[subrIndex + self.globalBias]
403
+ self.execute(subr)
404
+
405
+ def op_hstem(self, index):
406
+ self.countHints()
407
+
408
+ def op_vstem(self, index):
409
+ self.countHints()
410
+
411
+ def op_hstemhm(self, index):
412
+ self.countHints()
413
+
414
+ def op_vstemhm(self, index):
415
+ self.countHints()
416
+
417
+ def op_hintmask(self, index):
418
+ if not self.hintMaskBytes:
419
+ self.countHints()
420
+ self.hintMaskBytes = (self.hintCount + 7) // 8
421
+ hintMaskBytes, index = self.callingStack[-1].getBytes(index, self.hintMaskBytes)
422
+ return hintMaskBytes, index
423
+
424
+ op_cntrmask = op_hintmask
425
+
426
+ def countHints(self):
427
+ args = self.popall()
428
+ self.hintCount = self.hintCount + len(args) // 2
429
+
430
+ # misc
431
+ def op_and(self, index):
432
+ raise NotImplementedError
433
+
434
+ def op_or(self, index):
435
+ raise NotImplementedError
436
+
437
+ def op_not(self, index):
438
+ raise NotImplementedError
439
+
440
+ def op_store(self, index):
441
+ raise NotImplementedError
442
+
443
+ def op_abs(self, index):
444
+ raise NotImplementedError
445
+
446
+ def op_add(self, index):
447
+ raise NotImplementedError
448
+
449
+ def op_sub(self, index):
450
+ raise NotImplementedError
451
+
452
+ def op_div(self, index):
453
+ raise NotImplementedError
454
+
455
+ def op_load(self, index):
456
+ raise NotImplementedError
457
+
458
+ def op_neg(self, index):
459
+ raise NotImplementedError
460
+
461
+ def op_eq(self, index):
462
+ raise NotImplementedError
463
+
464
+ def op_drop(self, index):
465
+ raise NotImplementedError
466
+
467
+ def op_put(self, index):
468
+ raise NotImplementedError
469
+
470
+ def op_get(self, index):
471
+ raise NotImplementedError
472
+
473
+ def op_ifelse(self, index):
474
+ raise NotImplementedError
475
+
476
+ def op_random(self, index):
477
+ raise NotImplementedError
478
+
479
+ def op_mul(self, index):
480
+ raise NotImplementedError
481
+
482
+ def op_sqrt(self, index):
483
+ raise NotImplementedError
484
+
485
+ def op_dup(self, index):
486
+ raise NotImplementedError
487
+
488
+ def op_exch(self, index):
489
+ raise NotImplementedError
490
+
491
+ def op_index(self, index):
492
+ raise NotImplementedError
493
+
494
+ def op_roll(self, index):
495
+ raise NotImplementedError
496
+
497
+ def op_blend(self, index):
498
+ if self.numRegions == 0:
499
+ self.numRegions = self.private.getNumRegions()
500
+ numBlends = self.pop()
501
+ numOps = numBlends * (self.numRegions + 1)
502
+ if self.blender is None:
503
+ del self.operandStack[
504
+ -(numOps - numBlends) :
505
+ ] # Leave the default operands on the stack.
506
+ else:
507
+ argi = len(self.operandStack) - numOps
508
+ end_args = tuplei = argi + numBlends
509
+ while argi < end_args:
510
+ next_ti = tuplei + self.numRegions
511
+ deltas = self.operandStack[tuplei:next_ti]
512
+ delta = self.blender(self.vsIndex, deltas)
513
+ self.operandStack[argi] += delta
514
+ tuplei = next_ti
515
+ argi += 1
516
+ self.operandStack[end_args:] = []
517
+
518
+ def op_vsindex(self, index):
519
+ vi = self.pop()
520
+ self.vsIndex = vi
521
+ self.numRegions = self.private.getNumRegions(vi)
522
+
523
+
524
+ t1Operators = [
525
+ # opcode name
526
+ (1, "hstem"),
527
+ (3, "vstem"),
528
+ (4, "vmoveto"),
529
+ (5, "rlineto"),
530
+ (6, "hlineto"),
531
+ (7, "vlineto"),
532
+ (8, "rrcurveto"),
533
+ (9, "closepath"),
534
+ (10, "callsubr"),
535
+ (11, "return"),
536
+ (13, "hsbw"),
537
+ (14, "endchar"),
538
+ (21, "rmoveto"),
539
+ (22, "hmoveto"),
540
+ (30, "vhcurveto"),
541
+ (31, "hvcurveto"),
542
+ ((12, 0), "dotsection"),
543
+ ((12, 1), "vstem3"),
544
+ ((12, 2), "hstem3"),
545
+ ((12, 6), "seac"),
546
+ ((12, 7), "sbw"),
547
+ ((12, 12), "div"),
548
+ ((12, 16), "callothersubr"),
549
+ ((12, 17), "pop"),
550
+ ((12, 33), "setcurrentpoint"),
551
+ ]
552
+
553
+
554
+ class T2WidthExtractor(SimpleT2Decompiler):
555
+ def __init__(
556
+ self,
557
+ localSubrs,
558
+ globalSubrs,
559
+ nominalWidthX,
560
+ defaultWidthX,
561
+ private=None,
562
+ blender=None,
563
+ ):
564
+ SimpleT2Decompiler.__init__(self, localSubrs, globalSubrs, private, blender)
565
+ self.nominalWidthX = nominalWidthX
566
+ self.defaultWidthX = defaultWidthX
567
+
568
+ def reset(self):
569
+ SimpleT2Decompiler.reset(self)
570
+ self.gotWidth = 0
571
+ self.width = 0
572
+
573
+ def popallWidth(self, evenOdd=0):
574
+ args = self.popall()
575
+ if not self.gotWidth:
576
+ if evenOdd ^ (len(args) % 2):
577
+ # For CFF2 charstrings, this should never happen
578
+ assert (
579
+ self.defaultWidthX is not None
580
+ ), "CFF2 CharStrings must not have an initial width value"
581
+ self.width = self.nominalWidthX + args[0]
582
+ args = args[1:]
583
+ else:
584
+ self.width = self.defaultWidthX
585
+ self.gotWidth = 1
586
+ return args
587
+
588
+ def countHints(self):
589
+ args = self.popallWidth()
590
+ self.hintCount = self.hintCount + len(args) // 2
591
+
592
+ def op_rmoveto(self, index):
593
+ self.popallWidth()
594
+
595
+ def op_hmoveto(self, index):
596
+ self.popallWidth(1)
597
+
598
+ def op_vmoveto(self, index):
599
+ self.popallWidth(1)
600
+
601
+ def op_endchar(self, index):
602
+ self.popallWidth()
603
+
604
+
605
+ class T2OutlineExtractor(T2WidthExtractor):
606
+ def __init__(
607
+ self,
608
+ pen,
609
+ localSubrs,
610
+ globalSubrs,
611
+ nominalWidthX,
612
+ defaultWidthX,
613
+ private=None,
614
+ blender=None,
615
+ ):
616
+ T2WidthExtractor.__init__(
617
+ self,
618
+ localSubrs,
619
+ globalSubrs,
620
+ nominalWidthX,
621
+ defaultWidthX,
622
+ private,
623
+ blender,
624
+ )
625
+ self.pen = pen
626
+ self.subrLevel = 0
627
+
628
+ def reset(self):
629
+ T2WidthExtractor.reset(self)
630
+ self.currentPoint = (0, 0)
631
+ self.sawMoveTo = 0
632
+ self.subrLevel = 0
633
+
634
+ def execute(self, charString):
635
+ self.subrLevel += 1
636
+ super().execute(charString)
637
+ self.subrLevel -= 1
638
+ if self.subrLevel == 0:
639
+ self.endPath()
640
+
641
+ def _nextPoint(self, point):
642
+ x, y = self.currentPoint
643
+ point = x + point[0], y + point[1]
644
+ self.currentPoint = point
645
+ return point
646
+
647
+ def rMoveTo(self, point):
648
+ self.pen.moveTo(self._nextPoint(point))
649
+ self.sawMoveTo = 1
650
+
651
+ def rLineTo(self, point):
652
+ if not self.sawMoveTo:
653
+ self.rMoveTo((0, 0))
654
+ self.pen.lineTo(self._nextPoint(point))
655
+
656
+ def rCurveTo(self, pt1, pt2, pt3):
657
+ if not self.sawMoveTo:
658
+ self.rMoveTo((0, 0))
659
+ nextPoint = self._nextPoint
660
+ self.pen.curveTo(nextPoint(pt1), nextPoint(pt2), nextPoint(pt3))
661
+
662
+ def closePath(self):
663
+ if self.sawMoveTo:
664
+ self.pen.closePath()
665
+ self.sawMoveTo = 0
666
+
667
+ def endPath(self):
668
+ # In T2 there are no open paths, so always do a closePath when
669
+ # finishing a sub path. We avoid spurious calls to closePath()
670
+ # because its a real T1 op we're emulating in T2 whereas
671
+ # endPath() is just a means to that emulation
672
+ if self.sawMoveTo:
673
+ self.closePath()
674
+
675
+ #
676
+ # hint operators
677
+ #
678
+ # def op_hstem(self, index):
679
+ # self.countHints()
680
+ # def op_vstem(self, index):
681
+ # self.countHints()
682
+ # def op_hstemhm(self, index):
683
+ # self.countHints()
684
+ # def op_vstemhm(self, index):
685
+ # self.countHints()
686
+ # def op_hintmask(self, index):
687
+ # self.countHints()
688
+ # def op_cntrmask(self, index):
689
+ # self.countHints()
690
+
691
+ #
692
+ # path constructors, moveto
693
+ #
694
+ def op_rmoveto(self, index):
695
+ self.endPath()
696
+ self.rMoveTo(self.popallWidth())
697
+
698
+ def op_hmoveto(self, index):
699
+ self.endPath()
700
+ self.rMoveTo((self.popallWidth(1)[0], 0))
701
+
702
+ def op_vmoveto(self, index):
703
+ self.endPath()
704
+ self.rMoveTo((0, self.popallWidth(1)[0]))
705
+
706
+ def op_endchar(self, index):
707
+ self.endPath()
708
+ args = self.popallWidth()
709
+ if args:
710
+ from fontTools.encodings.StandardEncoding import StandardEncoding
711
+
712
+ # endchar can do seac accent bulding; The T2 spec says it's deprecated,
713
+ # but recent software that shall remain nameless does output it.
714
+ adx, ady, bchar, achar = args
715
+ baseGlyph = StandardEncoding[bchar]
716
+ self.pen.addComponent(baseGlyph, (1, 0, 0, 1, 0, 0))
717
+ accentGlyph = StandardEncoding[achar]
718
+ self.pen.addComponent(accentGlyph, (1, 0, 0, 1, adx, ady))
719
+
720
+ #
721
+ # path constructors, lines
722
+ #
723
+ def op_rlineto(self, index):
724
+ args = self.popall()
725
+ for i in range(0, len(args), 2):
726
+ point = args[i : i + 2]
727
+ self.rLineTo(point)
728
+
729
+ def op_hlineto(self, index):
730
+ self.alternatingLineto(1)
731
+
732
+ def op_vlineto(self, index):
733
+ self.alternatingLineto(0)
734
+
735
+ #
736
+ # path constructors, curves
737
+ #
738
+ def op_rrcurveto(self, index):
739
+ """{dxa dya dxb dyb dxc dyc}+ rrcurveto"""
740
+ args = self.popall()
741
+ for i in range(0, len(args), 6):
742
+ (
743
+ dxa,
744
+ dya,
745
+ dxb,
746
+ dyb,
747
+ dxc,
748
+ dyc,
749
+ ) = args[i : i + 6]
750
+ self.rCurveTo((dxa, dya), (dxb, dyb), (dxc, dyc))
751
+
752
+ def op_rcurveline(self, index):
753
+ """{dxa dya dxb dyb dxc dyc}+ dxd dyd rcurveline"""
754
+ args = self.popall()
755
+ for i in range(0, len(args) - 2, 6):
756
+ dxb, dyb, dxc, dyc, dxd, dyd = args[i : i + 6]
757
+ self.rCurveTo((dxb, dyb), (dxc, dyc), (dxd, dyd))
758
+ self.rLineTo(args[-2:])
759
+
760
+ def op_rlinecurve(self, index):
761
+ """{dxa dya}+ dxb dyb dxc dyc dxd dyd rlinecurve"""
762
+ args = self.popall()
763
+ lineArgs = args[:-6]
764
+ for i in range(0, len(lineArgs), 2):
765
+ self.rLineTo(lineArgs[i : i + 2])
766
+ dxb, dyb, dxc, dyc, dxd, dyd = args[-6:]
767
+ self.rCurveTo((dxb, dyb), (dxc, dyc), (dxd, dyd))
768
+
769
+ def op_vvcurveto(self, index):
770
+ "dx1? {dya dxb dyb dyc}+ vvcurveto"
771
+ args = self.popall()
772
+ if len(args) % 2:
773
+ dx1 = args[0]
774
+ args = args[1:]
775
+ else:
776
+ dx1 = 0
777
+ for i in range(0, len(args), 4):
778
+ dya, dxb, dyb, dyc = args[i : i + 4]
779
+ self.rCurveTo((dx1, dya), (dxb, dyb), (0, dyc))
780
+ dx1 = 0
781
+
782
+ def op_hhcurveto(self, index):
783
+ """dy1? {dxa dxb dyb dxc}+ hhcurveto"""
784
+ args = self.popall()
785
+ if len(args) % 2:
786
+ dy1 = args[0]
787
+ args = args[1:]
788
+ else:
789
+ dy1 = 0
790
+ for i in range(0, len(args), 4):
791
+ dxa, dxb, dyb, dxc = args[i : i + 4]
792
+ self.rCurveTo((dxa, dy1), (dxb, dyb), (dxc, 0))
793
+ dy1 = 0
794
+
795
+ def op_vhcurveto(self, index):
796
+ """dy1 dx2 dy2 dx3 {dxa dxb dyb dyc dyd dxe dye dxf}* dyf? vhcurveto (30)
797
+ {dya dxb dyb dxc dxd dxe dye dyf}+ dxf? vhcurveto
798
+ """
799
+ args = self.popall()
800
+ while args:
801
+ args = self.vcurveto(args)
802
+ if args:
803
+ args = self.hcurveto(args)
804
+
805
+ def op_hvcurveto(self, index):
806
+ """dx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf?
807
+ {dxa dxb dyb dyc dyd dxe dye dxf}+ dyf?
808
+ """
809
+ args = self.popall()
810
+ while args:
811
+ args = self.hcurveto(args)
812
+ if args:
813
+ args = self.vcurveto(args)
814
+
815
+ #
816
+ # path constructors, flex
817
+ #
818
+ def op_hflex(self, index):
819
+ dx1, dx2, dy2, dx3, dx4, dx5, dx6 = self.popall()
820
+ dy1 = dy3 = dy4 = dy6 = 0
821
+ dy5 = -dy2
822
+ self.rCurveTo((dx1, dy1), (dx2, dy2), (dx3, dy3))
823
+ self.rCurveTo((dx4, dy4), (dx5, dy5), (dx6, dy6))
824
+
825
+ def op_flex(self, index):
826
+ dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4, dx5, dy5, dx6, dy6, fd = self.popall()
827
+ self.rCurveTo((dx1, dy1), (dx2, dy2), (dx3, dy3))
828
+ self.rCurveTo((dx4, dy4), (dx5, dy5), (dx6, dy6))
829
+
830
+ def op_hflex1(self, index):
831
+ dx1, dy1, dx2, dy2, dx3, dx4, dx5, dy5, dx6 = self.popall()
832
+ dy3 = dy4 = 0
833
+ dy6 = -(dy1 + dy2 + dy3 + dy4 + dy5)
834
+
835
+ self.rCurveTo((dx1, dy1), (dx2, dy2), (dx3, dy3))
836
+ self.rCurveTo((dx4, dy4), (dx5, dy5), (dx6, dy6))
837
+
838
+ def op_flex1(self, index):
839
+ dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4, dx5, dy5, d6 = self.popall()
840
+ dx = dx1 + dx2 + dx3 + dx4 + dx5
841
+ dy = dy1 + dy2 + dy3 + dy4 + dy5
842
+ if abs(dx) > abs(dy):
843
+ dx6 = d6
844
+ dy6 = -dy
845
+ else:
846
+ dx6 = -dx
847
+ dy6 = d6
848
+ self.rCurveTo((dx1, dy1), (dx2, dy2), (dx3, dy3))
849
+ self.rCurveTo((dx4, dy4), (dx5, dy5), (dx6, dy6))
850
+
851
+ # misc
852
+ def op_and(self, index):
853
+ raise NotImplementedError
854
+
855
+ def op_or(self, index):
856
+ raise NotImplementedError
857
+
858
+ def op_not(self, index):
859
+ raise NotImplementedError
860
+
861
+ def op_store(self, index):
862
+ raise NotImplementedError
863
+
864
+ def op_abs(self, index):
865
+ raise NotImplementedError
866
+
867
+ def op_add(self, index):
868
+ raise NotImplementedError
869
+
870
+ def op_sub(self, index):
871
+ raise NotImplementedError
872
+
873
+ def op_div(self, index):
874
+ num2 = self.pop()
875
+ num1 = self.pop()
876
+ d1 = num1 // num2
877
+ d2 = num1 / num2
878
+ if d1 == d2:
879
+ self.push(d1)
880
+ else:
881
+ self.push(d2)
882
+
883
+ def op_load(self, index):
884
+ raise NotImplementedError
885
+
886
+ def op_neg(self, index):
887
+ raise NotImplementedError
888
+
889
+ def op_eq(self, index):
890
+ raise NotImplementedError
891
+
892
+ def op_drop(self, index):
893
+ raise NotImplementedError
894
+
895
+ def op_put(self, index):
896
+ raise NotImplementedError
897
+
898
+ def op_get(self, index):
899
+ raise NotImplementedError
900
+
901
+ def op_ifelse(self, index):
902
+ raise NotImplementedError
903
+
904
+ def op_random(self, index):
905
+ raise NotImplementedError
906
+
907
+ def op_mul(self, index):
908
+ raise NotImplementedError
909
+
910
+ def op_sqrt(self, index):
911
+ raise NotImplementedError
912
+
913
+ def op_dup(self, index):
914
+ raise NotImplementedError
915
+
916
+ def op_exch(self, index):
917
+ raise NotImplementedError
918
+
919
+ def op_index(self, index):
920
+ raise NotImplementedError
921
+
922
+ def op_roll(self, index):
923
+ raise NotImplementedError
924
+
925
+ #
926
+ # miscellaneous helpers
927
+ #
928
+ def alternatingLineto(self, isHorizontal):
929
+ args = self.popall()
930
+ for arg in args:
931
+ if isHorizontal:
932
+ point = (arg, 0)
933
+ else:
934
+ point = (0, arg)
935
+ self.rLineTo(point)
936
+ isHorizontal = not isHorizontal
937
+
938
+ def vcurveto(self, args):
939
+ dya, dxb, dyb, dxc = args[:4]
940
+ args = args[4:]
941
+ if len(args) == 1:
942
+ dyc = args[0]
943
+ args = []
944
+ else:
945
+ dyc = 0
946
+ self.rCurveTo((0, dya), (dxb, dyb), (dxc, dyc))
947
+ return args
948
+
949
+ def hcurveto(self, args):
950
+ dxa, dxb, dyb, dyc = args[:4]
951
+ args = args[4:]
952
+ if len(args) == 1:
953
+ dxc = args[0]
954
+ args = []
955
+ else:
956
+ dxc = 0
957
+ self.rCurveTo((dxa, 0), (dxb, dyb), (dxc, dyc))
958
+ return args
959
+
960
+
961
+ class T1OutlineExtractor(T2OutlineExtractor):
962
+ def __init__(self, pen, subrs):
963
+ self.pen = pen
964
+ self.subrs = subrs
965
+ self.reset()
966
+
967
+ def reset(self):
968
+ self.flexing = 0
969
+ self.width = 0
970
+ self.sbx = 0
971
+ T2OutlineExtractor.reset(self)
972
+
973
+ def endPath(self):
974
+ if self.sawMoveTo:
975
+ self.pen.endPath()
976
+ self.sawMoveTo = 0
977
+
978
+ def popallWidth(self, evenOdd=0):
979
+ return self.popall()
980
+
981
+ def exch(self):
982
+ stack = self.operandStack
983
+ stack[-1], stack[-2] = stack[-2], stack[-1]
984
+
985
+ #
986
+ # path constructors
987
+ #
988
+ def op_rmoveto(self, index):
989
+ if self.flexing:
990
+ return
991
+ self.endPath()
992
+ self.rMoveTo(self.popall())
993
+
994
+ def op_hmoveto(self, index):
995
+ if self.flexing:
996
+ # We must add a parameter to the stack if we are flexing
997
+ self.push(0)
998
+ return
999
+ self.endPath()
1000
+ self.rMoveTo((self.popall()[0], 0))
1001
+
1002
+ def op_vmoveto(self, index):
1003
+ if self.flexing:
1004
+ # We must add a parameter to the stack if we are flexing
1005
+ self.push(0)
1006
+ self.exch()
1007
+ return
1008
+ self.endPath()
1009
+ self.rMoveTo((0, self.popall()[0]))
1010
+
1011
+ def op_closepath(self, index):
1012
+ self.closePath()
1013
+
1014
+ def op_setcurrentpoint(self, index):
1015
+ args = self.popall()
1016
+ x, y = args
1017
+ self.currentPoint = x, y
1018
+
1019
+ def op_endchar(self, index):
1020
+ self.endPath()
1021
+
1022
+ def op_hsbw(self, index):
1023
+ sbx, wx = self.popall()
1024
+ self.width = wx
1025
+ self.sbx = sbx
1026
+ self.currentPoint = sbx, self.currentPoint[1]
1027
+
1028
+ def op_sbw(self, index):
1029
+ self.popall() # XXX
1030
+
1031
+ #
1032
+ def op_callsubr(self, index):
1033
+ subrIndex = self.pop()
1034
+ subr = self.subrs[subrIndex]
1035
+ self.execute(subr)
1036
+
1037
+ def op_callothersubr(self, index):
1038
+ subrIndex = self.pop()
1039
+ nArgs = self.pop()
1040
+ # print nArgs, subrIndex, "callothersubr"
1041
+ if subrIndex == 0 and nArgs == 3:
1042
+ self.doFlex()
1043
+ self.flexing = 0
1044
+ elif subrIndex == 1 and nArgs == 0:
1045
+ self.flexing = 1
1046
+ # ignore...
1047
+
1048
+ def op_pop(self, index):
1049
+ pass # ignore...
1050
+
1051
+ def doFlex(self):
1052
+ finaly = self.pop()
1053
+ finalx = self.pop()
1054
+ self.pop() # flex height is unused
1055
+
1056
+ p3y = self.pop()
1057
+ p3x = self.pop()
1058
+ bcp4y = self.pop()
1059
+ bcp4x = self.pop()
1060
+ bcp3y = self.pop()
1061
+ bcp3x = self.pop()
1062
+ p2y = self.pop()
1063
+ p2x = self.pop()
1064
+ bcp2y = self.pop()
1065
+ bcp2x = self.pop()
1066
+ bcp1y = self.pop()
1067
+ bcp1x = self.pop()
1068
+ rpy = self.pop()
1069
+ rpx = self.pop()
1070
+
1071
+ # call rrcurveto
1072
+ self.push(bcp1x + rpx)
1073
+ self.push(bcp1y + rpy)
1074
+ self.push(bcp2x)
1075
+ self.push(bcp2y)
1076
+ self.push(p2x)
1077
+ self.push(p2y)
1078
+ self.op_rrcurveto(None)
1079
+
1080
+ # call rrcurveto
1081
+ self.push(bcp3x)
1082
+ self.push(bcp3y)
1083
+ self.push(bcp4x)
1084
+ self.push(bcp4y)
1085
+ self.push(p3x)
1086
+ self.push(p3y)
1087
+ self.op_rrcurveto(None)
1088
+
1089
+ # Push back final coords so subr 0 can find them
1090
+ self.push(finalx)
1091
+ self.push(finaly)
1092
+
1093
+ def op_dotsection(self, index):
1094
+ self.popall() # XXX
1095
+
1096
+ def op_hstem3(self, index):
1097
+ self.popall() # XXX
1098
+
1099
+ def op_seac(self, index):
1100
+ "asb adx ady bchar achar seac"
1101
+ from fontTools.encodings.StandardEncoding import StandardEncoding
1102
+
1103
+ asb, adx, ady, bchar, achar = self.popall()
1104
+ baseGlyph = StandardEncoding[bchar]
1105
+ self.pen.addComponent(baseGlyph, (1, 0, 0, 1, 0, 0))
1106
+ accentGlyph = StandardEncoding[achar]
1107
+ adx = adx + self.sbx - asb # seac weirdness
1108
+ self.pen.addComponent(accentGlyph, (1, 0, 0, 1, adx, ady))
1109
+
1110
+ def op_vstem3(self, index):
1111
+ self.popall() # XXX
1112
+
1113
+
1114
+ class T2CharString(object):
1115
+ operandEncoding = t2OperandEncoding
1116
+ operators, opcodes = buildOperatorDict(t2Operators)
1117
+ decompilerClass = SimpleT2Decompiler
1118
+ outlineExtractor = T2OutlineExtractor
1119
+
1120
+ def __init__(self, bytecode=None, program=None, private=None, globalSubrs=None):
1121
+ if program is None:
1122
+ program = []
1123
+ self.bytecode = bytecode
1124
+ self.program = program
1125
+ self.private = private
1126
+ self.globalSubrs = globalSubrs if globalSubrs is not None else []
1127
+ self._cur_vsindex = None
1128
+
1129
+ def getNumRegions(self, vsindex=None):
1130
+ pd = self.private
1131
+ assert pd is not None
1132
+ if vsindex is not None:
1133
+ self._cur_vsindex = vsindex
1134
+ elif self._cur_vsindex is None:
1135
+ self._cur_vsindex = pd.vsindex if hasattr(pd, "vsindex") else 0
1136
+ return pd.getNumRegions(self._cur_vsindex)
1137
+
1138
+ def __repr__(self):
1139
+ if self.bytecode is None:
1140
+ return "<%s (source) at %x>" % (self.__class__.__name__, id(self))
1141
+ else:
1142
+ return "<%s (bytecode) at %x>" % (self.__class__.__name__, id(self))
1143
+
1144
+ def getIntEncoder(self):
1145
+ return encodeIntT2
1146
+
1147
+ def getFixedEncoder(self):
1148
+ return encodeFixed
1149
+
1150
+ def decompile(self):
1151
+ if not self.needsDecompilation():
1152
+ return
1153
+ subrs = getattr(self.private, "Subrs", [])
1154
+ decompiler = self.decompilerClass(subrs, self.globalSubrs, self.private)
1155
+ decompiler.execute(self)
1156
+
1157
+ def draw(self, pen, blender=None):
1158
+ subrs = getattr(self.private, "Subrs", [])
1159
+ extractor = self.outlineExtractor(
1160
+ pen,
1161
+ subrs,
1162
+ self.globalSubrs,
1163
+ self.private.nominalWidthX,
1164
+ self.private.defaultWidthX,
1165
+ self.private,
1166
+ blender,
1167
+ )
1168
+ extractor.execute(self)
1169
+ self.width = extractor.width
1170
+
1171
+ def calcBounds(self, glyphSet):
1172
+ boundsPen = BoundsPen(glyphSet)
1173
+ self.draw(boundsPen)
1174
+ return boundsPen.bounds
1175
+
1176
+ def compile(self, isCFF2=False):
1177
+ if self.bytecode is not None:
1178
+ return
1179
+ opcodes = self.opcodes
1180
+ program = self.program
1181
+
1182
+ if isCFF2:
1183
+ # If present, remove return and endchar operators.
1184
+ if program and program[-1] in ("return", "endchar"):
1185
+ program = program[:-1]
1186
+ elif program and not isinstance(program[-1], str):
1187
+ raise CharStringCompileError(
1188
+ "T2CharString or Subr has items on the stack after last operator."
1189
+ )
1190
+
1191
+ bytecode = []
1192
+ encodeInt = self.getIntEncoder()
1193
+ encodeFixed = self.getFixedEncoder()
1194
+ i = 0
1195
+ end = len(program)
1196
+ while i < end:
1197
+ token = program[i]
1198
+ i = i + 1
1199
+ if isinstance(token, str):
1200
+ try:
1201
+ bytecode.extend(bytechr(b) for b in opcodes[token])
1202
+ except KeyError:
1203
+ raise CharStringCompileError("illegal operator: %s" % token)
1204
+ if token in ("hintmask", "cntrmask"):
1205
+ bytecode.append(program[i]) # hint mask
1206
+ i = i + 1
1207
+ elif isinstance(token, int):
1208
+ bytecode.append(encodeInt(token))
1209
+ elif isinstance(token, float):
1210
+ bytecode.append(encodeFixed(token))
1211
+ else:
1212
+ assert 0, "unsupported type: %s" % type(token)
1213
+ try:
1214
+ bytecode = bytesjoin(bytecode)
1215
+ except TypeError:
1216
+ log.error(bytecode)
1217
+ raise
1218
+ self.setBytecode(bytecode)
1219
+
1220
+ def needsDecompilation(self):
1221
+ return self.bytecode is not None
1222
+
1223
+ def setProgram(self, program):
1224
+ self.program = program
1225
+ self.bytecode = None
1226
+
1227
+ def setBytecode(self, bytecode):
1228
+ self.bytecode = bytecode
1229
+ self.program = None
1230
+
1231
+ def getToken(self, index, len=len, byteord=byteord, isinstance=isinstance):
1232
+ if self.bytecode is not None:
1233
+ if index >= len(self.bytecode):
1234
+ return None, 0, 0
1235
+ b0 = byteord(self.bytecode[index])
1236
+ index = index + 1
1237
+ handler = self.operandEncoding[b0]
1238
+ token, index = handler(self, b0, self.bytecode, index)
1239
+ else:
1240
+ if index >= len(self.program):
1241
+ return None, 0, 0
1242
+ token = self.program[index]
1243
+ index = index + 1
1244
+ isOperator = isinstance(token, str)
1245
+ return token, isOperator, index
1246
+
1247
+ def getBytes(self, index, nBytes):
1248
+ if self.bytecode is not None:
1249
+ newIndex = index + nBytes
1250
+ bytes = self.bytecode[index:newIndex]
1251
+ index = newIndex
1252
+ else:
1253
+ bytes = self.program[index]
1254
+ index = index + 1
1255
+ assert len(bytes) == nBytes
1256
+ return bytes, index
1257
+
1258
+ def handle_operator(self, operator):
1259
+ return operator
1260
+
1261
+ def toXML(self, xmlWriter, ttFont=None):
1262
+ from fontTools.misc.textTools import num2binary
1263
+
1264
+ if self.bytecode is not None:
1265
+ xmlWriter.dumphex(self.bytecode)
1266
+ else:
1267
+ index = 0
1268
+ args = []
1269
+ while True:
1270
+ token, isOperator, index = self.getToken(index)
1271
+ if token is None:
1272
+ break
1273
+ if isOperator:
1274
+ if token in ("hintmask", "cntrmask"):
1275
+ hintMask, isOperator, index = self.getToken(index)
1276
+ bits = []
1277
+ for byte in hintMask:
1278
+ bits.append(num2binary(byteord(byte), 8))
1279
+ hintMask = strjoin(bits)
1280
+ line = " ".join(args + [token, hintMask])
1281
+ else:
1282
+ line = " ".join(args + [token])
1283
+ xmlWriter.write(line)
1284
+ xmlWriter.newline()
1285
+ args = []
1286
+ else:
1287
+ if isinstance(token, float):
1288
+ token = floatToFixedToStr(token, precisionBits=16)
1289
+ else:
1290
+ token = str(token)
1291
+ args.append(token)
1292
+ if args:
1293
+ # NOTE: only CFF2 charstrings/subrs can have numeric arguments on
1294
+ # the stack after the last operator. Compiling this would fail if
1295
+ # this is part of CFF 1.0 table.
1296
+ line = " ".join(args)
1297
+ xmlWriter.write(line)
1298
+
1299
+ def fromXML(self, name, attrs, content):
1300
+ from fontTools.misc.textTools import binary2num, readHex
1301
+
1302
+ if attrs.get("raw"):
1303
+ self.setBytecode(readHex(content))
1304
+ return
1305
+ content = strjoin(content)
1306
+ content = content.split()
1307
+ program = []
1308
+ end = len(content)
1309
+ i = 0
1310
+ while i < end:
1311
+ token = content[i]
1312
+ i = i + 1
1313
+ try:
1314
+ token = int(token)
1315
+ except ValueError:
1316
+ try:
1317
+ token = strToFixedToFloat(token, precisionBits=16)
1318
+ except ValueError:
1319
+ program.append(token)
1320
+ if token in ("hintmask", "cntrmask"):
1321
+ mask = content[i]
1322
+ maskBytes = b""
1323
+ for j in range(0, len(mask), 8):
1324
+ maskBytes = maskBytes + bytechr(binary2num(mask[j : j + 8]))
1325
+ program.append(maskBytes)
1326
+ i = i + 1
1327
+ else:
1328
+ program.append(token)
1329
+ else:
1330
+ program.append(token)
1331
+ self.setProgram(program)
1332
+
1333
+
1334
+ class T1CharString(T2CharString):
1335
+ operandEncoding = t1OperandEncoding
1336
+ operators, opcodes = buildOperatorDict(t1Operators)
1337
+
1338
+ def __init__(self, bytecode=None, program=None, subrs=None):
1339
+ super().__init__(bytecode, program)
1340
+ self.subrs = subrs
1341
+
1342
+ def getIntEncoder(self):
1343
+ return encodeIntT1
1344
+
1345
+ def getFixedEncoder(self):
1346
+ def encodeFixed(value):
1347
+ raise TypeError("Type 1 charstrings don't support floating point operands")
1348
+
1349
+ def decompile(self):
1350
+ if self.bytecode is None:
1351
+ return
1352
+ program = []
1353
+ index = 0
1354
+ while True:
1355
+ token, isOperator, index = self.getToken(index)
1356
+ if token is None:
1357
+ break
1358
+ program.append(token)
1359
+ self.setProgram(program)
1360
+
1361
+ def draw(self, pen):
1362
+ extractor = T1OutlineExtractor(pen, self.subrs)
1363
+ extractor.execute(self)
1364
+ self.width = extractor.width
1365
+
1366
+
1367
+ class DictDecompiler(object):
1368
+ operandEncoding = cffDictOperandEncoding
1369
+
1370
+ def __init__(self, strings, parent=None):
1371
+ self.stack = []
1372
+ self.strings = strings
1373
+ self.dict = {}
1374
+ self.parent = parent
1375
+
1376
+ def getDict(self):
1377
+ assert len(self.stack) == 0, "non-empty stack"
1378
+ return self.dict
1379
+
1380
+ def decompile(self, data):
1381
+ index = 0
1382
+ lenData = len(data)
1383
+ push = self.stack.append
1384
+ while index < lenData:
1385
+ b0 = byteord(data[index])
1386
+ index = index + 1
1387
+ handler = self.operandEncoding[b0]
1388
+ value, index = handler(self, b0, data, index)
1389
+ if value is not None:
1390
+ push(value)
1391
+
1392
+ def pop(self):
1393
+ value = self.stack[-1]
1394
+ del self.stack[-1]
1395
+ return value
1396
+
1397
+ def popall(self):
1398
+ args = self.stack[:]
1399
+ del self.stack[:]
1400
+ return args
1401
+
1402
+ def handle_operator(self, operator):
1403
+ operator, argType = operator
1404
+ if isinstance(argType, tuple):
1405
+ value = ()
1406
+ for i in range(len(argType) - 1, -1, -1):
1407
+ arg = argType[i]
1408
+ arghandler = getattr(self, "arg_" + arg)
1409
+ value = (arghandler(operator),) + value
1410
+ else:
1411
+ arghandler = getattr(self, "arg_" + argType)
1412
+ value = arghandler(operator)
1413
+ if operator == "blend":
1414
+ self.stack.extend(value)
1415
+ else:
1416
+ self.dict[operator] = value
1417
+
1418
+ def arg_number(self, name):
1419
+ if isinstance(self.stack[0], list):
1420
+ out = self.arg_blend_number(self.stack)
1421
+ else:
1422
+ out = self.pop()
1423
+ return out
1424
+
1425
+ def arg_blend_number(self, name):
1426
+ out = []
1427
+ blendArgs = self.pop()
1428
+ numMasters = len(blendArgs)
1429
+ out.append(blendArgs)
1430
+ out.append("blend")
1431
+ dummy = self.popall()
1432
+ return blendArgs
1433
+
1434
+ def arg_SID(self, name):
1435
+ return self.strings[self.pop()]
1436
+
1437
+ def arg_array(self, name):
1438
+ return self.popall()
1439
+
1440
+ def arg_blendList(self, name):
1441
+ """
1442
+ There may be non-blend args at the top of the stack. We first calculate
1443
+ where the blend args start in the stack. These are the last
1444
+ numMasters*numBlends) +1 args.
1445
+ The blend args starts with numMasters relative coordinate values, the BlueValues in the list from the default master font. This is followed by
1446
+ numBlends list of values. Each of value in one of these lists is the
1447
+ Variable Font delta for the matching region.
1448
+
1449
+ We re-arrange this to be a list of numMaster entries. Each entry starts with the corresponding default font relative value, and is followed by
1450
+ the delta values. We then convert the default values, the first item in each entry, to an absolute value.
1451
+ """
1452
+ vsindex = self.dict.get("vsindex", 0)
1453
+ numMasters = (
1454
+ self.parent.getNumRegions(vsindex) + 1
1455
+ ) # only a PrivateDict has blended ops.
1456
+ numBlends = self.pop()
1457
+ args = self.popall()
1458
+ numArgs = len(args)
1459
+ # The spec says that there should be no non-blended Blue Values,.
1460
+ assert numArgs == numMasters * numBlends
1461
+ value = [None] * numBlends
1462
+ numDeltas = numMasters - 1
1463
+ i = 0
1464
+ prevVal = 0
1465
+ while i < numBlends:
1466
+ newVal = args[i] + prevVal
1467
+ prevVal = newVal
1468
+ masterOffset = numBlends + (i * numDeltas)
1469
+ blendList = [newVal] + args[masterOffset : masterOffset + numDeltas]
1470
+ value[i] = blendList
1471
+ i += 1
1472
+ return value
1473
+
1474
+ def arg_delta(self, name):
1475
+ valueList = self.popall()
1476
+ out = []
1477
+ if valueList and isinstance(valueList[0], list):
1478
+ # arg_blendList() has already converted these to absolute values.
1479
+ out = valueList
1480
+ else:
1481
+ current = 0
1482
+ for v in valueList:
1483
+ current = current + v
1484
+ out.append(current)
1485
+ return out
1486
+
1487
+
1488
+ def calcSubrBias(subrs):
1489
+ nSubrs = len(subrs)
1490
+ if nSubrs < 1240:
1491
+ bias = 107
1492
+ elif nSubrs < 33900:
1493
+ bias = 1131
1494
+ else:
1495
+ bias = 32768
1496
+ return bias