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
@@ -0,0 +1,752 @@
1
+ from fontTools.misc import sstruct
2
+ from fontTools.misc.roundTools import otRound
3
+ from fontTools.misc.textTools import safeEval, num2binary, binary2num
4
+ from fontTools.ttLib.tables import DefaultTable
5
+ import bisect
6
+ import logging
7
+
8
+
9
+ log = logging.getLogger(__name__)
10
+
11
+ # panose classification
12
+
13
+ panoseFormat = """
14
+ bFamilyType: B
15
+ bSerifStyle: B
16
+ bWeight: B
17
+ bProportion: B
18
+ bContrast: B
19
+ bStrokeVariation: B
20
+ bArmStyle: B
21
+ bLetterForm: B
22
+ bMidline: B
23
+ bXHeight: B
24
+ """
25
+
26
+
27
+ class Panose(object):
28
+ def __init__(self, **kwargs):
29
+ _, names, _ = sstruct.getformat(panoseFormat)
30
+ for name in names:
31
+ setattr(self, name, kwargs.pop(name, 0))
32
+ for k in kwargs:
33
+ raise TypeError(f"Panose() got an unexpected keyword argument {k!r}")
34
+
35
+ def toXML(self, writer, ttFont):
36
+ formatstring, names, fixes = sstruct.getformat(panoseFormat)
37
+ for name in names:
38
+ writer.simpletag(name, value=getattr(self, name))
39
+ writer.newline()
40
+
41
+ def fromXML(self, name, attrs, content, ttFont):
42
+ setattr(self, name, safeEval(attrs["value"]))
43
+
44
+
45
+ # 'sfnt' OS/2 and Windows Metrics table - 'OS/2'
46
+
47
+ OS2_format_0 = """
48
+ > # big endian
49
+ version: H # version
50
+ xAvgCharWidth: h # average character width
51
+ usWeightClass: H # degree of thickness of strokes
52
+ usWidthClass: H # aspect ratio
53
+ fsType: H # type flags
54
+ ySubscriptXSize: h # subscript horizontal font size
55
+ ySubscriptYSize: h # subscript vertical font size
56
+ ySubscriptXOffset: h # subscript x offset
57
+ ySubscriptYOffset: h # subscript y offset
58
+ ySuperscriptXSize: h # superscript horizontal font size
59
+ ySuperscriptYSize: h # superscript vertical font size
60
+ ySuperscriptXOffset: h # superscript x offset
61
+ ySuperscriptYOffset: h # superscript y offset
62
+ yStrikeoutSize: h # strikeout size
63
+ yStrikeoutPosition: h # strikeout position
64
+ sFamilyClass: h # font family class and subclass
65
+ panose: 10s # panose classification number
66
+ ulUnicodeRange1: L # character range
67
+ ulUnicodeRange2: L # character range
68
+ ulUnicodeRange3: L # character range
69
+ ulUnicodeRange4: L # character range
70
+ achVendID: 4s # font vendor identification
71
+ fsSelection: H # font selection flags
72
+ usFirstCharIndex: H # first unicode character index
73
+ usLastCharIndex: H # last unicode character index
74
+ sTypoAscender: h # typographic ascender
75
+ sTypoDescender: h # typographic descender
76
+ sTypoLineGap: h # typographic line gap
77
+ usWinAscent: H # Windows ascender
78
+ usWinDescent: H # Windows descender
79
+ """
80
+
81
+ OS2_format_1_addition = """
82
+ ulCodePageRange1: L
83
+ ulCodePageRange2: L
84
+ """
85
+
86
+ OS2_format_2_addition = (
87
+ OS2_format_1_addition
88
+ + """
89
+ sxHeight: h
90
+ sCapHeight: h
91
+ usDefaultChar: H
92
+ usBreakChar: H
93
+ usMaxContext: H
94
+ """
95
+ )
96
+
97
+ OS2_format_5_addition = (
98
+ OS2_format_2_addition
99
+ + """
100
+ usLowerOpticalPointSize: H
101
+ usUpperOpticalPointSize: H
102
+ """
103
+ )
104
+
105
+ bigendian = " > # big endian\n"
106
+
107
+ OS2_format_1 = OS2_format_0 + OS2_format_1_addition
108
+ OS2_format_2 = OS2_format_0 + OS2_format_2_addition
109
+ OS2_format_5 = OS2_format_0 + OS2_format_5_addition
110
+ OS2_format_1_addition = bigendian + OS2_format_1_addition
111
+ OS2_format_2_addition = bigendian + OS2_format_2_addition
112
+ OS2_format_5_addition = bigendian + OS2_format_5_addition
113
+
114
+
115
+ class table_O_S_2f_2(DefaultTable.DefaultTable):
116
+ """OS/2 and Windows Metrics table
117
+
118
+ The ``OS/2`` table contains a variety of font-wide metrics and
119
+ parameters that may be useful to an operating system or other
120
+ software for system-integration purposes.
121
+
122
+ See also https://learn.microsoft.com/en-us/typography/opentype/spec/os2
123
+ """
124
+
125
+ dependencies = ["head"]
126
+
127
+ def decompile(self, data, ttFont):
128
+ dummy, data = sstruct.unpack2(OS2_format_0, data, self)
129
+
130
+ if self.version == 1:
131
+ dummy, data = sstruct.unpack2(OS2_format_1_addition, data, self)
132
+ elif self.version in (2, 3, 4):
133
+ dummy, data = sstruct.unpack2(OS2_format_2_addition, data, self)
134
+ elif self.version == 5:
135
+ dummy, data = sstruct.unpack2(OS2_format_5_addition, data, self)
136
+ self.usLowerOpticalPointSize /= 20
137
+ self.usUpperOpticalPointSize /= 20
138
+ elif self.version != 0:
139
+ from fontTools import ttLib
140
+
141
+ raise ttLib.TTLibError(
142
+ "unknown format for OS/2 table: version %s" % self.version
143
+ )
144
+ if len(data):
145
+ log.warning("too much 'OS/2' table data")
146
+
147
+ self.panose = sstruct.unpack(panoseFormat, self.panose, Panose())
148
+
149
+ def compile(self, ttFont):
150
+ self.updateFirstAndLastCharIndex(ttFont)
151
+ panose = self.panose
152
+ head = ttFont["head"]
153
+ if (self.fsSelection & 1) and not (head.macStyle & 1 << 1):
154
+ log.warning(
155
+ "fsSelection bit 0 (italic) and "
156
+ "head table macStyle bit 1 (italic) should match"
157
+ )
158
+ if (self.fsSelection & 1 << 5) and not (head.macStyle & 1):
159
+ log.warning(
160
+ "fsSelection bit 5 (bold) and "
161
+ "head table macStyle bit 0 (bold) should match"
162
+ )
163
+ if (self.fsSelection & 1 << 6) and (self.fsSelection & 1 + (1 << 5)):
164
+ log.warning(
165
+ "fsSelection bit 6 (regular) is set, "
166
+ "bits 0 (italic) and 5 (bold) must be clear"
167
+ )
168
+ if self.version < 4 and self.fsSelection & 0b1110000000:
169
+ log.warning(
170
+ "fsSelection bits 7, 8 and 9 are only defined in "
171
+ "OS/2 table version 4 and up: version %s",
172
+ self.version,
173
+ )
174
+ self.panose = sstruct.pack(panoseFormat, self.panose)
175
+ if self.version == 0:
176
+ data = sstruct.pack(OS2_format_0, self)
177
+ elif self.version == 1:
178
+ data = sstruct.pack(OS2_format_1, self)
179
+ elif self.version in (2, 3, 4):
180
+ data = sstruct.pack(OS2_format_2, self)
181
+ elif self.version == 5:
182
+ d = self.__dict__.copy()
183
+ d["usLowerOpticalPointSize"] = round(self.usLowerOpticalPointSize * 20)
184
+ d["usUpperOpticalPointSize"] = round(self.usUpperOpticalPointSize * 20)
185
+ data = sstruct.pack(OS2_format_5, d)
186
+ else:
187
+ from fontTools import ttLib
188
+
189
+ raise ttLib.TTLibError(
190
+ "unknown format for OS/2 table: version %s" % self.version
191
+ )
192
+ self.panose = panose
193
+ return data
194
+
195
+ def toXML(self, writer, ttFont):
196
+ writer.comment(
197
+ "The fields 'usFirstCharIndex' and 'usLastCharIndex'\n"
198
+ "will be recalculated by the compiler"
199
+ )
200
+ writer.newline()
201
+ if self.version == 1:
202
+ format = OS2_format_1
203
+ elif self.version in (2, 3, 4):
204
+ format = OS2_format_2
205
+ elif self.version == 5:
206
+ format = OS2_format_5
207
+ else:
208
+ format = OS2_format_0
209
+ formatstring, names, fixes = sstruct.getformat(format)
210
+ for name in names:
211
+ value = getattr(self, name)
212
+ if name == "panose":
213
+ writer.begintag("panose")
214
+ writer.newline()
215
+ value.toXML(writer, ttFont)
216
+ writer.endtag("panose")
217
+ elif name in (
218
+ "ulUnicodeRange1",
219
+ "ulUnicodeRange2",
220
+ "ulUnicodeRange3",
221
+ "ulUnicodeRange4",
222
+ "ulCodePageRange1",
223
+ "ulCodePageRange2",
224
+ ):
225
+ writer.simpletag(name, value=num2binary(value))
226
+ elif name in ("fsType", "fsSelection"):
227
+ writer.simpletag(name, value=num2binary(value, 16))
228
+ elif name == "achVendID":
229
+ writer.simpletag(name, value=repr(value)[1:-1])
230
+ else:
231
+ writer.simpletag(name, value=value)
232
+ writer.newline()
233
+
234
+ def fromXML(self, name, attrs, content, ttFont):
235
+ if name == "panose":
236
+ self.panose = panose = Panose()
237
+ for element in content:
238
+ if isinstance(element, tuple):
239
+ name, attrs, content = element
240
+ panose.fromXML(name, attrs, content, ttFont)
241
+ elif name in (
242
+ "ulUnicodeRange1",
243
+ "ulUnicodeRange2",
244
+ "ulUnicodeRange3",
245
+ "ulUnicodeRange4",
246
+ "ulCodePageRange1",
247
+ "ulCodePageRange2",
248
+ "fsType",
249
+ "fsSelection",
250
+ ):
251
+ setattr(self, name, binary2num(attrs["value"]))
252
+ elif name == "achVendID":
253
+ setattr(self, name, safeEval("'''" + attrs["value"] + "'''"))
254
+ else:
255
+ setattr(self, name, safeEval(attrs["value"]))
256
+
257
+ def updateFirstAndLastCharIndex(self, ttFont):
258
+ if "cmap" not in ttFont:
259
+ return
260
+ codes = set()
261
+ for table in getattr(ttFont["cmap"], "tables", []):
262
+ if table.isUnicode():
263
+ codes.update(table.cmap.keys())
264
+ if codes:
265
+ minCode = min(codes)
266
+ maxCode = max(codes)
267
+ # USHORT cannot hold codepoints greater than 0xFFFF
268
+ self.usFirstCharIndex = min(0xFFFF, minCode)
269
+ self.usLastCharIndex = min(0xFFFF, maxCode)
270
+
271
+ # misspelled attributes kept for legacy reasons
272
+
273
+ @property
274
+ def usMaxContex(self):
275
+ return self.usMaxContext
276
+
277
+ @usMaxContex.setter
278
+ def usMaxContex(self, value):
279
+ self.usMaxContext = value
280
+
281
+ @property
282
+ def fsFirstCharIndex(self):
283
+ return self.usFirstCharIndex
284
+
285
+ @fsFirstCharIndex.setter
286
+ def fsFirstCharIndex(self, value):
287
+ self.usFirstCharIndex = value
288
+
289
+ @property
290
+ def fsLastCharIndex(self):
291
+ return self.usLastCharIndex
292
+
293
+ @fsLastCharIndex.setter
294
+ def fsLastCharIndex(self, value):
295
+ self.usLastCharIndex = value
296
+
297
+ def getUnicodeRanges(self):
298
+ """Return the set of 'ulUnicodeRange*' bits currently enabled."""
299
+ bits = set()
300
+ ul1, ul2 = self.ulUnicodeRange1, self.ulUnicodeRange2
301
+ ul3, ul4 = self.ulUnicodeRange3, self.ulUnicodeRange4
302
+ for i in range(32):
303
+ if ul1 & (1 << i):
304
+ bits.add(i)
305
+ if ul2 & (1 << i):
306
+ bits.add(i + 32)
307
+ if ul3 & (1 << i):
308
+ bits.add(i + 64)
309
+ if ul4 & (1 << i):
310
+ bits.add(i + 96)
311
+ return bits
312
+
313
+ def setUnicodeRanges(self, bits):
314
+ """Set the 'ulUnicodeRange*' fields to the specified 'bits'."""
315
+ ul1, ul2, ul3, ul4 = 0, 0, 0, 0
316
+ for bit in bits:
317
+ if 0 <= bit < 32:
318
+ ul1 |= 1 << bit
319
+ elif 32 <= bit < 64:
320
+ ul2 |= 1 << (bit - 32)
321
+ elif 64 <= bit < 96:
322
+ ul3 |= 1 << (bit - 64)
323
+ elif 96 <= bit < 123:
324
+ ul4 |= 1 << (bit - 96)
325
+ else:
326
+ raise ValueError("expected 0 <= int <= 122, found: %r" % bit)
327
+ self.ulUnicodeRange1, self.ulUnicodeRange2 = ul1, ul2
328
+ self.ulUnicodeRange3, self.ulUnicodeRange4 = ul3, ul4
329
+
330
+ def recalcUnicodeRanges(self, ttFont, pruneOnly=False):
331
+ """Intersect the codepoints in the font's Unicode cmap subtables with
332
+ the Unicode block ranges defined in the OpenType specification (v1.7),
333
+ and set the respective 'ulUnicodeRange*' bits if there is at least ONE
334
+ intersection.
335
+ If 'pruneOnly' is True, only clear unused bits with NO intersection.
336
+ """
337
+ unicodes = set()
338
+ for table in ttFont["cmap"].tables:
339
+ if table.isUnicode():
340
+ unicodes.update(table.cmap.keys())
341
+ if pruneOnly:
342
+ empty = intersectUnicodeRanges(unicodes, inverse=True)
343
+ bits = self.getUnicodeRanges() - empty
344
+ else:
345
+ bits = intersectUnicodeRanges(unicodes)
346
+ self.setUnicodeRanges(bits)
347
+ return bits
348
+
349
+ def getCodePageRanges(self):
350
+ """Return the set of 'ulCodePageRange*' bits currently enabled."""
351
+ bits = set()
352
+ if self.version < 1:
353
+ return bits
354
+ ul1, ul2 = self.ulCodePageRange1, self.ulCodePageRange2
355
+ for i in range(32):
356
+ if ul1 & (1 << i):
357
+ bits.add(i)
358
+ if ul2 & (1 << i):
359
+ bits.add(i + 32)
360
+ return bits
361
+
362
+ def setCodePageRanges(self, bits):
363
+ """Set the 'ulCodePageRange*' fields to the specified 'bits'."""
364
+ ul1, ul2 = 0, 0
365
+ for bit in bits:
366
+ if 0 <= bit < 32:
367
+ ul1 |= 1 << bit
368
+ elif 32 <= bit < 64:
369
+ ul2 |= 1 << (bit - 32)
370
+ else:
371
+ raise ValueError(f"expected 0 <= int <= 63, found: {bit:r}")
372
+ if self.version < 1:
373
+ self.version = 1
374
+ self.ulCodePageRange1, self.ulCodePageRange2 = ul1, ul2
375
+
376
+ def recalcCodePageRanges(self, ttFont, pruneOnly=False):
377
+ unicodes = set()
378
+ for table in ttFont["cmap"].tables:
379
+ if table.isUnicode():
380
+ unicodes.update(table.cmap.keys())
381
+ bits = calcCodePageRanges(unicodes)
382
+ if pruneOnly:
383
+ bits &= self.getCodePageRanges()
384
+ # when no codepage ranges can be enabled, fall back to enabling bit 0
385
+ # (Latin 1) so that the font works in MS Word:
386
+ # https://github.com/googlei18n/fontmake/issues/468
387
+ if not bits:
388
+ bits = {0}
389
+ self.setCodePageRanges(bits)
390
+ return bits
391
+
392
+ def recalcAvgCharWidth(self, ttFont):
393
+ """Recalculate xAvgCharWidth using metrics from ttFont's 'hmtx' table.
394
+
395
+ Set it to 0 if the unlikely event 'hmtx' table is not found.
396
+ """
397
+ avg_width = 0
398
+ hmtx = ttFont.get("hmtx")
399
+ if hmtx is not None:
400
+ widths = [width for width, _ in hmtx.metrics.values() if width > 0]
401
+ if widths:
402
+ avg_width = otRound(sum(widths) / len(widths))
403
+ self.xAvgCharWidth = avg_width
404
+ return avg_width
405
+
406
+
407
+ # Unicode ranges data from the OpenType OS/2 table specification v1.7
408
+
409
+ OS2_UNICODE_RANGES = (
410
+ (("Basic Latin", (0x0000, 0x007F)),),
411
+ (("Latin-1 Supplement", (0x0080, 0x00FF)),),
412
+ (("Latin Extended-A", (0x0100, 0x017F)),),
413
+ (("Latin Extended-B", (0x0180, 0x024F)),),
414
+ (
415
+ ("IPA Extensions", (0x0250, 0x02AF)),
416
+ ("Phonetic Extensions", (0x1D00, 0x1D7F)),
417
+ ("Phonetic Extensions Supplement", (0x1D80, 0x1DBF)),
418
+ ),
419
+ (
420
+ ("Spacing Modifier Letters", (0x02B0, 0x02FF)),
421
+ ("Modifier Tone Letters", (0xA700, 0xA71F)),
422
+ ),
423
+ (
424
+ ("Combining Diacritical Marks", (0x0300, 0x036F)),
425
+ ("Combining Diacritical Marks Supplement", (0x1DC0, 0x1DFF)),
426
+ ),
427
+ (("Greek and Coptic", (0x0370, 0x03FF)),),
428
+ (("Coptic", (0x2C80, 0x2CFF)),),
429
+ (
430
+ ("Cyrillic", (0x0400, 0x04FF)),
431
+ ("Cyrillic Supplement", (0x0500, 0x052F)),
432
+ ("Cyrillic Extended-A", (0x2DE0, 0x2DFF)),
433
+ ("Cyrillic Extended-B", (0xA640, 0xA69F)),
434
+ ),
435
+ (("Armenian", (0x0530, 0x058F)),),
436
+ (("Hebrew", (0x0590, 0x05FF)),),
437
+ (("Vai", (0xA500, 0xA63F)),),
438
+ (("Arabic", (0x0600, 0x06FF)), ("Arabic Supplement", (0x0750, 0x077F))),
439
+ (("NKo", (0x07C0, 0x07FF)),),
440
+ (("Devanagari", (0x0900, 0x097F)),),
441
+ (("Bengali", (0x0980, 0x09FF)),),
442
+ (("Gurmukhi", (0x0A00, 0x0A7F)),),
443
+ (("Gujarati", (0x0A80, 0x0AFF)),),
444
+ (("Oriya", (0x0B00, 0x0B7F)),),
445
+ (("Tamil", (0x0B80, 0x0BFF)),),
446
+ (("Telugu", (0x0C00, 0x0C7F)),),
447
+ (("Kannada", (0x0C80, 0x0CFF)),),
448
+ (("Malayalam", (0x0D00, 0x0D7F)),),
449
+ (("Thai", (0x0E00, 0x0E7F)),),
450
+ (("Lao", (0x0E80, 0x0EFF)),),
451
+ (("Georgian", (0x10A0, 0x10FF)), ("Georgian Supplement", (0x2D00, 0x2D2F))),
452
+ (("Balinese", (0x1B00, 0x1B7F)),),
453
+ (("Hangul Jamo", (0x1100, 0x11FF)),),
454
+ (
455
+ ("Latin Extended Additional", (0x1E00, 0x1EFF)),
456
+ ("Latin Extended-C", (0x2C60, 0x2C7F)),
457
+ ("Latin Extended-D", (0xA720, 0xA7FF)),
458
+ ),
459
+ (("Greek Extended", (0x1F00, 0x1FFF)),),
460
+ (
461
+ ("General Punctuation", (0x2000, 0x206F)),
462
+ ("Supplemental Punctuation", (0x2E00, 0x2E7F)),
463
+ ),
464
+ (("Superscripts And Subscripts", (0x2070, 0x209F)),),
465
+ (("Currency Symbols", (0x20A0, 0x20CF)),),
466
+ (("Combining Diacritical Marks For Symbols", (0x20D0, 0x20FF)),),
467
+ (("Letterlike Symbols", (0x2100, 0x214F)),),
468
+ (("Number Forms", (0x2150, 0x218F)),),
469
+ (
470
+ ("Arrows", (0x2190, 0x21FF)),
471
+ ("Supplemental Arrows-A", (0x27F0, 0x27FF)),
472
+ ("Supplemental Arrows-B", (0x2900, 0x297F)),
473
+ ("Miscellaneous Symbols and Arrows", (0x2B00, 0x2BFF)),
474
+ ),
475
+ (
476
+ ("Mathematical Operators", (0x2200, 0x22FF)),
477
+ ("Supplemental Mathematical Operators", (0x2A00, 0x2AFF)),
478
+ ("Miscellaneous Mathematical Symbols-A", (0x27C0, 0x27EF)),
479
+ ("Miscellaneous Mathematical Symbols-B", (0x2980, 0x29FF)),
480
+ ),
481
+ (("Miscellaneous Technical", (0x2300, 0x23FF)),),
482
+ (("Control Pictures", (0x2400, 0x243F)),),
483
+ (("Optical Character Recognition", (0x2440, 0x245F)),),
484
+ (("Enclosed Alphanumerics", (0x2460, 0x24FF)),),
485
+ (("Box Drawing", (0x2500, 0x257F)),),
486
+ (("Block Elements", (0x2580, 0x259F)),),
487
+ (("Geometric Shapes", (0x25A0, 0x25FF)),),
488
+ (("Miscellaneous Symbols", (0x2600, 0x26FF)),),
489
+ (("Dingbats", (0x2700, 0x27BF)),),
490
+ (("CJK Symbols And Punctuation", (0x3000, 0x303F)),),
491
+ (("Hiragana", (0x3040, 0x309F)),),
492
+ (
493
+ ("Katakana", (0x30A0, 0x30FF)),
494
+ ("Katakana Phonetic Extensions", (0x31F0, 0x31FF)),
495
+ ),
496
+ (("Bopomofo", (0x3100, 0x312F)), ("Bopomofo Extended", (0x31A0, 0x31BF))),
497
+ (("Hangul Compatibility Jamo", (0x3130, 0x318F)),),
498
+ (("Phags-pa", (0xA840, 0xA87F)),),
499
+ (("Enclosed CJK Letters And Months", (0x3200, 0x32FF)),),
500
+ (("CJK Compatibility", (0x3300, 0x33FF)),),
501
+ (("Hangul Syllables", (0xAC00, 0xD7AF)),),
502
+ (("Non-Plane 0 *", (0xD800, 0xDFFF)),),
503
+ (("Phoenician", (0x10900, 0x1091F)),),
504
+ (
505
+ ("CJK Unified Ideographs", (0x4E00, 0x9FFF)),
506
+ ("CJK Radicals Supplement", (0x2E80, 0x2EFF)),
507
+ ("Kangxi Radicals", (0x2F00, 0x2FDF)),
508
+ ("Ideographic Description Characters", (0x2FF0, 0x2FFF)),
509
+ ("CJK Unified Ideographs Extension A", (0x3400, 0x4DBF)),
510
+ ("CJK Unified Ideographs Extension B", (0x20000, 0x2A6DF)),
511
+ ("Kanbun", (0x3190, 0x319F)),
512
+ ),
513
+ (("Private Use Area (plane 0)", (0xE000, 0xF8FF)),),
514
+ (
515
+ ("CJK Strokes", (0x31C0, 0x31EF)),
516
+ ("CJK Compatibility Ideographs", (0xF900, 0xFAFF)),
517
+ ("CJK Compatibility Ideographs Supplement", (0x2F800, 0x2FA1F)),
518
+ ),
519
+ (("Alphabetic Presentation Forms", (0xFB00, 0xFB4F)),),
520
+ (("Arabic Presentation Forms-A", (0xFB50, 0xFDFF)),),
521
+ (("Combining Half Marks", (0xFE20, 0xFE2F)),),
522
+ (
523
+ ("Vertical Forms", (0xFE10, 0xFE1F)),
524
+ ("CJK Compatibility Forms", (0xFE30, 0xFE4F)),
525
+ ),
526
+ (("Small Form Variants", (0xFE50, 0xFE6F)),),
527
+ (("Arabic Presentation Forms-B", (0xFE70, 0xFEFF)),),
528
+ (("Halfwidth And Fullwidth Forms", (0xFF00, 0xFFEF)),),
529
+ (("Specials", (0xFFF0, 0xFFFF)),),
530
+ (("Tibetan", (0x0F00, 0x0FFF)),),
531
+ (("Syriac", (0x0700, 0x074F)),),
532
+ (("Thaana", (0x0780, 0x07BF)),),
533
+ (("Sinhala", (0x0D80, 0x0DFF)),),
534
+ (("Myanmar", (0x1000, 0x109F)),),
535
+ (
536
+ ("Ethiopic", (0x1200, 0x137F)),
537
+ ("Ethiopic Supplement", (0x1380, 0x139F)),
538
+ ("Ethiopic Extended", (0x2D80, 0x2DDF)),
539
+ ),
540
+ (("Cherokee", (0x13A0, 0x13FF)),),
541
+ (("Unified Canadian Aboriginal Syllabics", (0x1400, 0x167F)),),
542
+ (("Ogham", (0x1680, 0x169F)),),
543
+ (("Runic", (0x16A0, 0x16FF)),),
544
+ (("Khmer", (0x1780, 0x17FF)), ("Khmer Symbols", (0x19E0, 0x19FF))),
545
+ (("Mongolian", (0x1800, 0x18AF)),),
546
+ (("Braille Patterns", (0x2800, 0x28FF)),),
547
+ (("Yi Syllables", (0xA000, 0xA48F)), ("Yi Radicals", (0xA490, 0xA4CF))),
548
+ (
549
+ ("Tagalog", (0x1700, 0x171F)),
550
+ ("Hanunoo", (0x1720, 0x173F)),
551
+ ("Buhid", (0x1740, 0x175F)),
552
+ ("Tagbanwa", (0x1760, 0x177F)),
553
+ ),
554
+ (("Old Italic", (0x10300, 0x1032F)),),
555
+ (("Gothic", (0x10330, 0x1034F)),),
556
+ (("Deseret", (0x10400, 0x1044F)),),
557
+ (
558
+ ("Byzantine Musical Symbols", (0x1D000, 0x1D0FF)),
559
+ ("Musical Symbols", (0x1D100, 0x1D1FF)),
560
+ ("Ancient Greek Musical Notation", (0x1D200, 0x1D24F)),
561
+ ),
562
+ (("Mathematical Alphanumeric Symbols", (0x1D400, 0x1D7FF)),),
563
+ (
564
+ ("Private Use (plane 15)", (0xF0000, 0xFFFFD)),
565
+ ("Private Use (plane 16)", (0x100000, 0x10FFFD)),
566
+ ),
567
+ (
568
+ ("Variation Selectors", (0xFE00, 0xFE0F)),
569
+ ("Variation Selectors Supplement", (0xE0100, 0xE01EF)),
570
+ ),
571
+ (("Tags", (0xE0000, 0xE007F)),),
572
+ (("Limbu", (0x1900, 0x194F)),),
573
+ (("Tai Le", (0x1950, 0x197F)),),
574
+ (("New Tai Lue", (0x1980, 0x19DF)),),
575
+ (("Buginese", (0x1A00, 0x1A1F)),),
576
+ (("Glagolitic", (0x2C00, 0x2C5F)),),
577
+ (("Tifinagh", (0x2D30, 0x2D7F)),),
578
+ (("Yijing Hexagram Symbols", (0x4DC0, 0x4DFF)),),
579
+ (("Syloti Nagri", (0xA800, 0xA82F)),),
580
+ (
581
+ ("Linear B Syllabary", (0x10000, 0x1007F)),
582
+ ("Linear B Ideograms", (0x10080, 0x100FF)),
583
+ ("Aegean Numbers", (0x10100, 0x1013F)),
584
+ ),
585
+ (("Ancient Greek Numbers", (0x10140, 0x1018F)),),
586
+ (("Ugaritic", (0x10380, 0x1039F)),),
587
+ (("Old Persian", (0x103A0, 0x103DF)),),
588
+ (("Shavian", (0x10450, 0x1047F)),),
589
+ (("Osmanya", (0x10480, 0x104AF)),),
590
+ (("Cypriot Syllabary", (0x10800, 0x1083F)),),
591
+ (("Kharoshthi", (0x10A00, 0x10A5F)),),
592
+ (("Tai Xuan Jing Symbols", (0x1D300, 0x1D35F)),),
593
+ (
594
+ ("Cuneiform", (0x12000, 0x123FF)),
595
+ ("Cuneiform Numbers and Punctuation", (0x12400, 0x1247F)),
596
+ ),
597
+ (("Counting Rod Numerals", (0x1D360, 0x1D37F)),),
598
+ (("Sundanese", (0x1B80, 0x1BBF)),),
599
+ (("Lepcha", (0x1C00, 0x1C4F)),),
600
+ (("Ol Chiki", (0x1C50, 0x1C7F)),),
601
+ (("Saurashtra", (0xA880, 0xA8DF)),),
602
+ (("Kayah Li", (0xA900, 0xA92F)),),
603
+ (("Rejang", (0xA930, 0xA95F)),),
604
+ (("Cham", (0xAA00, 0xAA5F)),),
605
+ (("Ancient Symbols", (0x10190, 0x101CF)),),
606
+ (("Phaistos Disc", (0x101D0, 0x101FF)),),
607
+ (
608
+ ("Carian", (0x102A0, 0x102DF)),
609
+ ("Lycian", (0x10280, 0x1029F)),
610
+ ("Lydian", (0x10920, 0x1093F)),
611
+ ),
612
+ (("Domino Tiles", (0x1F030, 0x1F09F)), ("Mahjong Tiles", (0x1F000, 0x1F02F))),
613
+ )
614
+
615
+
616
+ _unicodeStarts = []
617
+ _unicodeValues = [None]
618
+
619
+
620
+ def _getUnicodeRanges():
621
+ # build the ranges of codepoints for each unicode range bit, and cache result
622
+ if not _unicodeStarts:
623
+ unicodeRanges = [
624
+ (start, (stop, bit))
625
+ for bit, blocks in enumerate(OS2_UNICODE_RANGES)
626
+ for _, (start, stop) in blocks
627
+ ]
628
+ for start, (stop, bit) in sorted(unicodeRanges):
629
+ _unicodeStarts.append(start)
630
+ _unicodeValues.append((stop, bit))
631
+ return _unicodeStarts, _unicodeValues
632
+
633
+
634
+ def intersectUnicodeRanges(unicodes, inverse=False):
635
+ """Intersect a sequence of (int) Unicode codepoints with the Unicode block
636
+ ranges defined in the OpenType specification v1.7, and return the set of
637
+ 'ulUnicodeRanges' bits for which there is at least ONE intersection.
638
+ If 'inverse' is True, return the the bits for which there is NO intersection.
639
+
640
+ >>> intersectUnicodeRanges([0x0410]) == {9}
641
+ True
642
+ >>> intersectUnicodeRanges([0x0410, 0x1F000]) == {9, 57, 122}
643
+ True
644
+ >>> intersectUnicodeRanges([0x0410, 0x1F000], inverse=True) == (
645
+ ... set(range(len(OS2_UNICODE_RANGES))) - {9, 57, 122})
646
+ True
647
+ """
648
+ unicodes = set(unicodes)
649
+ unicodestarts, unicodevalues = _getUnicodeRanges()
650
+ bits = set()
651
+ for code in unicodes:
652
+ stop, bit = unicodevalues[bisect.bisect(unicodestarts, code)]
653
+ if code <= stop:
654
+ bits.add(bit)
655
+ # The spec says that bit 57 ("Non Plane 0") implies that there's
656
+ # at least one codepoint beyond the BMP; so I also include all
657
+ # the non-BMP codepoints here
658
+ if any(0x10000 <= code < 0x110000 for code in unicodes):
659
+ bits.add(57)
660
+ return set(range(len(OS2_UNICODE_RANGES))) - bits if inverse else bits
661
+
662
+
663
+ def calcCodePageRanges(unicodes):
664
+ """Given a set of Unicode codepoints (integers), calculate the
665
+ corresponding OS/2 CodePage range bits.
666
+ This is a direct translation of FontForge implementation:
667
+ https://github.com/fontforge/fontforge/blob/7b2c074/fontforge/tottf.c#L3158
668
+ """
669
+ bits = set()
670
+ hasAscii = set(range(0x20, 0x7E)).issubset(unicodes)
671
+ hasLineart = ord("┤") in unicodes
672
+
673
+ for uni in unicodes:
674
+ if uni == ord("Þ") and hasAscii:
675
+ bits.add(0) # Latin 1
676
+ elif uni == ord("Ľ") and hasAscii:
677
+ bits.add(1) # Latin 2: Eastern Europe
678
+ if hasLineart:
679
+ bits.add(58) # Latin 2
680
+ elif uni == ord("Б"):
681
+ bits.add(2) # Cyrillic
682
+ if ord("Ѕ") in unicodes and hasLineart:
683
+ bits.add(57) # IBM Cyrillic
684
+ if ord("╜") in unicodes and hasLineart:
685
+ bits.add(49) # MS-DOS Russian
686
+ elif uni == ord("Ά"):
687
+ bits.add(3) # Greek
688
+ if hasLineart and ord("½") in unicodes:
689
+ bits.add(48) # IBM Greek
690
+ if hasLineart and ord("√") in unicodes:
691
+ bits.add(60) # Greek, former 437 G
692
+ elif uni == ord("İ") and hasAscii:
693
+ bits.add(4) # Turkish
694
+ if hasLineart:
695
+ bits.add(56) # IBM turkish
696
+ elif uni == ord("א"):
697
+ bits.add(5) # Hebrew
698
+ if hasLineart and ord("√") in unicodes:
699
+ bits.add(53) # Hebrew
700
+ elif uni == ord("ر"):
701
+ bits.add(6) # Arabic
702
+ if ord("√") in unicodes:
703
+ bits.add(51) # Arabic
704
+ if hasLineart:
705
+ bits.add(61) # Arabic; ASMO 708
706
+ elif uni == ord("ŗ") and hasAscii:
707
+ bits.add(7) # Windows Baltic
708
+ if hasLineart:
709
+ bits.add(59) # MS-DOS Baltic
710
+ elif uni == ord("₫") and hasAscii:
711
+ bits.add(8) # Vietnamese
712
+ elif uni == ord("ๅ"):
713
+ bits.add(16) # Thai
714
+ elif uni == ord("エ"):
715
+ bits.add(17) # JIS/Japan
716
+ elif uni == ord("ㄅ"):
717
+ bits.add(18) # Chinese: Simplified
718
+ elif uni == ord("ㄱ"):
719
+ bits.add(19) # Korean wansung
720
+ elif uni == ord("央"):
721
+ bits.add(20) # Chinese: Traditional
722
+ elif uni == ord("곴"):
723
+ bits.add(21) # Korean Johab
724
+ elif uni == ord("♥") and hasAscii:
725
+ bits.add(30) # OEM Character Set
726
+ # TODO: Symbol bit has a special meaning (check the spec), we need
727
+ # to confirm if this is wanted by default.
728
+ # elif chr(0xF000) <= char <= chr(0xF0FF):
729
+ # codepageRanges.add(31) # Symbol Character Set
730
+ elif uni == ord("þ") and hasAscii and hasLineart:
731
+ bits.add(54) # MS-DOS Icelandic
732
+ elif uni == ord("╚") and hasAscii:
733
+ bits.add(62) # WE/Latin 1
734
+ bits.add(63) # US
735
+ elif hasAscii and hasLineart and ord("√") in unicodes:
736
+ if uni == ord("Å"):
737
+ bits.add(50) # MS-DOS Nordic
738
+ elif uni == ord("é"):
739
+ bits.add(52) # MS-DOS Canadian French
740
+ elif uni == ord("õ"):
741
+ bits.add(55) # MS-DOS Portuguese
742
+
743
+ if hasAscii and ord("‰") in unicodes and ord("∑") in unicodes:
744
+ bits.add(29) # Macintosh Character Set (US Roman)
745
+
746
+ return bits
747
+
748
+
749
+ if __name__ == "__main__":
750
+ import doctest, sys
751
+
752
+ sys.exit(doctest.testmod().failed)