rapier-math 2.4.0 → 2.6.1
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 +678 -229
- package/docs/api.md +6 -2
- package/docs/font-source.md +37 -29
- 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 +61 -65
- package/src/math/classic.js +1 -1
- package/src/math/font.js +23 -487
- package/src/math/layout.js +302 -112
- package/src/math/mathml.js +26 -7
- package/src/math/package-layout.mjs +1 -0
- package/src/math/package-readme.mjs +3 -4
- package/src/math/parser.js +306 -67
- package/src/tools/build-math.mjs +22 -7
- package/tests/adoption.mjs +0 -252
- package/tests/check.mjs +0 -133
- package/tests/semantics.mjs +0 -340
- package/tests/typeset.mjs +0 -172
- package/tests/verify.mjs +0 -49
|
@@ -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
|
+
the sharp s of 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,12 @@ 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.t1Lib import T1Font
|
|
23
24
|
from fontTools.ttLib import TTFont
|
|
24
25
|
|
|
25
26
|
|
|
@@ -32,7 +33,10 @@ LPPL_URL = "https://www.latex-project.org/lppl/lppl-1-3c.txt"
|
|
|
32
33
|
LPPL_SHA256 = "3d262cdf34dafa6955f703c634a8c238ec44109bc8dd6ef34fb7aa54809f7e66"
|
|
33
34
|
TEXT_URL = "https://raw.githubusercontent.com/jackskip22/rapier/326a7387a190b011543fae5f5f2c6144f6163b3d/src/shell/fonts/Geist.wght400-700.woff2"
|
|
34
35
|
TEXT_SHA256 = "6e3a140e3812161e292fbe42a1fc90533b2407b699c65abc7a098b0979df4e82"
|
|
35
|
-
|
|
36
|
+
MONO_URL = "https://ftp.riken.jp/CTAN/fonts/lm/fonts/opentype/public/lm/lmmono10-regular.otf"
|
|
37
|
+
MONO_SHA256 = "22deb6d3be3ffcb40b33f0e010afb256c677d97c2a2bdee1f5740cdc97751558"
|
|
38
|
+
HOOK_URL = "https://ftp.riken.jp/CTAN/fonts/lm/fonts/type1/public/lm/lmmi10.pfb"
|
|
39
|
+
HOOK_SHA256 = "c24662506b402f3e0033cc75eb746eb490a1b7477e6b3ef52053f5025ec0fc57"
|
|
36
40
|
|
|
37
41
|
|
|
38
42
|
def source_bytes(local: Path | None, remote: str, expected: str) -> bytes:
|
|
@@ -125,7 +129,6 @@ def extract(font: TTFont):
|
|
|
125
129
|
"flatAccents": {ids[name]: ids[alternates[0]] for name, alternates in flattened.items() if name in ids},
|
|
126
130
|
"dotless": {ids[name]: ids[alternates[0]] for name, alternates in dotless.items() if name in ids},
|
|
127
131
|
"extendedShapes": {ids[name]: 1 for name in (info.ExtendedShapeCoverage.glyphs if info.ExtendedShapeCoverage else []) if name in ids},
|
|
128
|
-
"edgeStep": EDGE_STEP,
|
|
129
132
|
}
|
|
130
133
|
for axis, key in (("Vert", "vertical"), ("Horiz", "horizontal")):
|
|
131
134
|
coverage = getattr(variants, axis + "GlyphCoverage")
|
|
@@ -150,17 +153,6 @@ def extract(font: TTFont):
|
|
|
150
153
|
corner = getattr(record, key)
|
|
151
154
|
corners.append([list(map(scalar, corner.CorrectionHeight)), list(map(scalar, corner.KernValue))] if corner else None)
|
|
152
155
|
data["kern"][ids[name]] = corners
|
|
153
|
-
# Script kerning reads a contour profile for Latin letters and digits, the italic and script alphabets
|
|
154
|
-
# (with U+210E, the italic h), and their optical and dotless forms. The decoder derives each profile.
|
|
155
|
-
profiled = {
|
|
156
|
-
name for cp, name in cmap.items()
|
|
157
|
-
if (cp < 128 and chr(cp).isalnum()) or cp == 0x210E
|
|
158
|
-
or any(style in unicodedata.name(chr(cp), "") for style in ("ITALIC", "SCRIPT"))
|
|
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)
|
|
164
156
|
return data
|
|
165
157
|
|
|
166
158
|
|
|
@@ -215,7 +207,7 @@ def pack_font(data):
|
|
|
215
207
|
for token in tokens:
|
|
216
208
|
if "." in token:
|
|
217
209
|
unit = math.lcm(unit, Fraction(token).denominator)
|
|
218
|
-
# Derived bounds
|
|
210
|
+
# Derived bounds divide by the unit; a power of two keeps every coordinate exact.
|
|
219
211
|
if unit & (unit - 1):
|
|
220
212
|
raise ValueError("Font coordinates need a power-of-two unit")
|
|
221
213
|
metric_unit = math.lcm(2, *(Fraction(value).denominator for glyph in glyphs for value in glyph[:3]))
|
|
@@ -336,11 +328,6 @@ def pack_font(data):
|
|
|
336
328
|
for index, value in enumerate(values):
|
|
337
329
|
signed(value - previous_values[index], indices)
|
|
338
330
|
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
331
|
for name in ("vertical", "horizontal"):
|
|
345
332
|
unsigned(len(data[name]), indices)
|
|
346
333
|
previous_key = 0
|
|
@@ -380,7 +367,7 @@ def pack_font(data):
|
|
|
380
367
|
|
|
381
368
|
packed = [(len(page), text(page)) for page in pages]
|
|
382
369
|
return packed, text(indices), len(indices), {
|
|
383
|
-
"contours": len(contours), "contourReferences": sum(map(len, references)),
|
|
370
|
+
"contours": len(contours), "contourReferences": sum(map(len, references)),
|
|
384
371
|
"pages": len(pages), "pageBytes": PAGE_BYTES, "indexBytes": len(indices),
|
|
385
372
|
"recordBytes": sum(map(len, pages)), "maxParentDepth": PARENT_DEPTH,
|
|
386
373
|
}
|
|
@@ -423,21 +410,20 @@ if(written!==bytes.length||position-Math.floor(available/8)!==source.length)inva
|
|
|
423
410
|
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
411
|
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
412
|
const complete=r=>{if(r[1]!==r[2])invalid();};
|
|
426
|
-
const [unit,metricUnit,metricBases,
|
|
413
|
+
const [unit,metricUnit,metricBases,glyphs,contours]=(()=>{
|
|
427
414
|
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
415
|
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
416
|
for(let i=0;i<count;i++){key+=unsigned(r);value+=signed(r);map[key]=value;}}
|
|
430
417
|
const scripts=MATH_FONT.scriptAlternates={},scriptCount=unsigned(r),previous=[0,0];let key=0;if(scriptCount>bytes.length)invalid();
|
|
431
418
|
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
419
|
for(const name of ['vertical','horizontal']){const map=MATH_FONT[name]={},count=unsigned(r);key=0;if(count>bytes.length)invalid();
|
|
434
420
|
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
421
|
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
422
|
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
|
|
423
|
+
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
424
|
})();
|
|
439
|
-
// Each page
|
|
440
|
-
const pageCache=[],glyphCache=new Map()
|
|
425
|
+
// Each page and glyph decodes once and stays: the font itself bounds every cache.
|
|
426
|
+
const pageCache=[],glyphCache=new Map();
|
|
441
427
|
const record=(offsets,id)=>{
|
|
442
428
|
if(!Number.isInteger(id)||id<0||id+1>=offsets.length)return;
|
|
443
429
|
const offset=offsets[id],page=offset>>>15,next=offsets[id+1];let bytes=pageCache[page];
|
|
@@ -454,8 +440,8 @@ for(const command of commands){if(command<1||command>5)invalid();values+=command
|
|
|
454
440
|
for(let i=0;i<values;i++)coordinates[i]=signed(r);}
|
|
455
441
|
complete(r);const value=[commands,coordinates,closes];local.set(id,value);return value;
|
|
456
442
|
};
|
|
457
|
-
// Bounds
|
|
458
|
-
//
|
|
443
|
+
// Bounds derive from the outline with fontTools' BoundsPen, operation for operation, so each value is the one
|
|
444
|
+
// the generator would have stored.
|
|
459
445
|
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
446
|
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
447
|
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 +449,10 @@ const inside=(box,x,y)=>box[0]<=x&&x<=box[2]&&box[1]<=y&&y<=box[3];
|
|
|
463
449
|
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
450
|
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
451
|
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
452
|
const glyphRecord=id=>{
|
|
484
453
|
let cached=glyphCache.get(id);if(cached)return cached;const r=record(glyphs,id);if(!r)return;
|
|
485
454
|
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()
|
|
455
|
+
const count=unsigned(r),local=new Map();let path='',box=null;
|
|
487
456
|
if(count>r[2]-r[1])invalid();
|
|
488
457
|
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
458
|
path+='M'+x/unit+' '+y/unit;box=add(box,x/unit,y/unit);
|
|
@@ -491,19 +460,13 @@ for(let c=0;c<commands.length;c++){const command=commands[c],from=[x/unit,y/unit
|
|
|
491
460
|
for(let index=0;index<commandLengths[command];index++){if(index)path+=' ';
|
|
492
461
|
const last=closes&&c===commands.length-2&&index>3;
|
|
493
462
|
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);}
|
|
463
|
+
if(command===5){x=firstX;y=firstY;continue;}
|
|
464
|
+
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
465
|
}complete(r);box??=[0,0,0,0];
|
|
498
466
|
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;
|
|
467
|
+
cached={glyph};glyphCache.set(id,cached);return cached;
|
|
501
468
|
};
|
|
502
469
|
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
470
|
}
|
|
508
471
|
"""
|
|
509
472
|
|
|
@@ -514,6 +477,8 @@ def main():
|
|
|
514
477
|
parser.add_argument("--license", type=Path, help="Optional pinned GUST Font License; otherwise fetch it")
|
|
515
478
|
parser.add_argument("--lppl", type=Path, help="Optional pinned LPPL 1.3c; otherwise fetch it")
|
|
516
479
|
parser.add_argument("--text-font", type=Path, help="Optional pinned Geist calibration font; otherwise use the editor copy or fetch it")
|
|
480
|
+
parser.add_argument("--mono-font", type=Path, help="Optional pinned Latin Modern Mono font for its sharp s; otherwise fetch it")
|
|
481
|
+
parser.add_argument("--hook-font", type=Path, help="Optional pinned Latin Modern Math Italic font for its arrow hook; otherwise fetch it")
|
|
517
482
|
parser.add_argument("--out", type=Path, default=Path(__file__).with_name("font.js"))
|
|
518
483
|
args = parser.parse_args()
|
|
519
484
|
font_bytes = source_bytes(args.font, SOURCE_URL, SOURCE_SHA256)
|
|
@@ -523,22 +488,53 @@ def main():
|
|
|
523
488
|
text_bytes = source_bytes(args.text_font or (local_text if local_text.exists() else None), TEXT_URL, TEXT_SHA256)
|
|
524
489
|
font = TTFont(io.BytesIO(font_bytes))
|
|
525
490
|
text_font = TTFont(io.BytesIO(text_bytes))
|
|
491
|
+
mono = TTFont(io.BytesIO(source_bytes(args.mono_font, MONO_URL, MONO_SHA256)))
|
|
526
492
|
data = extract(font)
|
|
493
|
+
# Unicode has no mathematical monospace sharp s; retain that one original Mono outline beside the math font.
|
|
494
|
+
if mono["head"].unitsPerEm != data["units"]:
|
|
495
|
+
raise ValueError("The monospace outline must share the math font's units")
|
|
496
|
+
mono_glyphs = mono.getGlyphSet()
|
|
497
|
+
name = mono.getBestCmap()[0xDF]
|
|
498
|
+
path = SVGPathPen(mono_glyphs, ntos=number)
|
|
499
|
+
mono_glyphs[name].draw(path)
|
|
500
|
+
advance = mono["hmtx"].metrics[name][0]
|
|
501
|
+
data["styledGlyphs"] = {"monospace": {0xDF: len(data["glyphs"])}}
|
|
502
|
+
data["glyphs"].append([advance, 0, advance / 2, path.getCommands()])
|
|
503
|
+
# amsmath's hooked arrow uses the small math-italic hook, not Unicode's taller hooked-arrow glyph.
|
|
504
|
+
with tempfile.NamedTemporaryFile() as source:
|
|
505
|
+
source.write(source_bytes(args.hook_font, HOOK_URL, HOOK_SHA256))
|
|
506
|
+
source.flush()
|
|
507
|
+
hook = T1Font(source.name, kind="PFB")
|
|
508
|
+
hook_glyphs = hook.getGlyphSet()
|
|
509
|
+
path = SVGPathPen(hook_glyphs, ntos=number)
|
|
510
|
+
hook_glyphs["arrowhookleft"].draw(path)
|
|
511
|
+
data["arrowHook"] = len(data["glyphs"])
|
|
512
|
+
# This is an outline-only endpoint; the arrow composer supplies TeX's five-mu advance.
|
|
513
|
+
data["glyphs"].append([0, 0, 0, path.getCommands()])
|
|
527
514
|
data.update(textXHeight=text_font["OS/2"].sxHeight, textUnits=text_font["head"].unitsPerEm)
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
515
|
+
heading = (font["name"].getDebugName(0) + "\n\n"
|
|
516
|
+
+ mono["name"].getDebugName(0) + "\n\n"
|
|
517
|
+
+ hook["FontInfo"]["Notice"] + "\n\n"
|
|
518
|
+
"Rapier math font data, derived from Latin Modern Math 1.959,\n"
|
|
519
|
+
"the sharp s of Latin Modern Mono 2.004, and one arrow hook\n"
|
|
520
|
+
"from Latin Modern Math Italic 10 Regular 2.003.\n"
|
|
521
|
+
"Changes: SVG outline conversion, character and MATH data extraction,\n"
|
|
522
|
+
"optical-form closure and lossless path packing.\n"
|
|
523
|
+
"Original outlines are unchanged. Hinting and text shaping tables are omitted.\n"
|
|
524
|
+
"The font authors do not maintain this conversion.\n"
|
|
525
|
+
"Complete original work: https://mirrors.ctan.org/fonts/lm-math.zip\n"
|
|
526
|
+
"Mono and hook original work: https://mirrors.ctan.org/fonts/lm.zip\n"
|
|
527
|
+
"Conversion details: FONT-SOURCE.md.\n\n").encode("utf-8")
|
|
528
|
+
notice = heading + gust + b"\n" + lppl
|
|
529
|
+
# The data file carries its copyright and notice; the complete license (GUST Font License and LPPL 1.3c) is the
|
|
530
|
+
# FONT-LICENSE.txt beside it, and the single-file renderer bundle carries that file whole.
|
|
531
|
+
pointer = b"Complete license: FONT-LICENSE.txt (GUST Font License and LPPL 1.3c).\n"
|
|
536
532
|
pages, index, size, packing = pack_font(data)
|
|
537
533
|
glyph_count = len(data["glyphs"])
|
|
538
534
|
character_count = len(data["chars"])
|
|
539
|
-
for name in ("glyphs", "
|
|
535
|
+
for name in ("glyphs", "vertical", "horizontal", *SCALAR_MAPS, "scriptAlternates"):
|
|
540
536
|
del data[name]
|
|
541
|
-
output = (b"/*!\n" +
|
|
537
|
+
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
538
|
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
543
539
|
args.out.write_bytes(output)
|
|
544
540
|
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.6.1', parse:parseMathTex,
|
|
4
4
|
render:renderMath, renderToString:mathRenderToString,
|
|
5
5
|
fit:mathFit, observe:mathObserve,
|
|
6
6
|
toMathML:mathToMathML, renderWithMathML:mathRenderWithMathML,
|