draftboard 0.0.1__tar.gz
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.
- draftboard-0.0.1/.env.example +15 -0
- draftboard-0.0.1/.gitignore +37 -0
- draftboard-0.0.1/.python-version +1 -0
- draftboard-0.0.1/PKG-INFO +16 -0
- draftboard-0.0.1/examples/integration_export.pptx +0 -0
- draftboard-0.0.1/examples/sample_deck.json +105 -0
- draftboard-0.0.1/examples/sample_deck.pptx +0 -0
- draftboard-0.0.1/pyproject.toml +49 -0
- draftboard-0.0.1/scripts/probe_render.py +222 -0
- draftboard-0.0.1/src/draftboard/__init__.py +41 -0
- draftboard-0.0.1/src/draftboard/__main__.py +225 -0
- draftboard-0.0.1/src/draftboard/agent.py +104 -0
- draftboard-0.0.1/src/draftboard/api.py +901 -0
- draftboard-0.0.1/src/draftboard/measure.py +225 -0
- draftboard-0.0.1/src/draftboard/models.py +407 -0
- draftboard-0.0.1/src/draftboard/pptx_export.py +479 -0
- draftboard-0.0.1/src/draftboard/render.py +80 -0
- draftboard-0.0.1/src/draftboard/static/404.html +1 -0
- draftboard-0.0.1/src/draftboard/static/__next.__PAGE__.txt +27 -0
- draftboard-0.0.1/src/draftboard/static/__next._full.txt +22 -0
- draftboard-0.0.1/src/draftboard/static/__next._tree.txt +3 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_buildManifest.js +11 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_clientMiddlewareManifest.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_ssgManifest.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/0cz1d0mv5g_q7.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/0oheds1fsp9jx.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/1vsonpqt4u2rw.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/24xul4hawiu8l.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/2r7iycbt4s29o.js +22 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/2utugak-w5oge.css +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/39_j1bdzreq0m.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/3qfy96eoyh-ek.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/3u8gxd9uztfzl.js +4 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/3v_59l1qr_8dp.js +31 -0
- draftboard-0.0.1/src/draftboard/static/_next/static/chunks/turbopack-2u1d16houkiyo.js +1 -0
- draftboard-0.0.1/src/draftboard/static/_not-found/__next._full.txt +20 -0
- draftboard-0.0.1/src/draftboard/static/_not-found/__next._not-found/__PAGE__.txt +26 -0
- draftboard-0.0.1/src/draftboard/static/_not-found/__next._tree.txt +4 -0
- draftboard-0.0.1/src/draftboard/static/_not-found.html +1 -0
- draftboard-0.0.1/src/draftboard/static/_not-found.txt +20 -0
- draftboard-0.0.1/src/draftboard/static/index.html +1 -0
- draftboard-0.0.1/src/draftboard/static/index.txt +22 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/__next._full.txt +27 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/__next._tree.txt +5 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/__next.p/$d$id/__PAGE__.txt +34 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/preview/__next._full.txt +27 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/preview/__next._tree.txt +6 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/preview/__next.p/$d$id/preview/__PAGE__.txt +35 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/preview.html +1 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__/preview.txt +27 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__.html +1 -0
- draftboard-0.0.1/src/draftboard/static/p/__placeholder__.txt +27 -0
- draftboard-0.0.1/src/draftboard/storage.py +183 -0
- draftboard-0.0.1/src/draftboard/tasks.py +464 -0
- draftboard-0.0.1/src/draftboard/themes.py +213 -0
- draftboard-0.0.1/src/draftboard/tools.py +723 -0
- draftboard-0.0.1/tests/__init__.py +1 -0
- draftboard-0.0.1/tests/conftest.py +24 -0
- draftboard-0.0.1/tests/fixtures/decks/long_title.json +26 -0
- draftboard-0.0.1/tests/fixtures/decks/many_bullets.json +61 -0
- draftboard-0.0.1/tests/fixtures/decks/mixed_punctuation.json +47 -0
- draftboard-0.0.1/tests/fixtures/decks/near_full_body.json +26 -0
- draftboard-0.0.1/tests/fixtures/decks/overflow_body.json +26 -0
- draftboard-0.0.1/tests/fixtures/decks/overflow_title.json +26 -0
- draftboard-0.0.1/tests/fixtures/decks/overlong_url.json +31 -0
- draftboard-0.0.1/tests/synthetic_fonts.py +46 -0
- draftboard-0.0.1/tests/test_api.py +823 -0
- draftboard-0.0.1/tests/test_m0.py +216 -0
- draftboard-0.0.1/tests/test_measure.py +157 -0
- draftboard-0.0.1/tests/test_models.py +139 -0
- draftboard-0.0.1/tests/test_pipeline.py +310 -0
- draftboard-0.0.1/tests/test_pptx_export.py +485 -0
- draftboard-0.0.1/tests/test_regression_decks.py +138 -0
- draftboard-0.0.1/tests/test_storage.py +147 -0
- draftboard-0.0.1/tests/test_tools.py +266 -0
- draftboard-0.0.1/uv.lock +1889 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Draftboard Environment Configuration
|
|
3
|
+
# ==============================================================================
|
|
4
|
+
|
|
5
|
+
# Option 1: Google AI Studio (Gemini) - Recommended if using your Gemini API Key
|
|
6
|
+
# ------------------------------------------------------------------------------
|
|
7
|
+
GEMINI_API_KEY=AIzaSy...
|
|
8
|
+
DRAFTBOARD_MODEL=gemini-3.5-flash-lite
|
|
9
|
+
# Optional: defaults to https://generativelanguage.googleapis.com/v1beta/openai/
|
|
10
|
+
# OPENAI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
|
|
11
|
+
|
|
12
|
+
# Option 2: OpenAI Direct
|
|
13
|
+
# ------------------------------------------------------------------------------
|
|
14
|
+
# OPENAI_API_KEY=sk-...
|
|
15
|
+
# DRAFTBOARD_MODEL=gpt-4o-mini
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
|
|
9
|
+
# Virtual Environments
|
|
10
|
+
.venv/
|
|
11
|
+
venv/
|
|
12
|
+
ENV/
|
|
13
|
+
|
|
14
|
+
# Environment Variables & Secrets
|
|
15
|
+
.env
|
|
16
|
+
*.pem
|
|
17
|
+
|
|
18
|
+
# Testing & Cache
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
.coverage
|
|
21
|
+
htmlcov/
|
|
22
|
+
|
|
23
|
+
# Outputs & Local Storage
|
|
24
|
+
outputs/
|
|
25
|
+
.draftboard/
|
|
26
|
+
|
|
27
|
+
# Generated by the CI license-gate job and uploaded as an artifact; do not hand-edit
|
|
28
|
+
THIRD_PARTY_LICENSES.md
|
|
29
|
+
|
|
30
|
+
# pytest session basetemp (pytest-of-<user>)
|
|
31
|
+
pytest-of-*/
|
|
32
|
+
|
|
33
|
+
# Local web workbench data (DRAFTBOARD_STORAGE_ROOT)
|
|
34
|
+
web-data/
|
|
35
|
+
|
|
36
|
+
# LibreOffice scratch for preview rendering
|
|
37
|
+
.lo-scratch/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: draftboard
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: AI material creation workbench - PPT generation module
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: fastapi>=0.115
|
|
8
|
+
Requires-Dist: fonttools>=4.68.0
|
|
9
|
+
Requires-Dist: openai-agents>=0.0.19
|
|
10
|
+
Requires-Dist: pillow>=10.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0
|
|
12
|
+
Requires-Dist: pypdfium2>=5.15.2
|
|
13
|
+
Requires-Dist: python-dotenv>=1.0
|
|
14
|
+
Requires-Dist: python-multipart>=0.0.34
|
|
15
|
+
Requires-Dist: python-pptx>=1.0.2
|
|
16
|
+
Requires-Dist: uvicorn>=0.30
|
|
Binary file
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"artifact_id": "art-sample01",
|
|
3
|
+
"project_id": "sample",
|
|
4
|
+
"artifact_revision": 1,
|
|
5
|
+
"outline_version": "v-sample01",
|
|
6
|
+
"template_id": "default",
|
|
7
|
+
"schema_version": "1.0",
|
|
8
|
+
"slides": [
|
|
9
|
+
{
|
|
10
|
+
"slide_id": "slide-001",
|
|
11
|
+
"layout": "cover",
|
|
12
|
+
"elements": [
|
|
13
|
+
{
|
|
14
|
+
"element_id": "s1-title",
|
|
15
|
+
"type": "title",
|
|
16
|
+
"content": "Draftboard 材料创作工作台"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"element_id": "s1-subtitle",
|
|
20
|
+
"type": "subtitle",
|
|
21
|
+
"content": "从 Markdown 材料到可编辑 PPT 初稿\nFrom materials to editable slides"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"slide_id": "slide-002",
|
|
27
|
+
"layout": "content",
|
|
28
|
+
"elements": [
|
|
29
|
+
{
|
|
30
|
+
"element_id": "s2-title",
|
|
31
|
+
"type": "title",
|
|
32
|
+
"content": "项目解决什么问题"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"element_id": "s2-text",
|
|
36
|
+
"type": "text",
|
|
37
|
+
"content": "把零散的 Markdown 笔记整理成演示文稿,目前需要手工复制、排版和反复调整,耗时且容易丢失内容。\nDraftboard 让程序负责排版与校验,让用户专注内容本身:确认大纲后,一键生成结构完整、文字可编辑的 PPTX 工作初稿。"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"slide_id": "slide-003",
|
|
43
|
+
"layout": "bullets",
|
|
44
|
+
"elements": [
|
|
45
|
+
{
|
|
46
|
+
"element_id": "s3-title",
|
|
47
|
+
"type": "title",
|
|
48
|
+
"content": "三个核心功能"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"element_id": "s3-bullet-1",
|
|
52
|
+
"type": "bullet",
|
|
53
|
+
"content": "材料读取与来源引用:每条内容都能追溯到原始材料"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"element_id": "s3-bullet-2",
|
|
57
|
+
"type": "bullet",
|
|
58
|
+
"content": "大纲确认:用户明确批准后才进入排版,模型不再偷偷改写"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"element_id": "s3-bullet-3",
|
|
62
|
+
"type": "bullet",
|
|
63
|
+
"content": "可编辑导出:文字与形状是独立对象,可在 PowerPoint 中直接修改"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"slide_id": "slide-004",
|
|
69
|
+
"layout": "two_column",
|
|
70
|
+
"elements": [
|
|
71
|
+
{
|
|
72
|
+
"element_id": "s4-title",
|
|
73
|
+
"type": "title",
|
|
74
|
+
"content": "现有方案与我们的方案"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"element_id": "s4-left",
|
|
78
|
+
"type": "column_left",
|
|
79
|
+
"content": "现有方案:整页渲染成图片,或生成后难以修改的模板堆砌。\n内容一旦溢出就被截断,用户无从发现。"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"element_id": "s4-right",
|
|
83
|
+
"type": "column_right",
|
|
84
|
+
"content": "我们的方案:程序按固定版式排版,逐块测量与校验。\n放不下就明确报出问题,绝不交出缺字的文件。"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"slide_id": "slide-005",
|
|
90
|
+
"layout": "closing",
|
|
91
|
+
"elements": [
|
|
92
|
+
{
|
|
93
|
+
"element_id": "s5-title",
|
|
94
|
+
"type": "title",
|
|
95
|
+
"content": "结论与下一步"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"element_id": "s5-conclusion",
|
|
99
|
+
"type": "conclusion",
|
|
100
|
+
"content": "先让程序在没有 AI 的情况下排出正确的 PPT,再接上模型。\n下一步:换行测量、布局引擎与固定样稿回归。"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "draftboard"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "AI material creation workbench - PPT generation module"
|
|
9
|
+
license = { text = "Apache-2.0" }
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"openai-agents>=0.0.19",
|
|
13
|
+
"pydantic>=2.0",
|
|
14
|
+
"fastapi>=0.115",
|
|
15
|
+
"uvicorn>=0.30",
|
|
16
|
+
"python-dotenv>=1.0",
|
|
17
|
+
"python-pptx>=1.0.2",
|
|
18
|
+
"pillow>=10.0",
|
|
19
|
+
"fonttools>=4.68.0",
|
|
20
|
+
"python-multipart>=0.0.34",
|
|
21
|
+
"pypdfium2>=5.15.2",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
draftboard = "draftboard.__main__:main"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel]
|
|
28
|
+
packages = ["src/draftboard"]
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=8.0",
|
|
33
|
+
"pytest-asyncio>=0.24",
|
|
34
|
+
"anyio[trio]>=4.0",
|
|
35
|
+
"pip-licenses>=5.5.5",
|
|
36
|
+
"pdfplumber>=0.11.10",
|
|
37
|
+
"httpx>=0.28.1",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
pythonpath = ["src"]
|
|
42
|
+
asyncio_mode = "auto"
|
|
43
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
44
|
+
filterwarnings = [
|
|
45
|
+
"ignore::DeprecationWarning:langsmith.*",
|
|
46
|
+
]
|
|
47
|
+
markers = [
|
|
48
|
+
"integration: requires API key (deselect with '-m not integration')",
|
|
49
|
+
]
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Real-render calibration probe (phase 1, step 7).
|
|
3
|
+
|
|
4
|
+
Exports the fixed regression decks with real system fonts, renders them via
|
|
5
|
+
headless LibreOffice to PDF, and compares the actual rendered text extents
|
|
6
|
+
against draftboard.measure estimates. Reports per-box line counts, occupied
|
|
7
|
+
height ratios, clipping, and font substitution.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
uv run python scripts/probe_render.py
|
|
11
|
+
|
|
12
|
+
NOTE: LibreOffice results only prove the LibreOffice environment. Final
|
|
13
|
+
acceptance for a PowerPoint target must happen in PowerPoint. Keep this
|
|
14
|
+
script for calibration and regression; it is not the sole acceptance basis.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import pathlib
|
|
19
|
+
import subprocess
|
|
20
|
+
import sys
|
|
21
|
+
import tempfile
|
|
22
|
+
|
|
23
|
+
import pdfplumber
|
|
24
|
+
from pptx import Presentation
|
|
25
|
+
from pptx.util import Emu
|
|
26
|
+
|
|
27
|
+
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent / "src"))
|
|
28
|
+
|
|
29
|
+
from draftboard.measure import HEIGHT_MARGIN, load_fonts, measure_box
|
|
30
|
+
from draftboard.models import Artifact
|
|
31
|
+
from draftboard.pptx_export import (
|
|
32
|
+
BULLET_INDENT_PT,
|
|
33
|
+
PAD_X_PT,
|
|
34
|
+
PAD_Y_PT,
|
|
35
|
+
_box_for,
|
|
36
|
+
_group_boxes,
|
|
37
|
+
_style_for,
|
|
38
|
+
export_pptx,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
ROOT = pathlib.Path(__file__).parent.parent
|
|
42
|
+
# soffice.com is the console wrapper; soffice.exe is a GUI-subprocess
|
|
43
|
+
# launcher that can hang without ever writing output on Windows.
|
|
44
|
+
SOFFICE = pathlib.Path(r"C:\Program Files\LibreOffice\program\soffice.com")
|
|
45
|
+
DECKS = [ROOT / "examples" / "sample_deck.json"] + sorted(
|
|
46
|
+
(ROOT / "tests" / "fixtures" / "decks").glob("*.json")
|
|
47
|
+
)
|
|
48
|
+
PASS_STEMS = {
|
|
49
|
+
"sample_deck", "long_title", "near_full_body", "many_bullets",
|
|
50
|
+
"mixed_punctuation",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def pt(emu) -> float:
|
|
55
|
+
return Emu(emu).pt
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def render_pdf(pptx_path: pathlib.Path, out_dir: pathlib.Path) -> pathlib.Path:
|
|
59
|
+
profile = out_dir / "lo-profile"
|
|
60
|
+
lo_tmp = out_dir / "lo-tmp"
|
|
61
|
+
lo_tmp.mkdir(exist_ok=True)
|
|
62
|
+
# LibreOffice's save pipeline writes temp files via %TMP%/%TEMP%; in
|
|
63
|
+
# sandboxed shells those point outside the writable area and the store
|
|
64
|
+
# fails with an Io Write error. Keep them inside out_dir.
|
|
65
|
+
env = dict(os.environ, TMP=str(lo_tmp), TEMP=str(lo_tmp))
|
|
66
|
+
subprocess.run(
|
|
67
|
+
[
|
|
68
|
+
str(SOFFICE),
|
|
69
|
+
f"-env:UserInstallation={profile.as_uri()}",
|
|
70
|
+
"--headless",
|
|
71
|
+
"--norestore",
|
|
72
|
+
"--nofirststartwizard",
|
|
73
|
+
"--convert-to", "pdf",
|
|
74
|
+
"--outdir", str(out_dir), str(pptx_path),
|
|
75
|
+
],
|
|
76
|
+
check=True, capture_output=True, timeout=180, env=env,
|
|
77
|
+
)
|
|
78
|
+
pdf = out_dir / (pptx_path.stem + ".pdf")
|
|
79
|
+
if not pdf.exists():
|
|
80
|
+
raise RuntimeError(f"LibreOffice produced no PDF for {pptx_path.name}")
|
|
81
|
+
return pdf
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def assign_chars(page, boxes):
|
|
85
|
+
"""Assign each PDF char to the nearest box above it with matching x-range.
|
|
86
|
+
|
|
87
|
+
boxes: list of dicts with left/top/width/height. Chars overflowing a
|
|
88
|
+
box bottom still belong to that box (nearest above), while chars of a
|
|
89
|
+
lower box are not stolen by the box above it.
|
|
90
|
+
"""
|
|
91
|
+
assigned = [[] for _ in boxes]
|
|
92
|
+
for c in page.chars:
|
|
93
|
+
cx = (c["x0"] + c["x1"]) / 2
|
|
94
|
+
best = None
|
|
95
|
+
for i, b in enumerate(boxes):
|
|
96
|
+
if not (b["left"] - 1 <= cx <= b["left"] + b["width"] + 1):
|
|
97
|
+
continue
|
|
98
|
+
if c["top"] < b["top"] - 1:
|
|
99
|
+
continue
|
|
100
|
+
if best is None or b["top"] > boxes[best]["top"]:
|
|
101
|
+
best = i
|
|
102
|
+
if best is not None:
|
|
103
|
+
assigned[best].append(c)
|
|
104
|
+
return assigned
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def line_count(chars) -> int:
|
|
108
|
+
# Bullet glyphs (OpenSymbol) sit on a different baseline; counting them
|
|
109
|
+
# would double every bullet line.
|
|
110
|
+
tops = sorted(
|
|
111
|
+
c["top"] for c in chars if "OpenSymbol" not in c["fontname"]
|
|
112
|
+
)
|
|
113
|
+
lines = 0
|
|
114
|
+
prev = None
|
|
115
|
+
for t in tops:
|
|
116
|
+
if prev is None or t - prev > 3:
|
|
117
|
+
lines += 1
|
|
118
|
+
prev = t
|
|
119
|
+
return lines
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def main() -> int:
|
|
123
|
+
if not SOFFICE.exists():
|
|
124
|
+
print(f"LibreOffice not found at {SOFFICE}", file=sys.stderr)
|
|
125
|
+
return 2
|
|
126
|
+
fonts = load_fonts()
|
|
127
|
+
max_ratio = 0.0
|
|
128
|
+
problems: list[str] = []
|
|
129
|
+
font_names: set[str] = set()
|
|
130
|
+
|
|
131
|
+
with tempfile.TemporaryDirectory(dir=ROOT) as tmp:
|
|
132
|
+
tmp = pathlib.Path(tmp)
|
|
133
|
+
for deck_path in DECKS:
|
|
134
|
+
if deck_path.stem not in PASS_STEMS:
|
|
135
|
+
continue
|
|
136
|
+
artifact = Artifact.model_validate_json(
|
|
137
|
+
deck_path.read_text(encoding="utf-8")
|
|
138
|
+
)
|
|
139
|
+
pptx_path = tmp / (deck_path.stem + ".pptx")
|
|
140
|
+
export_pptx(artifact, pptx_path, fonts=fonts)
|
|
141
|
+
pdf_path = render_pdf(pptx_path, tmp)
|
|
142
|
+
prs = Presentation(str(pptx_path))
|
|
143
|
+
|
|
144
|
+
with pdfplumber.open(pdf_path) as pdf:
|
|
145
|
+
for page, slide, ir_slide in zip(pdf.pages, prs.slides, artifact.slides):
|
|
146
|
+
records = []
|
|
147
|
+
for role, items in _group_boxes(ir_slide):
|
|
148
|
+
shape = next(
|
|
149
|
+
s for s in slide.shapes
|
|
150
|
+
if s.has_text_frame
|
|
151
|
+
and (pt(s.left), pt(s.top), pt(s.width), pt(s.height))
|
|
152
|
+
== _box_for(ir_slide.layout, role)
|
|
153
|
+
)
|
|
154
|
+
left, top = pt(shape.left), pt(shape.top)
|
|
155
|
+
width, height = pt(shape.width), pt(shape.height)
|
|
156
|
+
size_pt, line_pt, sa_pt = _style_for(ir_slide.layout, role)
|
|
157
|
+
contents = [c for _, c in items]
|
|
158
|
+
m = measure_box(
|
|
159
|
+
contents,
|
|
160
|
+
fonts=fonts, width_pt=width, height_pt=height,
|
|
161
|
+
size_pt=size_pt, line_pt=line_pt,
|
|
162
|
+
space_after_pt=sa_pt,
|
|
163
|
+
pad_x_pt=PAD_X_PT, pad_y_pt=PAD_Y_PT,
|
|
164
|
+
indent_pt=BULLET_INDENT_PT if role == "bullet" else 0,
|
|
165
|
+
)
|
|
166
|
+
empty_lines = sum(
|
|
167
|
+
seg == "" for t in contents for seg in t.split("\n")
|
|
168
|
+
)
|
|
169
|
+
records.append({
|
|
170
|
+
"left": left, "top": top,
|
|
171
|
+
"width": width, "height": height,
|
|
172
|
+
"m": m, "empty_lines": empty_lines,
|
|
173
|
+
"label": f"{deck_path.stem}/{ir_slide.slide_id}/{role}",
|
|
174
|
+
})
|
|
175
|
+
for rec, chars in zip(records, assign_chars(page, records)):
|
|
176
|
+
label = rec["label"]
|
|
177
|
+
m = rec["m"]
|
|
178
|
+
top, height = rec["top"], rec["height"]
|
|
179
|
+
if not chars:
|
|
180
|
+
problems.append(f"{label}: no rendered text found")
|
|
181
|
+
continue
|
|
182
|
+
for c in chars:
|
|
183
|
+
font_names.add(c["fontname"])
|
|
184
|
+
rendered_lines = line_count(chars)
|
|
185
|
+
expected_visible = m.total_lines - rec["empty_lines"]
|
|
186
|
+
text_bottom = max(c["bottom"] for c in chars)
|
|
187
|
+
occupied = (text_bottom - top) + PAD_Y_PT
|
|
188
|
+
ratio = occupied / m.required_height_pt
|
|
189
|
+
max_ratio = max(max_ratio, ratio)
|
|
190
|
+
clipped = text_bottom > top + height + 0.5
|
|
191
|
+
status = "CLIP" if clipped else "ok"
|
|
192
|
+
if clipped:
|
|
193
|
+
problems.append(f"{label}: text exceeds box bottom")
|
|
194
|
+
if rendered_lines != expected_visible:
|
|
195
|
+
problems.append(
|
|
196
|
+
f"{label}: line mismatch "
|
|
197
|
+
f"est={expected_visible} rendered={rendered_lines}"
|
|
198
|
+
)
|
|
199
|
+
status += " LINES"
|
|
200
|
+
print(
|
|
201
|
+
f"{label:42s} est_lines={expected_visible:2d} "
|
|
202
|
+
f"rendered={rendered_lines:2d} "
|
|
203
|
+
f"req={m.required_height_pt:6.1f}pt "
|
|
204
|
+
f"occupied={occupied:6.1f}pt "
|
|
205
|
+
f"ratio={ratio:.3f} {status}"
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
print()
|
|
209
|
+
print(f"fonts seen in PDF: {sorted(font_names)}")
|
|
210
|
+
print(f"max occupied/required ratio: {max_ratio:.3f}")
|
|
211
|
+
print(f"current HEIGHT_MARGIN: {HEIGHT_MARGIN} -> supported: {max_ratio <= 1 + HEIGHT_MARGIN}")
|
|
212
|
+
if problems:
|
|
213
|
+
print("\nPROBLEMS:")
|
|
214
|
+
for p in problems:
|
|
215
|
+
print(" -", p)
|
|
216
|
+
return 1
|
|
217
|
+
print("no clipping, all line counts match")
|
|
218
|
+
return 0
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
if __name__ == "__main__":
|
|
222
|
+
sys.exit(main())
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Draftboard package."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import pathlib
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
# Ensure backend/.venv/Lib/site-packages is present in sys.path
|
|
8
|
+
backend_venv_sp = (
|
|
9
|
+
pathlib.Path(__file__).resolve().parent.parent.parent
|
|
10
|
+
/ ".venv"
|
|
11
|
+
/ "Lib"
|
|
12
|
+
/ "site-packages"
|
|
13
|
+
)
|
|
14
|
+
if backend_venv_sp.exists():
|
|
15
|
+
sp_str = str(backend_venv_sp)
|
|
16
|
+
if sp_str not in sys.path:
|
|
17
|
+
sys.path.insert(0, sp_str)
|
|
18
|
+
|
|
19
|
+
# On Windows, pywin32 modules (win32, win32/lib, pywin32_system32) require their
|
|
20
|
+
# directories to be explicitly in sys.path and DLL search path if pywin32_bootstrap
|
|
21
|
+
# was skipped by trampolines or custom runners.
|
|
22
|
+
if sys.platform == "win32":
|
|
23
|
+
candidates: list[pathlib.Path] = []
|
|
24
|
+
for p in sys.path:
|
|
25
|
+
if "site-packages" in p:
|
|
26
|
+
candidates.append(pathlib.Path(p))
|
|
27
|
+
if backend_venv_sp.exists() and backend_venv_sp not in candidates:
|
|
28
|
+
candidates.append(backend_venv_sp)
|
|
29
|
+
|
|
30
|
+
for sp in candidates:
|
|
31
|
+
for sub in ("win32", "win32/lib", "pythonwin", "pywin32_system32"):
|
|
32
|
+
target = sp / sub
|
|
33
|
+
if target.exists():
|
|
34
|
+
t_str = str(target)
|
|
35
|
+
if t_str not in sys.path:
|
|
36
|
+
sys.path.append(t_str)
|
|
37
|
+
if hasattr(os, "add_dll_directory"):
|
|
38
|
+
try:
|
|
39
|
+
os.add_dll_directory(t_str)
|
|
40
|
+
except Exception:
|
|
41
|
+
pass
|