@clipen/clipen-cli 1.0.0 → 1.0.1
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.
- package/README.md +60 -50
- package/package.json +7 -4
- package/pyproject.toml +18 -2
- package/requirements/dev.txt +2 -0
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/__init__.py +7 -7
- package/src/clipen/analysis/artifacts.py +4 -10
- package/src/clipen/analysis/audio.py +10 -8
- package/src/clipen/analysis/evidence_service.py +345 -167
- package/src/clipen/analysis/image_similarity.py +5 -14
- package/src/clipen/analysis/keyframes.py +5 -17
- package/src/clipen/analysis/models.py +5 -7
- package/src/clipen/analysis/qwen_worker.py +19 -54
- package/src/clipen/analysis/resources.py +2 -1
- package/src/clipen/analysis/runtime.py +1 -3
- package/src/clipen/analysis/service.py +16 -48
- package/src/clipen/analysis/setup.py +11 -25
- package/src/clipen/analysis/setup_cli.py +5 -15
- package/src/clipen/analysis/storage.py +96 -278
- package/src/clipen/analysis/transcription.py +40 -82
- package/src/clipen/analysis/visual.py +109 -48
- package/src/clipen/annotations/__init__.py +5 -2
- package/src/clipen/annotations/models.py +1 -1
- package/src/clipen/annotations/storage.py +132 -84
- package/src/clipen/annotations/suggestions.py +3 -8
- package/src/clipen/asr_release.py +4 -11
- package/src/clipen/bootstrap.py +65 -54
- package/src/clipen/{planning/models.py → candidates.py} +29 -47
- package/src/clipen/cli.py +2 -2
- package/src/clipen/controller/app.py +401 -214
- package/src/clipen/controller/server.py +28 -38
- package/src/clipen/domain/__init__.py +1 -1
- package/src/clipen/domain/media_time.py +3 -10
- package/src/clipen/domain/timeline.py +45 -47
- package/src/clipen/domain/validation.py +0 -1
- package/src/clipen/editing/__init__.py +1 -1
- package/src/clipen/editing/agent_models.py +4 -11
- package/src/clipen/editing/agent_repository.py +391 -170
- package/src/clipen/editing/agent_tools.py +180 -99
- package/src/clipen/editing/alignment.py +92 -52
- package/src/clipen/editing/alignment_setup.py +118 -70
- package/src/clipen/editing/alignment_worker.py +11 -9
- package/src/clipen/editing/change_report.py +95 -38
- package/src/clipen/editing/compiler.py +0 -1
- package/src/clipen/editing/component_looks.py +58 -34
- package/src/clipen/editing/component_review.py +34 -38
- package/src/clipen/editing/coordinator.py +213 -90
- package/src/clipen/editing/editorial_review.py +217 -95
- package/src/clipen/editing/evidence_jobs.py +457 -200
- package/src/clipen/editing/history_changes.py +129 -68
- package/src/clipen/editing/music_choices.py +8 -5
- package/src/clipen/editing/production_catalog.py +573 -136
- package/src/clipen/editing/production_limits.py +43 -17
- package/src/clipen/editing/production_media.py +376 -167
- package/src/clipen/editing/production_preview.py +322 -129
- package/src/clipen/editing/production_progress.py +164 -69
- package/src/clipen/editing/production_requirements.py +106 -39
- package/src/clipen/editing/production_tools.py +1064 -462
- package/src/clipen/editing/program_audio.py +211 -81
- package/src/clipen/editing/program_direction.py +59 -25
- package/src/clipen/editing/program_story.py +83 -45
- package/src/clipen/editing/program_subtitles.py +194 -96
- package/src/clipen/editing/programme_review.py +98 -50
- package/src/clipen/editing/prompt_history.py +64 -27
- package/src/clipen/editing/recut.py +65 -25
- package/src/clipen/editing/refinement_references.py +176 -86
- package/src/clipen/editing/resolve_export.py +449 -218
- package/src/clipen/editing/resolve_titles.py +162 -105
- package/src/clipen/editing/skill_tools.py +530 -154
- package/src/clipen/editing/source_dialogue.py +177 -67
- package/src/clipen/editing/speech_coverage.py +42 -22
- package/src/clipen/editing/speech_quality.py +6 -1
- package/src/clipen/editing/tool_receipts.py +78 -32
- package/src/clipen/editing/versions.py +122 -64
- package/src/clipen/editing/visual_preview.py +157 -61
- package/src/clipen/editing/workbench.py +104 -42
- package/src/clipen/finishing/audio.py +69 -30
- package/src/clipen/finishing/catalog.py +176 -93
- package/src/clipen/finishing/models.py +1 -1
- package/src/clipen/finishing/renderer.py +33 -14
- package/src/clipen/mcp_editing/__main__.py +3 -1
- package/src/clipen/mcp_editing/server.py +77 -34
- package/src/clipen/media/__init__.py +3 -3
- package/src/clipen/media/discovery.py +7 -20
- package/src/clipen/media/models.py +7 -18
- package/src/clipen/media/preview.py +14 -24
- package/src/clipen/media/probe.py +16 -44
- package/src/clipen/media/service.py +6 -19
- package/src/clipen/media/storage.py +33 -81
- package/src/clipen/music_vocabulary.py +33 -4
- package/src/clipen/power.py +8 -3
- package/src/clipen/projects/__init__.py +1 -1
- package/src/clipen/projects/deletion.py +19 -32
- package/src/clipen/projects/finishing_schema.py +3 -1
- package/src/clipen/projects/models.py +2 -5
- package/src/clipen/projects/picker.py +13 -37
- package/src/clipen/projects/service.py +8 -24
- package/src/clipen/projects/storage.py +226 -246
- package/src/clipen/provider_registry.py +4 -2
- package/src/clipen/providers/account.py +86 -35
- package/src/clipen/providers/claude.py +59 -25
- package/src/clipen/providers/claude_editing.py +14 -7
- package/src/clipen/providers/codex.py +73 -118
- package/src/clipen/providers/codex_editing.py +2 -2
- package/src/clipen/providers/editing_agent.py +19 -17
- package/src/clipen/providers/recovery.py +7 -8
- package/src/clipen/rendering/cover.py +18 -5
- package/src/clipen/rendering/custom_components.py +167 -79
- package/src/clipen/rendering/custom_render.py +62 -41
- package/src/clipen/rendering/production_effects.py +77 -45
- package/src/clipen/rendering/program_components.py +134 -73
- package/src/clipen/rendering/program_creator.py +432 -277
- package/src/clipen/rendering/program_identities.py +277 -182
- package/src/clipen/rendering/program_motion.py +140 -95
- package/src/clipen/rendering/program_studio.py +175 -116
- package/src/clipen/rendering/program_styles.py +231 -145
- package/src/clipen/rendering/program_subtitles.py +71 -34
- package/src/clipen/rendering/renderer.py +150 -121
- package/src/clipen/rendering/storage.py +9 -22
- package/src/clipen/rendering/titles.py +193 -86
- package/src/clipen/skills/__init__.py +1 -0
- package/src/clipen/skills/catalog.py +151 -55
- package/src/clipen/skills/library.py +13 -7
- package/src/clipen/skills/package.py +46 -23
- package/src/clipen/skills/visual_styles.py +29 -18
- package/src/clipen/workspace.py +15 -44
- package/src/clipen/planning/__init__.py +0 -9
|
@@ -1,235 +1,321 @@
|
|
|
1
1
|
"""Distinct, trusted art directions for the same semantic programme components."""
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import hashlib
|
|
4
|
+
import os
|
|
5
|
+
from functools import lru_cache
|
|
4
6
|
from importlib.resources import files
|
|
5
7
|
from pathlib import Path
|
|
6
|
-
|
|
8
|
+
|
|
7
9
|
from PIL import ImageFont
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
def skin(profile):
|
|
11
|
-
return profile.get(
|
|
13
|
+
return profile.get("presets", {}).get("appearance", {}).get("skin", "variety")
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
def style_font(font_path, profile):
|
|
15
|
-
if os.environ.get(
|
|
17
|
+
if os.environ.get("CLIPEN_TITLE_FONT") or profile["presets"].get("appearance", {}).get("font_family") != "serif":
|
|
16
18
|
return font_path
|
|
17
|
-
for path in (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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)
|
|
21
26
|
return font_path
|
|
22
27
|
|
|
23
28
|
|
|
24
|
-
|
|
25
29
|
@lru_cache(maxsize=32)
|
|
26
30
|
def _font_face(path, direction):
|
|
27
|
-
preferred=
|
|
28
|
-
fallback=None
|
|
31
|
+
preferred = "Light" if direction == "cinema" else "Regular"
|
|
32
|
+
fallback = None
|
|
29
33
|
for index in range(16):
|
|
30
|
-
try:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
35
43
|
return fallback or 0
|
|
36
44
|
|
|
37
45
|
|
|
38
46
|
def font_role(profile):
|
|
39
|
-
kind=profile.get(
|
|
40
|
-
return
|
|
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
|
+
)
|
|
41
55
|
|
|
42
56
|
|
|
43
57
|
@lru_cache(maxsize=64)
|
|
44
58
|
def _role_face(path, weight):
|
|
45
|
-
preferred={
|
|
46
|
-
|
|
47
|
-
|
|
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 = []
|
|
48
66
|
for index in range(32):
|
|
49
|
-
try:
|
|
50
|
-
|
|
67
|
+
try:
|
|
68
|
+
family, face = ImageFont.truetype(path, 12, index=index).getname()
|
|
69
|
+
except OSError:
|
|
70
|
+
break
|
|
51
71
|
# Prefer Traditional Chinese faces when a collection contains both.
|
|
52
|
-
if
|
|
53
|
-
faces.append((index,face,family.endswith(
|
|
72
|
+
if " SC" not in family and "Interface" not in family and family != "STSong":
|
|
73
|
+
faces.append((index, face, family.endswith(" TC")))
|
|
54
74
|
# Taiwan forms first when a collection also ships HK or other regional faces.
|
|
55
|
-
faces=[(index,face) for index,face,_ in sorted(faces,key=lambda entry:not entry[2])]
|
|
75
|
+
faces = [(index, face) for index, face, _ in sorted(faces, key=lambda entry: not entry[2])]
|
|
56
76
|
for desired in preferred:
|
|
57
|
-
for index,face in faces:
|
|
58
|
-
if face==desired:
|
|
77
|
+
for index, face in faces:
|
|
78
|
+
if face == desired:
|
|
79
|
+
return index
|
|
59
80
|
return faces[0][0] if faces else 0
|
|
60
81
|
|
|
61
82
|
|
|
62
83
|
@lru_cache(maxsize=16)
|
|
63
84
|
def _verify_font(path, expected, modified_ns, length):
|
|
64
85
|
from .titles import TitleRenderError
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
|
|
87
|
+
if hashlib.sha256(Path(path).read_bytes()).hexdigest() != expected:
|
|
88
|
+
raise TitleRenderError("program_font_unavailable")
|
|
67
89
|
return path
|
|
68
90
|
|
|
69
91
|
|
|
70
92
|
def bundled_font(specification):
|
|
71
93
|
from .titles import TitleRenderError
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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")))
|
|
76
99
|
try:
|
|
77
|
-
stat=path.stat()
|
|
78
|
-
return _verify_font(str(path),specification[
|
|
79
|
-
except (OSError,KeyError) as error:
|
|
80
|
-
raise TitleRenderError(
|
|
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
|
|
81
104
|
|
|
82
105
|
|
|
83
106
|
@lru_cache(maxsize=8)
|
|
84
107
|
def _system_asset(name):
|
|
85
108
|
"""macOS installs some fonts on demand under a hashed asset folder."""
|
|
86
109
|
from glob import glob
|
|
87
|
-
|
|
110
|
+
|
|
111
|
+
return tuple(sorted(glob("/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*.asset/AssetData/" + name)))[:1]
|
|
88
112
|
|
|
89
113
|
|
|
90
114
|
def type_outline(profile, font, fallback):
|
|
91
|
-
specification=profile[
|
|
92
|
-
ratio=specification.get(
|
|
93
|
-
return fallback if ratio is None else max(1,round(font.size*ratio))
|
|
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))
|
|
94
118
|
|
|
95
119
|
|
|
96
120
|
def load_style_font(font_path, size, profile, role=None):
|
|
97
|
-
specification=profile[
|
|
121
|
+
specification = profile["presets"].get("font_roles", {}).get(role or font_role(profile))
|
|
98
122
|
if specification:
|
|
99
|
-
if specification.get(
|
|
100
|
-
return ImageFont.truetype(bundled_font(specification),size)
|
|
101
|
-
family=specification[
|
|
102
|
-
if family==
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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",),
|
|
107
132
|
# PingFang is the clean system sans creators expect on macOS; it is
|
|
108
133
|
# an on-demand system asset, so fall back to Hiragino Sans GB.
|
|
109
|
-
|
|
134
|
+
"modern": _system_asset("PingFang.ttc")
|
|
135
|
+
+ ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
|
|
110
136
|
# Display faces popular in Taiwanese variety and vlog packaging.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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",),
|
|
119
157
|
}[family]
|
|
120
|
-
candidates+=(
|
|
121
|
-
|
|
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
|
+
)
|
|
122
162
|
# The explicit local font override still has priority. No arbitrary font
|
|
123
163
|
# paths or remote URLs can be supplied through the editing MCP tools.
|
|
124
|
-
path=
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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)
|
|
130
175
|
|
|
131
176
|
|
|
132
177
|
@lru_cache(maxsize=2048)
|
|
133
178
|
def _has_glyph(path, size, index, character):
|
|
134
|
-
if character.isspace():
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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))
|
|
139
185
|
|
|
140
186
|
|
|
141
187
|
def _text_runs(value, font):
|
|
142
|
-
from .titles import TitleCardRenderer,TitleRenderError
|
|
143
|
-
|
|
188
|
+
from .titles import TitleCardRenderer, TitleRenderError
|
|
189
|
+
|
|
190
|
+
fallback = None
|
|
191
|
+
runs = []
|
|
144
192
|
for char in value:
|
|
145
|
-
selected=font
|
|
146
|
-
if not _has_glyph(str(font.path),font.size,font.index,char):
|
|
193
|
+
selected = font
|
|
194
|
+
if not _has_glyph(str(font.path), font.size, font.index, char):
|
|
147
195
|
if fallback is None:
|
|
148
|
-
path=TitleCardRenderer._font_path()
|
|
149
|
-
if path is None:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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))
|
|
156
207
|
return runs
|
|
157
208
|
|
|
158
209
|
|
|
159
|
-
def styled_text_length(value,font):
|
|
160
|
-
return sum(selected.getlength(part) for part,selected in _text_runs(value,font))
|
|
210
|
+
def styled_text_length(value, font):
|
|
211
|
+
return sum(selected.getlength(part) for part, selected in _text_runs(value, font))
|
|
161
212
|
|
|
162
213
|
|
|
163
|
-
def draw_style_text(draw,position,value,font,fill,stroke_width=0,stroke_fill=None):
|
|
164
|
-
if not value:
|
|
214
|
+
def draw_style_text(draw, position, value, font, fill, stroke_width=0, stroke_fill=None):
|
|
215
|
+
if not value:
|
|
216
|
+
return
|
|
165
217
|
# Share a real baseline across font runs so a fallback middle dot stays in
|
|
166
218
|
# the middle of CJK type rather than jumping to the top of the line.
|
|
167
|
-
baseline=position[1]-font.getbbox(value,anchor=
|
|
168
|
-
x=position[0]
|
|
169
|
-
for part,selected in _text_runs(value,font):
|
|
170
|
-
draw.text(
|
|
171
|
-
|
|
172
|
-
|
|
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)
|
|
173
232
|
|
|
174
233
|
|
|
175
234
|
def draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
|
|
176
|
-
if skin(profile) ==
|
|
235
|
+
if skin(profile) == "studio":
|
|
177
236
|
from .program_studio import draw_graphic
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
|
188
252
|
# The full entrance remains within the validated static footprint.
|
|
189
|
-
y+=round((1-ease)*pad
|
|
190
|
-
primary,_,detail=item.text.partition(
|
|
191
|
-
font_path=style_font(font_path,profile)
|
|
192
|
-
small=load_style_font(font_path,max(12,round(timeline.height
|
|
193
|
-
line=max(1,round(timeline.height
|
|
194
|
-
palette=profile[
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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):
|
|
199
265
|
if shadow:
|
|
200
|
-
draw_style_text(
|
|
201
|
-
|
|
202
|
-
|
|
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":
|
|
203
272
|
# Paper, ink and seal geometry: no slanted yellow panels or comic strokes.
|
|
204
|
-
draw.rounded_rectangle(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
draw.
|
|
211
|
-
draw.
|
|
212
|
-
|
|
213
|
-
|
|
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
|
+
)
|
|
214
294
|
else:
|
|
215
|
-
draw.rectangle((x,y,x+line*3,bottom),fill=color(
|
|
216
|
-
ty=y+h*(.31 if kind==
|
|
217
|
-
text((x+pad*1.5,ty),primary,fill=
|
|
218
|
-
if detail:
|
|
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)
|
|
219
300
|
else:
|
|
220
301
|
# Quiet lower-third grammar, hairline brackets and serif type. The small
|
|
221
302
|
# translucent backing preserves contrast on bright source footage.
|
|
222
|
-
draw.rectangle((x,y,right,bottom),fill=color(
|
|
223
|
-
length=min(pad*2,w
|
|
224
|
-
if kind==
|
|
225
|
-
draw.line((x,y+pad
|
|
226
|
-
elif kind in {
|
|
227
|
-
for cx,cy,sx,sy in ((x,y,1,1),(right,bottom
|
|
228
|
-
draw.line((cx,cy,cx+sx*length,cy),fill=color(
|
|
229
|
-
draw.line((cx,cy,cx,cy+sy*length),fill=color(
|
|
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)
|
|
230
311
|
else:
|
|
231
|
-
draw.line(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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)
|
|
235
321
|
return bounds
|
|
@@ -3,50 +3,87 @@
|
|
|
3
3
|
Rendered as native RGBA events, so the pipeline does not depend on libass being
|
|
4
4
|
installed in the user's FFmpeg build. No text box, chapter card or logo is drawn.
|
|
5
5
|
"""
|
|
6
|
+
|
|
6
7
|
from PIL import ImageFont
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def animation_boundaries(item):
|
|
10
|
-
return {
|
|
11
|
+
return {
|
|
12
|
+
item.start_frame + n
|
|
13
|
+
for n in (0, 2, 4, 7, item.duration_frames - 2, item.duration_frames)
|
|
14
|
+
if 0 <= n <= item.duration_frames
|
|
15
|
+
}
|
|
11
16
|
|
|
12
17
|
|
|
13
|
-
def draw_program_subtitle(draw,font_path,timeline,item,profile,relative_frame=None):
|
|
14
|
-
relative=7 if relative_frame is None or profile.get(
|
|
15
|
-
scale
|
|
16
|
-
size=max(16,round(timeline.height*profile.get(
|
|
17
|
-
index=0
|
|
18
|
+
def draw_program_subtitle(draw, font_path, timeline, item, profile, relative_frame=None):
|
|
19
|
+
relative = 7 if relative_frame is None or profile.get("motion") == "none" else relative_frame
|
|
20
|
+
scale = 0.88 if relative < 2 else 1.06 if relative < 4 else 0.98 if relative < 7 else 1.0
|
|
21
|
+
size = max(16, round(timeline.height * profile.get("font_size_ratio", 0.052) * scale))
|
|
22
|
+
index = 0
|
|
18
23
|
# Hiragino's W6 face is heavier than W3. Other families use their configured
|
|
19
24
|
# face and a small foreground stroke rather than assuming a TTC index.
|
|
20
25
|
try:
|
|
21
|
-
candidate=ImageFont.truetype(str(font_path),size,index=2)
|
|
22
|
-
if
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
candidate = ImageFont.truetype(str(font_path), size, index=2)
|
|
27
|
+
if "W6" in candidate.getname()[1]:
|
|
28
|
+
index = 2
|
|
29
|
+
except OSError:
|
|
30
|
+
pass
|
|
31
|
+
font = ImageFont.truetype(str(font_path), size, index=index)
|
|
32
|
+
layout_font = ImageFont.truetype(
|
|
33
|
+
str(font_path), max(16, round(timeline.height * profile.get("font_size_ratio", 0.052) * 1.06)), index=index
|
|
34
|
+
)
|
|
35
|
+
text = item.text.replace("\n", " ")
|
|
36
|
+
maximum = timeline.width * 0.86
|
|
37
|
+
lines = []
|
|
38
|
+
line = ""
|
|
28
39
|
for character in text:
|
|
29
|
-
if line and draw.textlength(line+character,font=layout_font)>maximum:
|
|
30
|
-
lines.append(line)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if
|
|
40
|
+
if line and draw.textlength(line + character, font=layout_font) > maximum:
|
|
41
|
+
lines.append(line)
|
|
42
|
+
line = ""
|
|
43
|
+
line += character
|
|
44
|
+
if line:
|
|
45
|
+
lines.append(line)
|
|
46
|
+
if len(lines) > 2:
|
|
34
47
|
from .titles import TitleRenderError
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
|
|
49
|
+
raise TitleRenderError("program_subtitle_overflow")
|
|
50
|
+
highlighted = set()
|
|
51
|
+
for word in profile.get("emphasis", []):
|
|
52
|
+
start = 0
|
|
53
|
+
while (start := text.find(word, start)) >= 0:
|
|
54
|
+
highlighted.update(range(start, start + len(word)))
|
|
55
|
+
start += len(word)
|
|
56
|
+
opacity = 255 if item.duration_frames - relative > 2 else 180
|
|
57
|
+
stroke = max(2, round(size * 0.095))
|
|
58
|
+
line_height = round(size * 1.35)
|
|
59
|
+
baseline = round(timeline.height * 0.90) - (len(lines) - 1) * line_height
|
|
60
|
+
offset = 0
|
|
45
61
|
for line in lines:
|
|
46
|
-
x=(timeline.width-draw.textlength(line,font=font))/2
|
|
62
|
+
x = (timeline.width - draw.textlength(line, font=font)) / 2
|
|
47
63
|
for character in line:
|
|
48
|
-
color=
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
color = (
|
|
65
|
+
tuple(profile.get("emphasis_color", [255, 217, 55, 255])[:3]) + (opacity,)
|
|
66
|
+
if offset in highlighted
|
|
67
|
+
else (255, 255, 255, opacity)
|
|
68
|
+
)
|
|
69
|
+
draw.text(
|
|
70
|
+
(x + 2, baseline + 3),
|
|
71
|
+
character,
|
|
72
|
+
font=font,
|
|
73
|
+
anchor="ls",
|
|
74
|
+
fill=(0, 0, 0, 110),
|
|
75
|
+
stroke_width=stroke + 1,
|
|
76
|
+
stroke_fill=(0, 0, 0, 110),
|
|
77
|
+
)
|
|
78
|
+
draw.text(
|
|
79
|
+
(x, baseline),
|
|
80
|
+
character,
|
|
81
|
+
font=font,
|
|
82
|
+
anchor="ls",
|
|
83
|
+
fill=color,
|
|
84
|
+
stroke_width=stroke,
|
|
85
|
+
stroke_fill=tuple(profile.get("outline_color", [10, 10, 14, 255])[:3]) + (opacity,),
|
|
86
|
+
)
|
|
87
|
+
x += draw.textlength(character, font=font)
|
|
88
|
+
offset += 1
|
|
89
|
+
baseline += line_height
|