rapier-math 2.4.1 → 2.7.0
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.
- package/CHANGELOG.md +10 -0
- package/LICENSE +10 -3
- package/README.md +4 -5
- package/dist/index.mjs +1 -1
- package/dist/markdown-rules.mjs +47 -0
- package/dist/rapier-math.js +875 -321
- package/docs/api.md +6 -2
- package/docs/font-source.md +54 -35
- package/docs/math-components.json +51 -7
- package/docs/math-resources.json +59 -64
- package/package.json +3 -3
- package/src/math/FONT-LICENSE.txt +9 -2
- package/src/math/build-font.py +88 -80
- package/src/math/classic.js +1 -1
- package/src/math/font.js +24 -488
- package/src/math/layout.js +356 -182
- package/src/math/mathml.js +79 -14
- package/src/math/package-layout.mjs +1 -0
- package/src/math/package-readme.mjs +3 -4
- package/src/math/parser.js +398 -82
- package/src/tools/build-math.mjs +22 -7
- package/tests/adoption.mjs +0 -252
- package/tests/check.mjs +0 -134
- package/tests/semantics.mjs +0 -340
- package/tests/typeset.mjs +0 -172
- package/tests/verify.mjs +0 -49
package/docs/math-resources.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundle": "rapier-math-2.
|
|
2
|
+
"bundle": "rapier-math-2.7.0.js",
|
|
3
3
|
"packageBundle": "dist/rapier-math.js",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.7.0",
|
|
5
5
|
"license": "MIT AND LicenseRef-GUST-Font-License",
|
|
6
|
-
"bytes":
|
|
7
|
-
"gzipBytes":
|
|
8
|
-
"sha256": "
|
|
9
|
-
"sha384": "
|
|
6
|
+
"bytes": 742684,
|
|
7
|
+
"gzipBytes": 421702,
|
|
8
|
+
"sha256": "cb1c935e84744d41d516c03607a8383ff801ecfc6acdfd63b2eb38be0bc20d80",
|
|
9
|
+
"sha384": "1rjhOOw690Mr3aVXwRTPlwQO2atMrWHY8Rm3nZ+SZRrm5mB9HK5FkY6ZWCDYtgzv",
|
|
10
10
|
"sources": [
|
|
11
11
|
{
|
|
12
12
|
"file": "math/font.js",
|
|
13
13
|
"packageFile": "src/math/font.js",
|
|
14
|
-
"bytes":
|
|
15
|
-
"sha256": "
|
|
14
|
+
"bytes": 446505,
|
|
15
|
+
"sha256": "5ee3578742901833510a218359eb54254a68d1cf737493aa65d49cecb437c2fb"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"file": "math/symbols.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
{
|
|
24
24
|
"file": "math/parser.js",
|
|
25
25
|
"packageFile": "src/math/parser.js",
|
|
26
|
-
"bytes":
|
|
27
|
-
"sha256": "
|
|
26
|
+
"bytes": 127337,
|
|
27
|
+
"sha256": "83bd49b4efe6d323bdcac45966e5248cf73abe3857a608d2277c313c7e720850"
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"file": "math/source.js",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
{
|
|
42
42
|
"file": "math/layout.js",
|
|
43
43
|
"packageFile": "src/math/layout.js",
|
|
44
|
-
"bytes":
|
|
45
|
-
"sha256": "
|
|
44
|
+
"bytes": 58681,
|
|
45
|
+
"sha256": "8ec4c3e25f65afc026d856e6f046e8822de1eae815456e967a39b9f4df61f99c"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
"file": "math/fallbacks.js",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
{
|
|
72
72
|
"file": "math/mathml.js",
|
|
73
73
|
"packageFile": "src/math/mathml.js",
|
|
74
|
-
"bytes":
|
|
75
|
-
"sha256": "
|
|
74
|
+
"bytes": 34551,
|
|
75
|
+
"sha256": "271f46dbb28eae4204958e16c293a8f859ffe1877c3a1fc2a8cc6c45175e82cd"
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
"file": "math/semantic-api.js",
|
|
@@ -90,39 +90,33 @@
|
|
|
90
90
|
"file": "math/classic.js",
|
|
91
91
|
"packageFile": "src/math/classic.js",
|
|
92
92
|
"bytes": 269,
|
|
93
|
-
"sha256": "
|
|
93
|
+
"sha256": "ecc0aabe977198d013ebcbcfd739910e55cbb28303af5db97eb31333d7de4189"
|
|
94
94
|
}
|
|
95
95
|
],
|
|
96
96
|
"recipe": [
|
|
97
97
|
{
|
|
98
98
|
"file": "math/build-font.py",
|
|
99
99
|
"packageFile": "src/math/build-font.py",
|
|
100
|
-
"bytes":
|
|
101
|
-
"sha256": "
|
|
100
|
+
"bytes": 32590,
|
|
101
|
+
"sha256": "f596533a50fe378c3c98478ff49b97e96c808065fbf20ee9597cfa7cf078f4bc"
|
|
102
102
|
},
|
|
103
103
|
{
|
|
104
104
|
"file": "math/FONT-SOURCE.md",
|
|
105
105
|
"packageFile": "docs/font-source.md",
|
|
106
|
-
"bytes":
|
|
107
|
-
"sha256": "
|
|
106
|
+
"bytes": 12702,
|
|
107
|
+
"sha256": "7d0d20d5982b5d4378a29aea803199df5f7618f88670f2c3b25545f7932db23d"
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
"file": "math/FONT-LICENSE.txt",
|
|
111
111
|
"packageFile": "src/math/FONT-LICENSE.txt",
|
|
112
|
-
"bytes":
|
|
113
|
-
"sha256": "
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"file": "math/package-verify.mjs",
|
|
117
|
-
"packageFile": "tests/verify.mjs",
|
|
118
|
-
"bytes": 3179,
|
|
119
|
-
"sha256": "5702cb77eb562b0230b145c09b8888b2b20bcf8dac92de19615aac99a0f09a47"
|
|
112
|
+
"bytes": 21695,
|
|
113
|
+
"sha256": "fb1f153e363d003180781b4a043f34ab76d17f1c338de9229c40149b52cfdf2f"
|
|
120
114
|
},
|
|
121
115
|
{
|
|
122
116
|
"file": "tools/build-math.mjs",
|
|
123
117
|
"packageFile": "src/tools/build-math.mjs",
|
|
124
|
-
"bytes":
|
|
125
|
-
"sha256": "
|
|
118
|
+
"bytes": 10967,
|
|
119
|
+
"sha256": "11c6f7d5ab962d24ff70a5497c23ccefd624f1add20b8840d8bb0c6f085ecbf9"
|
|
126
120
|
},
|
|
127
121
|
{
|
|
128
122
|
"file": "math/LICENSE-MIT",
|
|
@@ -130,12 +124,6 @@
|
|
|
130
124
|
"bytes": 1071,
|
|
131
125
|
"sha256": "a3bc5d619ab9159f4eef2924e48dfb935556f4bc163f5ea61610b66a5915de70"
|
|
132
126
|
},
|
|
133
|
-
{
|
|
134
|
-
"file": "math/adoption-verify.mjs",
|
|
135
|
-
"packageFile": "tests/adoption.mjs",
|
|
136
|
-
"bytes": 15517,
|
|
137
|
-
"sha256": "02e22c51e0c71de1fe992b3fddde04e2e2cfc482d1c05aa1467a1c97c7d63b58"
|
|
138
|
-
},
|
|
139
127
|
{
|
|
140
128
|
"file": "math/package-build.mjs",
|
|
141
129
|
"packageFile": "src/math/package-build.mjs",
|
|
@@ -145,44 +133,32 @@
|
|
|
145
133
|
{
|
|
146
134
|
"file": "math/package-layout.mjs",
|
|
147
135
|
"packageFile": "src/math/package-layout.mjs",
|
|
148
|
-
"bytes":
|
|
149
|
-
"sha256": "
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
"file": "math/package-check.mjs",
|
|
153
|
-
"packageFile": "tests/check.mjs",
|
|
154
|
-
"bytes": 8742,
|
|
155
|
-
"sha256": "25e06cb2b28a6fd404e624c22c8acefe41e988fe9383c91155c820e197cb54a8"
|
|
136
|
+
"bytes": 925,
|
|
137
|
+
"sha256": "72e90f365ff6ccf9741ab12a3bd9d7466389f1794c24b73dc86c831743923d36"
|
|
156
138
|
},
|
|
157
139
|
{
|
|
158
140
|
"file": "math/package-readme.mjs",
|
|
159
141
|
"packageFile": "src/math/package-readme.mjs",
|
|
160
|
-
"bytes":
|
|
161
|
-
"sha256": "
|
|
142
|
+
"bytes": 2458,
|
|
143
|
+
"sha256": "ed03aa38d7ed3d01fbab6836d2827ee0b2565bca4e998af7172e2da940611495"
|
|
162
144
|
},
|
|
163
145
|
{
|
|
164
146
|
"file": "math/README.md",
|
|
165
147
|
"packageFile": "docs/api.md",
|
|
166
|
-
"bytes":
|
|
167
|
-
"sha256": "
|
|
148
|
+
"bytes": 24062,
|
|
149
|
+
"sha256": "59963d4156549530b73d15d2dc66d4f7cec108e4767856785605e71fe1f6162a"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"file": "math/CHANGELOG.md",
|
|
153
|
+
"packageFile": "CHANGELOG.md",
|
|
154
|
+
"bytes": 389,
|
|
155
|
+
"sha256": "621ffa760f4ebeb72c7882e46caf8c8cb815abde50cd98d123da5a34ea105397"
|
|
168
156
|
},
|
|
169
157
|
{
|
|
170
158
|
"file": "math/SEMANTICS.md",
|
|
171
159
|
"packageFile": "docs/semantics.md",
|
|
172
160
|
"bytes": 18282,
|
|
173
161
|
"sha256": "98984313665984aaa29fd816cc7b79691deac7450d5d76b8e7dc0f79b575e2cf"
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
"file": "math/semantic-verify.mjs",
|
|
177
|
-
"packageFile": "tests/semantics.mjs",
|
|
178
|
-
"bytes": 27391,
|
|
179
|
-
"sha256": "9fc8a03da77d3532a0aaa69e02d773aaa9e9aa5e3386b666acb27a4b0079ffdb"
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
"file": "math/typeset-verify.mjs",
|
|
183
|
-
"packageFile": "tests/typeset.mjs",
|
|
184
|
-
"bytes": 12006,
|
|
185
|
-
"sha256": "45e8c0fd426cb497dfc65683d3b412ef57dc2d9cc92deef58311afa164fd931a"
|
|
186
162
|
}
|
|
187
163
|
],
|
|
188
164
|
"components": [
|
|
@@ -191,7 +167,26 @@
|
|
|
191
167
|
"version": "1.959",
|
|
192
168
|
"license": "LicenseRef-GUST-Font-License",
|
|
193
169
|
"source": "https://mirror.apps.cam.ac.uk/pub/tex-archive/fonts/lm-math/opentype/latinmodern-math.otf",
|
|
194
|
-
"sha256": "6075562b771f8b82f0c179e363389684f2dd09de30038269e2628e504bd7be0f"
|
|
170
|
+
"sha256": "6075562b771f8b82f0c179e363389684f2dd09de30038269e2628e504bd7be0f",
|
|
171
|
+
"copyright": "Copyright 2012--2014 for Latin Modern Math OTF by B. Jackowski, P. Strzelczyk and P. Pianowski (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details."
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"name": "Latin Modern Mono",
|
|
175
|
+
"version": "2.004",
|
|
176
|
+
"license": "LicenseRef-GUST-Font-License",
|
|
177
|
+
"source": "https://ftp.riken.jp/CTAN/fonts/lm/fonts/opentype/public/lm/lmmono10-regular.otf",
|
|
178
|
+
"sha256": "22deb6d3be3ffcb40b33f0e010afb256c677d97c2a2bdee1f5740cdc97751558",
|
|
179
|
+
"copyright": "Copyright 2003, 2009 B. Jackowski and J. M. Nowacki (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details.",
|
|
180
|
+
"note": "Monospace text outlines and advances; complete license in math-font-LICENSE.txt"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"name": "Latin Modern Math Italic10 Regular",
|
|
184
|
+
"version": "2.003",
|
|
185
|
+
"license": "LicenseRef-GUST-Font-License",
|
|
186
|
+
"source": "https://ftp.riken.jp/CTAN/fonts/lm/fonts/type1/public/lm/lmmi10.pfb",
|
|
187
|
+
"sha256": "c24662506b402f3e0033cc75eb746eb490a1b7477e6b3ef52053f5025ec0fc57",
|
|
188
|
+
"copyright": "Copyright 2003--2009 by B. Jackowski and J.M. Nowacki (on behalf of TeX USERS GROUPS).",
|
|
189
|
+
"note": "Small arrow hook outline; the composer supplies its advance; complete license in math-font-LICENSE.txt"
|
|
195
190
|
}
|
|
196
191
|
],
|
|
197
192
|
"font": {
|
|
@@ -204,8 +199,8 @@
|
|
|
204
199
|
"copyright": "Copyright 2012--2014 for Latin Modern Math OTF by B. Jackowski, P. Strzelczyk and P. Pianowski (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details.",
|
|
205
200
|
"licenseSource": "https://mirror.apps.cam.ac.uk/pub/tex-archive/fonts/lm-math/doc/GUST-FONT-LICENSE.txt",
|
|
206
201
|
"licenseFile": "math/FONT-LICENSE.txt",
|
|
207
|
-
"licenseSha256": "
|
|
208
|
-
"licenseBytes":
|
|
202
|
+
"licenseSha256": "fb1f153e363d003180781b4a043f34ab76d17f1c338de9229c40149b52cfdf2f",
|
|
203
|
+
"licenseBytes": 21695
|
|
209
204
|
},
|
|
210
205
|
"adoption": [
|
|
211
206
|
{
|
|
@@ -217,8 +212,8 @@
|
|
|
217
212
|
{
|
|
218
213
|
"file": "math/markdown-rules.mjs",
|
|
219
214
|
"packageFile": "dist/markdown-rules.mjs",
|
|
220
|
-
"bytes":
|
|
221
|
-
"sha256": "
|
|
215
|
+
"bytes": 6000,
|
|
216
|
+
"sha256": "f0e8fd1e899c99e90293088dd17d4ed14d3ef9a3a1e6558d13f7ce66999ba67d"
|
|
222
217
|
},
|
|
223
218
|
{
|
|
224
219
|
"file": "math/reuse.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapier-math",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Self-contained offline LaTeX-to-SVG rendering with Latin Modern outlines, optional Markdown integrations and streaming helpers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
"src",
|
|
79
79
|
"docs",
|
|
80
80
|
"examples",
|
|
81
|
-
"tests",
|
|
82
81
|
"LICENSE",
|
|
83
|
-
"README.md"
|
|
82
|
+
"README.md",
|
|
83
|
+
"CHANGELOG.md"
|
|
84
84
|
],
|
|
85
85
|
"license": "SEE LICENSE IN LICENSE",
|
|
86
86
|
"author": "Jack Skipworth",
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
Copyright 2012--2014 for Latin Modern Math OTF by B. Jackowski, P. Strzelczyk and P. Pianowski (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright 2003, 2009 B. Jackowski and J. M. Nowacki (on behalf of TeX users groups). This work is released under the GUST Font License -- see http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt for details.
|
|
4
|
+
|
|
5
|
+
Copyright 2003--2009 by B. Jackowski and J.M. Nowacki (on behalf of TeX USERS GROUPS).
|
|
6
|
+
|
|
7
|
+
Rapier math font data, derived from Latin Modern Math 1.959,
|
|
8
|
+
text outlines from Latin Modern Mono 2.004, and one arrow hook
|
|
9
|
+
from Latin Modern Math Italic 10 Regular 2.003.
|
|
4
10
|
Changes: SVG outline conversion, character and MATH data extraction,
|
|
5
|
-
optical-form closure
|
|
11
|
+
optical-form closure and lossless path packing.
|
|
6
12
|
Original outlines are unchanged. Hinting and text shaping tables are omitted.
|
|
7
13
|
The font authors do not maintain this conversion.
|
|
8
14
|
Complete original work: https://mirrors.ctan.org/fonts/lm-math.zip
|
|
15
|
+
Mono and hook original work: https://mirrors.ctan.org/fonts/lm.zip
|
|
9
16
|
Conversion details: FONT-SOURCE.md.
|
|
10
17
|
|
|
11
18
|
% This is a preliminary version (2006-09-30), barring acceptance from
|
package/src/math/build-font.py
CHANGED
|
@@ -15,11 +15,13 @@ import json
|
|
|
15
15
|
import math
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
import re
|
|
18
|
-
import
|
|
18
|
+
import tempfile
|
|
19
19
|
import urllib.request
|
|
20
20
|
import zlib
|
|
21
21
|
|
|
22
22
|
from fontTools.pens.svgPathPen import SVGPathPen
|
|
23
|
+
from fontTools.pens.boundsPen import BoundsPen, ControlBoundsPen
|
|
24
|
+
from fontTools.t1Lib import T1Font
|
|
23
25
|
from fontTools.ttLib import TTFont
|
|
24
26
|
|
|
25
27
|
|
|
@@ -32,7 +34,10 @@ LPPL_URL = "https://www.latex-project.org/lppl/lppl-1-3c.txt"
|
|
|
32
34
|
LPPL_SHA256 = "3d262cdf34dafa6955f703c634a8c238ec44109bc8dd6ef34fb7aa54809f7e66"
|
|
33
35
|
TEXT_URL = "https://raw.githubusercontent.com/jackskip22/rapier/326a7387a190b011543fae5f5f2c6144f6163b3d/src/shell/fonts/Geist.wght400-700.woff2"
|
|
34
36
|
TEXT_SHA256 = "6e3a140e3812161e292fbe42a1fc90533b2407b699c65abc7a098b0979df4e82"
|
|
35
|
-
|
|
37
|
+
MONO_URL = "https://ftp.riken.jp/CTAN/fonts/lm/fonts/opentype/public/lm/lmmono10-regular.otf"
|
|
38
|
+
MONO_SHA256 = "22deb6d3be3ffcb40b33f0e010afb256c677d97c2a2bdee1f5740cdc97751558"
|
|
39
|
+
HOOK_URL = "https://ftp.riken.jp/CTAN/fonts/lm/fonts/type1/public/lm/lmmi10.pfb"
|
|
40
|
+
HOOK_SHA256 = "c24662506b402f3e0033cc75eb746eb490a1b7477e6b3ef52053f5025ec0fc57"
|
|
36
41
|
|
|
37
42
|
|
|
38
43
|
def source_bytes(local: Path | None, remote: str, expected: str) -> bytes:
|
|
@@ -78,11 +83,11 @@ def extract(font: TTFont):
|
|
|
78
83
|
cmap = font.getBestCmap()
|
|
79
84
|
table = font["MATH"].table
|
|
80
85
|
variants = table.MathVariants
|
|
81
|
-
scripts,
|
|
86
|
+
scripts, dotless = (feature_alternates(font, tag) for tag in ("ssty", "dtls"))
|
|
82
87
|
used = set(cmap.values())
|
|
83
88
|
while True:
|
|
84
89
|
previous = len(used)
|
|
85
|
-
for feature in (scripts,
|
|
90
|
+
for feature in (scripts, dotless):
|
|
86
91
|
for name, alternates in feature.items():
|
|
87
92
|
if name in used:
|
|
88
93
|
used.update(alternates)
|
|
@@ -116,16 +121,13 @@ def extract(font: TTFont):
|
|
|
116
121
|
"xHeight": font["OS/2"].sxHeight,
|
|
117
122
|
"glyphs": glyphs,
|
|
118
123
|
"chars": {cp: ids[name] for cp, name in sorted(cmap.items())},
|
|
119
|
-
"constants": {key: scalar(value) for key, value in vars(table.MathConstants).items() if not key.startswith("_")},
|
|
124
|
+
"constants": {key: scalar(value) for key, value in vars(table.MathConstants).items() if not key.startswith("_") and key not in UNUSED_CONSTANTS},
|
|
120
125
|
"vertical": {},
|
|
121
126
|
"horizontal": {},
|
|
122
127
|
"minConnectorOverlap": variants.MinConnectorOverlap,
|
|
123
|
-
"kern": {},
|
|
124
128
|
"scriptAlternates": {ids[name]: [ids[alternate] for alternate in alternates] for name, alternates in scripts.items() if name in ids},
|
|
125
|
-
"flatAccents": {ids[name]: ids[alternates[0]] for name, alternates in flattened.items() if name in ids},
|
|
126
129
|
"dotless": {ids[name]: ids[alternates[0]] for name, alternates in dotless.items() if name in ids},
|
|
127
130
|
"extendedShapes": {ids[name]: 1 for name in (info.ExtendedShapeCoverage.glyphs if info.ExtendedShapeCoverage else []) if name in ids},
|
|
128
|
-
"edgeStep": EDGE_STEP,
|
|
129
131
|
}
|
|
130
132
|
for axis, key in (("Vert", "vertical"), ("Horiz", "horizontal")):
|
|
131
133
|
coverage = getattr(variants, axis + "GlyphCoverage")
|
|
@@ -141,33 +143,32 @@ def extract(font: TTFont):
|
|
|
141
143
|
"parts": [[ids[p.glyph], p.StartConnectorLength, p.EndConnectorLength, p.FullAdvance, p.PartFlags & 1] for p in assembly.PartRecords],
|
|
142
144
|
}
|
|
143
145
|
data[key][ids[name]] = record
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
for name in list(profiled):
|
|
161
|
-
profiled.update(scripts.get(name, ()))
|
|
162
|
-
profiled.update(dotless.get(name, ()))
|
|
163
|
-
data["profiled"] = sorted(ids[name] for name in profiled)
|
|
146
|
+
# LuaTeX's CFF loader bounds curves by their control points. Keep those semantic vertical boxes separate
|
|
147
|
+
# from the exact ink bounds the outline decoder computes; large operators use them when centering on the axis.
|
|
148
|
+
vertical_ids = set(data["vertical"])
|
|
149
|
+
for record in data["vertical"].values():
|
|
150
|
+
vertical_ids.update(glyph for glyph, _ in record["variants"])
|
|
151
|
+
data["verticalBounds"] = {}
|
|
152
|
+
for glyph in sorted(vertical_ids):
|
|
153
|
+
exact, control = BoundsPen(glyph_set), ControlBoundsPen(glyph_set)
|
|
154
|
+
glyph_set[names[glyph]].draw(exact)
|
|
155
|
+
glyph_set[names[glyph]].draw(control)
|
|
156
|
+
if exact.bounds and control.bounds:
|
|
157
|
+
ink = [math.floor(exact.bounds[1]), math.ceil(exact.bounds[3])]
|
|
158
|
+
box = [round(control.bounds[1]), round(control.bounds[3])]
|
|
159
|
+
if box != ink:
|
|
160
|
+
data["verticalBounds"][glyph] = box
|
|
164
161
|
return data
|
|
165
162
|
|
|
166
163
|
|
|
167
164
|
PAGE_BYTES = 16384
|
|
168
165
|
PAGE_STRIDE = 32768
|
|
169
166
|
PARENT_DEPTH = 4
|
|
170
|
-
|
|
167
|
+
# The pinned font has no MathKernInfo or flac records. These constants have no layout consumer.
|
|
168
|
+
UNUSED_CONSTANTS = {"DelimitedSubFormulaMinHeight", "FlattenedAccentBaseHeight", "StretchStackTopShiftUp",
|
|
169
|
+
"StretchStackBottomShiftDown", "StretchStackGapAboveMin", "StretchStackGapBelowMin",
|
|
170
|
+
"SkewedFractionHorizontalGap", "SkewedFractionVerticalGap"}
|
|
171
|
+
SCALAR_MAPS = ("chars", "dotless", "extendedShapes")
|
|
171
172
|
|
|
172
173
|
|
|
173
174
|
def unsigned(value, target):
|
|
@@ -215,7 +216,7 @@ def pack_font(data):
|
|
|
215
216
|
for token in tokens:
|
|
216
217
|
if "." in token:
|
|
217
218
|
unit = math.lcm(unit, Fraction(token).denominator)
|
|
218
|
-
# Derived bounds
|
|
219
|
+
# Derived bounds divide by the unit; a power of two keeps every coordinate exact.
|
|
219
220
|
if unit & (unit - 1):
|
|
220
221
|
raise ValueError("Font coordinates need a power-of-two unit")
|
|
221
222
|
metric_unit = math.lcm(2, *(Fraction(value).denominator for glyph in glyphs for value in glyph[:3]))
|
|
@@ -336,11 +337,6 @@ def pack_font(data):
|
|
|
336
337
|
for index, value in enumerate(values):
|
|
337
338
|
signed(value - previous_values[index], indices)
|
|
338
339
|
previous_values[index] = value
|
|
339
|
-
unsigned(len(data["profiled"]), indices)
|
|
340
|
-
previous_key = -1
|
|
341
|
-
for key in data["profiled"]:
|
|
342
|
-
unsigned(key - previous_key - 1, indices)
|
|
343
|
-
previous_key = key
|
|
344
340
|
for name in ("vertical", "horizontal"):
|
|
345
341
|
unsigned(len(data[name]), indices)
|
|
346
342
|
previous_key = 0
|
|
@@ -380,7 +376,7 @@ def pack_font(data):
|
|
|
380
376
|
|
|
381
377
|
packed = [(len(page), text(page)) for page in pages]
|
|
382
378
|
return packed, text(indices), len(indices), {
|
|
383
|
-
"contours": len(contours), "contourReferences": sum(map(len, references)),
|
|
379
|
+
"contours": len(contours), "contourReferences": sum(map(len, references)),
|
|
384
380
|
"pages": len(pages), "pageBytes": PAGE_BYTES, "indexBytes": len(indices),
|
|
385
381
|
"recordBytes": sum(map(len, pages)), "maxParentDepth": PARENT_DEPTH,
|
|
386
382
|
}
|
|
@@ -423,21 +419,20 @@ if(written!==bytes.length||position-Math.floor(available/8)!==source.length)inva
|
|
|
423
419
|
const unsigned=r=>{let value=0,shift=0,byte;do{if(r[1]>=r[2]||shift>49)invalid();byte=r[0][r[1]++];value+=(byte&127)*2**shift;shift+=7;}while(byte&128);if(!Number.isSafeInteger(value))invalid();return value;};
|
|
424
420
|
const signed=r=>{if(r[1]>=r[2])invalid();let value=r[0][r[1]++];if(value>=240){if(value===255){value=4080+unsigned(r);if(!Number.isSafeInteger(value))invalid();}else{if(r[1]>=r[2])invalid();value=240+(value-240)*256+r[0][r[1]++];}}return value%2?-(value+1)/2:value/2;};
|
|
425
421
|
const complete=r=>{if(r[1]!==r[2])invalid();};
|
|
426
|
-
const [unit,metricUnit,metricBases,
|
|
422
|
+
const [unit,metricUnit,metricBases,glyphs,contours]=(()=>{
|
|
427
423
|
const bytes=inflate(__INDEX__,__SIZE__),r=[bytes,0,bytes.length],unit=unsigned(r),metricUnit=unsigned(r);if(!unit||!metricUnit)invalid();const metricBases=Array.from({length:3},()=>signed(r));
|
|
428
424
|
for(const name of __MAP_FIELDS__){const count=unsigned(r),map=MATH_FONT[name]={};if(count>bytes.length)invalid();let key=0,value=0;
|
|
429
425
|
for(let i=0;i<count;i++){key+=unsigned(r);value+=signed(r);map[key]=value;}}
|
|
430
426
|
const scripts=MATH_FONT.scriptAlternates={},scriptCount=unsigned(r),previous=[0,0];let key=0;if(scriptCount>bytes.length)invalid();
|
|
431
427
|
for(let i=0;i<scriptCount;i++){key+=unsigned(r);const count=unsigned(r);if(count<1||count>2)invalid();const values=[];for(let j=0;j<count;j++){previous[j]+=signed(r);values.push(previous[j]);}scripts[key]=values;}
|
|
432
|
-
const profiled=new Set,profileCount=unsigned(r);key=-1;if(profileCount>bytes.length)invalid();for(let i=0;i<profileCount;i++)profiled.add(key+=unsigned(r)+1);
|
|
433
428
|
for(const name of ['vertical','horizontal']){const map=MATH_FONT[name]={},count=unsigned(r);key=0;if(count>bytes.length)invalid();
|
|
434
429
|
for(let i=0;i<count;i++){key+=unsigned(r);const variants=Array.from({length:unsigned(r)},()=>[key+signed(r),unsigned(r)]),parts=unsigned(r);if(variants.length>bytes.length||parts>bytes.length)invalid();
|
|
435
430
|
const record=map[key]={variants};if(parts)record.assembly={italic:signed(r),parts:Array.from({length:parts-1},()=>{const part=[key+signed(r),unsigned(r),unsigned(r)],full=unsigned(r);return [...part,Math.floor(full/2),full%2];})};}}
|
|
436
431
|
const tables=Array.from({length:2},()=>{const count=unsigned(r);if(count<1||count>bytes.length)invalid();const offsets=new Uint32Array(count);let previous=0;
|
|
437
|
-
for(let i=0;i<count;i++){previous+=unsigned(r);if(previous>=pages.length*32768)invalid();offsets[i]=previous;}return offsets;});complete(r);return [unit,metricUnit,metricBases
|
|
432
|
+
for(let i=0;i<count;i++){previous+=unsigned(r);if(previous>=pages.length*32768)invalid();offsets[i]=previous;}return offsets;});complete(r);return [unit,metricUnit,metricBases,...tables];
|
|
438
433
|
})();
|
|
439
|
-
// Each page
|
|
440
|
-
const pageCache=[],glyphCache=new Map()
|
|
434
|
+
// Each page and glyph decodes once and stays: the font itself bounds every cache.
|
|
435
|
+
const pageCache=[],glyphCache=new Map();
|
|
441
436
|
const record=(offsets,id)=>{
|
|
442
437
|
if(!Number.isInteger(id)||id<0||id+1>=offsets.length)return;
|
|
443
438
|
const offset=offsets[id],page=offset>>>15,next=offsets[id+1];let bytes=pageCache[page];
|
|
@@ -454,8 +449,8 @@ for(const command of commands){if(command<1||command>5)invalid();values+=command
|
|
|
454
449
|
for(let i=0;i<values;i++)coordinates[i]=signed(r);}
|
|
455
450
|
complete(r);const value=[commands,coordinates,closes];local.set(id,value);return value;
|
|
456
451
|
};
|
|
457
|
-
// Bounds
|
|
458
|
-
//
|
|
452
|
+
// Bounds derive from the outline with fontTools' BoundsPen, operation for operation, so each value is the one
|
|
453
|
+
// the generator would have stored.
|
|
459
454
|
const quadratic=(a,b,c)=>{if(Math.abs(a)<1e-10)return Math.abs(b)<1e-10?[]:[-c/b];const d=b*b-4*a*c;if(d<0)return [];const root=Math.sqrt(d);return [(-b+root)/2/a,(-b-root)/2/a];};
|
|
460
455
|
const cubic=s=>{const cx=(s[2]-s[0])*3,cy=(s[3]-s[1])*3,bx=(s[4]-s[2])*3-cx,by=(s[5]-s[3])*3-cy;return [s[6]-s[0]-cx-bx,s[7]-s[1]-cy-by,bx,by,cx,cy,s[0],s[1]];};
|
|
461
456
|
const add=(box,x,y)=>box?[Math.min(box[0],x),Math.min(box[1],y),Math.max(box[2],x),Math.max(box[3],y)]:[x,y,x,y];
|
|
@@ -463,27 +458,10 @@ const inside=(box,x,y)=>box[0]<=x&&x<=box[2]&&box[1]<=y&&y<=box[3];
|
|
|
463
458
|
const curveBox=(box,s)=>{const [ax,ay,bx,by,cx,cy,dx,dy]=cubic(s),roots=[...quadratic(ax*3,bx*2,cx).filter(t=>0<=t&&t<1),...quadratic(ay*3,by*2,cy).filter(t=>0<=t&&t<1)];
|
|
464
459
|
let curve=add(add(null,s[0],s[1]),s[6],s[7]);for(const t of roots)curve=add(curve,ax*t*t*t+bx*t*t+cx*t+dx,ay*t*t*t+by*t*t+cy*t+dy);
|
|
465
460
|
return [Math.min(box[0],curve[0]),Math.min(box[1],curve[1]),Math.max(box[2],curve[2]),Math.max(box[3],curve[3])];};
|
|
466
|
-
const profileOf=(segments,bottom,top)=>{
|
|
467
|
-
const step=__EDGE_STEP__,first=Math.floor(bottom/step)*step,strips=Array.from({length:Math.max(1,Math.ceil((top-first)/step))},()=>[]);
|
|
468
|
-
for(const s of segments){
|
|
469
|
-
if(s.length===4){const [x,y,endX,endY]=s;strips.forEach((strip,i)=>{const lower=first+i*step,upper=lower+step,values=[0,1];
|
|
470
|
-
if(endY!==y)values.push((lower-y)/(endY-y),(upper-y)/(endY-y));
|
|
471
|
-
for(const t of values){const at=y+t*(endY-y);if(0<=t&&t<=1&&lower-1e-7<=at&&at<=upper+1e-7)strip.push(x+t*(endX-x));}});continue;}
|
|
472
|
-
const [a0,a1,b0,b1,c0,c1,d0,d1]=cubic(s),vertical=t=>((a1*t+b1)*t+c1)*t+d1,extrema=[0,1,...quadratic(3*a0,2*b0,c0)],
|
|
473
|
-
critical=[0,1,...quadratic(3*a1,2*b1,c1).filter(t=>0<t&&t<1)].sort((p,q)=>p-q),crossings=new Map,
|
|
474
|
-
crossing=height=>{if(crossings.has(height))return crossings.get(height);const roots=[];
|
|
475
|
-
for(let i=1;i<critical.length;i++){let low=critical[i-1],high=critical[i];const yLow=vertical(low),yHigh=vertical(high);
|
|
476
|
-
if(!(Math.min(yLow,yHigh)<=height&&height<=Math.max(yLow,yHigh)))continue;
|
|
477
|
-
for(let k=0;k<45;k++){const middle=(low+high)/2;if((vertical(middle)<height)===(yLow<yHigh))low=middle;else high=middle;}roots.push((low+high)/2);}
|
|
478
|
-
crossings.set(height,roots);return roots;},ys=[s[1],s[3],s[5],s[7]],yMin=Math.min(...ys),yMax=Math.max(...ys);
|
|
479
|
-
strips.forEach((strip,i)=>{const lower=first+i*step,upper=lower+step;if(lower>yMax||upper<yMin)return;
|
|
480
|
-
for(const t of [...extrema,...crossing(lower),...crossing(upper)])if(0<=t&&t<=1){const y=((a1*t+b1)*t+c1)*t+d1;if(lower-1e-7<=y&&y<=upper+1e-7)strip.push(((a0*t+b0)*t+c0)*t+d0);}});}
|
|
481
|
-
return [first,...strips.map(strip=>strip.length?[Math.floor(Math.min(...strip)-1e-7),Math.ceil(Math.max(...strip)+1e-7)]:null)];
|
|
482
|
-
};
|
|
483
461
|
const glyphRecord=id=>{
|
|
484
462
|
let cached=glyphCache.get(id);if(cached)return cached;const r=record(glyphs,id);if(!r)return;
|
|
485
463
|
const metrics=[];for(let i=0;i<3;i++)metrics.push(signed(r)+metricBases[i]);metrics[2]+=metrics[0]/2;
|
|
486
|
-
const count=unsigned(r),local=new Map()
|
|
464
|
+
const count=unsigned(r),local=new Map();let path='',box=null;
|
|
487
465
|
if(count>r[2]-r[1])invalid();
|
|
488
466
|
for(let part=0;part<count;part++){const contourId=unsigned(r),firstX=signed(r),firstY=signed(r),[commands,coordinates,closes]=contour(contourId,local);let x=firstX,y=firstY,cursor=0;
|
|
489
467
|
path+='M'+x/unit+' '+y/unit;box=add(box,x/unit,y/unit);
|
|
@@ -491,19 +469,13 @@ for(let c=0;c<commands.length;c++){const command=commands[c],from=[x/unit,y/unit
|
|
|
491
469
|
for(let index=0;index<commandLengths[command];index++){if(index)path+=' ';
|
|
492
470
|
const last=closes&&c===commands.length-2&&index>3;
|
|
493
471
|
if(command===3||(command!==2&&command!==3&&index%2)){y=last?firstY:y+coordinates[cursor++];path+=y/unit;from.push(x/unit,y/unit);}else{x=last?firstX:x+coordinates[cursor++];path+=x/unit;if(command===2)from.push(x/unit,y/unit);}}
|
|
494
|
-
if(command===5){
|
|
495
|
-
if(command===4){const end=add(box,from[6],from[7]);box=inside(end,from[2],from[3])&&inside(end,from[4],from[5])?end:curveBox(end,from);}else box=add(box,from[2],from[3]);
|
|
496
|
-
if(keep)segments.push(from);}
|
|
472
|
+
if(command===5){x=firstX;y=firstY;continue;}
|
|
473
|
+
if(command===4){const end=add(box,from[6],from[7]);box=inside(end,from[2],from[3])&&inside(end,from[4],from[5])?end:curveBox(end,from);}else box=add(box,from[2],from[3]);}
|
|
497
474
|
}complete(r);box??=[0,0,0,0];
|
|
498
475
|
const glyph=[metrics[0]/metricUnit,Math.floor(box[0]),Math.floor(box[1]),Math.ceil(box[2]),Math.ceil(box[3]),metrics[1]/metricUnit,metrics[2]/metricUnit,path];
|
|
499
|
-
|
|
500
|
-
cached={glyph,segments:keep?segments:null,bottom:box[1],top:box[3]};glyphCache.set(id,cached);return cached;
|
|
476
|
+
cached={glyph};glyphCache.set(id,cached);return cached;
|
|
501
477
|
};
|
|
502
478
|
MATH_FONT.glyph=id=>glyphRecord(id)?.glyph;
|
|
503
|
-
MATH_FONT.profile=id=>{
|
|
504
|
-
if(profileCache.has(id))return profileCache.get(id);const glyph=glyphRecord(id),profile=glyph?.segments?.length?profileOf(glyph.segments,glyph.bottom,glyph.top):undefined;
|
|
505
|
-
profileCache.set(id,profile);return profile;
|
|
506
|
-
};
|
|
507
479
|
}
|
|
508
480
|
"""
|
|
509
481
|
|
|
@@ -514,6 +486,8 @@ def main():
|
|
|
514
486
|
parser.add_argument("--license", type=Path, help="Optional pinned GUST Font License; otherwise fetch it")
|
|
515
487
|
parser.add_argument("--lppl", type=Path, help="Optional pinned LPPL 1.3c; otherwise fetch it")
|
|
516
488
|
parser.add_argument("--text-font", type=Path, help="Optional pinned Geist calibration font; otherwise use the editor copy or fetch it")
|
|
489
|
+
parser.add_argument("--mono-font", type=Path, help="Optional pinned Latin Modern Mono font for text punctuation; otherwise fetch it")
|
|
490
|
+
parser.add_argument("--hook-font", type=Path, help="Optional pinned Latin Modern Math Italic font for its arrow hook; otherwise fetch it")
|
|
517
491
|
parser.add_argument("--out", type=Path, default=Path(__file__).with_name("font.js"))
|
|
518
492
|
args = parser.parse_args()
|
|
519
493
|
font_bytes = source_bytes(args.font, SOURCE_URL, SOURCE_SHA256)
|
|
@@ -523,22 +497,56 @@ def main():
|
|
|
523
497
|
text_bytes = source_bytes(args.text_font or (local_text if local_text.exists() else None), TEXT_URL, TEXT_SHA256)
|
|
524
498
|
font = TTFont(io.BytesIO(font_bytes))
|
|
525
499
|
text_font = TTFont(io.BytesIO(text_bytes))
|
|
500
|
+
mono = TTFont(io.BytesIO(source_bytes(args.mono_font, MONO_URL, MONO_SHA256)))
|
|
526
501
|
data = extract(font)
|
|
502
|
+
# The math font already carries the exact 62 Mono letters and digits. Text punctuation, visible space and
|
|
503
|
+
# sharp s have no mathematical monospace code points; keep their original Mono outlines beside it.
|
|
504
|
+
if mono["head"].unitsPerEm != data["units"]:
|
|
505
|
+
raise ValueError("The monospace outline must share the math font's units")
|
|
506
|
+
mono_glyphs = mono.getGlyphSet()
|
|
507
|
+
data["styledGlyphs"] = {"monospace": {}}
|
|
508
|
+
for cp in [0xDF, *(cp for cp in range(33, 127) if not chr(cp).isalnum()), 0x2423]:
|
|
509
|
+
name = mono.getBestCmap()[cp]
|
|
510
|
+
path = SVGPathPen(mono_glyphs, ntos=number)
|
|
511
|
+
mono_glyphs[name].draw(path)
|
|
512
|
+
advance = mono["hmtx"].metrics[name][0]
|
|
513
|
+
data["styledGlyphs"]["monospace"][cp] = len(data["glyphs"])
|
|
514
|
+
data["glyphs"].append([advance, 0, advance / 2, path.getCommands()])
|
|
515
|
+
# amsmath's hooked arrow uses the small math-italic hook, not Unicode's taller hooked-arrow glyph.
|
|
516
|
+
with tempfile.NamedTemporaryFile() as source:
|
|
517
|
+
source.write(source_bytes(args.hook_font, HOOK_URL, HOOK_SHA256))
|
|
518
|
+
source.flush()
|
|
519
|
+
hook = T1Font(source.name, kind="PFB")
|
|
520
|
+
hook_glyphs = hook.getGlyphSet()
|
|
521
|
+
path = SVGPathPen(hook_glyphs, ntos=number)
|
|
522
|
+
hook_glyphs["arrowhookleft"].draw(path)
|
|
523
|
+
data["arrowHook"] = len(data["glyphs"])
|
|
524
|
+
# This is an outline-only endpoint; the arrow composer supplies TeX's five-mu advance.
|
|
525
|
+
data["glyphs"].append([0, 0, 0, path.getCommands()])
|
|
527
526
|
data.update(textXHeight=text_font["OS/2"].sxHeight, textUnits=text_font["head"].unitsPerEm)
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
527
|
+
heading = (font["name"].getDebugName(0) + "\n\n"
|
|
528
|
+
+ mono["name"].getDebugName(0) + "\n\n"
|
|
529
|
+
+ hook["FontInfo"]["Notice"] + "\n\n"
|
|
530
|
+
"Rapier math font data, derived from Latin Modern Math 1.959,\n"
|
|
531
|
+
"text outlines from Latin Modern Mono 2.004, and one arrow hook\n"
|
|
532
|
+
"from Latin Modern Math Italic 10 Regular 2.003.\n"
|
|
533
|
+
"Changes: SVG outline conversion, character and MATH data extraction,\n"
|
|
534
|
+
"optical-form closure and lossless path packing.\n"
|
|
535
|
+
"Original outlines are unchanged. Hinting and text shaping tables are omitted.\n"
|
|
536
|
+
"The font authors do not maintain this conversion.\n"
|
|
537
|
+
"Complete original work: https://mirrors.ctan.org/fonts/lm-math.zip\n"
|
|
538
|
+
"Mono and hook original work: https://mirrors.ctan.org/fonts/lm.zip\n"
|
|
539
|
+
"Conversion details: FONT-SOURCE.md.\n\n").encode("utf-8")
|
|
540
|
+
notice = heading + gust + b"\n" + lppl
|
|
541
|
+
# The data file carries its copyright and notice; the complete license (GUST Font License and LPPL 1.3c) is the
|
|
542
|
+
# FONT-LICENSE.txt beside it, and the single-file renderer bundle carries that file whole.
|
|
543
|
+
pointer = b"Complete license: FONT-LICENSE.txt (GUST Font License and LPPL 1.3c).\n"
|
|
536
544
|
pages, index, size, packing = pack_font(data)
|
|
537
545
|
glyph_count = len(data["glyphs"])
|
|
538
546
|
character_count = len(data["chars"])
|
|
539
|
-
for name in ("glyphs", "
|
|
547
|
+
for name in ("glyphs", "vertical", "horizontal", *SCALAR_MAPS, "scriptAlternates"):
|
|
540
548
|
del data[name]
|
|
541
|
-
output = (b"/*!\n" +
|
|
549
|
+
output = (b"/*!\n" + heading + pointer + b"*/\nconst MATH_FONT=" + json.dumps(data, ensure_ascii=True, separators=(",", ":")).encode("utf-8") + b";\n" + PATH_DECODER.replace("__PAGES__", json.dumps(pages, separators=(",", ":"))).replace("__INDEX__", json.dumps(index)).replace("__SIZE__", str(size)).replace("__MAP_FIELDS__", json.dumps(SCALAR_MAPS, separators=(",", ":"))).encode("utf-8") + b"\n\nexport {MATH_FONT};\n")
|
|
542
550
|
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
543
551
|
args.out.write_bytes(output)
|
|
544
552
|
args.out.with_name("FONT-LICENSE.txt").write_bytes(notice)
|
package/src/math/classic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
globalThis.RapierMath=Object.freeze({
|
|
3
|
-
version:'2.
|
|
3
|
+
version:'2.7.0', parse:parseMathTex,
|
|
4
4
|
render:renderMath, renderToString:mathRenderToString,
|
|
5
5
|
fit:mathFit, observe:mathObserve,
|
|
6
6
|
toMathML:mathToMathML, renderWithMathML:mathRenderWithMathML,
|