@clipen/clipen-cli 1.0.8 → 1.0.9

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 (80) hide show
  1. package/README.md +13 -4
  2. package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
  3. package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
  4. package/apps/web/dist/index.html +2 -2
  5. package/bin/clipen.js +6 -15
  6. package/package.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/src/clipen/__init__.py +1 -1
  9. package/src/clipen/bootstrap.py +130 -23
  10. package/src/clipen/controller/app.py +83 -21
  11. package/src/clipen/controller/server.py +5 -0
  12. package/src/clipen/editing/agent_tools.py +1 -1
  13. package/src/clipen/editing/caption_design.py +134 -0
  14. package/src/clipen/editing/component_looks.py +3 -3
  15. package/src/clipen/editing/component_review.py +0 -38
  16. package/src/clipen/editing/coordinator.py +14 -0
  17. package/src/clipen/editing/production_catalog.py +67 -13
  18. package/src/clipen/editing/production_media.py +13 -2
  19. package/src/clipen/editing/production_preview.py +11 -9
  20. package/src/clipen/editing/production_progress.py +2 -0
  21. package/src/clipen/editing/production_tools.py +11 -20
  22. package/src/clipen/editing/program_subtitles.py +5 -13
  23. package/src/clipen/editing/resolve_export.py +2 -183
  24. package/src/clipen/editing/skill_tools.py +142 -218
  25. package/src/clipen/editing/tool_receipts.py +2 -1
  26. package/src/clipen/editing/versions.py +2 -0
  27. package/src/clipen/editing/visual_preview.py +62 -0
  28. package/src/clipen/editing/workbench.py +21 -1
  29. package/src/clipen/locale_en.py +18 -0
  30. package/src/clipen/media/storage.py +2 -2
  31. package/src/clipen/own_ffmpeg.py +113 -0
  32. package/src/clipen/providers/editing_agent.py +6 -4
  33. package/src/clipen/rendering/custom_components.py +216 -25
  34. package/src/clipen/rendering/custom_render.py +90 -54
  35. package/src/clipen/rendering/fetched_fonts.py +127 -0
  36. package/src/clipen/rendering/production_effects.py +24 -2
  37. package/src/clipen/rendering/program_components.py +18 -240
  38. package/src/clipen/rendering/renderer.py +23 -17
  39. package/src/clipen/rendering/titles.py +29 -12
  40. package/src/clipen/skills/builtin/SKILL.md +3 -3
  41. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  42. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  43. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  44. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  45. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  46. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  47. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  48. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  49. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  50. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  51. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  52. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  53. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  54. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  55. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  56. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  57. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  58. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  59. package/src/clipen/skills/builtin/references/captions.md +12 -0
  60. package/src/clipen/skills/builtin/references/graphics.md +6 -5
  61. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
  62. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
  63. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
  64. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
  65. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
  66. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
  67. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
  68. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
  69. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
  70. package/src/clipen/skills/catalog.py +0 -8
  71. package/src/clipen/skills/package.py +1 -10
  72. package/apps/web/dist/assets/index-CJ80KHsQ.css +0 -1
  73. package/apps/web/dist/assets/index-C_4u_hVf.js +0 -16
  74. package/src/clipen/editing/resolve_titles.py +0 -291
  75. package/src/clipen/rendering/program_creator.py +0 -804
  76. package/src/clipen/rendering/program_identities.py +0 -350
  77. package/src/clipen/rendering/program_motion.py +0 -186
  78. package/src/clipen/rendering/program_studio.py +0 -227
  79. package/src/clipen/rendering/program_styles.py +0 -321
  80. package/src/clipen/skills/builtin/components.json +0 -133
@@ -1,227 +0,0 @@
1
- """Original editorial identity: type lockups, cut-paper tickets and drawn marks.
2
-
3
- All decoration and motion stays inside the measured component footprint. This is
4
- procedural artwork, so no remote assets, invented source facts or raster scaling.
5
- """
6
-
7
- import math
8
-
9
- from .program_styles import draw_style_text, load_style_font, styled_text_length, type_outline
10
- from .titles import TitleRenderError
11
-
12
- HERO = {"program_title", "headline", "impact", "chapter", "burst"}
13
-
14
-
15
- def title_lines(value):
16
- if "・" in value:
17
- return tuple(value.split("・", 1))
18
- if len(value) > 3:
19
- middle = (len(value) + 1) // 2
20
- return value[:middle], value[middle:]
21
- return (value,)
22
-
23
-
24
- def layout(draw, font_path, timeline, item, profile):
25
- kind = profile["component_id"]
26
- hero = kind in HERO
27
- w, h = timeline.width, timeline.height
28
- x, y = round(w * profile["x"]), round(h * profile["y"])
29
- primary, _, detail = item.text.partition("\n")
30
- split = kind == "program_title"
31
- lines = title_lines(primary) if split else (primary,)
32
- scale = 0.108 if split else 0.091 if hero else 0.061 if kind == "reaction" else 0.040
33
- pad = max(8, round(h * 0.022))
34
- limit = min(w * (0.83 if hero else 0.58), w * 0.945 - x)
35
- minimum = max(14, round(h * scale * 0.70))
36
- size = max(14, round(h * scale))
37
- small = load_style_font(font_path, max(12, round(h * 0.024)), profile, role="detail")
38
- # Reserve a separate column for a rosette; artwork never covers title type.
39
- ornament = h * 0.13 if split else pad * 2
40
- while True:
41
- font = load_style_font(font_path, size, profile)
42
- text_width = max(styled_text_length(line, font) for line in lines)
43
- width = max(
44
- text_width + pad * 4 + ornament,
45
- styled_text_length(detail, small) + pad * 4 if detail else 0,
46
- w * (0.39 if split else 0.19 if hero else 0.13),
47
- )
48
- if width <= limit or size <= minimum:
49
- break
50
- size -= 1
51
- height = round(size * len(lines) * 1.18 + pad * 3 + (small.size * 1.35 if detail else 0))
52
- if split:
53
- height += round(pad * 0.5)
54
- if width > limit or y + height > h * 0.77:
55
- raise TitleRenderError("program_component_overflow")
56
- return (x, y, x + math.ceil(width), y + height), font, pad
57
-
58
-
59
- def draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
60
- kind = profile["component_id"]
61
- hero = kind in HERO
62
- appearance = profile["presets"]["appearance"]
63
- motion = profile["presets"]["motion"]
64
- entry = appearance["hero_entry_frames"] if hero else motion["entry_frames"]
65
- end = appearance["hero_exit_frames"] if hero else motion["exit_frames"]
66
- relative = entry if relative_frame is None else relative_frame
67
- p = min(1.0, max(0.0, (relative + 1) / entry))
68
- exit_progress = min(1.0, max(0.0, (item.duration_frames - relative) / end))
69
- alpha = min(1.0, p * 3, exit_progress)
70
- ease = 1 - (1 - p) ** 3
71
- x, y, right, bottom = bounds
72
- width, height = right - x, bottom - y
73
- primary, _, detail = item.text.partition("\n")
74
- palette = profile["presets"]["palette"]
75
- stroke = max(1, round(timeline.height * 0.0025))
76
- small = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
77
- micro = load_style_font(font_path, max(9, round(timeline.height * 0.017)), profile, role="detail")
78
-
79
- def color(name, opacity=1):
80
- r, g, b, a = palette[name]
81
- return r, g, b, round(a * alpha * opacity)
82
-
83
- def text(pos, value, selected=font, fill="paper", outline=False):
84
- draw_style_text(
85
- draw,
86
- pos,
87
- value,
88
- selected,
89
- color(fill),
90
- type_outline(profile, selected, stroke * 3) if outline else 0,
91
- color("ink"),
92
- )
93
- if selected is font and not profile["presets"].get("font_roles"):
94
- draw_style_text(draw, pos, value, selected, color(fill), max(1, stroke), color(fill))
95
-
96
- def rosette(cx, cy, radius, fill="accent"):
97
- points = []
98
- for n in range(32):
99
- angle = math.tau * n / 32 - 0.18 * (1 - ease)
100
- r = radius * (1 if n % 2 == 0 else 0.76) * (0.65 + 0.35 * ease)
101
- points.append((cx + math.cos(angle) * r, cy + math.sin(angle) * r))
102
- draw.polygon(points, fill=color(fill))
103
- # Original four-point cutout inside the print rosette.
104
- r = radius * 0.40
105
- draw.polygon(
106
- [
107
- (cx, cy - r),
108
- (cx + r * 0.22, cy - r * 0.22),
109
- (cx + r, cy),
110
- (cx + r * 0.22, cy + r * 0.22),
111
- (cx, cy + r),
112
- (cx - r * 0.22, cy + r * 0.22),
113
- (cx - r, cy),
114
- (cx - r * 0.22, cy - r * 0.22),
115
- ],
116
- fill=color("paper"),
117
- )
118
-
119
- if kind == "program_title":
120
- # Open typographic lockup with staggered rows, a registration rail and
121
- # a separate decorative seal. No enclosing title rectangle.
122
- rail = x + pad * 0.25
123
- draw.line((rail, y + pad, rail, y + height * ease - pad), fill=color("paper"), width=stroke)
124
- for dy in (pad, height * 0.49, height - pad):
125
- draw.line((rail - stroke * 2, y + dy, rail + stroke * 2, y + dy), fill=color("paper"), width=stroke)
126
- badge_x = x + pad * 1.2
127
- badge_w = micro.getlength("FIELD NOTES") + pad * 1.8
128
- draw.rounded_rectangle(
129
- (badge_x, y + pad * 0.2, badge_x + badge_w, y + pad * 1.35), radius=pad * 0.55, fill=color("accent")
130
- )
131
- text((badge_x + pad * 0.9, y + pad * 0.40), "FIELD NOTES", micro, "ink")
132
- lines = title_lines(primary)
133
- ty = y + pad * 1.9
134
- for n, line in enumerate(lines):
135
- phase = min(1.0, max(0.0, p * 1.65 - n * 0.35))
136
- if not phase:
137
- continue
138
- shift = (1 - phase) ** 3 * pad
139
- tx = x + pad * (1.2 + n * 0.7) + shift
140
- yy = ty + n * font.size * 1.18
141
- shadow = stroke if profile["presets"].get("font_roles") else stroke * 2
142
- text((tx + shadow, yy + shadow), line, fill="ink", outline=True)
143
- text((tx, yy), line, outline=True)
144
- r = min(timeline.height * 0.055, height * 0.19)
145
- rosette(right - r - pad * 0.6, y + pad * 2 + r, r)
146
- underline_y = ty + font.size * len(lines) * 1.18 + pad * 0.12
147
- length = max(styled_text_length(line, font) for line in lines)
148
- draw.line(
149
- [
150
- (x + pad * 1.4, underline_y),
151
- (x + pad + length * ease, underline_y - pad * 0.3),
152
- (x + pad + length * ease, underline_y + stroke * 2),
153
- ],
154
- fill=color("accent"),
155
- width=stroke * 3,
156
- )
157
- elif kind in {"impact", "reaction", "burst"}:
158
- # A cut-paper sticker with offset ink edge and an asymmetrical silhouette.
159
- top = y + pad * 0.7
160
- points = [
161
- (x + pad, top),
162
- (right - pad * 2, y + pad * 0.2),
163
- (right - pad * 0.3, top + pad),
164
- (right - pad, bottom - pad * 0.65),
165
- (x + pad * 0.5, bottom - pad * 0.3),
166
- (x + pad * 0.15, top + pad),
167
- ]
168
- draw.polygon([(a + stroke * 2, b + stroke * 2) for a, b in points], fill=color("ink"))
169
- draw.polygon(points, fill=color("accent"), outline=color("paper"), width=stroke * 2)
170
- if kind == "burst":
171
- rosette(right - pad * 1.25, y + pad * 1.25, pad * 0.8, "secondary")
172
- if p > 0.18:
173
- text((x + pad * 1.3, y + pad * 1.3 + (1 - ease) * pad * 0.5), primary, fill="ink")
174
- for n in range(3):
175
- xx = x + pad * (1.2 + n * 0.5)
176
- draw.line((xx, y + pad * 0.5, xx + pad * 0.2, y + pad * 0.1), fill=color("paper"), width=stroke)
177
- elif kind == "chapter":
178
- # A coloured tab and open ruled heading, without a full panel.
179
- tab_width = styled_text_length("CHAPTER", micro) + pad * 1.2
180
- draw.rounded_rectangle(
181
- (x + pad * 0.3, y + pad * 0.2, x + pad * 0.3 + tab_width, y + pad * 1.35),
182
- radius=pad * 0.2,
183
- fill=color("accent"),
184
- )
185
- text((x + pad * 0.6, y + pad * 0.35), "CHAPTER", micro, "ink")
186
- text((x + pad, y + pad * 1.9 + (1 - ease) * pad), primary, outline=True)
187
- draw.line(
188
- (x + pad, bottom - pad * 0.5, x + pad + (width - pad * 2) * ease, bottom - pad * 0.5),
189
- fill=color("paper"),
190
- width=stroke * 2,
191
- )
192
- else:
193
- # Ticket shape: clipped corners, perforation line, coloured folded tab.
194
- notch = pad * 0.4
195
- bx, by, br, bb = x + pad * 0.15, y + pad * 0.2, right - pad * 0.2, bottom - pad * 0.2
196
- draw.polygon(
197
- [
198
- (bx + notch, by),
199
- (br - notch, by),
200
- (br, by + notch),
201
- (br, bb - notch),
202
- (br - notch, bb),
203
- (bx + notch, bb),
204
- (bx, bb - notch),
205
- (bx, by + notch),
206
- ],
207
- fill=color("paper"),
208
- )
209
- draw.polygon([(bx, by), (bx + pad * 0.9, by), (bx, by + pad * 0.9)], fill=color("accent"))
210
- for yy in range(round(by + pad * 0.5), round(bb - pad * 0.3), max(3, stroke * 4)):
211
- draw.line((br - pad * 0.65, yy, br - pad * 0.65, yy + stroke), fill=color("secondary"), width=stroke)
212
- text((bx + pad, y + pad * 0.85 + (1 - ease) * pad * 0.2), primary, fill="ink")
213
- draw.line(
214
- (bx + pad, bb - pad * 0.35, bx + pad + (width - pad * 3) * ease, bb - pad * 0.35),
215
- fill=color("accent"),
216
- width=stroke * 2,
217
- )
218
- if detail:
219
- # Secondary line is reserved below the primary composition.
220
- ty = bottom - small.size - pad * 0.7
221
- if kind in {"program_title", "chapter"}:
222
- tw = styled_text_length(detail, small)
223
- draw.rectangle((x + pad, ty - pad * 0.25, x + pad * 2 + tw, bottom - pad * 0.35), fill=color("ink"))
224
- text((x + pad * 1.5, ty), detail, small)
225
- else:
226
- text((x + pad * 1.3, ty), detail, small, "ink")
227
- return bounds
@@ -1,321 +0,0 @@
1
- """Distinct, trusted art directions for the same semantic programme components."""
2
-
3
- import hashlib
4
- import os
5
- from functools import lru_cache
6
- from importlib.resources import files
7
- from pathlib import Path
8
-
9
- from PIL import ImageFont
10
-
11
-
12
- def skin(profile):
13
- return profile.get("presets", {}).get("appearance", {}).get("skin", "variety")
14
-
15
-
16
- def style_font(font_path, profile):
17
- if os.environ.get("CLIPEN_TITLE_FONT") or profile["presets"].get("appearance", {}).get("font_family") != "serif":
18
- return font_path
19
- for path in (
20
- "/System/Library/Fonts/Supplemental/Songti.ttc",
21
- "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc",
22
- "C:/Windows/Fonts/simsun.ttc",
23
- ):
24
- if Path(path).is_file():
25
- return Path(path)
26
- return font_path
27
-
28
-
29
- @lru_cache(maxsize=32)
30
- def _font_face(path, direction):
31
- preferred = "Light" if direction == "cinema" else "Regular"
32
- fallback = None
33
- for index in range(16):
34
- try:
35
- family, weight = ImageFont.truetype(path, 12, index=index).getname()
36
- except OSError:
37
- break
38
- if family in {"Songti TC", "Noto Serif CJK TC", "NotoSerifCJKtc"}:
39
- if weight == preferred:
40
- return index
41
- if fallback is None:
42
- fallback = index
43
- return fallback or 0
44
-
45
-
46
- def font_role(profile):
47
- kind = profile.get("component_id")
48
- return (
49
- "impact"
50
- if kind in {"impact", "burst", "reaction"}
51
- else "title"
52
- if kind in {"program_title", "headline", "chapter"}
53
- else "information"
54
- )
55
-
56
-
57
- @lru_cache(maxsize=64)
58
- def _role_face(path, weight):
59
- preferred = {
60
- "bold": ("Bold", "W6", "Semibold", "Heavy", "Black"),
61
- "medium": ("Medium", "W6", "Regular"),
62
- "light": ("Light", "W3", "Regular"),
63
- "regular": ("Regular", "W3", "Medium"),
64
- }[weight]
65
- faces = []
66
- for index in range(32):
67
- try:
68
- family, face = ImageFont.truetype(path, 12, index=index).getname()
69
- except OSError:
70
- break
71
- # Prefer Traditional Chinese faces when a collection contains both.
72
- if " SC" not in family and "Interface" not in family and family != "STSong":
73
- faces.append((index, face, family.endswith(" TC")))
74
- # Taiwan forms first when a collection also ships HK or other regional faces.
75
- faces = [(index, face) for index, face, _ in sorted(faces, key=lambda entry: not entry[2])]
76
- for desired in preferred:
77
- for index, face in faces:
78
- if face == desired:
79
- return index
80
- return faces[0][0] if faces else 0
81
-
82
-
83
- @lru_cache(maxsize=16)
84
- def _verify_font(path, expected, modified_ns, length):
85
- from .titles import TitleRenderError
86
-
87
- if hashlib.sha256(Path(path).read_bytes()).hexdigest() != expected:
88
- raise TitleRenderError("program_font_unavailable")
89
- return path
90
-
91
-
92
- def bundled_font(specification):
93
- from .titles import TitleRenderError
94
-
95
- identifier = specification["bundled_font"]
96
- if identifier not in {"chenyu", "iansui"}:
97
- raise TitleRenderError("program_font_unavailable")
98
- path = Path(str(files("clipen.rendering").joinpath("fonts", identifier + ".ttf")))
99
- try:
100
- stat = path.stat()
101
- return _verify_font(str(path), specification["sha256"], stat.st_mtime_ns, stat.st_size)
102
- except (OSError, KeyError) as error:
103
- raise TitleRenderError("program_font_unavailable") from error
104
-
105
-
106
- @lru_cache(maxsize=8)
107
- def _system_asset(name):
108
- """macOS installs some fonts on demand under a hashed asset folder."""
109
- from glob import glob
110
-
111
- return tuple(sorted(glob("/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*.asset/AssetData/" + name)))[:1]
112
-
113
-
114
- def type_outline(profile, font, fallback):
115
- specification = profile["presets"].get("font_roles", {}).get(font_role(profile), {})
116
- ratio = specification.get("outline_em")
117
- return fallback if ratio is None else max(1, round(font.size * ratio))
118
-
119
-
120
- def load_style_font(font_path, size, profile, role=None):
121
- specification = profile["presets"].get("font_roles", {}).get(role or font_role(profile))
122
- if specification:
123
- if specification.get("bundled_font") and not os.environ.get("CLIPEN_TITLE_FONT"):
124
- return ImageFont.truetype(bundled_font(specification), size)
125
- family = specification["family"]
126
- if family == "handwriting":
127
- family = "sans"
128
- candidates = {
129
- "gothic": ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
130
- "sans": ("/System/Library/Fonts/STHeiti Medium.ttc", "/System/Library/Fonts/Hiragino Sans GB.ttc"),
131
- "serif": ("/System/Library/Fonts/Supplemental/Songti.ttc",),
132
- # PingFang is the clean system sans creators expect on macOS; it is
133
- # an on-demand system asset, so fall back to Hiragino Sans GB.
134
- "modern": _system_asset("PingFang.ttc")
135
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
136
- # Display faces popular in Taiwanese variety and vlog packaging.
137
- "lantinghei": _system_asset("Lantinghei.ttc")
138
- + _system_asset("PingFang.ttc")
139
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
140
- "wawa": _system_asset("WawaTC-Regular.otf")
141
- + _system_asset("PingFang.ttc")
142
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
143
- "hannotate": _system_asset("Hannotate.ttc")
144
- + _system_asset("PingFang.ttc")
145
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
146
- "hanzipen": _system_asset("Hanzipen.ttc")
147
- + _system_asset("PingFang.ttc")
148
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
149
- "yuanti": _system_asset("Yuanti.ttc")
150
- + _system_asset("PingFang.ttc")
151
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
152
- "kaiti": _system_asset("Kaiti.ttc") + ("/System/Library/Fonts/Supplemental/Songti.ttc",),
153
- "lingwai": _system_asset("LingWaiTC-Medium.otf") + ("/System/Library/Fonts/Supplemental/Songti.ttc",),
154
- "weibei": _system_asset("WeibeiTC-Bold.otf")
155
- + _system_asset("Lantinghei.ttc")
156
- + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
157
- }[family]
158
- candidates += (
159
- "/usr/share/fonts/opentype/noto/Noto" + ("Serif" if family == "serif" else "Sans") + "CJK-Regular.ttc",
160
- "C:/Windows/Fonts/" + ("simsun.ttc" if family == "serif" else "msjh.ttc"),
161
- )
162
- # The explicit local font override still has priority. No arbitrary font
163
- # paths or remote URLs can be supplied through the editing MCP tools.
164
- path = (
165
- str(font_path)
166
- if os.environ.get("CLIPEN_TITLE_FONT")
167
- else next((p for p in candidates if Path(p).is_file()), str(font_path))
168
- )
169
- return ImageFont.truetype(path, size, index=_role_face(path, specification["weight"]))
170
- path = str(style_font(font_path, profile))
171
- face = (
172
- _font_face(path, skin(profile)) if profile["presets"].get("appearance", {}).get("font_family") == "serif" else 0
173
- )
174
- return ImageFont.truetype(path, size, index=face)
175
-
176
-
177
- @lru_cache(maxsize=2048)
178
- def _has_glyph(path, size, index, character):
179
- if character.isspace():
180
- return True
181
- font = ImageFont.truetype(path, size, index=index)
182
- glyph = font.getmask(character)
183
- missing = font.getmask("\U0010ffff")
184
- return glyph.getbbox() is not None and (glyph.size != missing.size or bytes(glyph) != bytes(missing))
185
-
186
-
187
- def _text_runs(value, font):
188
- from .titles import TitleCardRenderer, TitleRenderError
189
-
190
- fallback = None
191
- runs = []
192
- for char in value:
193
- selected = font
194
- if not _has_glyph(str(font.path), font.size, font.index, char):
195
- if fallback is None:
196
- path = TitleCardRenderer._font_path()
197
- if path is None:
198
- raise TitleRenderError("program_component_missing_glyph")
199
- fallback = ImageFont.truetype(str(path), font.size)
200
- if not _has_glyph(str(fallback.path), fallback.size, fallback.index, char):
201
- raise TitleRenderError("program_component_missing_glyph")
202
- selected = fallback
203
- if runs and runs[-1][1] is selected:
204
- runs[-1] = (runs[-1][0] + char, selected)
205
- else:
206
- runs.append((char, selected))
207
- return runs
208
-
209
-
210
- def styled_text_length(value, font):
211
- return sum(selected.getlength(part) for part, selected in _text_runs(value, font))
212
-
213
-
214
- def draw_style_text(draw, position, value, font, fill, stroke_width=0, stroke_fill=None):
215
- if not value:
216
- return
217
- # Share a real baseline across font runs so a fallback middle dot stays in
218
- # the middle of CJK type rather than jumping to the top of the line.
219
- baseline = position[1] - font.getbbox(value, anchor="ls")[1]
220
- x = position[0]
221
- for part, selected in _text_runs(value, font):
222
- draw.text(
223
- (x, baseline),
224
- part,
225
- font=selected,
226
- fill=fill,
227
- anchor="ls",
228
- stroke_width=stroke_width,
229
- stroke_fill=stroke_fill,
230
- )
231
- x += selected.getlength(part)
232
-
233
-
234
- def draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
235
- if skin(profile) == "studio":
236
- from .program_studio import draw_graphic
237
-
238
- return draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
239
- kind = profile["component_id"]
240
- hero = kind in {"program_title", "headline", "impact", "chapter", "burst"}
241
- appearance = profile["presets"].get("appearance", {})
242
- motion = profile["presets"]["motion"]
243
- entry = appearance.get("hero_entry_frames", 18) if hero else motion["entry_frames"]
244
- exit_frames = appearance.get("hero_exit_frames", 8) if hero else motion["exit_frames"]
245
- relative = entry if relative_frame is None else relative_frame
246
- progress = min(1.0, max(0.0, (relative + 1) / entry))
247
- ease = 1 - (1 - progress) ** 3
248
- opacity = min(progress, min(1.0, max(0.0, (item.duration_frames - relative) / exit_frames)))
249
- x, y, right, bottom = bounds
250
- w = right - x
251
- h = bottom - y
252
- # The full entrance remains within the validated static footprint.
253
- y += round((1 - ease) * pad * 0.35)
254
- primary, _, detail = item.text.partition("\n")
255
- font_path = style_font(font_path, profile)
256
- small = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
257
- line = max(1, round(timeline.height * 0.002))
258
- palette = profile["presets"]["palette"]
259
-
260
- def color(name, alpha=1.0):
261
- r, g, b, a = palette[name]
262
- return r, g, b, round(a * opacity * alpha)
263
-
264
- def text(position, value, selected=font, fill="ink", shadow=False):
265
- if shadow:
266
- draw_style_text(
267
- draw, (position[0] + line, position[1] + line), value, selected, color("ink"), line, color("ink")
268
- )
269
- draw_style_text(draw, position, value, selected, color(fill))
270
-
271
- if skin(profile) == "editorial":
272
- # Paper, ink and seal geometry: no slanted yellow panels or comic strokes.
273
- draw.rounded_rectangle(
274
- (x, y, right, bottom), radius=max(2, pad // 3), fill=color("paper"), outline=color("ink"), width=line
275
- )
276
- if kind == "burst":
277
- cx, cy = (x + right) / 2, y + h * 0.43
278
- radius = min(w * 0.45, h * 0.40)
279
- draw.ellipse((cx - radius, cy - radius, cx + radius, cy + radius), outline=color("accent"), width=line * 2)
280
- draw.ellipse(
281
- (cx - radius + line * 4, cy - radius + line * 4, cx + radius - line * 4, cy + radius - line * 4),
282
- outline=color("accent"),
283
- width=line,
284
- )
285
- elif kind == "program_title":
286
- draw.rectangle((x + pad, y + pad * 0.65, x + pad * 2, y + pad * 1.5), fill=color("accent"))
287
- draw.line((x + pad * 2.5, y + pad * 1.1, x + w * ease - pad, y + pad * 1.1), fill=color("ink"), width=line)
288
- elif kind in {"headline", "impact"}:
289
- draw.line(
290
- (x + pad, bottom - pad * 0.6, x + (w - pad) * ease, bottom - pad * 0.6),
291
- fill=color("accent"),
292
- width=line * 3,
293
- )
294
- else:
295
- draw.rectangle((x, y, x + line * 3, bottom), fill=color("accent"))
296
- ty = y + h * (0.31 if kind == "program_title" else 0.23 if hero else 0.22)
297
- text((x + pad * 1.5, ty), primary, fill="accent" if kind in {"impact", "burst"} else "ink")
298
- if detail:
299
- text((x + pad * 1.5, bottom - pad * 1.9), detail, small)
300
- else:
301
- # Quiet lower-third grammar, hairline brackets and serif type. The small
302
- # translucent backing preserves contrast on bright source footage.
303
- draw.rectangle((x, y, right, bottom), fill=color("ink", 0.30))
304
- length = min(pad * 2, w * 0.16) * ease
305
- if kind == "chapter":
306
- draw.line((x, y + pad * 0.5, x + pad * 0.8, bottom - pad * 0.5), fill=color("accent"), width=line * 2)
307
- elif kind in {"program_title", "burst"}:
308
- for cx, cy, sx, sy in ((x, y, 1, 1), (right, bottom, -1, -1)):
309
- draw.line((cx, cy, cx + sx * length, cy), fill=color("accent"), width=line)
310
- draw.line((cx, cy, cx, cy + sy * length), fill=color("accent"), width=line)
311
- else:
312
- draw.line(
313
- (x + pad, bottom - pad * 0.6, x + (w - pad) * ease, bottom - pad * 0.6),
314
- fill=color("accent"),
315
- width=line,
316
- )
317
- ty = y + h * (0.30 if kind == "program_title" else 0.23 if hero else 0.22)
318
- text((x + pad * 1.5, ty), primary, fill="paper", shadow=True)
319
- if detail:
320
- text((x + pad * 1.5, bottom - pad * 1.9), detail, small, fill="paper", shadow=True)
321
- return bounds
@@ -1,133 +0,0 @@
1
- [
2
- {
3
- "component_id": "location",
4
- "name": "地點識別",
5
- "purpose": "第一次建立地點或明確換場",
6
- "max_characters": 32,
7
- "default_position": {
8
- "x": 0.06,
9
- "y": 0.08
10
- },
11
- "requires_target": false
12
- },
13
- {
14
- "component_id": "person",
15
- "name": "人物介紹",
16
- "purpose": "人物第一次出場或需要辨識身份",
17
- "max_characters": 24,
18
- "default_position": {
19
- "x": 0.06,
20
- "y": 0.58
21
- },
22
- "requires_target": false
23
- },
24
- {
25
- "component_id": "fact",
26
- "name": "品名與資訊",
27
- "purpose": "補充有來源的品名、價格與事實",
28
- "max_characters": 48,
29
- "default_position": {
30
- "x": 0.06,
31
- "y": 0.16
32
- },
33
- "requires_target": false
34
- },
35
- {
36
- "component_id": "pointer",
37
- "name": "細節指示",
38
- "purpose": "用短標註和箭頭引導觀眾看指定細節",
39
- "max_characters": 24,
40
- "default_position": {
41
- "x": 0.06,
42
- "y": 0.12
43
- },
44
- "requires_target": true
45
- },
46
- {
47
- "component_id": "circle",
48
- "name": "重點圈選",
49
- "purpose": "圈出短暫但重要的畫面細節",
50
- "max_characters": 16,
51
- "default_position": {
52
- "x": 0.06,
53
- "y": 0.12
54
- },
55
- "requires_target": true
56
- },
57
- {
58
- "component_id": "reaction",
59
- "name": "反應強調",
60
- "purpose": "強調實際發生的反應,不捏造人物心聲或發言",
61
- "max_characters": 18,
62
- "default_position": {
63
- "x": 0.56,
64
- "y": 0.18
65
- },
66
- "requires_target": false
67
- },
68
- {
69
- "component_id": "program_title",
70
- "name": "節目主標",
71
- "purpose": "開場建立節目名稱與本集主題;直接疊在有內容的鏡頭上",
72
- "max_characters": 14,
73
- "default_position": {
74
- "x": 0.075,
75
- "y": 0.15
76
- },
77
- "requires_target": false,
78
- "motion": "雙色框線展開、標題上升",
79
- "visual_weight": "hero"
80
- },
81
- {
82
- "component_id": "headline",
83
- "name": "動態大字",
84
- "purpose": "揭示當下的問題、目標或關鍵發現,不代替一般字幕",
85
- "max_characters": 14,
86
- "default_position": {
87
- "x": 0.08,
88
- "y": 0.25
89
- },
90
- "requires_target": false,
91
- "motion": "斜切色帶展開、逐字彈入",
92
- "visual_weight": "hero"
93
- },
94
- {
95
- "component_id": "impact",
96
- "name": "撞擊強調字",
97
- "purpose": "實際反應或劇情轉折的一次重擊,保留人物表情",
98
- "max_characters": 10,
99
- "default_position": {
100
- "x": 0.12,
101
- "y": 0.28
102
- },
103
- "requires_target": false,
104
- "motion": "錯位重影收攏、雙側撞擊線",
105
- "visual_weight": "hero"
106
- },
107
- {
108
- "component_id": "chapter",
109
- "name": "章節橫幅",
110
- "purpose": "進入新的地點或體驗階段,讓觀眾知道故事往哪走",
111
- "max_characters": 18,
112
- "default_position": {
113
- "x": 0.06,
114
- "y": 0.1
115
- },
116
- "requires_target": false,
117
- "motion": "斜切底板擦入、雙色延伸線",
118
- "visual_weight": "hero"
119
- },
120
- {
121
- "component_id": "burst",
122
- "name": "放射反應框",
123
- "purpose": "有來源依據的驚訝、疑問或反應,避免捏造台詞",
124
- "max_characters": 8,
125
- "default_position": {
126
- "x": 0.2,
127
- "y": 0.22
128
- },
129
- "requires_target": false,
130
- "motion": "放射外框展開、重點字落入",
131
- "visual_weight": "hero"
132
- }
133
- ]