From a9089531d5c53db7a3d657bb7c7db99cce70a209 Mon Sep 17 00:00:00 2001 From: szdytom Date: Fri, 11 Jul 2025 13:40:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=86=85=E5=AD=98=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=94=AF=E6=8C=81=E4=BB=A5=E5=9C=A8Linux=E4=B8=8A?= =?UTF-8?q?=E5=B0=86PDF=E7=94=9F=E6=88=90=E5=88=B0=E5=86=85=E5=AD=98?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: szdytom --- make.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/make.py b/make.py index d692a52..ef70e6a 100644 --- a/make.py +++ b/make.py @@ -171,13 +171,20 @@ def prepare_typst(): print(f"Typst downloaded and extracted to {typst_bin_path}.") return True -def invoke_typst(mode="c"): +def invoke_typst(mode="c", mem_mode=False): """调用 typst 命令""" if not typst_bin_path.exists(): print("Typst executable not found.") return False command = [str(typst_bin_path), mode, "--font-path", str(fonts_dir), "--ignore-system-fonts", "main.typ"] + if mem_mode: + if platform.system().lower() == "linux": + command.extend(["/dev/shm/main.pdf"]) + else: + print("Memory mode is only supported on Linux.") + return False + print("Executing command: ", " ".join(command)) try: os.execv(str(typst_bin_path), command) @@ -189,6 +196,8 @@ def main(): parser = argparse.ArgumentParser(description="Run Typst with specified mode.") parser.add_argument('--mode', type=str, choices=['w', 'c'], default='c', help="Mode to run Typst: 'w' for watch mode, 'c' for compile mode.") + parser.add_argument('--mem', action='store_true', + help="Generate PDF to memory (/dev/shm) instead of file system. (Linux only)") args = parser.parse_args() if not prepare_fonts(): @@ -196,7 +205,7 @@ def main(): if not prepare_typst(): return - invoke_typst(mode=args.mode) + invoke_typst(mode=args.mode, mem_mode=args.mem) if __name__ == "__main__": main()