@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.7

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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
  4. package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
  5. package/bundled-assets/skill/LICENSE +21 -0
  6. package/bundled-assets/skill/README.md +61 -0
  7. package/bundled-assets/skill/SKILL.md +185 -0
  8. package/bundled-assets/skill/references/art-directions.md +99 -0
  9. package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
  10. package/bundled-assets/skill/references/design-baseline.txt +1 -0
  11. package/bundled-assets/skill/references/prompt-compiler.md +99 -0
  12. package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
  13. package/bundled-assets/skill/references/staged-pptx.md +71 -0
  14. package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
  15. package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
  16. package/bundled-assets/skill/scripts/brand_ref.py +776 -0
  17. package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
  18. package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
  19. package/bundled-assets/skill/scripts/export_images.py +280 -0
  20. package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
  21. package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
  22. package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
  23. package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
  24. package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
  25. package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
  26. package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
  27. package/bundled-assets/skill/scripts/render_gradient.py +258 -0
  28. package/bundled-assets/skill/scripts/slide_brand.py +111 -0
  29. package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
  30. package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
  31. package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
  32. package/bundled-assets/skill/vendor/README.md +4 -0
  33. package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
  34. package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
  35. package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
  36. package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
  37. package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
  38. package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
  39. package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
  40. package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
  41. package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
  42. package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
  43. package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
  44. package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
  45. package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
  46. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
  47. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
  48. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
  49. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
  50. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
  51. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
  52. package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
  53. package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
  54. package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
  55. package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
  56. package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
  57. package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
  58. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
  59. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
  60. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
  61. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
  62. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
  63. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
  64. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
  65. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
  66. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
  67. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
  68. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
  69. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
  70. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
  71. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
  72. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
  73. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
  74. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
  75. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
  76. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
  77. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
  78. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
  79. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
  80. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
  81. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
  82. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
  83. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
  84. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
  85. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
  86. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
  87. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
  88. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
  89. package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
  90. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
  91. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
  92. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
  93. package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
  94. package/cordis.patch.yml +3 -0
  95. package/lib/client.js +11282 -0
  96. package/lib/index.js +2638 -0
  97. package/package.json +140 -4
@@ -0,0 +1,309 @@
1
+ #!/usr/bin/env python3
2
+ """Measure text line boxes and font sizes from source.png as advisory hints.
3
+
4
+ Run BEFORE writing the page manifest. The output is a reference, not a
5
+ mutation: the page author reads `text_hints.json` (or looks at the labeled
6
+ `text_hints.png` overlay), matches each detected line to the text it can read
7
+ in the source, and copies the measured `box_px` and font size into
8
+ `text_boxes`. Boxes sized from these measurements should carry
9
+ `"font_size_source": "measured"` so the deterministic builder trusts the size
10
+ instead of applying its conservative shrink.
11
+
12
+ Detection is classical and dependency-free: per-tile binarization, recursive
13
+ XY-cut layout segmentation, then per-leaf ink measurement (glyph height, line
14
+ count). Solid regions (photos, color blocks) and line-like bands (dividers)
15
+ are filtered out. Detection is advisory — missed or mis-grouped lines are
16
+ filled by the author's own reading of the source image. Known limitation:
17
+ small text sharing a row band with a much taller graphic can be swallowed by
18
+ the band-relative column gap threshold and go unreported.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import argparse
24
+ import json
25
+ from pathlib import Path
26
+
27
+ import numpy as np
28
+ from PIL import Image, ImageDraw, ImageFont
29
+
30
+ from build_pptx_from_manifest import choose_preview_font, content_box_for_manifest
31
+ from page_text_metrics import crop_ink_mask, despeckle, glyph_em_ratio, load_gray, measure_crop
32
+
33
+
34
+ TILE = 96
35
+ MIN_GLYPH_PX = 6
36
+ MAX_TEXT_FILL = 0.65
37
+ CJK_EM_RATIO = glyph_em_ratio("中")
38
+ LATIN_EM_RATIO = glyph_em_ratio("A1")
39
+
40
+
41
+ def binarize_page(gray: np.ndarray, tile: int = TILE) -> np.ndarray:
42
+ """Assemble a page ink mask from per-tile local binarization.
43
+
44
+ Local Otsu adapts to dark cards versus light page background; tiles whose
45
+ binarization is unreliable (photos, gradients) contribute no ink.
46
+ """
47
+ height, width = gray.shape
48
+ mask = np.zeros((height, width), dtype=bool)
49
+ for top in range(0, height, tile):
50
+ for left in range(0, width, tile):
51
+ crop = gray[top : top + tile, left : left + tile]
52
+ ink = crop_ink_mask(crop)
53
+ if ink["reliable"]:
54
+ mask[top : top + crop.shape[0], left : left + crop.shape[1]] = ink["mask"]
55
+ return despeckle(mask)
56
+
57
+
58
+ def split_runs(profile: np.ndarray, min_gap: int) -> list[tuple[int, int]]:
59
+ """Split a 1-D has-ink profile into runs separated by gaps >= min_gap."""
60
+ index = np.flatnonzero(profile)
61
+ if index.size == 0:
62
+ return []
63
+ breaks = np.flatnonzero(np.diff(index) > min_gap)
64
+ starts = [int(index[0]), *(int(index[i + 1]) for i in breaks)]
65
+ ends = [*(int(index[i]) + 1 for i in breaks), int(index[-1]) + 1]
66
+ return list(zip(starts, ends))
67
+
68
+
69
+ # Gap tolerances are asymmetric. Rows: a small absolute tolerance, so a thin
70
+ # vertical line crossing a blank band still reads as a gap while sparse small
71
+ # text (a 12px label has only ~25 ink px per row) survives. Columns: relative
72
+ # to the row band height, so connectors shorter than a quarter of the band
73
+ # (arrows between cards, dashes) no longer bridge blocks, while real glyph
74
+ # columns — which fill most of the band — stay solid.
75
+ ROW_GAP_ABS_FRACTION = 0.003
76
+ COL_GAP_BAND_FRACTION = 0.25
77
+
78
+
79
+ def xy_cut(mask: np.ndarray, x0: int, y0: int, min_gap_y: int, min_gap_x: int,
80
+ boxes: list, depth: int = 0) -> None:
81
+ """Recursive XY-cut: alternate row/column gap splits until leaves remain."""
82
+ if not mask.any():
83
+ return
84
+ height, width = mask.shape
85
+ row_ink = mask.sum(axis=1) > max(2, ROW_GAP_ABS_FRACTION * width)
86
+ rows = split_runs(row_ink, min_gap_y) or [(0, height)]
87
+ if len(rows) > 1 and depth < 16:
88
+ for top, bottom in rows:
89
+ xy_cut(mask[top:bottom, :], x0, y0 + top, min_gap_y, min_gap_x, boxes, depth + 1)
90
+ return
91
+ top, bottom = rows[0]
92
+ column_ink = mask[top:bottom, :].sum(axis=0) > max(2, COL_GAP_BAND_FRACTION * (bottom - top))
93
+ columns = split_runs(column_ink, min_gap_x) or [(0, width)]
94
+ if len(columns) > 1 and depth < 16:
95
+ for left, right in columns:
96
+ xy_cut(mask[top:bottom, left:right], x0 + left, y0 + top, min_gap_y, min_gap_x, boxes, depth + 1)
97
+ return
98
+ left, right = columns[0]
99
+ boxes.append((x0 + left, y0 + top, right - left, bottom - top))
100
+
101
+
102
+ def measure_leaves(gray: np.ndarray, page_mask: np.ndarray, boxes: list, min_glyph: int) -> list[dict]:
103
+ """Re-measure each leaf on the grayscale source and keep text-like ones."""
104
+ height, width = gray.shape
105
+ lines = []
106
+ for x, y, w, h in boxes:
107
+ if w < min_glyph or h < min_glyph:
108
+ continue
109
+ # Pre-check solidity on the polarity-correct page mask: photo rims and
110
+ # color-block slices are near-solid there, while the local re-measure
111
+ # below can flip polarity around them and mistake their light border
112
+ # for glyphs.
113
+ if float(page_mask[y : y + h, x : x + w].mean()) > MAX_TEXT_FILL:
114
+ continue
115
+ pad = 3
116
+ left, top = max(0, x - pad), max(0, y - pad)
117
+ right, bottom = min(width, x + w + pad), min(height, y + h + pad)
118
+ measured = measure_crop(gray[top:bottom, left:right], clean_border=False)
119
+ if not measured["ok"]:
120
+ continue
121
+ glyph = measured["glyph_height_px"]
122
+ if glyph < min_glyph:
123
+ continue
124
+ bx, by, bw, bh = measured["bbox"]
125
+ fill = float(measured["mask"][by : by + bh, bx : bx + bw].mean())
126
+ if fill > MAX_TEXT_FILL:
127
+ continue # solid region: photo, color block, badge silhouette
128
+ if glyph > bw + 2:
129
+ continue # taller than wide: a graphic blob, not a horizontal text line
130
+ # Pad the tight ink box so it is directly usable as a text_boxes
131
+ # box_px: the builder's line-height fit needs ~1.22x the font size of
132
+ # box height, so a tight box would force the font smaller than the
133
+ # source. Padding: 0.30 glyph vertically, 0.35 glyph horizontally.
134
+ pad_x = max(2, int(round(glyph * 0.35)))
135
+ pad_y = max(1, int(round(glyph * 0.30)))
136
+ box_left = max(0, left + bx - pad_x)
137
+ box_top = max(0, top + by - pad_y)
138
+ lines.append(
139
+ {
140
+ "box_px": [
141
+ box_left,
142
+ box_top,
143
+ min(width, left + bx + bw + pad_x) - box_left,
144
+ min(height, top + by + bh + pad_y) - box_top,
145
+ ],
146
+ "glyph_height_px": round(glyph, 1),
147
+ "line_count": measured["line_count"],
148
+ }
149
+ )
150
+ return lines
151
+
152
+
153
+ # Same-level text in a design uses one font size; measured glyph heights
154
+ # jitter a few percent from glyph content and antialiasing (<=3%), while
155
+ # design type scales step >=8% between levels. Groups split where the sorted
156
+ # values jump by more than MIN_LEVEL_GAP; a group that still spans more than
157
+ # MAX_GROUP_SPREAD is force-split at its largest internal jump.
158
+ SIZE_GROUP_MIN_LEVEL_GAP = 0.05
159
+ SIZE_GROUP_MAX_SPREAD = 1.12
160
+
161
+
162
+ def cluster_glyph_heights(values: list[float], min_gap: float = SIZE_GROUP_MIN_LEVEL_GAP,
163
+ max_spread: float = SIZE_GROUP_MAX_SPREAD) -> list[list[int]]:
164
+ """Group indices of similar values, splitting at relative jumps."""
165
+ order = sorted(range(len(values)), key=lambda i: values[i])
166
+ groups: list[list[int]] = [[order[0]]] if order else []
167
+ for index in order[1:]:
168
+ previous = values[groups[-1][-1]]
169
+ if previous > 0 and values[index] / previous > 1 + min_gap:
170
+ groups.append([index])
171
+ else:
172
+ groups[-1].append(index)
173
+
174
+ final: list[list[int]] = []
175
+ for group in groups:
176
+ stack = [group]
177
+ while stack:
178
+ current = stack.pop()
179
+ lo, hi = values[current[0]], values[current[-1]]
180
+ if len(current) < 2 or lo <= 0 or hi / lo <= max_spread:
181
+ final.append(current)
182
+ continue
183
+ jumps = [values[current[i + 1]] / max(values[current[i]], 0.1) for i in range(len(current) - 1)]
184
+ cut = jumps.index(max(jumps)) + 1
185
+ stack.append(current[:cut])
186
+ stack.append(current[cut:])
187
+ return final
188
+
189
+
190
+ def attach_font_sizes(lines: list[dict], manifest_like: dict) -> None:
191
+ source_height = float(manifest_like["source"]["height_px"])
192
+ content_box = content_box_for_manifest(manifest_like)
193
+ inches_per_px = float(content_box["height"]) / source_height
194
+ if not lines:
195
+ return
196
+ glyphs = [line["glyph_height_px"] for line in lines]
197
+ clusters = cluster_glyph_heights(glyphs)
198
+ # Stable group ids ordered by size, largest first.
199
+ clusters.sort(key=lambda cluster: -glyphs[cluster[0]])
200
+ for group_number, cluster in enumerate(clusters, 1):
201
+ members = sorted(glyphs[i] for i in cluster)
202
+ median = members[len(members) // 2]
203
+ glyph_in = median * inches_per_px
204
+ cjk_pt = round(glyph_in / CJK_EM_RATIO * 72 * 2) / 2
205
+ latin_pt = round(glyph_in / LATIN_EM_RATIO * 72 * 2) / 2
206
+ for index in cluster:
207
+ lines[index]["size_group"] = f"g{group_number}"
208
+ lines[index]["group_glyph_px"] = median
209
+ lines[index]["font_pt_if_cjk"] = cjk_pt
210
+ lines[index]["font_pt_if_latin"] = latin_pt
211
+
212
+
213
+ def draw_overlay(source: Image.Image, lines: list[dict], out_path: Path) -> None:
214
+ overlay = source.convert("RGB")
215
+ draw = ImageDraw.Draw(overlay)
216
+ font_path = choose_preview_font(None)
217
+ label_size = max(14, source.size[0] // 90)
218
+ try:
219
+ font = ImageFont.truetype(font_path, size=label_size) if font_path else ImageFont.load_default()
220
+ except Exception:
221
+ font = ImageFont.load_default()
222
+ for line in lines:
223
+ x, y, w, h = line["box_px"]
224
+ draw.rectangle([x, y, x + w, y + h], outline="#e02020", width=2)
225
+ label_pt = line.get("font_pt") or line["font_pt_if_cjk"]
226
+ label = f"{line['id']} {label_pt}pt"
227
+ if line["line_count"] > 1:
228
+ label += f" x{line['line_count']}"
229
+ ly = y - label_size - 4 if y > label_size + 6 else y + h + 2
230
+ text_w = draw.textlength(label, font=font)
231
+ draw.rectangle([x, ly - 1, x + text_w + 4, ly + label_size + 3], fill="#fff7cc")
232
+ draw.text((x + 2, ly), label, fill="#b00000", font=font)
233
+ out_path.parent.mkdir(parents=True, exist_ok=True)
234
+ overlay.save(out_path)
235
+
236
+
237
+ def page_text_hints(page_dir: Path, source_name: str = "source.png",
238
+ min_glyph: int = MIN_GLYPH_PX) -> dict:
239
+ source_path = page_dir / source_name
240
+ if not source_path.exists():
241
+ raise SystemExit(f"Missing source image: {source_path}")
242
+ gray = load_gray(source_path)
243
+ height, width = gray.shape
244
+
245
+ request_path = page_dir / "page_request.json"
246
+ manifest_like = {"source": {"width_px": width, "height_px": height}, "slide": {"width": 13.333, "height": 7.5}}
247
+ if request_path.exists():
248
+ request = json.loads(request_path.read_text(encoding="utf-8"))
249
+ for key in ("slide", "content_box"):
250
+ if request.get(key):
251
+ manifest_like[key] = request[key]
252
+
253
+ mask = binarize_page(gray)
254
+ min_gap_y = max(6, round(height * 0.008))
255
+ min_gap_x = max(14, round(width * 0.011))
256
+ boxes: list = []
257
+ xy_cut(mask, 0, 0, min_gap_y, min_gap_x, boxes)
258
+ lines = measure_leaves(gray, mask, boxes, min_glyph)
259
+ lines.sort(key=lambda line: (line["box_px"][1], line["box_px"][0]))
260
+ for index, line in enumerate(lines, 1):
261
+ line["id"] = f"L{index:02d}"
262
+ attach_font_sizes(lines, manifest_like)
263
+
264
+ return {
265
+ "schema_version": 1,
266
+ "backend": "builtin-ink",
267
+ "source": {"width_px": width, "height_px": height},
268
+ "lines": lines,
269
+ "note": (
270
+ "ADVISORY ONLY: these measurements are a reference, and some text lines may be "
271
+ "missed or merged with graphics. Lines sharing a size_group are the same text "
272
+ "level and must use exactly one font size. When assembling the final PPT: keep "
273
+ "same-level text at identical font sizes (apply the group's size to similar "
274
+ "lines, including ones you add yourself), and fill in every text the detector "
275
+ "missed from your own reading of the source image. box_px values are source "
276
+ "pixels usable directly in text_boxes. Pick font_pt_if_cjk for CJK text and "
277
+ "font_pt_if_latin for Latin text, and add \"font_size_source\": \"measured\" "
278
+ "to boxes you size from these hints."
279
+ ),
280
+ }
281
+
282
+
283
+ def main() -> int:
284
+ parser = argparse.ArgumentParser(
285
+ description="Measure text line boxes and font sizes from source.png as advisory hints for the page author.",
286
+ )
287
+ parser.add_argument("page_dir", help="Page directory containing source.png.")
288
+ parser.add_argument("--source", default="source.png", help="Source image relative to the page directory.")
289
+ parser.add_argument("--out", default="text_hints.json", help="Hints JSON relative to the page directory.")
290
+ parser.add_argument("--overlay", default="text_hints.png", help="Labeled overlay image. Pass an empty string to skip.")
291
+ parser.add_argument("--min-glyph", type=int, default=MIN_GLYPH_PX, help="Smallest glyph height in px to report. Default: 6.")
292
+ args = parser.parse_args()
293
+
294
+ page_dir = Path(args.page_dir).expanduser().resolve()
295
+ hints = page_text_hints(page_dir, source_name=args.source, min_glyph=args.min_glyph)
296
+
297
+ out_path = page_dir / args.out
298
+ out_path.parent.mkdir(parents=True, exist_ok=True)
299
+ out_path.write_text(json.dumps(hints, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
300
+ if args.overlay:
301
+ source = Image.open(page_dir / args.source)
302
+ draw_overlay(source, hints["lines"], page_dir / args.overlay)
303
+ hints["overlay"] = args.overlay
304
+ print(json.dumps(hints, ensure_ascii=False, indent=2))
305
+ return 0
306
+
307
+
308
+ if __name__ == "__main__":
309
+ raise SystemExit(main())