feat: 新增 page3 演职员表并拆分多页资源

- 新增 page3.html:无「天」背景的演职员表与火山场景
- 重构为页面专属 CSS/JS 与共用的 text-scene 渲染引擎
- PDF 导出支持 --page 参数
This commit is contained in:
rogerwang2008 committed 2026-11-11 00:13:14 +08:00
1 parent b9ed01d91b
commit 319ba1890a
11 files changed
+539 -258

No files matched your search

+13 -5
View File
@@ -1,10 +1,11 @@
"""将 index.html 导出为 PDF,画面四边各留恰好 1em。
"""将文字画页面导出为 PDF,画面四边各留恰好 1em。
页面为 28 × 44 格文字画,1em 即一个汉字格。导出页尺寸为 30em × 46em,
场景四周各留 1em;底色铺满整页。
用法:
uv run python scripts/export_pdf.py
uv run python scripts/export_pdf.py --page page2.html -o dist/page2.pdf
uv run python scripts/export_pdf.py --em 16 -o dist/封面demo-16.pdf
"""
@@ -16,7 +17,6 @@ import pathlib
from playwright.sync_api import sync_playwright
ROOT = pathlib.Path(__file__).resolve().parents[1]
HTML = ROOT / "index.html"
COLS = 28
ROWS = 44
@@ -71,7 +71,7 @@ def launch_browser(pw):
)
def export(em: float, out: pathlib.Path) -> None:
def export(em: float, out: pathlib.Path, html: pathlib.Path) -> None:
css, page_w, page_h = export_css(em)
with sync_playwright() as pw:
@@ -80,7 +80,7 @@ def export(em: float, out: pathlib.Path) -> None:
viewport={"width": round(page_w), "height": round(page_h)},
device_scale_factor=1,
)
page.goto(HTML.as_uri(), wait_until="load")
page.goto(html.as_uri(), wait_until="load")
page.evaluate("() => document.fonts.ready")
if not page.evaluate("document.fonts.check('16px Zpix')"):
raise SystemExit("Zpix 字体未加载,无法导出。")
@@ -128,6 +128,11 @@ def export(em: float, out: pathlib.Path) -> None:
def main() -> None:
parser = argparse.ArgumentParser(description="将文字画页面导出为 PDF(四周各留 1em)")
parser.add_argument(
"--page",
default="page1.html",
help="要导出的 HTML 文件,默认 page1.html",
)
parser.add_argument(
"--em",
type=float,
@@ -144,7 +149,10 @@ def main() -> None:
args = parser.parse_args()
if args.em <= 0:
parser.error("--em 必须大于 0")
export(args.em, args.out.resolve())
html = (ROOT / args.page).resolve()
if not html.is_file():
parser.error(f"页面不存在:{args.page}")
export(args.em, args.out.resolve(), html)
if __name__ == "__main__":