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,643 @@
1
+ """
2
+ =========
3
+ PointPens
4
+ =========
5
+
6
+ Where **SegmentPens** have an intuitive approach to drawing
7
+ (if you're familiar with postscript anyway), the **PointPen**
8
+ is geared towards accessing all the data in the contours of
9
+ the glyph. A PointPen has a very simple interface, it just
10
+ steps through all the points in a call from glyph.drawPoints().
11
+ This allows the caller to provide more data for each point.
12
+ For instance, whether or not a point is smooth, and its name.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import math
18
+ from typing import Any, Dict, List, Optional, Tuple
19
+
20
+ from fontTools.misc.enumTools import StrEnum
21
+ from fontTools.misc.loggingTools import LogMixin
22
+ from fontTools.misc.transform import DecomposedTransform, Identity
23
+ from fontTools.pens.basePen import AbstractPen, MissingComponentError, PenError
24
+
25
+ __all__ = [
26
+ "AbstractPointPen",
27
+ "BasePointToSegmentPen",
28
+ "PointToSegmentPen",
29
+ "SegmentToPointPen",
30
+ "GuessSmoothPointPen",
31
+ "ReverseContourPointPen",
32
+ "ReverseFlipped",
33
+ ]
34
+
35
+ # Some type aliases to make it easier below
36
+ Point = Tuple[float, float]
37
+ PointName = Optional[str]
38
+ # [(pt, smooth, name, kwargs)]
39
+ SegmentPointList = List[Tuple[Optional[Point], bool, PointName, Any]]
40
+ SegmentType = Optional[str]
41
+ SegmentList = List[Tuple[SegmentType, SegmentPointList]]
42
+
43
+
44
+ class ReverseFlipped(StrEnum):
45
+ """How to handle flipped components during decomposition.
46
+
47
+ NO: Don't reverse flipped components
48
+ KEEP_START: Reverse flipped components, keeping original starting point
49
+ ON_CURVE_FIRST: Reverse flipped components, ensuring first point is on-curve
50
+ """
51
+
52
+ NO = "no"
53
+ KEEP_START = "keep_start"
54
+ ON_CURVE_FIRST = "on_curve_first"
55
+
56
+
57
+ class AbstractPointPen:
58
+ """Baseclass for all PointPens."""
59
+
60
+ def beginPath(self, identifier: Optional[str] = None, **kwargs: Any) -> None:
61
+ """Start a new sub path."""
62
+ raise NotImplementedError
63
+
64
+ def endPath(self) -> None:
65
+ """End the current sub path."""
66
+ raise NotImplementedError
67
+
68
+ def addPoint(
69
+ self,
70
+ pt: Tuple[float, float],
71
+ segmentType: Optional[str] = None,
72
+ smooth: bool = False,
73
+ name: Optional[str] = None,
74
+ identifier: Optional[str] = None,
75
+ **kwargs: Any,
76
+ ) -> None:
77
+ """Add a point to the current sub path."""
78
+ raise NotImplementedError
79
+
80
+ def addComponent(
81
+ self,
82
+ baseGlyphName: str,
83
+ transformation: Tuple[float, float, float, float, float, float],
84
+ identifier: Optional[str] = None,
85
+ **kwargs: Any,
86
+ ) -> None:
87
+ """Add a sub glyph."""
88
+ raise NotImplementedError
89
+
90
+ def addVarComponent(
91
+ self,
92
+ glyphName: str,
93
+ transformation: DecomposedTransform,
94
+ location: Dict[str, float],
95
+ identifier: Optional[str] = None,
96
+ **kwargs: Any,
97
+ ) -> None:
98
+ """Add a VarComponent sub glyph. The 'transformation' argument
99
+ must be a DecomposedTransform from the fontTools.misc.transform module,
100
+ and the 'location' argument must be a dictionary mapping axis tags
101
+ to their locations.
102
+ """
103
+ # ttGlyphSet decomposes for us
104
+ raise AttributeError
105
+
106
+
107
+ class BasePointToSegmentPen(AbstractPointPen):
108
+ """
109
+ Base class for retrieving the outline in a segment-oriented
110
+ way. The PointPen protocol is simple yet also a little tricky,
111
+ so when you need an outline presented as segments but you have
112
+ as points, do use this base implementation as it properly takes
113
+ care of all the edge cases.
114
+ """
115
+
116
+ def __init__(self) -> None:
117
+ self.currentPath = None
118
+
119
+ def beginPath(self, identifier=None, **kwargs):
120
+ if self.currentPath is not None:
121
+ raise PenError("Path already begun.")
122
+ self.currentPath = []
123
+
124
+ def _flushContour(self, segments: SegmentList) -> None:
125
+ """Override this method.
126
+
127
+ It will be called for each non-empty sub path with a list
128
+ of segments: the 'segments' argument.
129
+
130
+ The segments list contains tuples of length 2:
131
+ (segmentType, points)
132
+
133
+ segmentType is one of "move", "line", "curve" or "qcurve".
134
+ "move" may only occur as the first segment, and it signifies
135
+ an OPEN path. A CLOSED path does NOT start with a "move", in
136
+ fact it will not contain a "move" at ALL.
137
+
138
+ The 'points' field in the 2-tuple is a list of point info
139
+ tuples. The list has 1 or more items, a point tuple has
140
+ four items:
141
+ (point, smooth, name, kwargs)
142
+ 'point' is an (x, y) coordinate pair.
143
+
144
+ For a closed path, the initial moveTo point is defined as
145
+ the last point of the last segment.
146
+
147
+ The 'points' list of "move" and "line" segments always contains
148
+ exactly one point tuple.
149
+ """
150
+ raise NotImplementedError
151
+
152
+ def endPath(self) -> None:
153
+ if self.currentPath is None:
154
+ raise PenError("Path not begun.")
155
+ points = self.currentPath
156
+ self.currentPath = None
157
+ if not points:
158
+ return
159
+ if len(points) == 1:
160
+ # Not much more we can do than output a single move segment.
161
+ pt, segmentType, smooth, name, kwargs = points[0]
162
+ segments: SegmentList = [("move", [(pt, smooth, name, kwargs)])]
163
+ self._flushContour(segments)
164
+ return
165
+ segments = []
166
+ if points[0][1] == "move":
167
+ # It's an open contour, insert a "move" segment for the first
168
+ # point and remove that first point from the point list.
169
+ pt, segmentType, smooth, name, kwargs = points[0]
170
+ segments.append(("move", [(pt, smooth, name, kwargs)]))
171
+ points.pop(0)
172
+ else:
173
+ # It's a closed contour. Locate the first on-curve point, and
174
+ # rotate the point list so that it _ends_ with an on-curve
175
+ # point.
176
+ firstOnCurve = None
177
+ for i in range(len(points)):
178
+ segmentType = points[i][1]
179
+ if segmentType is not None:
180
+ firstOnCurve = i
181
+ break
182
+ if firstOnCurve is None:
183
+ # Special case for quadratics: a contour with no on-curve
184
+ # points. Add a "None" point. (See also the Pen protocol's
185
+ # qCurveTo() method and fontTools.pens.basePen.py.)
186
+ points.append((None, "qcurve", None, None, None))
187
+ else:
188
+ points = points[firstOnCurve + 1 :] + points[: firstOnCurve + 1]
189
+
190
+ currentSegment: SegmentPointList = []
191
+ for pt, segmentType, smooth, name, kwargs in points:
192
+ currentSegment.append((pt, smooth, name, kwargs))
193
+ if segmentType is None:
194
+ continue
195
+ segments.append((segmentType, currentSegment))
196
+ currentSegment = []
197
+
198
+ self._flushContour(segments)
199
+
200
+ def addPoint(
201
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
202
+ ):
203
+ if self.currentPath is None:
204
+ raise PenError("Path not begun")
205
+ self.currentPath.append((pt, segmentType, smooth, name, kwargs))
206
+
207
+
208
+ class PointToSegmentPen(BasePointToSegmentPen):
209
+ """
210
+ Adapter class that converts the PointPen protocol to the
211
+ (Segment)Pen protocol.
212
+
213
+ NOTE: The segment pen does not support and will drop point names, identifiers
214
+ and kwargs.
215
+ """
216
+
217
+ def __init__(self, segmentPen, outputImpliedClosingLine: bool = False) -> None:
218
+ BasePointToSegmentPen.__init__(self)
219
+ self.pen = segmentPen
220
+ self.outputImpliedClosingLine = outputImpliedClosingLine
221
+
222
+ def _flushContour(self, segments):
223
+ if not segments:
224
+ raise PenError("Must have at least one segment.")
225
+ pen = self.pen
226
+ if segments[0][0] == "move":
227
+ # It's an open path.
228
+ closed = False
229
+ points = segments[0][1]
230
+ if len(points) != 1:
231
+ raise PenError(f"Illegal move segment point count: {len(points)}")
232
+ movePt, _, _, _ = points[0]
233
+ del segments[0]
234
+ else:
235
+ # It's a closed path, do a moveTo to the last
236
+ # point of the last segment.
237
+ closed = True
238
+ segmentType, points = segments[-1]
239
+ movePt, _, _, _ = points[-1]
240
+ if movePt is None:
241
+ # quad special case: a contour with no on-curve points contains
242
+ # one "qcurve" segment that ends with a point that's None. We
243
+ # must not output a moveTo() in that case.
244
+ pass
245
+ else:
246
+ pen.moveTo(movePt)
247
+ outputImpliedClosingLine = self.outputImpliedClosingLine
248
+ nSegments = len(segments)
249
+ lastPt = movePt
250
+ for i in range(nSegments):
251
+ segmentType, points = segments[i]
252
+ points = [pt for pt, _, _, _ in points]
253
+ if segmentType == "line":
254
+ if len(points) != 1:
255
+ raise PenError(f"Illegal line segment point count: {len(points)}")
256
+ pt = points[0]
257
+ # For closed contours, a 'lineTo' is always implied from the last oncurve
258
+ # point to the starting point, thus we can omit it when the last and
259
+ # starting point don't overlap.
260
+ # However, when the last oncurve point is a "line" segment and has same
261
+ # coordinates as the starting point of a closed contour, we need to output
262
+ # the closing 'lineTo' explicitly (regardless of the value of the
263
+ # 'outputImpliedClosingLine' option) in order to disambiguate this case from
264
+ # the implied closing 'lineTo', otherwise the duplicate point would be lost.
265
+ # See https://github.com/googlefonts/fontmake/issues/572.
266
+ if (
267
+ i + 1 != nSegments
268
+ or outputImpliedClosingLine
269
+ or not closed
270
+ or pt == lastPt
271
+ ):
272
+ pen.lineTo(pt)
273
+ lastPt = pt
274
+ elif segmentType == "curve":
275
+ pen.curveTo(*points)
276
+ lastPt = points[-1]
277
+ elif segmentType == "qcurve":
278
+ pen.qCurveTo(*points)
279
+ lastPt = points[-1]
280
+ else:
281
+ raise PenError(f"Illegal segmentType: {segmentType}")
282
+ if closed:
283
+ pen.closePath()
284
+ else:
285
+ pen.endPath()
286
+
287
+ def addComponent(self, glyphName, transform, identifier=None, **kwargs):
288
+ del identifier # unused
289
+ del kwargs # unused
290
+ self.pen.addComponent(glyphName, transform)
291
+
292
+
293
+ class SegmentToPointPen(AbstractPen):
294
+ """
295
+ Adapter class that converts the (Segment)Pen protocol to the
296
+ PointPen protocol.
297
+ """
298
+
299
+ def __init__(self, pointPen, guessSmooth=True) -> None:
300
+ if guessSmooth:
301
+ self.pen = GuessSmoothPointPen(pointPen)
302
+ else:
303
+ self.pen = pointPen
304
+ self.contour: Optional[List[Tuple[Point, SegmentType]]] = None
305
+
306
+ def _flushContour(self) -> None:
307
+ pen = self.pen
308
+ pen.beginPath()
309
+ for pt, segmentType in self.contour:
310
+ pen.addPoint(pt, segmentType=segmentType)
311
+ pen.endPath()
312
+
313
+ def moveTo(self, pt):
314
+ self.contour = []
315
+ self.contour.append((pt, "move"))
316
+
317
+ def lineTo(self, pt):
318
+ if self.contour is None:
319
+ raise PenError("Contour missing required initial moveTo")
320
+ self.contour.append((pt, "line"))
321
+
322
+ def curveTo(self, *pts):
323
+ if not pts:
324
+ raise TypeError("Must pass in at least one point")
325
+ if self.contour is None:
326
+ raise PenError("Contour missing required initial moveTo")
327
+ for pt in pts[:-1]:
328
+ self.contour.append((pt, None))
329
+ self.contour.append((pts[-1], "curve"))
330
+
331
+ def qCurveTo(self, *pts):
332
+ if not pts:
333
+ raise TypeError("Must pass in at least one point")
334
+ if pts[-1] is None:
335
+ self.contour = []
336
+ else:
337
+ if self.contour is None:
338
+ raise PenError("Contour missing required initial moveTo")
339
+ for pt in pts[:-1]:
340
+ self.contour.append((pt, None))
341
+ if pts[-1] is not None:
342
+ self.contour.append((pts[-1], "qcurve"))
343
+
344
+ def closePath(self):
345
+ if self.contour is None:
346
+ raise PenError("Contour missing required initial moveTo")
347
+ if len(self.contour) > 1 and self.contour[0][0] == self.contour[-1][0]:
348
+ self.contour[0] = self.contour[-1]
349
+ del self.contour[-1]
350
+ else:
351
+ # There's an implied line at the end, replace "move" with "line"
352
+ # for the first point
353
+ pt, tp = self.contour[0]
354
+ if tp == "move":
355
+ self.contour[0] = pt, "line"
356
+ self._flushContour()
357
+ self.contour = None
358
+
359
+ def endPath(self):
360
+ if self.contour is None:
361
+ raise PenError("Contour missing required initial moveTo")
362
+ self._flushContour()
363
+ self.contour = None
364
+
365
+ def addComponent(self, glyphName, transform):
366
+ if self.contour is not None:
367
+ raise PenError("Components must be added before or after contours")
368
+ self.pen.addComponent(glyphName, transform)
369
+
370
+
371
+ class GuessSmoothPointPen(AbstractPointPen):
372
+ """
373
+ Filtering PointPen that tries to determine whether an on-curve point
374
+ should be "smooth", ie. that it's a "tangent" point or a "curve" point.
375
+ """
376
+
377
+ def __init__(self, outPen, error=0.05):
378
+ self._outPen = outPen
379
+ self._error = error
380
+ self._points = None
381
+
382
+ def _flushContour(self):
383
+ if self._points is None:
384
+ raise PenError("Path not begun")
385
+ points = self._points
386
+ nPoints = len(points)
387
+ if not nPoints:
388
+ return
389
+ if points[0][1] == "move":
390
+ # Open path.
391
+ indices = range(1, nPoints - 1)
392
+ elif nPoints > 1:
393
+ # Closed path. To avoid having to mod the contour index, we
394
+ # simply abuse Python's negative index feature, and start at -1
395
+ indices = range(-1, nPoints - 1)
396
+ else:
397
+ # closed path containing 1 point (!), ignore.
398
+ indices = []
399
+ for i in indices:
400
+ pt, segmentType, _, name, kwargs = points[i]
401
+ if segmentType is None:
402
+ continue
403
+ prev = i - 1
404
+ next = i + 1
405
+ if points[prev][1] is not None and points[next][1] is not None:
406
+ continue
407
+ # At least one of our neighbors is an off-curve point
408
+ pt = points[i][0]
409
+ prevPt = points[prev][0]
410
+ nextPt = points[next][0]
411
+ if pt != prevPt and pt != nextPt:
412
+ dx1, dy1 = pt[0] - prevPt[0], pt[1] - prevPt[1]
413
+ dx2, dy2 = nextPt[0] - pt[0], nextPt[1] - pt[1]
414
+ a1 = math.atan2(dy1, dx1)
415
+ a2 = math.atan2(dy2, dx2)
416
+ if abs(a1 - a2) < self._error:
417
+ points[i] = pt, segmentType, True, name, kwargs
418
+
419
+ for pt, segmentType, smooth, name, kwargs in points:
420
+ self._outPen.addPoint(pt, segmentType, smooth, name, **kwargs)
421
+
422
+ def beginPath(self, identifier=None, **kwargs):
423
+ if self._points is not None:
424
+ raise PenError("Path already begun")
425
+ self._points = []
426
+ if identifier is not None:
427
+ kwargs["identifier"] = identifier
428
+ self._outPen.beginPath(**kwargs)
429
+
430
+ def endPath(self):
431
+ self._flushContour()
432
+ self._outPen.endPath()
433
+ self._points = None
434
+
435
+ def addPoint(
436
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
437
+ ):
438
+ if self._points is None:
439
+ raise PenError("Path not begun")
440
+ if identifier is not None:
441
+ kwargs["identifier"] = identifier
442
+ self._points.append((pt, segmentType, False, name, kwargs))
443
+
444
+ def addComponent(self, glyphName, transformation, identifier=None, **kwargs):
445
+ if self._points is not None:
446
+ raise PenError("Components must be added before or after contours")
447
+ if identifier is not None:
448
+ kwargs["identifier"] = identifier
449
+ self._outPen.addComponent(glyphName, transformation, **kwargs)
450
+
451
+ def addVarComponent(
452
+ self, glyphName, transformation, location, identifier=None, **kwargs
453
+ ):
454
+ if self._points is not None:
455
+ raise PenError("VarComponents must be added before or after contours")
456
+ if identifier is not None:
457
+ kwargs["identifier"] = identifier
458
+ self._outPen.addVarComponent(glyphName, transformation, location, **kwargs)
459
+
460
+
461
+ class ReverseContourPointPen(AbstractPointPen):
462
+ """
463
+ This is a PointPen that passes outline data to another PointPen, but
464
+ reversing the winding direction of all contours. Components are simply
465
+ passed through unchanged.
466
+
467
+ Closed contours are reversed in such a way that the first point remains
468
+ the first point.
469
+ """
470
+
471
+ def __init__(self, outputPointPen):
472
+ self.pen = outputPointPen
473
+ # a place to store the points for the current sub path
474
+ self.currentContour = None
475
+
476
+ def _flushContour(self):
477
+ pen = self.pen
478
+ contour = self.currentContour
479
+ if not contour:
480
+ pen.beginPath(identifier=self.currentContourIdentifier)
481
+ pen.endPath()
482
+ return
483
+
484
+ closed = contour[0][1] != "move"
485
+ if not closed:
486
+ lastSegmentType = "move"
487
+ else:
488
+ # Remove the first point and insert it at the end. When
489
+ # the list of points gets reversed, this point will then
490
+ # again be at the start. In other words, the following
491
+ # will hold:
492
+ # for N in range(len(originalContour)):
493
+ # originalContour[N] == reversedContour[-N]
494
+ contour.append(contour.pop(0))
495
+ # Find the first on-curve point.
496
+ firstOnCurve = None
497
+ for i in range(len(contour)):
498
+ if contour[i][1] is not None:
499
+ firstOnCurve = i
500
+ break
501
+ if firstOnCurve is None:
502
+ # There are no on-curve points, be basically have to
503
+ # do nothing but contour.reverse().
504
+ lastSegmentType = None
505
+ else:
506
+ lastSegmentType = contour[firstOnCurve][1]
507
+
508
+ contour.reverse()
509
+ if not closed:
510
+ # Open paths must start with a move, so we simply dump
511
+ # all off-curve points leading up to the first on-curve.
512
+ while contour[0][1] is None:
513
+ contour.pop(0)
514
+ pen.beginPath(identifier=self.currentContourIdentifier)
515
+ for pt, nextSegmentType, smooth, name, kwargs in contour:
516
+ if nextSegmentType is not None:
517
+ segmentType = lastSegmentType
518
+ lastSegmentType = nextSegmentType
519
+ else:
520
+ segmentType = None
521
+ pen.addPoint(
522
+ pt, segmentType=segmentType, smooth=smooth, name=name, **kwargs
523
+ )
524
+ pen.endPath()
525
+
526
+ def beginPath(self, identifier=None, **kwargs):
527
+ if self.currentContour is not None:
528
+ raise PenError("Path already begun")
529
+ self.currentContour = []
530
+ self.currentContourIdentifier = identifier
531
+ self.onCurve = []
532
+
533
+ def endPath(self):
534
+ if self.currentContour is None:
535
+ raise PenError("Path not begun")
536
+ self._flushContour()
537
+ self.currentContour = None
538
+
539
+ def addPoint(
540
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
541
+ ):
542
+ if self.currentContour is None:
543
+ raise PenError("Path not begun")
544
+ if identifier is not None:
545
+ kwargs["identifier"] = identifier
546
+ self.currentContour.append((pt, segmentType, smooth, name, kwargs))
547
+
548
+ def addComponent(self, glyphName, transform, identifier=None, **kwargs):
549
+ if self.currentContour is not None:
550
+ raise PenError("Components must be added before or after contours")
551
+ self.pen.addComponent(glyphName, transform, identifier=identifier, **kwargs)
552
+
553
+
554
+ class DecomposingPointPen(LogMixin, AbstractPointPen):
555
+ """Implements a 'addComponent' method that decomposes components
556
+ (i.e. draws them onto self as simple contours).
557
+ It can also be used as a mixin class (e.g. see DecomposingRecordingPointPen).
558
+
559
+ You must override beginPath, addPoint, endPath. You may
560
+ additionally override addVarComponent and addComponent.
561
+
562
+ By default a warning message is logged when a base glyph is missing;
563
+ set the class variable ``skipMissingComponents`` to False if you want
564
+ all instances of a sub-class to raise a :class:`MissingComponentError`
565
+ exception by default.
566
+ """
567
+
568
+ skipMissingComponents = True
569
+ # alias error for convenience
570
+ MissingComponentError = MissingComponentError
571
+
572
+ def __init__(
573
+ self,
574
+ glyphSet,
575
+ *args,
576
+ skipMissingComponents=None,
577
+ reverseFlipped: bool | ReverseFlipped = False,
578
+ **kwargs,
579
+ ):
580
+ """Takes a 'glyphSet' argument (dict), in which the glyphs that are referenced
581
+ as components are looked up by their name.
582
+
583
+ If the optional 'reverseFlipped' argument is True or a ReverseFlipped enum value,
584
+ components whose transformation matrix has a negative determinant will be decomposed
585
+ with a reversed path direction to compensate for the flip.
586
+
587
+ The reverseFlipped parameter can be:
588
+ - False or ReverseFlipped.NO: Don't reverse flipped components
589
+ - True or ReverseFlipped.KEEP_START: Reverse, keeping original starting point
590
+ - ReverseFlipped.ON_CURVE_FIRST: Reverse, ensuring first point is on-curve
591
+
592
+ The optional 'skipMissingComponents' argument can be set to True/False to
593
+ override the homonymous class attribute for a given pen instance.
594
+ """
595
+ super().__init__(*args, **kwargs)
596
+ self.glyphSet = glyphSet
597
+ self.skipMissingComponents = (
598
+ self.__class__.skipMissingComponents
599
+ if skipMissingComponents is None
600
+ else skipMissingComponents
601
+ )
602
+ # Handle backward compatibility and validate string inputs
603
+ if reverseFlipped is False:
604
+ self.reverseFlipped = ReverseFlipped.NO
605
+ elif reverseFlipped is True:
606
+ self.reverseFlipped = ReverseFlipped.KEEP_START
607
+ else:
608
+ self.reverseFlipped = ReverseFlipped(reverseFlipped)
609
+
610
+ def addComponent(self, baseGlyphName, transformation, identifier=None, **kwargs):
611
+ """Transform the points of the base glyph and draw it onto self.
612
+
613
+ The `identifier` parameter and any extra kwargs are ignored.
614
+ """
615
+ from fontTools.pens.transformPen import TransformPointPen
616
+
617
+ try:
618
+ glyph = self.glyphSet[baseGlyphName]
619
+ except KeyError:
620
+ if not self.skipMissingComponents:
621
+ raise MissingComponentError(baseGlyphName)
622
+ self.log.warning(
623
+ "glyph '%s' is missing from glyphSet; skipped" % baseGlyphName
624
+ )
625
+ else:
626
+ pen = self
627
+ if transformation != Identity:
628
+ pen = TransformPointPen(pen, transformation)
629
+ if self.reverseFlipped != ReverseFlipped.NO:
630
+ # if the transformation has a negative determinant, it will
631
+ # reverse the contour direction of the component
632
+ a, b, c, d = transformation[:4]
633
+ if a * d - b * c < 0:
634
+ pen = ReverseContourPointPen(pen)
635
+
636
+ if self.reverseFlipped == ReverseFlipped.ON_CURVE_FIRST:
637
+ from fontTools.pens.filterPen import OnCurveFirstPointPen
638
+
639
+ # Ensure the starting point is an on-curve.
640
+ # Wrap last so this filter runs first during drawPoints
641
+ pen = OnCurveFirstPointPen(pen)
642
+
643
+ glyph.drawPoints(pen)
@@ -0,0 +1,29 @@
1
+ from fontTools.pens.basePen import BasePen
2
+
3
+
4
+ __all__ = ["QtPen"]
5
+
6
+
7
+ class QtPen(BasePen):
8
+ def __init__(self, glyphSet, path=None):
9
+ BasePen.__init__(self, glyphSet)
10
+ if path is None:
11
+ from PyQt5.QtGui import QPainterPath
12
+
13
+ path = QPainterPath()
14
+ self.path = path
15
+
16
+ def _moveTo(self, p):
17
+ self.path.moveTo(*p)
18
+
19
+ def _lineTo(self, p):
20
+ self.path.lineTo(*p)
21
+
22
+ def _curveToOne(self, p1, p2, p3):
23
+ self.path.cubicTo(*p1, *p2, *p3)
24
+
25
+ def _qCurveToOne(self, p1, p2):
26
+ self.path.quadTo(*p1, *p2)
27
+
28
+ def _closePath(self):
29
+ self.path.closeSubpath()