Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate SVG paths from the exact Type1 programs embedded in math PDFs.
|
||||
|
||||
Requires fontTools only when regenerating. Runtime previews use the bundled
|
||||
paths, so they need neither installed fonts nor an external conversion tool.
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from fontTools.pens.svgPathPen import SVGPathPen
|
||||
from fontTools.t1Lib import T1Font
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
NAMES = ["cmr10", "cmr7", "cmr5", "cmmi10", "cmmi7", "cmmi5",
|
||||
"cmsy10", "cmsy7", "cmsy5", "cmex10"]
|
||||
result = []
|
||||
for name in NAMES:
|
||||
font = T1Font(str(ROOT / "assets/fonts" / (name + ".pfb")))
|
||||
glyphs = font.getGlyphSet()
|
||||
encoding = font["Encoding"]
|
||||
paths = []
|
||||
for slot in range(256):
|
||||
glyph = encoding[slot]
|
||||
if glyph == ".notdef" or glyph not in glyphs:
|
||||
paths.append("")
|
||||
continue
|
||||
pen = SVGPathPen(glyphs)
|
||||
glyphs[glyph].draw(pen)
|
||||
paths.append(pen.getCommands())
|
||||
result.append(paths)
|
||||
output = ROOT / "crates/texrra-tex-core/assets/math-outlines.json"
|
||||
output.write_text(json.dumps(result, separators=(",", ":")) + "\n")
|
||||
print(output)
|
||||
Reference in new issue
Block a user