@clipen/clipen-cli 0.0.0-stage → 1.0.0

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 (232) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -2
  3. package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
  4. package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
  5. package/apps/web/dist/favicon.svg +1 -0
  6. package/apps/web/dist/index.html +16 -0
  7. package/bin/clipen.js +157 -0
  8. package/clipen +18 -0
  9. package/install +25 -0
  10. package/package.json +52 -4
  11. package/pyproject.toml +28 -0
  12. package/requirements/asr-runtime.txt +13 -0
  13. package/requirements/runtime.txt +20 -0
  14. package/src/clipen/__init__.py +3 -0
  15. package/src/clipen/analysis/__init__.py +89 -0
  16. package/src/clipen/analysis/artifacts.py +416 -0
  17. package/src/clipen/analysis/audio.py +392 -0
  18. package/src/clipen/analysis/evidence.py +102 -0
  19. package/src/clipen/analysis/evidence_service.py +751 -0
  20. package/src/clipen/analysis/image_similarity.py +143 -0
  21. package/src/clipen/analysis/keyframes.py +171 -0
  22. package/src/clipen/analysis/models.py +230 -0
  23. package/src/clipen/analysis/qwen_worker.py +629 -0
  24. package/src/clipen/analysis/resources.py +21 -0
  25. package/src/clipen/analysis/runtime.py +64 -0
  26. package/src/clipen/analysis/service.py +626 -0
  27. package/src/clipen/analysis/setup.py +935 -0
  28. package/src/clipen/analysis/setup_cli.py +117 -0
  29. package/src/clipen/analysis/storage.py +2046 -0
  30. package/src/clipen/analysis/transcription.py +948 -0
  31. package/src/clipen/analysis/visual.py +176 -0
  32. package/src/clipen/annotations/__init__.py +10 -0
  33. package/src/clipen/annotations/models.py +22 -0
  34. package/src/clipen/annotations/storage.py +380 -0
  35. package/src/clipen/annotations/suggestions.py +120 -0
  36. package/src/clipen/asr_release.py +139 -0
  37. package/src/clipen/bootstrap.py +967 -0
  38. package/src/clipen/cli.py +84 -0
  39. package/src/clipen/controller/__init__.py +17 -0
  40. package/src/clipen/controller/app.py +1470 -0
  41. package/src/clipen/controller/server.py +543 -0
  42. package/src/clipen/domain/__init__.py +30 -0
  43. package/src/clipen/domain/errors.py +5 -0
  44. package/src/clipen/domain/media_time.py +117 -0
  45. package/src/clipen/domain/timeline.py +584 -0
  46. package/src/clipen/domain/validation.py +15 -0
  47. package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
  48. package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
  49. package/src/clipen/editing/README.md +115 -0
  50. package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
  51. package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
  52. package/src/clipen/editing/__init__.py +15 -0
  53. package/src/clipen/editing/agent.py +13 -0
  54. package/src/clipen/editing/agent_models.py +134 -0
  55. package/src/clipen/editing/agent_repository.py +757 -0
  56. package/src/clipen/editing/agent_tools.py +532 -0
  57. package/src/clipen/editing/alignment.py +110 -0
  58. package/src/clipen/editing/alignment_setup.py +108 -0
  59. package/src/clipen/editing/alignment_worker.py +22 -0
  60. package/src/clipen/editing/change_report.py +71 -0
  61. package/src/clipen/editing/compiler.py +41 -0
  62. package/src/clipen/editing/component_looks.py +107 -0
  63. package/src/clipen/editing/component_review.py +78 -0
  64. package/src/clipen/editing/coordinator.py +374 -0
  65. package/src/clipen/editing/editorial_review.py +187 -0
  66. package/src/clipen/editing/evidence_jobs.py +295 -0
  67. package/src/clipen/editing/history_changes.py +131 -0
  68. package/src/clipen/editing/music_choices.py +15 -0
  69. package/src/clipen/editing/production_catalog.py +192 -0
  70. package/src/clipen/editing/production_limits.py +59 -0
  71. package/src/clipen/editing/production_media.py +226 -0
  72. package/src/clipen/editing/production_preview.py +180 -0
  73. package/src/clipen/editing/production_progress.py +141 -0
  74. package/src/clipen/editing/production_requirements.py +50 -0
  75. package/src/clipen/editing/production_tools.py +596 -0
  76. package/src/clipen/editing/program_audio.py +118 -0
  77. package/src/clipen/editing/program_direction.py +49 -0
  78. package/src/clipen/editing/program_story.py +53 -0
  79. package/src/clipen/editing/program_subtitles.py +134 -0
  80. package/src/clipen/editing/programme_review.py +73 -0
  81. package/src/clipen/editing/prompt_history.py +47 -0
  82. package/src/clipen/editing/recut.py +127 -0
  83. package/src/clipen/editing/refinement_references.py +188 -0
  84. package/src/clipen/editing/resolve_export.py +616 -0
  85. package/src/clipen/editing/resolve_titles.py +234 -0
  86. package/src/clipen/editing/skill_tools.py +575 -0
  87. package/src/clipen/editing/source_dialogue.py +82 -0
  88. package/src/clipen/editing/speech_coverage.py +30 -0
  89. package/src/clipen/editing/speech_quality.py +6 -0
  90. package/src/clipen/editing/tool_receipts.py +52 -0
  91. package/src/clipen/editing/versions.py +161 -0
  92. package/src/clipen/editing/visual_preview.py +93 -0
  93. package/src/clipen/editing/workbench.py +74 -0
  94. package/src/clipen/filesystem.py +25 -0
  95. package/src/clipen/finishing/README.md +103 -0
  96. package/src/clipen/finishing/__init__.py +1 -0
  97. package/src/clipen/finishing/audio.py +149 -0
  98. package/src/clipen/finishing/catalog.py +181 -0
  99. package/src/clipen/finishing/models.py +14 -0
  100. package/src/clipen/finishing/renderer.py +26 -0
  101. package/src/clipen/mcp_editing/__init__.py +5 -0
  102. package/src/clipen/mcp_editing/__main__.py +40 -0
  103. package/src/clipen/mcp_editing/server.py +353 -0
  104. package/src/clipen/media/__init__.py +50 -0
  105. package/src/clipen/media/discovery.py +266 -0
  106. package/src/clipen/media/models.py +360 -0
  107. package/src/clipen/media/preview.py +147 -0
  108. package/src/clipen/media/probe.py +446 -0
  109. package/src/clipen/media/service.py +317 -0
  110. package/src/clipen/media/storage.py +742 -0
  111. package/src/clipen/music_vocabulary.py +5 -0
  112. package/src/clipen/planning/__init__.py +9 -0
  113. package/src/clipen/planning/models.py +240 -0
  114. package/src/clipen/power.py +23 -0
  115. package/src/clipen/projects/__init__.py +26 -0
  116. package/src/clipen/projects/agent_schema.py +94 -0
  117. package/src/clipen/projects/annotation_schema.py +40 -0
  118. package/src/clipen/projects/deletion.py +269 -0
  119. package/src/clipen/projects/evidence_schema.py +52 -0
  120. package/src/clipen/projects/finishing_schema.py +34 -0
  121. package/src/clipen/projects/models.py +192 -0
  122. package/src/clipen/projects/picker.py +256 -0
  123. package/src/clipen/projects/preview_schema.py +29 -0
  124. package/src/clipen/projects/service.py +175 -0
  125. package/src/clipen/projects/storage.py +1478 -0
  126. package/src/clipen/projects/timeline_schema.py +32 -0
  127. package/src/clipen/projects/validation_schema.py +28 -0
  128. package/src/clipen/provider_registry.py +75 -0
  129. package/src/clipen/providers/__init__.py +43 -0
  130. package/src/clipen/providers/account.py +194 -0
  131. package/src/clipen/providers/claude.py +375 -0
  132. package/src/clipen/providers/claude_editing.py +111 -0
  133. package/src/clipen/providers/codex.py +1036 -0
  134. package/src/clipen/providers/codex_editing.py +91 -0
  135. package/src/clipen/providers/editing_agent.py +565 -0
  136. package/src/clipen/providers/errors.py +51 -0
  137. package/src/clipen/providers/recovery.py +270 -0
  138. package/src/clipen/py.typed +1 -0
  139. package/src/clipen/rendering/__init__.py +12 -0
  140. package/src/clipen/rendering/cover.py +126 -0
  141. package/src/clipen/rendering/custom_components.py +240 -0
  142. package/src/clipen/rendering/custom_render.py +197 -0
  143. package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
  144. package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
  145. package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
  146. package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
  147. package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
  148. package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
  149. package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
  150. package/src/clipen/rendering/fonts/manifest.json +145 -0
  151. package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
  152. package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
  153. package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
  154. package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
  155. package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
  156. package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
  157. package/src/clipen/rendering/production_effects.py +64 -0
  158. package/src/clipen/rendering/program_components.py +193 -0
  159. package/src/clipen/rendering/program_creator.py +649 -0
  160. package/src/clipen/rendering/program_identities.py +255 -0
  161. package/src/clipen/rendering/program_motion.py +141 -0
  162. package/src/clipen/rendering/program_studio.py +168 -0
  163. package/src/clipen/rendering/program_styles.py +235 -0
  164. package/src/clipen/rendering/program_subtitles.py +52 -0
  165. package/src/clipen/rendering/renderer.py +708 -0
  166. package/src/clipen/rendering/storage.py +243 -0
  167. package/src/clipen/rendering/titles.py +360 -0
  168. package/src/clipen/skills/__init__.py +4 -0
  169. package/src/clipen/skills/builtin/SKILL.md +72 -0
  170. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  171. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  172. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  173. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  174. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  175. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  176. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  177. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  178. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  179. package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
  180. package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
  181. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  182. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  183. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  184. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  185. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  186. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  187. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  188. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  189. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  190. package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
  191. package/src/clipen/skills/builtin/components.json +133 -0
  192. package/src/clipen/skills/builtin/font_sources.json +20 -0
  193. package/src/clipen/skills/builtin/font_styles.json +329 -0
  194. package/src/clipen/skills/builtin/manifest.json +32 -0
  195. package/src/clipen/skills/builtin/presets.json +8 -0
  196. package/src/clipen/skills/builtin/references/captions.md +14 -0
  197. package/src/clipen/skills/builtin/references/channel-design.md +37 -0
  198. package/src/clipen/skills/builtin/references/editing.md +30 -0
  199. package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
  200. package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
  201. package/src/clipen/skills/builtin/references/graphics.md +59 -0
  202. package/src/clipen/skills/builtin/references/review.md +16 -0
  203. package/src/clipen/skills/builtin/references/sound.md +8 -0
  204. package/src/clipen/skills/builtin/references/story.md +7 -0
  205. package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
  206. package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
  207. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
  208. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
  209. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
  210. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
  211. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
  212. package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
  213. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
  214. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
  215. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
  216. package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
  217. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
  218. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
  219. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
  220. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
  221. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
  222. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
  223. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
  224. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
  225. package/src/clipen/skills/builtin/templates.json +284 -0
  226. package/src/clipen/skills/builtin/visual_styles.json +1074 -0
  227. package/src/clipen/skills/catalog.py +218 -0
  228. package/src/clipen/skills/library.py +131 -0
  229. package/src/clipen/skills/package.py +231 -0
  230. package/src/clipen/skills/visual_styles.py +44 -0
  231. package/src/clipen/workspace.py +210 -0
  232. package/uninstall +25 -0
@@ -0,0 +1,235 @@
1
+ """Distinct, trusted art directions for the same semantic programme components."""
2
+ import os
3
+ import hashlib
4
+ from importlib.resources import files
5
+ from pathlib import Path
6
+ from functools import lru_cache
7
+ from PIL import ImageFont
8
+
9
+
10
+ def skin(profile):
11
+ return profile.get('presets',{}).get('appearance',{}).get('skin','variety')
12
+
13
+
14
+ def style_font(font_path, profile):
15
+ if os.environ.get('CLIPEN_TITLE_FONT') or profile['presets'].get('appearance',{}).get('font_family')!='serif':
16
+ return font_path
17
+ for path in ('/System/Library/Fonts/Supplemental/Songti.ttc',
18
+ '/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc',
19
+ 'C:/Windows/Fonts/simsun.ttc'):
20
+ if Path(path).is_file():return Path(path)
21
+ return font_path
22
+
23
+
24
+
25
+ @lru_cache(maxsize=32)
26
+ def _font_face(path, direction):
27
+ preferred='Light' if direction=='cinema' else 'Regular'
28
+ fallback=None
29
+ for index in range(16):
30
+ try:family,weight=ImageFont.truetype(path,12,index=index).getname()
31
+ except OSError:break
32
+ if family in {'Songti TC','Noto Serif CJK TC','NotoSerifCJKtc'}:
33
+ if weight==preferred:return index
34
+ if fallback is None:fallback=index
35
+ return fallback or 0
36
+
37
+
38
+ def font_role(profile):
39
+ kind=profile.get('component_id')
40
+ return 'impact' if kind in {'impact','burst','reaction'} else 'title' if kind in {'program_title','headline','chapter'} else 'information'
41
+
42
+
43
+ @lru_cache(maxsize=64)
44
+ def _role_face(path, weight):
45
+ preferred={'bold':('Bold','W6','Semibold','Heavy','Black'), 'medium':('Medium','W6','Regular'),
46
+ 'light':('Light','W3','Regular'), 'regular':('Regular','W3','Medium')}[weight]
47
+ faces=[]
48
+ for index in range(32):
49
+ try:family,face=ImageFont.truetype(path,12,index=index).getname()
50
+ except OSError:break
51
+ # Prefer Traditional Chinese faces when a collection contains both.
52
+ if ' SC' not in family and 'Interface' not in family and family!='STSong':
53
+ faces.append((index,face,family.endswith(' TC')))
54
+ # 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])]
56
+ for desired in preferred:
57
+ for index,face in faces:
58
+ if face==desired:return index
59
+ return faces[0][0] if faces else 0
60
+
61
+
62
+ @lru_cache(maxsize=16)
63
+ def _verify_font(path, expected, modified_ns, length):
64
+ from .titles import TitleRenderError
65
+ if hashlib.sha256(Path(path).read_bytes()).hexdigest()!=expected:
66
+ raise TitleRenderError('program_font_unavailable')
67
+ return path
68
+
69
+
70
+ def bundled_font(specification):
71
+ from .titles import TitleRenderError
72
+ identifier=specification['bundled_font']
73
+ if identifier not in {'chenyu','iansui'}:
74
+ raise TitleRenderError('program_font_unavailable')
75
+ path=Path(str(files('clipen.rendering').joinpath('fonts',identifier+'.ttf')))
76
+ try:
77
+ stat=path.stat()
78
+ return _verify_font(str(path),specification['sha256'],stat.st_mtime_ns,stat.st_size)
79
+ except (OSError,KeyError) as error:
80
+ raise TitleRenderError('program_font_unavailable') from error
81
+
82
+
83
+ @lru_cache(maxsize=8)
84
+ def _system_asset(name):
85
+ """macOS installs some fonts on demand under a hashed asset folder."""
86
+ from glob import glob
87
+ return tuple(sorted(glob('/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*.asset/AssetData/'+name)))[:1]
88
+
89
+
90
+ def type_outline(profile, font, fallback):
91
+ specification=profile['presets'].get('font_roles',{}).get(font_role(profile),{})
92
+ ratio=specification.get('outline_em')
93
+ return fallback if ratio is None else max(1,round(font.size*ratio))
94
+
95
+
96
+ def load_style_font(font_path, size, profile, role=None):
97
+ specification=profile['presets'].get('font_roles',{}).get(role or font_role(profile))
98
+ if specification:
99
+ if specification.get('bundled_font') and not os.environ.get('CLIPEN_TITLE_FONT'):
100
+ return ImageFont.truetype(bundled_font(specification),size)
101
+ family=specification['family']
102
+ if family=='handwriting':family='sans'
103
+ candidates={
104
+ 'gothic':('/System/Library/Fonts/Hiragino Sans GB.ttc','/System/Library/Fonts/STHeiti Medium.ttc'),
105
+ 'sans':('/System/Library/Fonts/STHeiti Medium.ttc','/System/Library/Fonts/Hiragino Sans GB.ttc'),
106
+ 'serif':('/System/Library/Fonts/Supplemental/Songti.ttc',),
107
+ # PingFang is the clean system sans creators expect on macOS; it is
108
+ # an on-demand system asset, so fall back to Hiragino Sans GB.
109
+ 'modern':_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc','/System/Library/Fonts/STHeiti Medium.ttc'),
110
+ # Display faces popular in Taiwanese variety and vlog packaging.
111
+ 'lantinghei':_system_asset('Lantinghei.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
112
+ 'wawa':_system_asset('WawaTC-Regular.otf')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
113
+ 'hannotate':_system_asset('Hannotate.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
114
+ 'hanzipen':_system_asset('Hanzipen.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
115
+ 'yuanti':_system_asset('Yuanti.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
116
+ 'kaiti':_system_asset('Kaiti.ttc')+('/System/Library/Fonts/Supplemental/Songti.ttc',),
117
+ 'lingwai':_system_asset('LingWaiTC-Medium.otf')+('/System/Library/Fonts/Supplemental/Songti.ttc',),
118
+ 'weibei':_system_asset('WeibeiTC-Bold.otf')+_system_asset('Lantinghei.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
119
+ }[family]
120
+ candidates+=('/usr/share/fonts/opentype/noto/Noto'+('Serif' if family=='serif' else 'Sans')+'CJK-Regular.ttc',
121
+ 'C:/Windows/Fonts/'+('simsun.ttc' if family=='serif' else 'msjh.ttc'))
122
+ # The explicit local font override still has priority. No arbitrary font
123
+ # paths or remote URLs can be supplied through the editing MCP tools.
124
+ path=str(font_path) if os.environ.get('CLIPEN_TITLE_FONT') else next((p for p in candidates if Path(p).is_file()),str(font_path))
125
+ return ImageFont.truetype(path,size,index=_role_face(path,specification['weight']))
126
+ path=str(style_font(font_path,profile))
127
+ face=_font_face(path,skin(profile)) if profile['presets'].get('appearance',{}).get('font_family')=='serif' else 0
128
+ return ImageFont.truetype(path,size,index=face)
129
+
130
+
131
+
132
+ @lru_cache(maxsize=2048)
133
+ def _has_glyph(path, size, index, character):
134
+ if character.isspace():return True
135
+ font=ImageFont.truetype(path,size,index=index)
136
+ glyph=font.getmask(character)
137
+ missing=font.getmask('\U0010ffff')
138
+ return glyph.getbbox() is not None and (glyph.size!=missing.size or bytes(glyph)!=bytes(missing))
139
+
140
+
141
+ def _text_runs(value, font):
142
+ from .titles import TitleCardRenderer,TitleRenderError
143
+ fallback=None;runs=[]
144
+ for char in value:
145
+ selected=font
146
+ if not _has_glyph(str(font.path),font.size,font.index,char):
147
+ if fallback is None:
148
+ path=TitleCardRenderer._font_path()
149
+ if path is None:raise TitleRenderError('program_component_missing_glyph')
150
+ fallback=ImageFont.truetype(str(path),font.size)
151
+ if not _has_glyph(str(fallback.path),fallback.size,fallback.index,char):
152
+ raise TitleRenderError('program_component_missing_glyph')
153
+ selected=fallback
154
+ if runs and runs[-1][1] is selected:runs[-1]=(runs[-1][0]+char,selected)
155
+ else:runs.append((char,selected))
156
+ return runs
157
+
158
+
159
+ def styled_text_length(value,font):
160
+ return sum(selected.getlength(part) for part,selected in _text_runs(value,font))
161
+
162
+
163
+ def draw_style_text(draw,position,value,font,fill,stroke_width=0,stroke_fill=None):
164
+ if not value:return
165
+ # Share a real baseline across font runs so a fallback middle dot stays in
166
+ # the middle of CJK type rather than jumping to the top of the line.
167
+ baseline=position[1]-font.getbbox(value,anchor='ls')[1]
168
+ x=position[0]
169
+ for part,selected in _text_runs(value,font):
170
+ draw.text((x,baseline),part,font=selected,fill=fill,anchor='ls',
171
+ stroke_width=stroke_width,stroke_fill=stroke_fill)
172
+ x+=selected.getlength(part)
173
+
174
+
175
+ def draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
176
+ if skin(profile) == 'studio':
177
+ from .program_studio import draw_graphic
178
+ return draw_graphic(draw,font_path,timeline,item,profile,bounds,font,pad,relative_frame)
179
+ kind=profile['component_id'];hero=kind in {'program_title','headline','impact','chapter','burst'}
180
+ appearance=profile['presets'].get('appearance',{})
181
+ motion=profile['presets']['motion']
182
+ entry=appearance.get('hero_entry_frames',18) if hero else motion['entry_frames']
183
+ exit_frames=appearance.get('hero_exit_frames',8) if hero else motion['exit_frames']
184
+ relative=entry if relative_frame is None else relative_frame
185
+ progress=min(1.,max(0.,(relative+1)/entry));ease=1-(1-progress)**3
186
+ opacity=min(progress,min(1.,max(0.,(item.duration_frames-relative)/exit_frames)))
187
+ x,y,right,bottom=bounds;w=right-x;h=bottom-y
188
+ # The full entrance remains within the validated static footprint.
189
+ y+=round((1-ease)*pad*.35)
190
+ primary,_,detail=item.text.partition('\n')
191
+ font_path=style_font(font_path,profile)
192
+ small=load_style_font(font_path,max(12,round(timeline.height*.024)),profile,role='detail')
193
+ line=max(1,round(timeline.height*.002))
194
+ palette=profile['presets']['palette']
195
+ def color(name,alpha=1.):
196
+ r,g,b,a=palette[name]
197
+ return r,g,b,round(a*opacity*alpha)
198
+ def text(position,value,selected=font,fill='ink',shadow=False):
199
+ if shadow:
200
+ draw_style_text(draw,(position[0]+line,position[1]+line),value,selected,color('ink'),line,color('ink'))
201
+ draw_style_text(draw,position,value,selected,color(fill))
202
+ if skin(profile)=='editorial':
203
+ # Paper, ink and seal geometry: no slanted yellow panels or comic strokes.
204
+ draw.rounded_rectangle((x,y,right,bottom),radius=max(2,pad//3),fill=color('paper'),outline=color('ink'),width=line)
205
+ if kind=='burst':
206
+ cx,cy=(x+right)/2,y+h*.43;radius=min(w*.45,h*.40)
207
+ draw.ellipse((cx-radius,cy-radius,cx+radius,cy+radius),outline=color('accent'),width=line*2)
208
+ draw.ellipse((cx-radius+line*4,cy-radius+line*4,cx+radius-line*4,cy+radius-line*4),outline=color('accent'),width=line)
209
+ elif kind=='program_title':
210
+ draw.rectangle((x+pad,y+pad*.65,x+pad*2,y+pad*1.5),fill=color('accent'))
211
+ draw.line((x+pad*2.5,y+pad*1.1,x+w*ease-pad,y+pad*1.1),fill=color('ink'),width=line)
212
+ elif kind in {'headline','impact'}:
213
+ draw.line((x+pad,bottom-pad*.6,x+(w-pad)*ease,bottom-pad*.6),fill=color('accent'),width=line*3)
214
+ else:
215
+ draw.rectangle((x,y,x+line*3,bottom),fill=color('accent'))
216
+ ty=y+h*(.31 if kind=='program_title' else .23 if hero else .22)
217
+ text((x+pad*1.5,ty),primary,fill='accent' if kind in {'impact','burst'} else 'ink')
218
+ if detail:text((x+pad*1.5,bottom-pad*1.9),detail,small)
219
+ else:
220
+ # Quiet lower-third grammar, hairline brackets and serif type. The small
221
+ # translucent backing preserves contrast on bright source footage.
222
+ draw.rectangle((x,y,right,bottom),fill=color('ink',.30))
223
+ length=min(pad*2,w*.16)*ease
224
+ if kind=='chapter':
225
+ draw.line((x,y+pad*.5,x+pad*.8,bottom-pad*.5),fill=color('accent'),width=line*2)
226
+ elif kind in {'program_title','burst'}:
227
+ for cx,cy,sx,sy in ((x,y,1,1),(right,bottom,-1,-1)):
228
+ draw.line((cx,cy,cx+sx*length,cy),fill=color('accent'),width=line)
229
+ draw.line((cx,cy,cx,cy+sy*length),fill=color('accent'),width=line)
230
+ else:
231
+ draw.line((x+pad,bottom-pad*.6,x+(w-pad)*ease,bottom-pad*.6),fill=color('accent'),width=line)
232
+ ty=y+h*(.30 if kind=='program_title' else .23 if hero else .22)
233
+ text((x+pad*1.5,ty),primary,fill='paper',shadow=True)
234
+ if detail:text((x+pad*1.5,bottom-pad*1.9),detail,small,fill='paper',shadow=True)
235
+ return bounds
@@ -0,0 +1,52 @@
1
+ """Outlined programme captions with in-sentence emphasis and bounded animation.
2
+
3
+ Rendered as native RGBA events, so the pipeline does not depend on libass being
4
+ installed in the user's FFmpeg build. No text box, chapter card or logo is drawn.
5
+ """
6
+ from PIL import ImageFont
7
+
8
+
9
+ def animation_boundaries(item):
10
+ return {item.start_frame+n for n in (0,2,4,7,item.duration_frames-2,item.duration_frames) if 0<=n<=item.duration_frames}
11
+
12
+
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('motion')=='none' else relative_frame
15
+ scale=.88 if relative<2 else 1.06 if relative<4 else .98 if relative<7 else 1.
16
+ size=max(16,round(timeline.height*profile.get('font_size_ratio',.052)*scale))
17
+ index=0
18
+ # Hiragino's W6 face is heavier than W3. Other families use their configured
19
+ # face and a small foreground stroke rather than assuming a TTC index.
20
+ try:
21
+ candidate=ImageFont.truetype(str(font_path),size,index=2)
22
+ if 'W6' in candidate.getname()[1]:index=2
23
+ except OSError:pass
24
+ font=ImageFont.truetype(str(font_path),size,index=index)
25
+ layout_font=ImageFont.truetype(str(font_path),max(16,round(timeline.height*profile.get('font_size_ratio',.052)*1.06)),index=index)
26
+ text=item.text.replace('\n',' ');maximum=timeline.width*.86
27
+ lines=[];line=''
28
+ for character in text:
29
+ if line and draw.textlength(line+character,font=layout_font)>maximum:
30
+ lines.append(line);line=''
31
+ line+=character
32
+ if line:lines.append(line)
33
+ if len(lines)>2:
34
+ from .titles import TitleRenderError
35
+ raise TitleRenderError('program_subtitle_overflow')
36
+ highlighted=set()
37
+ for word in profile.get('emphasis',[]):
38
+ start=0
39
+ while (start:=text.find(word,start))>=0:
40
+ highlighted.update(range(start,start+len(word)));start+=len(word)
41
+ opacity=255 if item.duration_frames-relative>2 else 180
42
+ stroke=max(2,round(size*.095));line_height=round(size*1.35)
43
+ baseline=round(timeline.height*.90)-(len(lines)-1)*line_height
44
+ offset=0
45
+ for line in lines:
46
+ x=(timeline.width-draw.textlength(line,font=font))/2
47
+ for character in line:
48
+ color=tuple(profile.get('emphasis_color',[255,217,55,255])[:3])+(opacity,) if offset in highlighted else (255,255,255,opacity)
49
+ draw.text((x+2,baseline+3),character,font=font,anchor='ls',fill=(0,0,0,110),stroke_width=stroke+1,stroke_fill=(0,0,0,110))
50
+ draw.text((x,baseline),character,font=font,anchor='ls',fill=color,stroke_width=stroke,stroke_fill=tuple(profile.get('outline_color',[10,10,14,255])[:3])+(opacity,))
51
+ x+=draw.textlength(character,font=font);offset+=1
52
+ baseline+=line_height