fonttools 4.55.6__cp311-cp311-musllinux_1_2_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-311-x86_64-linux-musl.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-311-x86_64-linux-musl.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-311-x86_64-linux-musl.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-311-x86_64-linux-musl.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-311-x86_64-linux-musl.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-311-x86_64-linux-musl.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 +5 -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,253 @@
1
+ """Compute name information for a given location in user-space coordinates
2
+ using STAT data. This can be used to fill-in automatically the names of an
3
+ instance:
4
+
5
+ .. code:: python
6
+
7
+ instance = doc.instances[0]
8
+ names = getStatNames(doc, instance.getFullUserLocation(doc))
9
+ print(names.styleNames)
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from dataclasses import dataclass
15
+ from typing import Dict, Optional, Tuple, Union
16
+ import logging
17
+
18
+ from fontTools.designspaceLib import (
19
+ AxisDescriptor,
20
+ AxisLabelDescriptor,
21
+ DesignSpaceDocument,
22
+ DesignSpaceDocumentError,
23
+ DiscreteAxisDescriptor,
24
+ SimpleLocationDict,
25
+ SourceDescriptor,
26
+ )
27
+
28
+ LOGGER = logging.getLogger(__name__)
29
+
30
+ # TODO(Python 3.8): use Literal
31
+ # RibbiStyleName = Union[Literal["regular"], Literal["bold"], Literal["italic"], Literal["bold italic"]]
32
+ RibbiStyle = str
33
+ BOLD_ITALIC_TO_RIBBI_STYLE = {
34
+ (False, False): "regular",
35
+ (False, True): "italic",
36
+ (True, False): "bold",
37
+ (True, True): "bold italic",
38
+ }
39
+
40
+
41
+ @dataclass
42
+ class StatNames:
43
+ """Name data generated from the STAT table information."""
44
+
45
+ familyNames: Dict[str, str]
46
+ styleNames: Dict[str, str]
47
+ postScriptFontName: Optional[str]
48
+ styleMapFamilyNames: Dict[str, str]
49
+ styleMapStyleName: Optional[RibbiStyle]
50
+
51
+
52
+ def getStatNames(
53
+ doc: DesignSpaceDocument, userLocation: SimpleLocationDict
54
+ ) -> StatNames:
55
+ """Compute the family, style, PostScript names of the given ``userLocation``
56
+ using the document's STAT information.
57
+
58
+ Also computes localizations.
59
+
60
+ If not enough STAT data is available for a given name, either its dict of
61
+ localized names will be empty (family and style names), or the name will be
62
+ None (PostScript name).
63
+
64
+ .. versionadded:: 5.0
65
+ """
66
+ familyNames: Dict[str, str] = {}
67
+ defaultSource: Optional[SourceDescriptor] = doc.findDefault()
68
+ if defaultSource is None:
69
+ LOGGER.warning("Cannot determine default source to look up family name.")
70
+ elif defaultSource.familyName is None:
71
+ LOGGER.warning(
72
+ "Cannot look up family name, assign the 'familyname' attribute to the default source."
73
+ )
74
+ else:
75
+ familyNames = {
76
+ "en": defaultSource.familyName,
77
+ **defaultSource.localisedFamilyName,
78
+ }
79
+
80
+ styleNames: Dict[str, str] = {}
81
+ # If a free-standing label matches the location, use it for name generation.
82
+ label = doc.labelForUserLocation(userLocation)
83
+ if label is not None:
84
+ styleNames = {"en": label.name, **label.labelNames}
85
+ # Otherwise, scour the axis labels for matches.
86
+ else:
87
+ # Gather all languages in which at least one translation is provided
88
+ # Then build names for all these languages, but fallback to English
89
+ # whenever a translation is missing.
90
+ labels = _getAxisLabelsForUserLocation(doc.axes, userLocation)
91
+ if labels:
92
+ languages = set(
93
+ language for label in labels for language in label.labelNames
94
+ )
95
+ languages.add("en")
96
+ for language in languages:
97
+ styleName = " ".join(
98
+ label.labelNames.get(language, label.defaultName)
99
+ for label in labels
100
+ if not label.elidable
101
+ )
102
+ if not styleName and doc.elidedFallbackName is not None:
103
+ styleName = doc.elidedFallbackName
104
+ styleNames[language] = styleName
105
+
106
+ if "en" not in familyNames or "en" not in styleNames:
107
+ # Not enough information to compute PS names of styleMap names
108
+ return StatNames(
109
+ familyNames=familyNames,
110
+ styleNames=styleNames,
111
+ postScriptFontName=None,
112
+ styleMapFamilyNames={},
113
+ styleMapStyleName=None,
114
+ )
115
+
116
+ postScriptFontName = f"{familyNames['en']}-{styleNames['en']}".replace(" ", "")
117
+
118
+ styleMapStyleName, regularUserLocation = _getRibbiStyle(doc, userLocation)
119
+
120
+ styleNamesForStyleMap = styleNames
121
+ if regularUserLocation != userLocation:
122
+ regularStatNames = getStatNames(doc, regularUserLocation)
123
+ styleNamesForStyleMap = regularStatNames.styleNames
124
+
125
+ styleMapFamilyNames = {}
126
+ for language in set(familyNames).union(styleNames.keys()):
127
+ familyName = familyNames.get(language, familyNames["en"])
128
+ styleName = styleNamesForStyleMap.get(language, styleNamesForStyleMap["en"])
129
+ styleMapFamilyNames[language] = (familyName + " " + styleName).strip()
130
+
131
+ return StatNames(
132
+ familyNames=familyNames,
133
+ styleNames=styleNames,
134
+ postScriptFontName=postScriptFontName,
135
+ styleMapFamilyNames=styleMapFamilyNames,
136
+ styleMapStyleName=styleMapStyleName,
137
+ )
138
+
139
+
140
+ def _getSortedAxisLabels(
141
+ axes: list[Union[AxisDescriptor, DiscreteAxisDescriptor]],
142
+ ) -> Dict[str, list[AxisLabelDescriptor]]:
143
+ """Returns axis labels sorted by their ordering, with unordered ones appended as
144
+ they are listed."""
145
+
146
+ # First, get the axis labels with explicit ordering...
147
+ sortedAxes = sorted(
148
+ (axis for axis in axes if axis.axisOrdering is not None),
149
+ key=lambda a: a.axisOrdering,
150
+ )
151
+ sortedLabels: Dict[str, list[AxisLabelDescriptor]] = {
152
+ axis.name: axis.axisLabels for axis in sortedAxes
153
+ }
154
+
155
+ # ... then append the others in the order they appear.
156
+ # NOTE: This relies on Python 3.7+ dict's preserved insertion order.
157
+ for axis in axes:
158
+ if axis.axisOrdering is None:
159
+ sortedLabels[axis.name] = axis.axisLabels
160
+
161
+ return sortedLabels
162
+
163
+
164
+ def _getAxisLabelsForUserLocation(
165
+ axes: list[Union[AxisDescriptor, DiscreteAxisDescriptor]],
166
+ userLocation: SimpleLocationDict,
167
+ ) -> list[AxisLabelDescriptor]:
168
+ labels: list[AxisLabelDescriptor] = []
169
+
170
+ allAxisLabels = _getSortedAxisLabels(axes)
171
+ if allAxisLabels.keys() != userLocation.keys():
172
+ LOGGER.warning(
173
+ f"Mismatch between user location '{userLocation.keys()}' and available "
174
+ f"labels for '{allAxisLabels.keys()}'."
175
+ )
176
+
177
+ for axisName, axisLabels in allAxisLabels.items():
178
+ userValue = userLocation[axisName]
179
+ label: Optional[AxisLabelDescriptor] = next(
180
+ (
181
+ l
182
+ for l in axisLabels
183
+ if l.userValue == userValue
184
+ or (
185
+ l.userMinimum is not None
186
+ and l.userMaximum is not None
187
+ and l.userMinimum <= userValue <= l.userMaximum
188
+ )
189
+ ),
190
+ None,
191
+ )
192
+ if label is None:
193
+ LOGGER.debug(
194
+ f"Document needs a label for axis '{axisName}', user value '{userValue}'."
195
+ )
196
+ else:
197
+ labels.append(label)
198
+
199
+ return labels
200
+
201
+
202
+ def _getRibbiStyle(
203
+ self: DesignSpaceDocument, userLocation: SimpleLocationDict
204
+ ) -> Tuple[RibbiStyle, SimpleLocationDict]:
205
+ """Compute the RIBBI style name of the given user location,
206
+ return the location of the matching Regular in the RIBBI group.
207
+
208
+ .. versionadded:: 5.0
209
+ """
210
+ regularUserLocation = {}
211
+ axes_by_tag = {axis.tag: axis for axis in self.axes}
212
+
213
+ bold: bool = False
214
+ italic: bool = False
215
+
216
+ axis = axes_by_tag.get("wght")
217
+ if axis is not None:
218
+ for regular_label in axis.axisLabels:
219
+ if (
220
+ regular_label.linkedUserValue == userLocation[axis.name]
221
+ # In the "recursive" case where both the Regular has
222
+ # linkedUserValue pointing the Bold, and the Bold has
223
+ # linkedUserValue pointing to the Regular, only consider the
224
+ # first case: Regular (e.g. 400) has linkedUserValue pointing to
225
+ # Bold (e.g. 700, higher than Regular)
226
+ and regular_label.userValue < regular_label.linkedUserValue
227
+ ):
228
+ regularUserLocation[axis.name] = regular_label.userValue
229
+ bold = True
230
+ break
231
+
232
+ axis = axes_by_tag.get("ital") or axes_by_tag.get("slnt")
233
+ if axis is not None:
234
+ for upright_label in axis.axisLabels:
235
+ if (
236
+ upright_label.linkedUserValue == userLocation[axis.name]
237
+ # In the "recursive" case where both the Upright has
238
+ # linkedUserValue pointing the Italic, and the Italic has
239
+ # linkedUserValue pointing to the Upright, only consider the
240
+ # first case: Upright (e.g. ital=0, slant=0) has
241
+ # linkedUserValue pointing to Italic (e.g ital=1, slant=-12 or
242
+ # slant=12 for backwards italics, in any case higher than
243
+ # Upright in absolute value, hence the abs() below.
244
+ and abs(upright_label.userValue) < abs(upright_label.linkedUserValue)
245
+ ):
246
+ regularUserLocation[axis.name] = upright_label.userValue
247
+ italic = True
248
+ break
249
+
250
+ return BOLD_ITALIC_TO_RIBBI_STYLE[bold, italic], {
251
+ **userLocation,
252
+ **regularUserLocation,
253
+ }
@@ -0,0 +1,147 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Dict, List, Optional, Union, cast
5
+
6
+ from fontTools.designspaceLib import (
7
+ AxisDescriptor,
8
+ DesignSpaceDocument,
9
+ DesignSpaceDocumentError,
10
+ RangeAxisSubsetDescriptor,
11
+ SimpleLocationDict,
12
+ ValueAxisSubsetDescriptor,
13
+ VariableFontDescriptor,
14
+ )
15
+
16
+
17
+ def clamp(value, minimum, maximum):
18
+ return min(max(value, minimum), maximum)
19
+
20
+
21
+ @dataclass
22
+ class Range:
23
+ minimum: float
24
+ """Inclusive minimum of the range."""
25
+ maximum: float
26
+ """Inclusive maximum of the range."""
27
+ default: float = 0
28
+ """Default value"""
29
+
30
+ def __post_init__(self):
31
+ self.minimum, self.maximum = sorted((self.minimum, self.maximum))
32
+ self.default = clamp(self.default, self.minimum, self.maximum)
33
+
34
+ def __contains__(self, value: Union[float, Range]) -> bool:
35
+ if isinstance(value, Range):
36
+ return self.minimum <= value.minimum and value.maximum <= self.maximum
37
+ return self.minimum <= value <= self.maximum
38
+
39
+ def intersection(self, other: Range) -> Optional[Range]:
40
+ if self.maximum < other.minimum or self.minimum > other.maximum:
41
+ return None
42
+ else:
43
+ return Range(
44
+ max(self.minimum, other.minimum),
45
+ min(self.maximum, other.maximum),
46
+ self.default, # We don't care about the default in this use-case
47
+ )
48
+
49
+
50
+ # A region selection is either a range or a single value, as a Designspace v5
51
+ # axis-subset element only allows a single discrete value or a range for a
52
+ # variable-font element.
53
+ Region = Dict[str, Union[Range, float]]
54
+
55
+ # A conditionset is a set of named ranges.
56
+ ConditionSet = Dict[str, Range]
57
+
58
+ # A rule is a list of conditionsets where any has to be relevant for the whole rule to be relevant.
59
+ Rule = List[ConditionSet]
60
+ Rules = Dict[str, Rule]
61
+
62
+
63
+ def locationInRegion(location: SimpleLocationDict, region: Region) -> bool:
64
+ for name, value in location.items():
65
+ if name not in region:
66
+ return False
67
+ regionValue = region[name]
68
+ if isinstance(regionValue, (float, int)):
69
+ if value != regionValue:
70
+ return False
71
+ else:
72
+ if value not in regionValue:
73
+ return False
74
+ return True
75
+
76
+
77
+ def regionInRegion(region: Region, superRegion: Region) -> bool:
78
+ for name, value in region.items():
79
+ if not name in superRegion:
80
+ return False
81
+ superValue = superRegion[name]
82
+ if isinstance(superValue, (float, int)):
83
+ if value != superValue:
84
+ return False
85
+ else:
86
+ if value not in superValue:
87
+ return False
88
+ return True
89
+
90
+
91
+ def userRegionToDesignRegion(doc: DesignSpaceDocument, userRegion: Region) -> Region:
92
+ designRegion = {}
93
+ for name, value in userRegion.items():
94
+ axis = doc.getAxis(name)
95
+ if axis is None:
96
+ raise DesignSpaceDocumentError(
97
+ f"Cannot find axis named '{name}' for region."
98
+ )
99
+ if isinstance(value, (float, int)):
100
+ designRegion[name] = axis.map_forward(value)
101
+ else:
102
+ designRegion[name] = Range(
103
+ axis.map_forward(value.minimum),
104
+ axis.map_forward(value.maximum),
105
+ axis.map_forward(value.default),
106
+ )
107
+ return designRegion
108
+
109
+
110
+ def getVFUserRegion(doc: DesignSpaceDocument, vf: VariableFontDescriptor) -> Region:
111
+ vfUserRegion: Region = {}
112
+ # For each axis, 2 cases:
113
+ # - it has a range = it's an axis in the VF DS
114
+ # - it's a single location = use it to know which rules should apply in the VF
115
+ for axisSubset in vf.axisSubsets:
116
+ axis = doc.getAxis(axisSubset.name)
117
+ if axis is None:
118
+ raise DesignSpaceDocumentError(
119
+ f"Cannot find axis named '{axisSubset.name}' for variable font '{vf.name}'."
120
+ )
121
+ if hasattr(axisSubset, "userMinimum"):
122
+ # Mypy doesn't support narrowing union types via hasattr()
123
+ # TODO(Python 3.10): use TypeGuard
124
+ # https://mypy.readthedocs.io/en/stable/type_narrowing.html
125
+ axisSubset = cast(RangeAxisSubsetDescriptor, axisSubset)
126
+ if not hasattr(axis, "minimum"):
127
+ raise DesignSpaceDocumentError(
128
+ f"Cannot select a range over '{axis.name}' for variable font '{vf.name}' "
129
+ "because it's a discrete axis, use only 'userValue' instead."
130
+ )
131
+ axis = cast(AxisDescriptor, axis)
132
+ vfUserRegion[axis.name] = Range(
133
+ max(axisSubset.userMinimum, axis.minimum),
134
+ min(axisSubset.userMaximum, axis.maximum),
135
+ axisSubset.userDefault or axis.default,
136
+ )
137
+ else:
138
+ axisSubset = cast(ValueAxisSubsetDescriptor, axisSubset)
139
+ vfUserRegion[axis.name] = axisSubset.userValue
140
+ # Any axis not mentioned explicitly has a single location = default value
141
+ for axis in doc.axes:
142
+ if axis.name not in vfUserRegion:
143
+ assert isinstance(
144
+ axis.default, (int, float)
145
+ ), f"Axis '{axis.name}' has no valid default value."
146
+ vfUserRegion[axis.name] = axis.default
147
+ return vfUserRegion
@@ -0,0 +1,258 @@
1
+ MacRoman = [
2
+ "NUL",
3
+ "Eth",
4
+ "eth",
5
+ "Lslash",
6
+ "lslash",
7
+ "Scaron",
8
+ "scaron",
9
+ "Yacute",
10
+ "yacute",
11
+ "HT",
12
+ "LF",
13
+ "Thorn",
14
+ "thorn",
15
+ "CR",
16
+ "Zcaron",
17
+ "zcaron",
18
+ "DLE",
19
+ "DC1",
20
+ "DC2",
21
+ "DC3",
22
+ "DC4",
23
+ "onehalf",
24
+ "onequarter",
25
+ "onesuperior",
26
+ "threequarters",
27
+ "threesuperior",
28
+ "twosuperior",
29
+ "brokenbar",
30
+ "minus",
31
+ "multiply",
32
+ "RS",
33
+ "US",
34
+ "space",
35
+ "exclam",
36
+ "quotedbl",
37
+ "numbersign",
38
+ "dollar",
39
+ "percent",
40
+ "ampersand",
41
+ "quotesingle",
42
+ "parenleft",
43
+ "parenright",
44
+ "asterisk",
45
+ "plus",
46
+ "comma",
47
+ "hyphen",
48
+ "period",
49
+ "slash",
50
+ "zero",
51
+ "one",
52
+ "two",
53
+ "three",
54
+ "four",
55
+ "five",
56
+ "six",
57
+ "seven",
58
+ "eight",
59
+ "nine",
60
+ "colon",
61
+ "semicolon",
62
+ "less",
63
+ "equal",
64
+ "greater",
65
+ "question",
66
+ "at",
67
+ "A",
68
+ "B",
69
+ "C",
70
+ "D",
71
+ "E",
72
+ "F",
73
+ "G",
74
+ "H",
75
+ "I",
76
+ "J",
77
+ "K",
78
+ "L",
79
+ "M",
80
+ "N",
81
+ "O",
82
+ "P",
83
+ "Q",
84
+ "R",
85
+ "S",
86
+ "T",
87
+ "U",
88
+ "V",
89
+ "W",
90
+ "X",
91
+ "Y",
92
+ "Z",
93
+ "bracketleft",
94
+ "backslash",
95
+ "bracketright",
96
+ "asciicircum",
97
+ "underscore",
98
+ "grave",
99
+ "a",
100
+ "b",
101
+ "c",
102
+ "d",
103
+ "e",
104
+ "f",
105
+ "g",
106
+ "h",
107
+ "i",
108
+ "j",
109
+ "k",
110
+ "l",
111
+ "m",
112
+ "n",
113
+ "o",
114
+ "p",
115
+ "q",
116
+ "r",
117
+ "s",
118
+ "t",
119
+ "u",
120
+ "v",
121
+ "w",
122
+ "x",
123
+ "y",
124
+ "z",
125
+ "braceleft",
126
+ "bar",
127
+ "braceright",
128
+ "asciitilde",
129
+ "DEL",
130
+ "Adieresis",
131
+ "Aring",
132
+ "Ccedilla",
133
+ "Eacute",
134
+ "Ntilde",
135
+ "Odieresis",
136
+ "Udieresis",
137
+ "aacute",
138
+ "agrave",
139
+ "acircumflex",
140
+ "adieresis",
141
+ "atilde",
142
+ "aring",
143
+ "ccedilla",
144
+ "eacute",
145
+ "egrave",
146
+ "ecircumflex",
147
+ "edieresis",
148
+ "iacute",
149
+ "igrave",
150
+ "icircumflex",
151
+ "idieresis",
152
+ "ntilde",
153
+ "oacute",
154
+ "ograve",
155
+ "ocircumflex",
156
+ "odieresis",
157
+ "otilde",
158
+ "uacute",
159
+ "ugrave",
160
+ "ucircumflex",
161
+ "udieresis",
162
+ "dagger",
163
+ "degree",
164
+ "cent",
165
+ "sterling",
166
+ "section",
167
+ "bullet",
168
+ "paragraph",
169
+ "germandbls",
170
+ "registered",
171
+ "copyright",
172
+ "trademark",
173
+ "acute",
174
+ "dieresis",
175
+ "notequal",
176
+ "AE",
177
+ "Oslash",
178
+ "infinity",
179
+ "plusminus",
180
+ "lessequal",
181
+ "greaterequal",
182
+ "yen",
183
+ "mu",
184
+ "partialdiff",
185
+ "summation",
186
+ "product",
187
+ "pi",
188
+ "integral",
189
+ "ordfeminine",
190
+ "ordmasculine",
191
+ "Omega",
192
+ "ae",
193
+ "oslash",
194
+ "questiondown",
195
+ "exclamdown",
196
+ "logicalnot",
197
+ "radical",
198
+ "florin",
199
+ "approxequal",
200
+ "Delta",
201
+ "guillemotleft",
202
+ "guillemotright",
203
+ "ellipsis",
204
+ "nbspace",
205
+ "Agrave",
206
+ "Atilde",
207
+ "Otilde",
208
+ "OE",
209
+ "oe",
210
+ "endash",
211
+ "emdash",
212
+ "quotedblleft",
213
+ "quotedblright",
214
+ "quoteleft",
215
+ "quoteright",
216
+ "divide",
217
+ "lozenge",
218
+ "ydieresis",
219
+ "Ydieresis",
220
+ "fraction",
221
+ "currency",
222
+ "guilsinglleft",
223
+ "guilsinglright",
224
+ "fi",
225
+ "fl",
226
+ "daggerdbl",
227
+ "periodcentered",
228
+ "quotesinglbase",
229
+ "quotedblbase",
230
+ "perthousand",
231
+ "Acircumflex",
232
+ "Ecircumflex",
233
+ "Aacute",
234
+ "Edieresis",
235
+ "Egrave",
236
+ "Iacute",
237
+ "Icircumflex",
238
+ "Idieresis",
239
+ "Igrave",
240
+ "Oacute",
241
+ "Ocircumflex",
242
+ "apple",
243
+ "Ograve",
244
+ "Uacute",
245
+ "Ucircumflex",
246
+ "Ugrave",
247
+ "dotlessi",
248
+ "circumflex",
249
+ "tilde",
250
+ "macron",
251
+ "breve",
252
+ "dotaccent",
253
+ "ring",
254
+ "cedilla",
255
+ "hungarumlaut",
256
+ "ogonek",
257
+ "caron",
258
+ ]