fonttools 4.55.6__cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fonttools might be problematic. Click here for more details.

Files changed (329) hide show
  1. fontTools/__init__.py +8 -0
  2. fontTools/__main__.py +35 -0
  3. fontTools/afmLib.py +439 -0
  4. fontTools/agl.py +5233 -0
  5. fontTools/cffLib/CFF2ToCFF.py +203 -0
  6. fontTools/cffLib/CFFToCFF2.py +305 -0
  7. fontTools/cffLib/__init__.py +3659 -0
  8. fontTools/cffLib/specializer.py +924 -0
  9. fontTools/cffLib/transforms.py +490 -0
  10. fontTools/cffLib/width.py +210 -0
  11. fontTools/colorLib/__init__.py +0 -0
  12. fontTools/colorLib/builder.py +664 -0
  13. fontTools/colorLib/errors.py +2 -0
  14. fontTools/colorLib/geometry.py +143 -0
  15. fontTools/colorLib/table_builder.py +223 -0
  16. fontTools/colorLib/unbuilder.py +81 -0
  17. fontTools/config/__init__.py +75 -0
  18. fontTools/cu2qu/__init__.py +15 -0
  19. fontTools/cu2qu/__main__.py +6 -0
  20. fontTools/cu2qu/benchmark.py +54 -0
  21. fontTools/cu2qu/cli.py +198 -0
  22. fontTools/cu2qu/cu2qu.c +14829 -0
  23. fontTools/cu2qu/cu2qu.cpython-39-x86_64-linux-gnu.so +0 -0
  24. fontTools/cu2qu/cu2qu.py +531 -0
  25. fontTools/cu2qu/errors.py +77 -0
  26. fontTools/cu2qu/ufo.py +349 -0
  27. fontTools/designspaceLib/__init__.py +3338 -0
  28. fontTools/designspaceLib/__main__.py +6 -0
  29. fontTools/designspaceLib/split.py +475 -0
  30. fontTools/designspaceLib/statNames.py +253 -0
  31. fontTools/designspaceLib/types.py +147 -0
  32. fontTools/encodings/MacRoman.py +258 -0
  33. fontTools/encodings/StandardEncoding.py +258 -0
  34. fontTools/encodings/__init__.py +1 -0
  35. fontTools/encodings/codecs.py +135 -0
  36. fontTools/feaLib/__init__.py +4 -0
  37. fontTools/feaLib/__main__.py +78 -0
  38. fontTools/feaLib/ast.py +2134 -0
  39. fontTools/feaLib/builder.py +1747 -0
  40. fontTools/feaLib/error.py +22 -0
  41. fontTools/feaLib/lexer.c +17986 -0
  42. fontTools/feaLib/lexer.cpython-39-x86_64-linux-gnu.so +0 -0
  43. fontTools/feaLib/lexer.py +287 -0
  44. fontTools/feaLib/location.py +12 -0
  45. fontTools/feaLib/lookupDebugInfo.py +12 -0
  46. fontTools/feaLib/parser.py +2359 -0
  47. fontTools/feaLib/variableScalar.py +113 -0
  48. fontTools/fontBuilder.py +1008 -0
  49. fontTools/help.py +36 -0
  50. fontTools/merge/__init__.py +248 -0
  51. fontTools/merge/__main__.py +6 -0
  52. fontTools/merge/base.py +81 -0
  53. fontTools/merge/cmap.py +141 -0
  54. fontTools/merge/layout.py +526 -0
  55. fontTools/merge/options.py +85 -0
  56. fontTools/merge/tables.py +341 -0
  57. fontTools/merge/unicode.py +78 -0
  58. fontTools/merge/util.py +143 -0
  59. fontTools/misc/__init__.py +1 -0
  60. fontTools/misc/arrayTools.py +424 -0
  61. fontTools/misc/bezierTools.c +41831 -0
  62. fontTools/misc/bezierTools.cpython-39-x86_64-linux-gnu.so +0 -0
  63. fontTools/misc/bezierTools.py +1497 -0
  64. fontTools/misc/classifyTools.py +170 -0
  65. fontTools/misc/cliTools.py +53 -0
  66. fontTools/misc/configTools.py +349 -0
  67. fontTools/misc/cython.py +27 -0
  68. fontTools/misc/dictTools.py +83 -0
  69. fontTools/misc/eexec.py +119 -0
  70. fontTools/misc/encodingTools.py +72 -0
  71. fontTools/misc/etree.py +479 -0
  72. fontTools/misc/filenames.py +245 -0
  73. fontTools/misc/fixedTools.py +253 -0
  74. fontTools/misc/intTools.py +25 -0
  75. fontTools/misc/iterTools.py +12 -0
  76. fontTools/misc/lazyTools.py +42 -0
  77. fontTools/misc/loggingTools.py +543 -0
  78. fontTools/misc/macCreatorType.py +56 -0
  79. fontTools/misc/macRes.py +261 -0
  80. fontTools/misc/plistlib/__init__.py +681 -0
  81. fontTools/misc/plistlib/py.typed +0 -0
  82. fontTools/misc/psCharStrings.py +1496 -0
  83. fontTools/misc/psLib.py +398 -0
  84. fontTools/misc/psOperators.py +572 -0
  85. fontTools/misc/py23.py +96 -0
  86. fontTools/misc/roundTools.py +110 -0
  87. fontTools/misc/sstruct.py +231 -0
  88. fontTools/misc/symfont.py +244 -0
  89. fontTools/misc/testTools.py +229 -0
  90. fontTools/misc/textTools.py +154 -0
  91. fontTools/misc/timeTools.py +88 -0
  92. fontTools/misc/transform.py +516 -0
  93. fontTools/misc/treeTools.py +45 -0
  94. fontTools/misc/vector.py +147 -0
  95. fontTools/misc/visitor.py +142 -0
  96. fontTools/misc/xmlReader.py +188 -0
  97. fontTools/misc/xmlWriter.py +204 -0
  98. fontTools/mtiLib/__init__.py +1402 -0
  99. fontTools/mtiLib/__main__.py +5 -0
  100. fontTools/otlLib/__init__.py +1 -0
  101. fontTools/otlLib/builder.py +3221 -0
  102. fontTools/otlLib/error.py +11 -0
  103. fontTools/otlLib/maxContextCalc.py +96 -0
  104. fontTools/otlLib/optimize/__init__.py +53 -0
  105. fontTools/otlLib/optimize/__main__.py +6 -0
  106. fontTools/otlLib/optimize/gpos.py +453 -0
  107. fontTools/pens/__init__.py +1 -0
  108. fontTools/pens/areaPen.py +52 -0
  109. fontTools/pens/basePen.py +475 -0
  110. fontTools/pens/boundsPen.py +98 -0
  111. fontTools/pens/cairoPen.py +26 -0
  112. fontTools/pens/cocoaPen.py +26 -0
  113. fontTools/pens/cu2quPen.py +325 -0
  114. fontTools/pens/explicitClosingLinePen.py +101 -0
  115. fontTools/pens/filterPen.py +241 -0
  116. fontTools/pens/freetypePen.py +462 -0
  117. fontTools/pens/hashPointPen.py +89 -0
  118. fontTools/pens/momentsPen.c +13448 -0
  119. fontTools/pens/momentsPen.cpython-39-x86_64-linux-gnu.so +0 -0
  120. fontTools/pens/momentsPen.py +879 -0
  121. fontTools/pens/perimeterPen.py +69 -0
  122. fontTools/pens/pointInsidePen.py +192 -0
  123. fontTools/pens/pointPen.py +600 -0
  124. fontTools/pens/qtPen.py +29 -0
  125. fontTools/pens/qu2cuPen.py +105 -0
  126. fontTools/pens/quartzPen.py +43 -0
  127. fontTools/pens/recordingPen.py +335 -0
  128. fontTools/pens/reportLabPen.py +79 -0
  129. fontTools/pens/reverseContourPen.py +96 -0
  130. fontTools/pens/roundingPen.py +130 -0
  131. fontTools/pens/statisticsPen.py +312 -0
  132. fontTools/pens/svgPathPen.py +310 -0
  133. fontTools/pens/t2CharStringPen.py +68 -0
  134. fontTools/pens/teePen.py +55 -0
  135. fontTools/pens/transformPen.py +115 -0
  136. fontTools/pens/ttGlyphPen.py +335 -0
  137. fontTools/pens/wxPen.py +29 -0
  138. fontTools/qu2cu/__init__.py +15 -0
  139. fontTools/qu2cu/__main__.py +7 -0
  140. fontTools/qu2cu/benchmark.py +56 -0
  141. fontTools/qu2cu/cli.py +125 -0
  142. fontTools/qu2cu/qu2cu.c +16269 -0
  143. fontTools/qu2cu/qu2cu.cpython-39-x86_64-linux-gnu.so +0 -0
  144. fontTools/qu2cu/qu2cu.py +405 -0
  145. fontTools/subset/__init__.py +3838 -0
  146. fontTools/subset/__main__.py +6 -0
  147. fontTools/subset/cff.py +184 -0
  148. fontTools/subset/svg.py +253 -0
  149. fontTools/subset/util.py +25 -0
  150. fontTools/svgLib/__init__.py +3 -0
  151. fontTools/svgLib/path/__init__.py +65 -0
  152. fontTools/svgLib/path/arc.py +154 -0
  153. fontTools/svgLib/path/parser.py +322 -0
  154. fontTools/svgLib/path/shapes.py +183 -0
  155. fontTools/t1Lib/__init__.py +648 -0
  156. fontTools/tfmLib.py +460 -0
  157. fontTools/ttLib/__init__.py +26 -0
  158. fontTools/ttLib/__main__.py +109 -0
  159. fontTools/ttLib/macUtils.py +54 -0
  160. fontTools/ttLib/removeOverlaps.py +393 -0
  161. fontTools/ttLib/reorderGlyphs.py +284 -0
  162. fontTools/ttLib/scaleUpem.py +436 -0
  163. fontTools/ttLib/sfnt.py +662 -0
  164. fontTools/ttLib/standardGlyphOrder.py +271 -0
  165. fontTools/ttLib/tables/B_A_S_E_.py +14 -0
  166. fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
  167. fontTools/ttLib/tables/C_B_D_T_.py +113 -0
  168. fontTools/ttLib/tables/C_B_L_C_.py +19 -0
  169. fontTools/ttLib/tables/C_F_F_.py +61 -0
  170. fontTools/ttLib/tables/C_F_F__2.py +26 -0
  171. fontTools/ttLib/tables/C_O_L_R_.py +165 -0
  172. fontTools/ttLib/tables/C_P_A_L_.py +305 -0
  173. fontTools/ttLib/tables/D_S_I_G_.py +158 -0
  174. fontTools/ttLib/tables/D__e_b_g.py +17 -0
  175. fontTools/ttLib/tables/DefaultTable.py +49 -0
  176. fontTools/ttLib/tables/E_B_D_T_.py +835 -0
  177. fontTools/ttLib/tables/E_B_L_C_.py +718 -0
  178. fontTools/ttLib/tables/F_F_T_M_.py +52 -0
  179. fontTools/ttLib/tables/F__e_a_t.py +149 -0
  180. fontTools/ttLib/tables/G_D_E_F_.py +13 -0
  181. fontTools/ttLib/tables/G_M_A_P_.py +148 -0
  182. fontTools/ttLib/tables/G_P_K_G_.py +133 -0
  183. fontTools/ttLib/tables/G_P_O_S_.py +14 -0
  184. fontTools/ttLib/tables/G_S_U_B_.py +13 -0
  185. fontTools/ttLib/tables/G__l_a_t.py +235 -0
  186. fontTools/ttLib/tables/G__l_o_c.py +85 -0
  187. fontTools/ttLib/tables/H_V_A_R_.py +13 -0
  188. fontTools/ttLib/tables/J_S_T_F_.py +13 -0
  189. fontTools/ttLib/tables/L_T_S_H_.py +58 -0
  190. fontTools/ttLib/tables/M_A_T_H_.py +13 -0
  191. fontTools/ttLib/tables/M_E_T_A_.py +352 -0
  192. fontTools/ttLib/tables/M_V_A_R_.py +13 -0
  193. fontTools/ttLib/tables/O_S_2f_2.py +752 -0
  194. fontTools/ttLib/tables/S_I_N_G_.py +99 -0
  195. fontTools/ttLib/tables/S_T_A_T_.py +15 -0
  196. fontTools/ttLib/tables/S_V_G_.py +223 -0
  197. fontTools/ttLib/tables/S__i_l_f.py +1040 -0
  198. fontTools/ttLib/tables/S__i_l_l.py +92 -0
  199. fontTools/ttLib/tables/T_S_I_B_.py +13 -0
  200. fontTools/ttLib/tables/T_S_I_C_.py +14 -0
  201. fontTools/ttLib/tables/T_S_I_D_.py +13 -0
  202. fontTools/ttLib/tables/T_S_I_J_.py +13 -0
  203. fontTools/ttLib/tables/T_S_I_P_.py +13 -0
  204. fontTools/ttLib/tables/T_S_I_S_.py +13 -0
  205. fontTools/ttLib/tables/T_S_I_V_.py +26 -0
  206. fontTools/ttLib/tables/T_S_I__0.py +59 -0
  207. fontTools/ttLib/tables/T_S_I__1.py +166 -0
  208. fontTools/ttLib/tables/T_S_I__2.py +17 -0
  209. fontTools/ttLib/tables/T_S_I__3.py +22 -0
  210. fontTools/ttLib/tables/T_S_I__5.py +49 -0
  211. fontTools/ttLib/tables/T_T_F_A_.py +14 -0
  212. fontTools/ttLib/tables/TupleVariation.py +884 -0
  213. fontTools/ttLib/tables/V_A_R_C_.py +12 -0
  214. fontTools/ttLib/tables/V_D_M_X_.py +249 -0
  215. fontTools/ttLib/tables/V_O_R_G_.py +165 -0
  216. fontTools/ttLib/tables/V_V_A_R_.py +13 -0
  217. fontTools/ttLib/tables/__init__.py +97 -0
  218. fontTools/ttLib/tables/_a_n_k_r.py +15 -0
  219. fontTools/ttLib/tables/_a_v_a_r.py +191 -0
  220. fontTools/ttLib/tables/_b_s_l_n.py +15 -0
  221. fontTools/ttLib/tables/_c_i_d_g.py +24 -0
  222. fontTools/ttLib/tables/_c_m_a_p.py +1578 -0
  223. fontTools/ttLib/tables/_c_v_a_r.py +94 -0
  224. fontTools/ttLib/tables/_c_v_t.py +55 -0
  225. fontTools/ttLib/tables/_f_e_a_t.py +15 -0
  226. fontTools/ttLib/tables/_f_p_g_m.py +60 -0
  227. fontTools/ttLib/tables/_f_v_a_r.py +261 -0
  228. fontTools/ttLib/tables/_g_a_s_p.py +63 -0
  229. fontTools/ttLib/tables/_g_c_i_d.py +13 -0
  230. fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
  231. fontTools/ttLib/tables/_g_v_a_r.py +292 -0
  232. fontTools/ttLib/tables/_h_d_m_x.py +127 -0
  233. fontTools/ttLib/tables/_h_e_a_d.py +130 -0
  234. fontTools/ttLib/tables/_h_h_e_a.py +147 -0
  235. fontTools/ttLib/tables/_h_m_t_x.py +160 -0
  236. fontTools/ttLib/tables/_k_e_r_n.py +289 -0
  237. fontTools/ttLib/tables/_l_c_a_r.py +13 -0
  238. fontTools/ttLib/tables/_l_o_c_a.py +70 -0
  239. fontTools/ttLib/tables/_l_t_a_g.py +72 -0
  240. fontTools/ttLib/tables/_m_a_x_p.py +147 -0
  241. fontTools/ttLib/tables/_m_e_t_a.py +112 -0
  242. fontTools/ttLib/tables/_m_o_r_t.py +14 -0
  243. fontTools/ttLib/tables/_m_o_r_x.py +15 -0
  244. fontTools/ttLib/tables/_n_a_m_e.py +1237 -0
  245. fontTools/ttLib/tables/_o_p_b_d.py +14 -0
  246. fontTools/ttLib/tables/_p_o_s_t.py +317 -0
  247. fontTools/ttLib/tables/_p_r_e_p.py +16 -0
  248. fontTools/ttLib/tables/_p_r_o_p.py +12 -0
  249. fontTools/ttLib/tables/_s_b_i_x.py +129 -0
  250. fontTools/ttLib/tables/_t_r_a_k.py +332 -0
  251. fontTools/ttLib/tables/_v_h_e_a.py +139 -0
  252. fontTools/ttLib/tables/_v_m_t_x.py +19 -0
  253. fontTools/ttLib/tables/asciiTable.py +20 -0
  254. fontTools/ttLib/tables/grUtils.py +92 -0
  255. fontTools/ttLib/tables/otBase.py +1465 -0
  256. fontTools/ttLib/tables/otConverters.py +2065 -0
  257. fontTools/ttLib/tables/otData.py +6400 -0
  258. fontTools/ttLib/tables/otTables.py +2700 -0
  259. fontTools/ttLib/tables/otTraverse.py +162 -0
  260. fontTools/ttLib/tables/sbixGlyph.py +149 -0
  261. fontTools/ttLib/tables/sbixStrike.py +177 -0
  262. fontTools/ttLib/tables/table_API_readme.txt +91 -0
  263. fontTools/ttLib/tables/ttProgram.py +594 -0
  264. fontTools/ttLib/ttCollection.py +125 -0
  265. fontTools/ttLib/ttFont.py +1155 -0
  266. fontTools/ttLib/ttGlyphSet.py +500 -0
  267. fontTools/ttLib/ttVisitor.py +32 -0
  268. fontTools/ttLib/woff2.py +1683 -0
  269. fontTools/ttx.py +467 -0
  270. fontTools/ufoLib/__init__.py +2477 -0
  271. fontTools/ufoLib/converters.py +334 -0
  272. fontTools/ufoLib/errors.py +22 -0
  273. fontTools/ufoLib/etree.py +6 -0
  274. fontTools/ufoLib/filenames.py +291 -0
  275. fontTools/ufoLib/glifLib.py +2022 -0
  276. fontTools/ufoLib/kerning.py +91 -0
  277. fontTools/ufoLib/plistlib.py +47 -0
  278. fontTools/ufoLib/pointPen.py +6 -0
  279. fontTools/ufoLib/utils.py +76 -0
  280. fontTools/ufoLib/validators.py +1186 -0
  281. fontTools/unicode.py +50 -0
  282. fontTools/unicodedata/Blocks.py +802 -0
  283. fontTools/unicodedata/OTTags.py +50 -0
  284. fontTools/unicodedata/ScriptExtensions.py +806 -0
  285. fontTools/unicodedata/Scripts.py +3618 -0
  286. fontTools/unicodedata/__init__.py +298 -0
  287. fontTools/varLib/__init__.py +1511 -0
  288. fontTools/varLib/__main__.py +6 -0
  289. fontTools/varLib/avar.py +260 -0
  290. fontTools/varLib/avarPlanner.py +1004 -0
  291. fontTools/varLib/builder.py +215 -0
  292. fontTools/varLib/cff.py +631 -0
  293. fontTools/varLib/errors.py +219 -0
  294. fontTools/varLib/featureVars.py +689 -0
  295. fontTools/varLib/instancer/__init__.py +1937 -0
  296. fontTools/varLib/instancer/__main__.py +5 -0
  297. fontTools/varLib/instancer/featureVars.py +190 -0
  298. fontTools/varLib/instancer/names.py +388 -0
  299. fontTools/varLib/instancer/solver.py +309 -0
  300. fontTools/varLib/interpolatable.py +1209 -0
  301. fontTools/varLib/interpolatableHelpers.py +396 -0
  302. fontTools/varLib/interpolatablePlot.py +1269 -0
  303. fontTools/varLib/interpolatableTestContourOrder.py +82 -0
  304. fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
  305. fontTools/varLib/interpolate_layout.py +124 -0
  306. fontTools/varLib/iup.c +19154 -0
  307. fontTools/varLib/iup.cpython-39-x86_64-linux-gnu.so +0 -0
  308. fontTools/varLib/iup.py +490 -0
  309. fontTools/varLib/merger.py +1717 -0
  310. fontTools/varLib/models.py +642 -0
  311. fontTools/varLib/multiVarStore.py +253 -0
  312. fontTools/varLib/mutator.py +518 -0
  313. fontTools/varLib/mvar.py +40 -0
  314. fontTools/varLib/plot.py +238 -0
  315. fontTools/varLib/stat.py +149 -0
  316. fontTools/varLib/varStore.py +767 -0
  317. fontTools/voltLib/__init__.py +5 -0
  318. fontTools/voltLib/ast.py +448 -0
  319. fontTools/voltLib/error.py +12 -0
  320. fontTools/voltLib/lexer.py +99 -0
  321. fontTools/voltLib/parser.py +656 -0
  322. fontTools/voltLib/voltToFea.py +730 -0
  323. fonttools-4.55.6.data/data/share/man/man1/ttx.1 +225 -0
  324. fonttools-4.55.6.dist-info/LICENSE +21 -0
  325. fonttools-4.55.6.dist-info/METADATA +3413 -0
  326. fonttools-4.55.6.dist-info/RECORD +329 -0
  327. fonttools-4.55.6.dist-info/WHEEL +6 -0
  328. fonttools-4.55.6.dist-info/entry_points.txt +5 -0
  329. fonttools-4.55.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,600 @@
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
+ import math
16
+ from typing import Any, Optional, Tuple, Dict
17
+
18
+ from fontTools.misc.loggingTools import LogMixin
19
+ from fontTools.pens.basePen import AbstractPen, MissingComponentError, PenError
20
+ from fontTools.misc.transform import DecomposedTransform, Identity
21
+
22
+ __all__ = [
23
+ "AbstractPointPen",
24
+ "BasePointToSegmentPen",
25
+ "PointToSegmentPen",
26
+ "SegmentToPointPen",
27
+ "GuessSmoothPointPen",
28
+ "ReverseContourPointPen",
29
+ ]
30
+
31
+
32
+ class AbstractPointPen:
33
+ """Baseclass for all PointPens."""
34
+
35
+ def beginPath(self, identifier: Optional[str] = None, **kwargs: Any) -> None:
36
+ """Start a new sub path."""
37
+ raise NotImplementedError
38
+
39
+ def endPath(self) -> None:
40
+ """End the current sub path."""
41
+ raise NotImplementedError
42
+
43
+ def addPoint(
44
+ self,
45
+ pt: Tuple[float, float],
46
+ segmentType: Optional[str] = None,
47
+ smooth: bool = False,
48
+ name: Optional[str] = None,
49
+ identifier: Optional[str] = None,
50
+ **kwargs: Any,
51
+ ) -> None:
52
+ """Add a point to the current sub path."""
53
+ raise NotImplementedError
54
+
55
+ def addComponent(
56
+ self,
57
+ baseGlyphName: str,
58
+ transformation: Tuple[float, float, float, float, float, float],
59
+ identifier: Optional[str] = None,
60
+ **kwargs: Any,
61
+ ) -> None:
62
+ """Add a sub glyph."""
63
+ raise NotImplementedError
64
+
65
+ def addVarComponent(
66
+ self,
67
+ glyphName: str,
68
+ transformation: DecomposedTransform,
69
+ location: Dict[str, float],
70
+ identifier: Optional[str] = None,
71
+ **kwargs: Any,
72
+ ) -> None:
73
+ """Add a VarComponent sub glyph. The 'transformation' argument
74
+ must be a DecomposedTransform from the fontTools.misc.transform module,
75
+ and the 'location' argument must be a dictionary mapping axis tags
76
+ to their locations.
77
+ """
78
+ # ttGlyphSet decomposes for us
79
+ raise AttributeError
80
+
81
+
82
+ class BasePointToSegmentPen(AbstractPointPen):
83
+ """
84
+ Base class for retrieving the outline in a segment-oriented
85
+ way. The PointPen protocol is simple yet also a little tricky,
86
+ so when you need an outline presented as segments but you have
87
+ as points, do use this base implementation as it properly takes
88
+ care of all the edge cases.
89
+ """
90
+
91
+ def __init__(self):
92
+ self.currentPath = None
93
+
94
+ def beginPath(self, identifier=None, **kwargs):
95
+ if self.currentPath is not None:
96
+ raise PenError("Path already begun.")
97
+ self.currentPath = []
98
+
99
+ def _flushContour(self, segments):
100
+ """Override this method.
101
+
102
+ It will be called for each non-empty sub path with a list
103
+ of segments: the 'segments' argument.
104
+
105
+ The segments list contains tuples of length 2:
106
+ (segmentType, points)
107
+
108
+ segmentType is one of "move", "line", "curve" or "qcurve".
109
+ "move" may only occur as the first segment, and it signifies
110
+ an OPEN path. A CLOSED path does NOT start with a "move", in
111
+ fact it will not contain a "move" at ALL.
112
+
113
+ The 'points' field in the 2-tuple is a list of point info
114
+ tuples. The list has 1 or more items, a point tuple has
115
+ four items:
116
+ (point, smooth, name, kwargs)
117
+ 'point' is an (x, y) coordinate pair.
118
+
119
+ For a closed path, the initial moveTo point is defined as
120
+ the last point of the last segment.
121
+
122
+ The 'points' list of "move" and "line" segments always contains
123
+ exactly one point tuple.
124
+ """
125
+ raise NotImplementedError
126
+
127
+ def endPath(self):
128
+ if self.currentPath is None:
129
+ raise PenError("Path not begun.")
130
+ points = self.currentPath
131
+ self.currentPath = None
132
+ if not points:
133
+ return
134
+ if len(points) == 1:
135
+ # Not much more we can do than output a single move segment.
136
+ pt, segmentType, smooth, name, kwargs = points[0]
137
+ segments = [("move", [(pt, smooth, name, kwargs)])]
138
+ self._flushContour(segments)
139
+ return
140
+ segments = []
141
+ if points[0][1] == "move":
142
+ # It's an open contour, insert a "move" segment for the first
143
+ # point and remove that first point from the point list.
144
+ pt, segmentType, smooth, name, kwargs = points[0]
145
+ segments.append(("move", [(pt, smooth, name, kwargs)]))
146
+ points.pop(0)
147
+ else:
148
+ # It's a closed contour. Locate the first on-curve point, and
149
+ # rotate the point list so that it _ends_ with an on-curve
150
+ # point.
151
+ firstOnCurve = None
152
+ for i in range(len(points)):
153
+ segmentType = points[i][1]
154
+ if segmentType is not None:
155
+ firstOnCurve = i
156
+ break
157
+ if firstOnCurve is None:
158
+ # Special case for quadratics: a contour with no on-curve
159
+ # points. Add a "None" point. (See also the Pen protocol's
160
+ # qCurveTo() method and fontTools.pens.basePen.py.)
161
+ points.append((None, "qcurve", None, None, None))
162
+ else:
163
+ points = points[firstOnCurve + 1 :] + points[: firstOnCurve + 1]
164
+
165
+ currentSegment = []
166
+ for pt, segmentType, smooth, name, kwargs in points:
167
+ currentSegment.append((pt, smooth, name, kwargs))
168
+ if segmentType is None:
169
+ continue
170
+ segments.append((segmentType, currentSegment))
171
+ currentSegment = []
172
+
173
+ self._flushContour(segments)
174
+
175
+ def addPoint(
176
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
177
+ ):
178
+ if self.currentPath is None:
179
+ raise PenError("Path not begun")
180
+ self.currentPath.append((pt, segmentType, smooth, name, kwargs))
181
+
182
+
183
+ class PointToSegmentPen(BasePointToSegmentPen):
184
+ """
185
+ Adapter class that converts the PointPen protocol to the
186
+ (Segment)Pen protocol.
187
+
188
+ NOTE: The segment pen does not support and will drop point names, identifiers
189
+ and kwargs.
190
+ """
191
+
192
+ def __init__(self, segmentPen, outputImpliedClosingLine=False):
193
+ BasePointToSegmentPen.__init__(self)
194
+ self.pen = segmentPen
195
+ self.outputImpliedClosingLine = outputImpliedClosingLine
196
+
197
+ def _flushContour(self, segments):
198
+ if not segments:
199
+ raise PenError("Must have at least one segment.")
200
+ pen = self.pen
201
+ if segments[0][0] == "move":
202
+ # It's an open path.
203
+ closed = False
204
+ points = segments[0][1]
205
+ if len(points) != 1:
206
+ raise PenError(f"Illegal move segment point count: {len(points)}")
207
+ movePt, _, _, _ = points[0]
208
+ del segments[0]
209
+ else:
210
+ # It's a closed path, do a moveTo to the last
211
+ # point of the last segment.
212
+ closed = True
213
+ segmentType, points = segments[-1]
214
+ movePt, _, _, _ = points[-1]
215
+ if movePt is None:
216
+ # quad special case: a contour with no on-curve points contains
217
+ # one "qcurve" segment that ends with a point that's None. We
218
+ # must not output a moveTo() in that case.
219
+ pass
220
+ else:
221
+ pen.moveTo(movePt)
222
+ outputImpliedClosingLine = self.outputImpliedClosingLine
223
+ nSegments = len(segments)
224
+ lastPt = movePt
225
+ for i in range(nSegments):
226
+ segmentType, points = segments[i]
227
+ points = [pt for pt, _, _, _ in points]
228
+ if segmentType == "line":
229
+ if len(points) != 1:
230
+ raise PenError(f"Illegal line segment point count: {len(points)}")
231
+ pt = points[0]
232
+ # For closed contours, a 'lineTo' is always implied from the last oncurve
233
+ # point to the starting point, thus we can omit it when the last and
234
+ # starting point don't overlap.
235
+ # However, when the last oncurve point is a "line" segment and has same
236
+ # coordinates as the starting point of a closed contour, we need to output
237
+ # the closing 'lineTo' explicitly (regardless of the value of the
238
+ # 'outputImpliedClosingLine' option) in order to disambiguate this case from
239
+ # the implied closing 'lineTo', otherwise the duplicate point would be lost.
240
+ # See https://github.com/googlefonts/fontmake/issues/572.
241
+ if (
242
+ i + 1 != nSegments
243
+ or outputImpliedClosingLine
244
+ or not closed
245
+ or pt == lastPt
246
+ ):
247
+ pen.lineTo(pt)
248
+ lastPt = pt
249
+ elif segmentType == "curve":
250
+ pen.curveTo(*points)
251
+ lastPt = points[-1]
252
+ elif segmentType == "qcurve":
253
+ pen.qCurveTo(*points)
254
+ lastPt = points[-1]
255
+ else:
256
+ raise PenError(f"Illegal segmentType: {segmentType}")
257
+ if closed:
258
+ pen.closePath()
259
+ else:
260
+ pen.endPath()
261
+
262
+ def addComponent(self, glyphName, transform, identifier=None, **kwargs):
263
+ del identifier # unused
264
+ del kwargs # unused
265
+ self.pen.addComponent(glyphName, transform)
266
+
267
+
268
+ class SegmentToPointPen(AbstractPen):
269
+ """
270
+ Adapter class that converts the (Segment)Pen protocol to the
271
+ PointPen protocol.
272
+ """
273
+
274
+ def __init__(self, pointPen, guessSmooth=True):
275
+ if guessSmooth:
276
+ self.pen = GuessSmoothPointPen(pointPen)
277
+ else:
278
+ self.pen = pointPen
279
+ self.contour = None
280
+
281
+ def _flushContour(self):
282
+ pen = self.pen
283
+ pen.beginPath()
284
+ for pt, segmentType in self.contour:
285
+ pen.addPoint(pt, segmentType=segmentType)
286
+ pen.endPath()
287
+
288
+ def moveTo(self, pt):
289
+ self.contour = []
290
+ self.contour.append((pt, "move"))
291
+
292
+ def lineTo(self, pt):
293
+ if self.contour is None:
294
+ raise PenError("Contour missing required initial moveTo")
295
+ self.contour.append((pt, "line"))
296
+
297
+ def curveTo(self, *pts):
298
+ if not pts:
299
+ raise TypeError("Must pass in at least one point")
300
+ if self.contour is None:
301
+ raise PenError("Contour missing required initial moveTo")
302
+ for pt in pts[:-1]:
303
+ self.contour.append((pt, None))
304
+ self.contour.append((pts[-1], "curve"))
305
+
306
+ def qCurveTo(self, *pts):
307
+ if not pts:
308
+ raise TypeError("Must pass in at least one point")
309
+ if pts[-1] is None:
310
+ self.contour = []
311
+ else:
312
+ if self.contour is None:
313
+ raise PenError("Contour missing required initial moveTo")
314
+ for pt in pts[:-1]:
315
+ self.contour.append((pt, None))
316
+ if pts[-1] is not None:
317
+ self.contour.append((pts[-1], "qcurve"))
318
+
319
+ def closePath(self):
320
+ if self.contour is None:
321
+ raise PenError("Contour missing required initial moveTo")
322
+ if len(self.contour) > 1 and self.contour[0][0] == self.contour[-1][0]:
323
+ self.contour[0] = self.contour[-1]
324
+ del self.contour[-1]
325
+ else:
326
+ # There's an implied line at the end, replace "move" with "line"
327
+ # for the first point
328
+ pt, tp = self.contour[0]
329
+ if tp == "move":
330
+ self.contour[0] = pt, "line"
331
+ self._flushContour()
332
+ self.contour = None
333
+
334
+ def endPath(self):
335
+ if self.contour is None:
336
+ raise PenError("Contour missing required initial moveTo")
337
+ self._flushContour()
338
+ self.contour = None
339
+
340
+ def addComponent(self, glyphName, transform):
341
+ if self.contour is not None:
342
+ raise PenError("Components must be added before or after contours")
343
+ self.pen.addComponent(glyphName, transform)
344
+
345
+
346
+ class GuessSmoothPointPen(AbstractPointPen):
347
+ """
348
+ Filtering PointPen that tries to determine whether an on-curve point
349
+ should be "smooth", ie. that it's a "tangent" point or a "curve" point.
350
+ """
351
+
352
+ def __init__(self, outPen, error=0.05):
353
+ self._outPen = outPen
354
+ self._error = error
355
+ self._points = None
356
+
357
+ def _flushContour(self):
358
+ if self._points is None:
359
+ raise PenError("Path not begun")
360
+ points = self._points
361
+ nPoints = len(points)
362
+ if not nPoints:
363
+ return
364
+ if points[0][1] == "move":
365
+ # Open path.
366
+ indices = range(1, nPoints - 1)
367
+ elif nPoints > 1:
368
+ # Closed path. To avoid having to mod the contour index, we
369
+ # simply abuse Python's negative index feature, and start at -1
370
+ indices = range(-1, nPoints - 1)
371
+ else:
372
+ # closed path containing 1 point (!), ignore.
373
+ indices = []
374
+ for i in indices:
375
+ pt, segmentType, _, name, kwargs = points[i]
376
+ if segmentType is None:
377
+ continue
378
+ prev = i - 1
379
+ next = i + 1
380
+ if points[prev][1] is not None and points[next][1] is not None:
381
+ continue
382
+ # At least one of our neighbors is an off-curve point
383
+ pt = points[i][0]
384
+ prevPt = points[prev][0]
385
+ nextPt = points[next][0]
386
+ if pt != prevPt and pt != nextPt:
387
+ dx1, dy1 = pt[0] - prevPt[0], pt[1] - prevPt[1]
388
+ dx2, dy2 = nextPt[0] - pt[0], nextPt[1] - pt[1]
389
+ a1 = math.atan2(dy1, dx1)
390
+ a2 = math.atan2(dy2, dx2)
391
+ if abs(a1 - a2) < self._error:
392
+ points[i] = pt, segmentType, True, name, kwargs
393
+
394
+ for pt, segmentType, smooth, name, kwargs in points:
395
+ self._outPen.addPoint(pt, segmentType, smooth, name, **kwargs)
396
+
397
+ def beginPath(self, identifier=None, **kwargs):
398
+ if self._points is not None:
399
+ raise PenError("Path already begun")
400
+ self._points = []
401
+ if identifier is not None:
402
+ kwargs["identifier"] = identifier
403
+ self._outPen.beginPath(**kwargs)
404
+
405
+ def endPath(self):
406
+ self._flushContour()
407
+ self._outPen.endPath()
408
+ self._points = None
409
+
410
+ def addPoint(
411
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
412
+ ):
413
+ if self._points is None:
414
+ raise PenError("Path not begun")
415
+ if identifier is not None:
416
+ kwargs["identifier"] = identifier
417
+ self._points.append((pt, segmentType, False, name, kwargs))
418
+
419
+ def addComponent(self, glyphName, transformation, identifier=None, **kwargs):
420
+ if self._points is not None:
421
+ raise PenError("Components must be added before or after contours")
422
+ if identifier is not None:
423
+ kwargs["identifier"] = identifier
424
+ self._outPen.addComponent(glyphName, transformation, **kwargs)
425
+
426
+ def addVarComponent(
427
+ self, glyphName, transformation, location, identifier=None, **kwargs
428
+ ):
429
+ if self._points is not None:
430
+ raise PenError("VarComponents must be added before or after contours")
431
+ if identifier is not None:
432
+ kwargs["identifier"] = identifier
433
+ self._outPen.addVarComponent(glyphName, transformation, location, **kwargs)
434
+
435
+
436
+ class ReverseContourPointPen(AbstractPointPen):
437
+ """
438
+ This is a PointPen that passes outline data to another PointPen, but
439
+ reversing the winding direction of all contours. Components are simply
440
+ passed through unchanged.
441
+
442
+ Closed contours are reversed in such a way that the first point remains
443
+ the first point.
444
+ """
445
+
446
+ def __init__(self, outputPointPen):
447
+ self.pen = outputPointPen
448
+ # a place to store the points for the current sub path
449
+ self.currentContour = None
450
+
451
+ def _flushContour(self):
452
+ pen = self.pen
453
+ contour = self.currentContour
454
+ if not contour:
455
+ pen.beginPath(identifier=self.currentContourIdentifier)
456
+ pen.endPath()
457
+ return
458
+
459
+ closed = contour[0][1] != "move"
460
+ if not closed:
461
+ lastSegmentType = "move"
462
+ else:
463
+ # Remove the first point and insert it at the end. When
464
+ # the list of points gets reversed, this point will then
465
+ # again be at the start. In other words, the following
466
+ # will hold:
467
+ # for N in range(len(originalContour)):
468
+ # originalContour[N] == reversedContour[-N]
469
+ contour.append(contour.pop(0))
470
+ # Find the first on-curve point.
471
+ firstOnCurve = None
472
+ for i in range(len(contour)):
473
+ if contour[i][1] is not None:
474
+ firstOnCurve = i
475
+ break
476
+ if firstOnCurve is None:
477
+ # There are no on-curve points, be basically have to
478
+ # do nothing but contour.reverse().
479
+ lastSegmentType = None
480
+ else:
481
+ lastSegmentType = contour[firstOnCurve][1]
482
+
483
+ contour.reverse()
484
+ if not closed:
485
+ # Open paths must start with a move, so we simply dump
486
+ # all off-curve points leading up to the first on-curve.
487
+ while contour[0][1] is None:
488
+ contour.pop(0)
489
+ pen.beginPath(identifier=self.currentContourIdentifier)
490
+ for pt, nextSegmentType, smooth, name, kwargs in contour:
491
+ if nextSegmentType is not None:
492
+ segmentType = lastSegmentType
493
+ lastSegmentType = nextSegmentType
494
+ else:
495
+ segmentType = None
496
+ pen.addPoint(
497
+ pt, segmentType=segmentType, smooth=smooth, name=name, **kwargs
498
+ )
499
+ pen.endPath()
500
+
501
+ def beginPath(self, identifier=None, **kwargs):
502
+ if self.currentContour is not None:
503
+ raise PenError("Path already begun")
504
+ self.currentContour = []
505
+ self.currentContourIdentifier = identifier
506
+ self.onCurve = []
507
+
508
+ def endPath(self):
509
+ if self.currentContour is None:
510
+ raise PenError("Path not begun")
511
+ self._flushContour()
512
+ self.currentContour = None
513
+
514
+ def addPoint(
515
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
516
+ ):
517
+ if self.currentContour is None:
518
+ raise PenError("Path not begun")
519
+ if identifier is not None:
520
+ kwargs["identifier"] = identifier
521
+ self.currentContour.append((pt, segmentType, smooth, name, kwargs))
522
+
523
+ def addComponent(self, glyphName, transform, identifier=None, **kwargs):
524
+ if self.currentContour is not None:
525
+ raise PenError("Components must be added before or after contours")
526
+ self.pen.addComponent(glyphName, transform, identifier=identifier, **kwargs)
527
+
528
+
529
+ class DecomposingPointPen(LogMixin, AbstractPointPen):
530
+ """Implements a 'addComponent' method that decomposes components
531
+ (i.e. draws them onto self as simple contours).
532
+ It can also be used as a mixin class (e.g. see DecomposingRecordingPointPen).
533
+
534
+ You must override beginPath, addPoint, endPath. You may
535
+ additionally override addVarComponent and addComponent.
536
+
537
+ By default a warning message is logged when a base glyph is missing;
538
+ set the class variable ``skipMissingComponents`` to False if you want
539
+ all instances of a sub-class to raise a :class:`MissingComponentError`
540
+ exception by default.
541
+ """
542
+
543
+ skipMissingComponents = True
544
+ # alias error for convenience
545
+ MissingComponentError = MissingComponentError
546
+
547
+ def __init__(
548
+ self,
549
+ glyphSet,
550
+ *args,
551
+ skipMissingComponents=None,
552
+ reverseFlipped=False,
553
+ **kwargs,
554
+ ):
555
+ """Takes a 'glyphSet' argument (dict), in which the glyphs that are referenced
556
+ as components are looked up by their name.
557
+
558
+ If the optional 'reverseFlipped' argument is True, components whose transformation
559
+ matrix has a negative determinant will be decomposed with a reversed path direction
560
+ to compensate for the flip.
561
+
562
+ The optional 'skipMissingComponents' argument can be set to True/False to
563
+ override the homonymous class attribute for a given pen instance.
564
+ """
565
+ super().__init__(*args, **kwargs)
566
+ self.glyphSet = glyphSet
567
+ self.skipMissingComponents = (
568
+ self.__class__.skipMissingComponents
569
+ if skipMissingComponents is None
570
+ else skipMissingComponents
571
+ )
572
+ self.reverseFlipped = reverseFlipped
573
+
574
+ def addComponent(self, baseGlyphName, transformation, identifier=None, **kwargs):
575
+ """Transform the points of the base glyph and draw it onto self.
576
+
577
+ The `identifier` parameter and any extra kwargs are ignored.
578
+ """
579
+ from fontTools.pens.transformPen import TransformPointPen
580
+
581
+ try:
582
+ glyph = self.glyphSet[baseGlyphName]
583
+ except KeyError:
584
+ if not self.skipMissingComponents:
585
+ raise MissingComponentError(baseGlyphName)
586
+ self.log.warning(
587
+ "glyph '%s' is missing from glyphSet; skipped" % baseGlyphName
588
+ )
589
+ else:
590
+ pen = self
591
+ if transformation != Identity:
592
+ pen = TransformPointPen(pen, transformation)
593
+ if self.reverseFlipped:
594
+ # if the transformation has a negative determinant, it will
595
+ # reverse the contour direction of the component
596
+ a, b, c, d = transformation[:4]
597
+ det = a * d - b * c
598
+ if a * d - b * c < 0:
599
+ pen = ReverseContourPointPen(pen)
600
+ 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()