@lark-apaas/coding-steering 0.1.32-beta.0 → 0.1.32-dev.a87aa13
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/package.json +6 -6
- package/steering/design-html/skills/charts/SKILL.md +4 -0
- package/steering/design-html/skills/pptx-style-extract/SKILL.md +58 -22
- package/steering/design-html/skills/pptx-style-extract/font-fallback.yaml +3 -3
- package/steering/design-html/skills/pptx-style-extract/scripts/census.py +18 -12
- package/steering/design-html/skills/pptx-style-extract/scripts/check_v2.py +153 -8
- package/steering/design-html/skills/pptx-style-extract/scripts/draft.py +1768 -241
- package/steering/design-html/skills/pptx-style-extract/scripts/extract.py +325 -22
- package/steering/design-html/skills/pptx-style-extract/scripts/ooxml.py +1 -1
- package/steering/design-html/skills/pptx-style-extract/scripts/package.py +379 -156
- package/steering/design-html/skills/pptx-style-extract/scripts/parts.py +6 -3
- package/steering/design-html/skills/pptx-style-extract/scripts/query.py +4 -9
- package/steering/design-html/skills/pptx-style-extract/scripts/render_pages.py +16 -10
- package/steering/design-html/skills/pptx-style-extract/scripts/test_background_composite.py +57 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_color_contract.py +60 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_design_consumer_contract.py +62 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_flow_layout_contract.py +378 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_layout_css.py +98 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_rounded_contract.py +112 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_text_role_contract.py +168 -0
- package/steering/design-html/skills/pptx-style-extract/v2-format-spec.md +27 -15
- package/steering/design-html/skills/preflight/scripts/probe.sh +0 -0
- package/steering/nestjs-react-fullstack/skills/app-init-feasibility-guide/SKILL.md +1 -0
- package/steering/nestjs-react-fullstack/skills/authn-guide/SKILL.md +6 -0
- package/steering/nestjs-react-fullstack/skills/authz-guide/SKILL.md +5 -5
- package/steering/nestjs-react-fullstack/skills/authz-guide/references/dynamic-permission-guide.md +1 -1
- package/steering/nestjs-react-fullstack/skills/client-builtins-file-storage-service/SKILL.md +37 -113
- package/steering/nestjs-react-fullstack/skills/client-builtins-user-service/SKILL.md +13 -2
- package/steering/nestjs-react-fullstack/skills/code-fix/SKILL.md +7 -7
- package/steering/nestjs-react-fullstack/skills/coding-guide/SKILL.md +149 -24
- package/steering/nestjs-react-fullstack/skills/connections-sdk/SKILL.md +202 -0
- package/steering/nestjs-react-fullstack/skills/nestjs-cache/SKILL.md +255 -0
- package/steering/nestjs-react-fullstack/skills/plugin-guide/SKILL.md +158 -543
- package/steering/nestjs-react-fullstack/skills/plugin-guide/references/plugin-coding-guide.md +15 -1
- package/steering/nestjs-react-fullstack/skills/plugin-guide/references/table.md +30 -14
- package/steering/nestjs-react-fullstack/skills/raw-sql-boundary-audit/SKILL.md +63 -0
- package/steering/nestjs-react-fullstack/skills/server-builtins-file-storage-service/SKILL.md +1 -1
- package/steering/nestjs-react-fullstack/skills_common/trigger-guide/SKILL.md +284 -12
- package/steering/nestjs-react-fullstack/skills_local/plugin-guide/SKILL.md +4 -0
- package/steering/vite-react/skills/plugin-guide/SKILL.md +3 -1
- package/steering/vite-react/skills/react-three-fiber/SKILL.md +4 -0
- package/steering/nestjs-react-fullstack/skills/client-add-aily-web-chat/SKILL.md +0 -139
- package/steering/nestjs-react-fullstack/skills/feishu/SKILL.md +0 -269
- package/steering/nestjs-react-fullstack/skills/feishu/references/approval.md +0 -214
- package/steering/nestjs-react-fullstack/skills/feishu/references/attendance.md +0 -163
- package/steering/nestjs-react-fullstack/skills/feishu/references/bitable.md +0 -311
- package/steering/nestjs-react-fullstack/skills/feishu/references/calendar.md +0 -190
- package/steering/nestjs-react-fullstack/skills/feishu/references/contacts.md +0 -160
- package/steering/nestjs-react-fullstack/skills/feishu/references/doc.md +0 -257
- package/steering/nestjs-react-fullstack/skills/feishu/references/drive.md +0 -104
- package/steering/nestjs-react-fullstack/skills/feishu/references/events.md +0 -199
- package/steering/nestjs-react-fullstack/skills/feishu/references/id-convert.md +0 -128
- package/steering/nestjs-react-fullstack/skills/feishu/references/messaging.md +0 -207
- package/steering/nestjs-react-fullstack/skills/feishu/references/oauth.md +0 -165
- package/steering/nestjs-react-fullstack/skills/feishu/references/perm.md +0 -91
- package/steering/nestjs-react-fullstack/skills/feishu/references/wiki.md +0 -165
- package/steering/nestjs-react-fullstack/skills_common/trigger-guide/references/trigger-lifecycle.md +0 -301
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
(package.py 见 TODO 即 FAIL),由 L 层改掉。
|
|
13
13
|
"""
|
|
14
14
|
import argparse
|
|
15
|
+
import copy
|
|
15
16
|
import json
|
|
16
17
|
import os
|
|
17
18
|
import re
|
|
@@ -19,12 +20,39 @@ import shutil
|
|
|
19
20
|
import sys
|
|
20
21
|
from collections import Counter, defaultdict
|
|
21
22
|
|
|
23
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
24
|
+
from ooxml import OFFICE_DEFAULT_FONTS # noqa: E402
|
|
25
|
+
from census import (ASSET_WARN_SINGLE, FULLSCREEN_COVERAGE, LUM_MID, # noqa: E402
|
|
26
|
+
REPEAT_MIN, SMALL_IMG_W_PCT, canvas_coverage)
|
|
27
|
+
|
|
28
|
+
OPAQUE_ENOUGH = 128 # 能当背景的最低不透明度:低于半透明就遮不住底下的东西,
|
|
29
|
+
# 那是叠加装饰不是背景
|
|
30
|
+
FILL_MANY = 5 # 「被大量当填充铺开」的次数下限,用于区分卡片底与偶发用色
|
|
31
|
+
BG_CONTENT_CAP = 5 # 内容页背景收几张:再多消费端也挑不过来,超出的写进 TODO 交人取舍
|
|
32
|
+
SHEET_CAP = 12 # 联系表展示上限;进包的资产不受它约束,一张都不截
|
|
33
|
+
|
|
22
34
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
23
35
|
SKILL_ROOT = os.path.dirname(HERE)
|
|
24
36
|
SYS_FALLBACK = '"PingFang SC", "Microsoft YaHei", sans-serif'
|
|
25
37
|
|
|
26
38
|
|
|
27
39
|
# ---------------------------------------------------------------- 小工具
|
|
40
|
+
# 被名额截掉的东西统一记在这里,最后并进 gaps。截断本身是必要的(色板 40 个 token
|
|
41
|
+
# 消费端挑不过来),但**不说**就成了「悄悄少了东西而产物看起来正常」——消费端会以为
|
|
42
|
+
# 它拿到的就是全部。
|
|
43
|
+
_TRUNCATED = []
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def note_truncation(kind, kept, total, advice='', where=''):
|
|
47
|
+
"""记一条「这里按名额截断了」。kept >= total 时什么都不记。
|
|
48
|
+
|
|
49
|
+
按 kind 归并成一条 gap:同一类截断逐处各写一行会淹掉别的 gaps。
|
|
50
|
+
"""
|
|
51
|
+
if total > kept:
|
|
52
|
+
_TRUNCATED.append((kind, kept, total, advice, where))
|
|
53
|
+
return kept
|
|
54
|
+
|
|
55
|
+
|
|
28
56
|
def hex2rgb(h):
|
|
29
57
|
h = h.lstrip('#')
|
|
30
58
|
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
|
|
@@ -82,7 +110,64 @@ def q(v):
|
|
|
82
110
|
|
|
83
111
|
|
|
84
112
|
# ---------------------------------------------------------------- 颜色
|
|
85
|
-
def
|
|
113
|
+
def bg_colors(d):
|
|
114
|
+
"""页面/版式/母版的 `background` 声明里出现的底色,按声明次数排序。
|
|
115
|
+
|
|
116
|
+
「哪个色是底色」是直读事实(bgPr / bgRef),不用靠亮度猜:渐变里出现的浅色,
|
|
117
|
+
亮度可能比真底色更像底色。
|
|
118
|
+
"""
|
|
119
|
+
cnt = Counter()
|
|
120
|
+
rows = (d.get('slides') or []) + (d.get('layouts') or []) \
|
|
121
|
+
+ ((d.get('masters') or {}).get('masters') or [])
|
|
122
|
+
for row in rows:
|
|
123
|
+
bg = row.get('background')
|
|
124
|
+
if not isinstance(bg, dict):
|
|
125
|
+
continue
|
|
126
|
+
cols = []
|
|
127
|
+
if isinstance(bg.get('color'), dict):
|
|
128
|
+
cols.append(bg['color'])
|
|
129
|
+
for st in (bg.get('stops') or []):
|
|
130
|
+
if isinstance(st.get('color'), dict):
|
|
131
|
+
cols.append(st['color'])
|
|
132
|
+
for c in cols:
|
|
133
|
+
h = (c.get('hex') or '').upper()
|
|
134
|
+
if h:
|
|
135
|
+
cnt[h] += 1
|
|
136
|
+
return [h for h, _ in cnt.most_common()]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _gap_cut(vals, lo, hi):
|
|
140
|
+
"""在排序后的值里找最大间隙,切点取间隙中点。
|
|
141
|
+
|
|
142
|
+
不用中位数:中位数会正好落在某个样本自己身上,它归哪边就只取决于写 >= 还是 >,
|
|
143
|
+
纯属任意。真正的分界在两族之间的空档里。夹在 [lo, hi] 内,避免整套同色的模板
|
|
144
|
+
把界推到极端。
|
|
145
|
+
"""
|
|
146
|
+
v = sorted(vals)
|
|
147
|
+
if len(v) < 2:
|
|
148
|
+
return (lo + hi) / 2.0
|
|
149
|
+
_, mid = max((v[i + 1] - v[i], (v[i + 1] + v[i]) / 2.0) for i in range(len(v) - 1))
|
|
150
|
+
return min(max(mid, lo), hi)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def palette_cuts(rows):
|
|
154
|
+
"""「有彩 vs 中性」「深 vs 浅」的分界,按本模板自己的色分布切。
|
|
155
|
+
|
|
156
|
+
固定分界必然错一边:低饱和的莫兰迪配色整套都在低位,高饱和的品牌配色整套都在高位。
|
|
157
|
+
"""
|
|
158
|
+
sat_cut = _gap_cut([r['sat'] for r in rows], 0.12, 0.45)
|
|
159
|
+
lums = sorted(r['lum'] for r in rows) or [0.0]
|
|
160
|
+
return sat_cut, lums[len(lums) // 2]
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def draft_colors(d, cusage=None):
|
|
164
|
+
"""色板 token:名字按**实际用法**定,不只看亮度饱和度。
|
|
165
|
+
|
|
166
|
+
只看 lum/sat 会把「主要用来填色的纯黑」命名成 ink(文字色)、把「只出现在渐变里的
|
|
167
|
+
浅蓝」命名成 surface-alt。这里先看它在形状上主要干什么,再结合
|
|
168
|
+
亮度定名;用量太少的直接不进色板。
|
|
169
|
+
"""
|
|
170
|
+
cusage = cusage or {}
|
|
86
171
|
pool = [c for c in d['color_freq']
|
|
87
172
|
if c.get('class') == 'design' and abs((c.get('alpha') or 100) - 100) < 0.1]
|
|
88
173
|
seen, rows = set(), []
|
|
@@ -92,29 +177,63 @@ def draft_colors(d):
|
|
|
92
177
|
continue
|
|
93
178
|
seen.add(h)
|
|
94
179
|
rgb = hex2rgb(h)
|
|
95
|
-
|
|
96
|
-
|
|
180
|
+
u = cusage.get(h) or Counter()
|
|
181
|
+
tot = sum(u.values())
|
|
182
|
+
main = u.most_common(1)[0][0] if tot else None
|
|
183
|
+
rows.append({'hex': h, 'n': c['n'], 'lum': lum(rgb), 'sat': satu(rgb),
|
|
184
|
+
'use': u, 'use_n': tot, 'main': main})
|
|
185
|
+
# 用量只用来**命名**,不作准入门槛——color_usage 只数形状级的填充/描边/文字,
|
|
186
|
+
# 背景 p:bg 与主题色不在其中,拿它筛会把色板砍到只剩极少数几个。
|
|
187
|
+
strong = sorted(rows, key=lambda r: -r['n'])
|
|
188
|
+
|
|
189
|
+
SAT_CUT, LUM_CUT = palette_cuts(rows)
|
|
97
190
|
|
|
98
191
|
tokens, used = [], set()
|
|
99
192
|
|
|
100
193
|
def take(pred, names):
|
|
101
194
|
for name in names:
|
|
102
|
-
for r in
|
|
195
|
+
for r in strong:
|
|
103
196
|
if r['hex'] in used or not pred(r):
|
|
104
197
|
continue
|
|
105
198
|
used.add(r['hex'])
|
|
106
199
|
tokens.append((name, r))
|
|
107
200
|
break
|
|
108
201
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
202
|
+
def kind(r):
|
|
203
|
+
if r['main'] == '文字':
|
|
204
|
+
return 'text'
|
|
205
|
+
if r['main'] in ('填充', '渐变', '描边'):
|
|
206
|
+
return 'paint'
|
|
207
|
+
return 'unknown' # 形状层看不到用法,退回亮度/饱和度判断
|
|
208
|
+
|
|
209
|
+
# 墨色:主要用来写字(或看不出用法但本身是深中性色),且不是彩色
|
|
210
|
+
take(lambda r: r['sat'] < SAT_CUT and r['lum'] < min(LUM_CUT, LUM_MID)
|
|
211
|
+
and (kind(r) == 'text' or kind(r) == 'unknown'), ['ink', 'ink-muted'])
|
|
212
|
+
# 底色:直接取页面 background 声明里的色,按声明次数排
|
|
213
|
+
grounds = bg_colors(d)
|
|
214
|
+
for name in ('surface', 'surface-alt'):
|
|
215
|
+
for h in grounds:
|
|
216
|
+
r = next((x for x in strong if x['hex'] == h and x['hex'] not in used), None)
|
|
217
|
+
if r:
|
|
218
|
+
used.add(r['hex'])
|
|
219
|
+
tokens.append((name, r))
|
|
220
|
+
break
|
|
221
|
+
|
|
222
|
+
# 卡片/面板底:页面底色之外,真被大量当填充铺开的浅色(≥5 处才算)
|
|
223
|
+
take(lambda r: r['lum'] > max(LUM_CUT, 0.85) and r['sat'] < SAT_CUT
|
|
224
|
+
and (r['use'].get('填充') or 0) >= FILL_MANY, ['surface-raised'])
|
|
225
|
+
# 表达色:有彩度的按频次排
|
|
226
|
+
take(lambda r: r['sat'] >= SAT_CUT, ['primary', 'accent', 'accent-2', 'accent-3'])
|
|
227
|
+
# 其余低饱和色一律 neutral-N——它到底是卡片底、分隔线还是描边,数据分不出来,
|
|
228
|
+
# 就不要用名字去替消费方下结论;真实用法写在 Colors 表的用途列里。
|
|
229
|
+
take(lambda r: r['sat'] < SAT_CUT, ['neutral', 'neutral-2', 'neutral-3'])
|
|
230
|
+
spare = [r for r in rows if r['hex'] not in used]
|
|
231
|
+
note_truncation('设计色', 6, len(spare), '色板只收主要色,其余在联系表里看')
|
|
232
|
+
rest = spare[:6]
|
|
115
233
|
return tokens, rest, rows
|
|
116
234
|
|
|
117
235
|
|
|
236
|
+
|
|
118
237
|
# ---------------------------------------------------------------- 字体
|
|
119
238
|
def parse_fallback_table():
|
|
120
239
|
path = os.path.join(SKILL_ROOT, 'font-fallback.yaml')
|
|
@@ -142,6 +261,48 @@ def norm(s):
|
|
|
142
261
|
return re.sub(r'[\s\-_]', '', s or '').lower()
|
|
143
262
|
|
|
144
263
|
|
|
264
|
+
OFFICE_DEFAULT_FONTS_NORM = {norm(x) for x in OFFICE_DEFAULT_FONTS}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def cover_slot_colors(tokens, archetypes, rows, cusage):
|
|
268
|
+
"""slot CSS 里出现的每个色值都必须在色板里有名字。
|
|
269
|
+
|
|
270
|
+
Hard Rules 写「颜色只用 colors 里的 token」,而 slot CSS 的 color 是从模板直读的,
|
|
271
|
+
两者不对齐就等于产物自己违反自己的规则——slot 的色值直读自模板,未必都已进
|
|
272
|
+
色板。这里把缺的补进色板,按用法归族命名。
|
|
273
|
+
"""
|
|
274
|
+
have = {r['hex'].upper() for _, r in tokens}
|
|
275
|
+
by_hex = {r['hex'].upper(): r for r in rows}
|
|
276
|
+
sat_cut, lum_cut = palette_cuts(rows) # 与 draft_colors 同一套切点,别各切各的
|
|
277
|
+
used = [n for n, _ in tokens]
|
|
278
|
+
|
|
279
|
+
def nxt(fam):
|
|
280
|
+
if fam not in used:
|
|
281
|
+
return fam
|
|
282
|
+
i = 2
|
|
283
|
+
while '%s-%d' % (fam, i) in used:
|
|
284
|
+
i += 1
|
|
285
|
+
return '%s-%d' % (fam, i)
|
|
286
|
+
|
|
287
|
+
added = []
|
|
288
|
+
for a in archetypes:
|
|
289
|
+
for s in a['slots']:
|
|
290
|
+
h = (s.get('_color') or '').upper()
|
|
291
|
+
if not h.startswith('#') or h in have:
|
|
292
|
+
continue
|
|
293
|
+
have.add(h)
|
|
294
|
+
r = by_hex.get(h)
|
|
295
|
+
if r is None: # 普查里没有这个色(理论上不该发生),跳过不编造
|
|
296
|
+
continue
|
|
297
|
+
fam = ('ink' if r['sat'] < sat_cut and r['lum'] < min(lum_cut, LUM_MID)
|
|
298
|
+
else 'accent' if r['sat'] >= sat_cut else 'neutral')
|
|
299
|
+
name = nxt(fam)
|
|
300
|
+
used.append(name)
|
|
301
|
+
tokens.append((name, r))
|
|
302
|
+
added.append((name, h))
|
|
303
|
+
return added
|
|
304
|
+
|
|
305
|
+
|
|
145
306
|
def draft_fonts(d):
|
|
146
307
|
table = parse_fallback_table()
|
|
147
308
|
groups = defaultdict(lambda: {'rendered': 0, 'weights': set(), 'names': set(), 'bold': 0})
|
|
@@ -167,6 +328,7 @@ def draft_fonts(d):
|
|
|
167
328
|
return None
|
|
168
329
|
|
|
169
330
|
out = []
|
|
331
|
+
note_truncation('字族', 4, len(ranked), '只报渲染量最大的几族')
|
|
170
332
|
for key, g in ranked[:4]:
|
|
171
333
|
fam = resolve(sorted(g['names'], key=len))
|
|
172
334
|
stack = [sorted(g['names'], key=len)[0]]
|
|
@@ -201,35 +363,193 @@ def import_line(fonts):
|
|
|
201
363
|
return "@import url('%s?%s&display=swap');" % (MIRROR, fam), webs
|
|
202
364
|
|
|
203
365
|
|
|
366
|
+
def quant(hit, total):
|
|
367
|
+
"""覆盖率决定量词——不到一半就不许说「一律/每页」。"""
|
|
368
|
+
if not total:
|
|
369
|
+
return None
|
|
370
|
+
r = hit / float(total)
|
|
371
|
+
if r >= 0.9:
|
|
372
|
+
return '一律'
|
|
373
|
+
if r >= 0.5:
|
|
374
|
+
return '多数'
|
|
375
|
+
return None
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def color_usage(shapes, d=None):
|
|
379
|
+
"""每个色值在形状上的真实用法计数:填充 / 渐变 / 描边 / 文字。
|
|
380
|
+
|
|
381
|
+
用途列不能靠预设字典猜——同一个色在不同模板里的主用途完全不同。这里从 shapes
|
|
382
|
+
直接数,数不到就如实说数不到。
|
|
383
|
+
"""
|
|
384
|
+
def hx(c):
|
|
385
|
+
return (c.get('hex') or '').upper() if isinstance(c, dict) else ''
|
|
386
|
+
|
|
387
|
+
def walk_text_colors(node, out):
|
|
388
|
+
"""文本样式可能嵌在 lstStyle.lvlNpPr / defRPr / rPr 任一层——通用遍历,
|
|
389
|
+
别逐层枚举(枚举漏过 lvl2pPr,导致主色被写成「用途待确认」)。"""
|
|
390
|
+
if isinstance(node, dict):
|
|
391
|
+
if isinstance(node.get('color'), dict) and hx(node['color']):
|
|
392
|
+
out.append(hx(node['color']))
|
|
393
|
+
for v in node.values():
|
|
394
|
+
walk_text_colors(v, out)
|
|
395
|
+
elif isinstance(node, list):
|
|
396
|
+
for v in node:
|
|
397
|
+
walk_text_colors(v, out)
|
|
398
|
+
|
|
399
|
+
use = defaultdict(Counter)
|
|
400
|
+
for s in shapes:
|
|
401
|
+
f = s.get('fill') or {}
|
|
402
|
+
if f.get('type') == 'solid' and hx(f.get('color')):
|
|
403
|
+
use[hx(f['color'])]['填充'] += 1
|
|
404
|
+
for st in (f.get('stops') or []):
|
|
405
|
+
if hx(st.get('color')):
|
|
406
|
+
use[hx(st['color'])]['渐变'] += 1
|
|
407
|
+
ln = s.get('line') or {}
|
|
408
|
+
if hx(ln.get('color')):
|
|
409
|
+
use[hx(ln['color'])]['描边'] += 1
|
|
410
|
+
cols = []
|
|
411
|
+
walk_text_colors(s.get('text') or {}, cols)
|
|
412
|
+
for h in cols:
|
|
413
|
+
use[h]['文字'] += 1
|
|
414
|
+
for h in bg_colors(d or {}):
|
|
415
|
+
use[h]['页面背景'] += 1
|
|
416
|
+
# 主题 clrScheme:这类色常常只在主题里声明、页面上由 schemeClr 间接引用,
|
|
417
|
+
# 不记上就会在用途列写「未落在形状上」,看着像没人用。
|
|
418
|
+
for th in ((d or {}).get('themes') or []):
|
|
419
|
+
if not th.get('picked'):
|
|
420
|
+
continue
|
|
421
|
+
for slot, hexv in (th.get('clrScheme') or {}).items():
|
|
422
|
+
if isinstance(hexv, str) and hexv.startswith('#'):
|
|
423
|
+
use[hexv.upper()]['主题 ' + slot] += 1
|
|
424
|
+
return use
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def usage_phrase(counter):
|
|
428
|
+
"""把用法计数写成一句话;主用法占六成以上就直接点名,否则并列前三。"""
|
|
429
|
+
if not counter:
|
|
430
|
+
return '普查里有声明,但未落在形状/背景/主题色上——用途待确认'
|
|
431
|
+
items = counter.most_common()
|
|
432
|
+
tot = sum(counter.values())
|
|
433
|
+
if items[0][1] >= tot * 0.6:
|
|
434
|
+
return '主要作%s(%d/%d 处)' % (items[0][0], items[0][1], tot)
|
|
435
|
+
return '、'.join('%s %d 处' % (k, v) for k, v in items[:3])
|
|
436
|
+
|
|
437
|
+
|
|
204
438
|
def draft_anchors(d, tokens, fonts, roles, assets, archetypes):
|
|
205
|
-
|
|
439
|
+
"""anchors 只报测到的数,不下「这套风格是什么」的结论。
|
|
440
|
+
|
|
441
|
+
这一段在 design.md 里读起来像「设计总纲」,消费端会照它建全局样式。脚本写进去的
|
|
442
|
+
每一句解读都会被当成规则执行——实测把 1/8 覆盖率的 logo 描述成「跨页不动」,
|
|
443
|
+
消费端就建了全局 CSS 类,12 页全铺了 logo。所以这里只给覆盖率和计数,
|
|
444
|
+
「这是不是这套风格的特征」由看得到图的人判断。
|
|
445
|
+
"""
|
|
446
|
+
A = []
|
|
447
|
+
n_arch = len(archetypes) or 1
|
|
448
|
+
|
|
449
|
+
# 1. 表达色:未取用的高频彩色要如实带上,不能说「其余全是中性」
|
|
450
|
+
names = [x[0] for x in tokens]
|
|
206
451
|
chroma = [n for n in names if n.startswith(('primary', 'accent'))]
|
|
452
|
+
if chroma:
|
|
453
|
+
A.append((chroma[0] + '-led-palette', 'token',
|
|
454
|
+
'有彩色 token 共 %d 个,用量最大的是 %s'
|
|
455
|
+
% (len(chroma), '、'.join(chroma[:3]))))
|
|
456
|
+
|
|
457
|
+
# 2. 圆角:按普查占比
|
|
207
458
|
radii = d.get('radii_census') or []
|
|
208
459
|
zero = next((r for r in radii if r['px'] == 0), None)
|
|
209
|
-
|
|
210
|
-
|
|
460
|
+
tot_r = sum(r['n'] for r in radii) or 1
|
|
461
|
+
if zero:
|
|
462
|
+
q0 = quant(zero['n'], tot_r)
|
|
463
|
+
if q0:
|
|
464
|
+
A.append(('zero-radius', 'token',
|
|
465
|
+
'圆角量为零的形状占 %d%%(普查 %d 个带圆角声明的形状)'
|
|
466
|
+
% (round(100.0 * zero['n'] / tot_r), tot_r)))
|
|
467
|
+
|
|
468
|
+
# 3. 满屏底图:按有背景的页型占比
|
|
469
|
+
with_bg = sum(1 for a in archetypes if a.get('bg'))
|
|
470
|
+
qb = quant(with_bg, n_arch)
|
|
471
|
+
if qb:
|
|
472
|
+
A.append(('full-bleed-ground', 'pattern',
|
|
473
|
+
'%d/%d 个页型声明了整幅铺满的底图' % (with_bg, n_arch)))
|
|
474
|
+
|
|
475
|
+
# 4. 标识:位置是不是真的固定,看有几个不同的 box
|
|
476
|
+
logo_slots = [s for a in archetypes for s in a['slots']
|
|
477
|
+
if str(s.get('asset') or '').startswith(('logo', 'slogan'))]
|
|
478
|
+
logo_arch = sum(1 for a in archetypes
|
|
479
|
+
if any(str(s.get('asset') or '').startswith(('logo', 'slogan'))
|
|
480
|
+
for s in a['slots']))
|
|
481
|
+
boxes = {tuple(s['box']) for s in logo_slots}
|
|
482
|
+
# anchors 是「这套风格的定义性特征」,消费端读它来建全局样式。只在少数页型出现的
|
|
483
|
+
# 东西写进来,等于宣布它是全局元素——实测某模板 logo 只在 1/8 个页型上,anchor 仍
|
|
484
|
+
# 写成「跨页不动」,消费端据此建了个全局 CSS 类,12 页全铺了 logo。
|
|
485
|
+
# 所以这里和其他 anchor 用同一把尺:覆盖率不过半就不进 anchors。
|
|
486
|
+
ql = quant(logo_arch, n_arch)
|
|
487
|
+
if logo_arch and len(boxes) == 1 and ql:
|
|
488
|
+
A.append(('corner-locked-logo', 'component',
|
|
489
|
+
'品牌标识出现在 %d/%d 个页型上,这些页型里它的 box 完全一致'
|
|
490
|
+
% (logo_arch, n_arch)))
|
|
491
|
+
elif len(boxes) > 1:
|
|
492
|
+
A.append(('logo-moves-by-archetype', 'component',
|
|
493
|
+
'品牌标识按页型换位换尺寸(共 %d 种摆法),必须按 layouts 里该页型的 box 放,'
|
|
494
|
+
'不能沿用上一页' % len(boxes)))
|
|
495
|
+
|
|
496
|
+
# 5. 渐变:按普查计数
|
|
497
|
+
if (d.get('geom_census') or {}).get('gradient_fills'):
|
|
498
|
+
A.append(('gradient-accent', 'pattern',
|
|
499
|
+
'全档共 %d 处渐变填充' % (d['geom_census']['gradient_fills'])))
|
|
500
|
+
|
|
501
|
+
# 6. 层级:字号跨度 + 字重是否单一(字重真单一才敢说「不靠字重」)
|
|
502
|
+
disp, body = roles.get('display'), roles.get('body')
|
|
503
|
+
if disp and body and disp['sz_px'] > body['sz_px']:
|
|
504
|
+
ws = {s.get('_font_weight') for a in archetypes for s in a['slots']
|
|
505
|
+
if s.get('_font_weight')}
|
|
506
|
+
tail = (',字重只用 %s 一档' % list(ws)[0]) if len(ws) == 1 else ''
|
|
507
|
+
A.append(('size-driven-hierarchy', 'pattern',
|
|
508
|
+
'最大字号档与正文档相差 %.1f 倍(见 typography)%s'
|
|
509
|
+
% (disp['sz_px'] / body['sz_px'], tail)))
|
|
510
|
+
|
|
511
|
+
# 7. 阴影:只在描边极少时才敢说「不用描边分隔」
|
|
211
512
|
eff = d.get('effects_census') or {}
|
|
212
|
-
A = []
|
|
213
|
-
if chroma:
|
|
214
|
-
A.append((chroma[0] + '-led-palette', 'token',
|
|
215
|
-
'表达色只有 %s 这一组,其余全是中性底与墨色,见 colors' % '、'.join(chroma[:3])))
|
|
216
|
-
if zero and zero['n'] >= total_r * 0.7:
|
|
217
|
-
A.append(('zero-radius', 'token', '卡片、按钮、面板一律直角,圆角量在全 deck 压倒性为零'))
|
|
218
|
-
if any(a['kind'] == 'background' for a in assets):
|
|
219
|
-
A.append(('full-bleed-ground', 'pattern', '每页由整幅铺满的底图打底,元素浮在图上而不是浮在纯色块上'))
|
|
220
|
-
if any(a['kind'] == 'logo' for a in assets):
|
|
221
|
-
A.append(('corner-locked-logo', 'component', '品牌标识固定在同一角位,跨页不移动、不缩放'))
|
|
222
|
-
if geom.get('gradient_fills'):
|
|
223
|
-
A.append(('gradient-accent', 'pattern', '强调元素靠线性渐变承载,而不是纯色块'))
|
|
224
|
-
if len(fonts) >= 2:
|
|
225
|
-
A.append(('dual-family-typesetting', 'token', '中文与拉丁数字分属两套字族,同一行里混排'))
|
|
226
513
|
if eff.get('outerShdw'):
|
|
227
|
-
A.append(('soft-shadow-card', 'component',
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
514
|
+
A.append(('soft-shadow-card', 'component',
|
|
515
|
+
'全档 %d 处 outerShdw 外阴影' % eff['outerShdw']))
|
|
516
|
+
|
|
517
|
+
# 8. 双字族:只陈述分工存在,不断言「同一行混排」(普查没采集混排)
|
|
518
|
+
tot_r_font = sum(f['rendered'] for f in fonts) or 1
|
|
519
|
+
if len(fonts) >= 2 and fonts[1]['rendered']:
|
|
520
|
+
A.append(('dual-family-typesetting', 'token',
|
|
521
|
+
'用了两套字族:%s 渲染 %d 处、%s 渲染 %d 处'
|
|
522
|
+
% (fonts[0]['names'][0], fonts[0]['rendered'],
|
|
523
|
+
fonts[1]['names'][0], fonts[1]['rendered'])))
|
|
524
|
+
|
|
525
|
+
# 9. 安全区:只在各页型正文左边界真的收敛时才写
|
|
526
|
+
# 「多宽算正文槽」按本包自己的槽宽分布定:固定 px 门槛在窄版心模板上会一个都不剩
|
|
527
|
+
widths = sorted(s['box'][2] for a in archetypes for s in a['slots'] if not s.get('asset'))
|
|
528
|
+
w_cut = widths[len(widths) // 2] if widths else 0
|
|
529
|
+
lefts = [s['box'][0] for a in archetypes for s in a['slots']
|
|
530
|
+
if not s.get('asset') and s['box'][2] >= w_cut]
|
|
531
|
+
if len(lefts) >= 4:
|
|
532
|
+
common = Counter(lefts).most_common(1)[0]
|
|
533
|
+
qs = quant(common[1], len(lefts))
|
|
534
|
+
if qs:
|
|
535
|
+
A.append(('shared-left-margin', 'token',
|
|
536
|
+
'%d/%d 个正文槽的左边界落在同一个 x 上(坐标见 layouts)'
|
|
537
|
+
% (common[1], len(lefts))))
|
|
538
|
+
|
|
539
|
+
# 10. 双主题:直读事实
|
|
540
|
+
themes = (d.get('theme_topology') or {}).get('themes') or []
|
|
541
|
+
if len(themes) > 1:
|
|
542
|
+
A.append(('dual-theme-masters', 'token',
|
|
543
|
+
'模板声明了 %s 两套主题母版' % ' / '.join(themes)))
|
|
544
|
+
|
|
545
|
+
# 11. 画布:直读事实(兜底凑数也只用真事实)
|
|
546
|
+
cv = d['canvas']['px']
|
|
547
|
+
A.append(('fixed-canvas', 'token',
|
|
548
|
+
'画布 %d×%d,layouts 里的坐标都是这张画布上的绝对像素' % (cv[0], cv[1])))
|
|
549
|
+
if len(archetypes) >= 3:
|
|
550
|
+
A.append(('archetype-catalog', 'pattern',
|
|
551
|
+
'归纳出 %d 种页型' % len(archetypes)))
|
|
552
|
+
|
|
233
553
|
seen, out = set(), []
|
|
234
554
|
for a in A:
|
|
235
555
|
if a[0] in seen:
|
|
@@ -238,8 +558,6 @@ def draft_anchors(d, tokens, fonts, roles, assets, archetypes):
|
|
|
238
558
|
out.append(a)
|
|
239
559
|
return out[:8]
|
|
240
560
|
|
|
241
|
-
|
|
242
|
-
# ---------------------------------------------------------------- 字号轴
|
|
243
561
|
def draft_scale(d, archetypes=()):
|
|
244
562
|
ts = [t for t in d['text_scale'] if t['sz_px'] >= 10]
|
|
245
563
|
ts.sort(key=lambda t: -t['sz_px'])
|
|
@@ -251,8 +569,9 @@ def draft_scale(d, archetypes=()):
|
|
|
251
569
|
display = by_px.get(max(title_sz)) if title_sz else None
|
|
252
570
|
big = [t for t in ts if t['n'] >= 2] or ts
|
|
253
571
|
display = display or big[0]
|
|
254
|
-
|
|
255
|
-
|
|
572
|
+
# 正文档 = 渲染次数最多的那一档。不设「多大算正文」的上限:大字号排版的模板
|
|
573
|
+
# 正文本来就可能比别的模板的标题还大,预设上限会把它整档判错。
|
|
574
|
+
body = max([t for t in ts if t is not display] or ts, key=lambda t: t['n'])
|
|
256
575
|
heading_pool = [t for t in ts if body['sz_px'] * 1.3 <= t['sz_px'] < display['sz_px']]
|
|
257
576
|
heading = max(heading_pool, key=lambda t: t['n']) if heading_pool else None
|
|
258
577
|
small_pool = [t for t in ts if t['sz_px'] < body['sz_px']]
|
|
@@ -296,6 +615,53 @@ def probe_image(path):
|
|
|
296
615
|
return info
|
|
297
616
|
|
|
298
617
|
|
|
618
|
+
def bg_busy_map(path, canvas, cells=12):
|
|
619
|
+
"""把背景图切成网格,报每格的**局部对比度**(该格内亮度极差)。
|
|
620
|
+
|
|
621
|
+
「哪里不能压文字」的本质是「哪里花」。整幅渐变的底图各格对比度都低,说明没有
|
|
622
|
+
视觉主体;有山峰、人物、产品图的底图会在主体处出现明显更高的对比度。这里只出
|
|
623
|
+
客观数值和一个据此推出的草案,最终由看得到图的人定。
|
|
624
|
+
"""
|
|
625
|
+
try:
|
|
626
|
+
from PIL import Image
|
|
627
|
+
except Exception:
|
|
628
|
+
return None
|
|
629
|
+
try:
|
|
630
|
+
im = Image.open(path).convert('L').resize((cells * 8, cells * 8))
|
|
631
|
+
except Exception:
|
|
632
|
+
return None
|
|
633
|
+
px = im.load()
|
|
634
|
+
grid = []
|
|
635
|
+
for gy in range(cells):
|
|
636
|
+
row = []
|
|
637
|
+
for gx in range(cells):
|
|
638
|
+
vals = [px[gx * 8 + x, gy * 8 + y] for y in range(8) for x in range(8)]
|
|
639
|
+
row.append(max(vals) - min(vals))
|
|
640
|
+
grid.append(row)
|
|
641
|
+
flat = sorted(v for row in grid for v in row)
|
|
642
|
+
if not flat:
|
|
643
|
+
return None
|
|
644
|
+
med = flat[len(flat) // 2]
|
|
645
|
+
hi = flat[int(len(flat) * 0.9)]
|
|
646
|
+
# 主体 = 对比度显著高于全图中位数的连片格子。阈值取「中位数与九分位的中点」,
|
|
647
|
+
# 由本图自己的分布定,不用固定值。
|
|
648
|
+
cut = (med + hi) / 2.0
|
|
649
|
+
cW, cH = canvas
|
|
650
|
+
hot = [(gx, gy) for gy in range(cells) for gx in range(cells) if grid[gy][gx] > cut]
|
|
651
|
+
if not hot:
|
|
652
|
+
return {'busy': None, 'median': med, 'p90': hi, 'why': '各处对比度一致,没有更花的区域'}
|
|
653
|
+
xs = [g[0] for g in hot]
|
|
654
|
+
ys = [g[1] for g in hot]
|
|
655
|
+
span = ((max(xs) - min(xs) + 1) * (max(ys) - min(ys) + 1)) / float(cells * cells)
|
|
656
|
+
if span > 0.5:
|
|
657
|
+
# 热格散落全图,外接矩形几乎覆盖整幅——圈出来等于没圈
|
|
658
|
+
return {'busy': None, 'median': med, 'p90': hi, 'why': '较花的格子散布全图,圈不出单一主体'}
|
|
659
|
+
box = [round(min(xs) * cW / cells), round(min(ys) * cH / cells),
|
|
660
|
+
round((max(xs) - min(xs) + 1) * cW / cells),
|
|
661
|
+
round((max(ys) - min(ys) + 1) * cH / cells)]
|
|
662
|
+
return {'busy': box, 'median': med, 'p90': hi, 'span': round(span, 2)}
|
|
663
|
+
|
|
664
|
+
|
|
299
665
|
def copy_logo_candidates(outdir, logo_pool):
|
|
300
666
|
if not logo_pool:
|
|
301
667
|
return []
|
|
@@ -347,6 +713,7 @@ def draft_assets(d, outdir, bg_needed=(), cover_media=None, bg_under=None):
|
|
|
347
713
|
cands.append({
|
|
348
714
|
'media': m['media'], 'file': os.path.basename(out_rel), 'out': out_rel,
|
|
349
715
|
'bytes': m.get('bytes'), 'n': img.get('n', m.get('used_n', 0)),
|
|
716
|
+
'has_compressed': bool(m.get('compressed_out')),
|
|
350
717
|
'fullscreen': bool(img.get('fullscreen')), 'w_pct': img.get('max_w_pct', 0),
|
|
351
718
|
'box': top.get('box') or {}, 'slides': slides,
|
|
352
719
|
'layer_only': bool(parts) and not slides,
|
|
@@ -362,35 +729,58 @@ def draft_assets(d, outdir, bg_needed=(), cover_media=None, bg_under=None):
|
|
|
362
729
|
if k not in best_of or c['n'] > best_of[k]['n']:
|
|
363
730
|
best_of[k] = c
|
|
364
731
|
kept = sorted(best_of.values(), key=lambda c: (-c['n'], -(c['bytes'] or 0)))
|
|
732
|
+
# 被同簇兄弟淘汰的 media 仍要能指到胜出者——封面底图常常是簇里 n 最小的那张
|
|
733
|
+
alias = {}
|
|
734
|
+
for c in cands:
|
|
735
|
+
w = best_of.get(c['cluster'] or c['media'])
|
|
736
|
+
if w and w['media'] != c['media']:
|
|
737
|
+
alias[c['media']] = w['media']
|
|
738
|
+
cover_media = alias.get(cover_media, cover_media)
|
|
739
|
+
bg_needed = {alias.get(m, m) for m in (bg_needed or ())}
|
|
365
740
|
|
|
366
741
|
assets, rejected, todos = [], [], []
|
|
742
|
+
over_cap_bgs = []
|
|
367
743
|
logo_pool = []
|
|
368
744
|
bg_under = bg_under or {}
|
|
369
745
|
bg_i = 0
|
|
370
|
-
canvas_w = d['canvas']['px']
|
|
746
|
+
canvas_w, canvas_h = d['canvas']['px']
|
|
371
747
|
for c in kept:
|
|
372
748
|
if c['probe'].get('near_blank'):
|
|
373
749
|
rejected.append((c, '近全透明(alpha 均值 %.0f/255),PPT 里看不见' % c['probe']['alpha_mean']))
|
|
374
750
|
continue
|
|
751
|
+
# 铺满 ≠ 能当背景。背景的定义性属性是**遮盖**:它得挡住底下的东西。一张大半透明
|
|
752
|
+
# 的图铺满整页也遮不住任何像素,它在 PPT 里是叠在幻灯片底色上的一层装饰(顶部
|
|
753
|
+
# 光晕之类),底色才是真背景。实测某模板一张 alpha 均值 30/255、72% 完全透明的
|
|
754
|
+
# 顶部光晕被当成满屏背景收进包,消费端每页铺它,顶部就多出一条原稿没有的浓色带。
|
|
755
|
+
am = c['probe'].get('alpha_mean')
|
|
756
|
+
if c['fullscreen'] and am is not None and am < OPAQUE_ENOUGH:
|
|
757
|
+
rejected.append((c, 'alpha 均值只有 %.0f/255,遮不住底下的东西——'
|
|
758
|
+
'它是叠在底色上的装饰层,不是背景' % am))
|
|
759
|
+
continue
|
|
375
760
|
if c['fullscreen']:
|
|
376
761
|
if c['media'] == cover_media:
|
|
377
762
|
assets.append({'id': 'bg-cover', 'kind': 'background', 'role': 'cover',
|
|
378
|
-
'src': c,
|
|
379
|
-
|
|
763
|
+
'src': c,
|
|
764
|
+
# 只有真出了压缩版才能带原图;否则 path/full 指向同一
|
|
765
|
+
# 文件,package.py 必 FAIL(封面不需要转码时就会踩到)
|
|
766
|
+
'use_full': c['has_compressed']})
|
|
767
|
+
elif c['media'] in bg_needed and bg_i < BG_CONTENT_CAP:
|
|
380
768
|
bg_i += 1
|
|
381
769
|
assets.append({'id': 'bg-content-%d' % bg_i, 'kind': 'background',
|
|
382
770
|
'role': 'content', 'src': c, 'use_full': False})
|
|
771
|
+
elif c['media'] in bg_needed:
|
|
772
|
+
over_cap_bgs.append(c)
|
|
773
|
+
rejected.append((c, '有页型以它为主底,但内容页背景已收满 %d 张' % BG_CONTENT_CAP))
|
|
383
774
|
else:
|
|
384
775
|
rejected.append((c, '满屏图但没有页面以它为主底(只在版式层备用)'))
|
|
385
|
-
elif c['w_pct'] <
|
|
776
|
+
elif c['w_pct'] < SMALL_IMG_W_PCT and c['n'] >= REPEAT_MIN:
|
|
777
|
+
# 品牌标识的共性是「小、重复出现、贴角」。这里只按贴角程度排序给出首选,
|
|
778
|
+
# 不设及格线——「多少分算 logo」没有客观依据,判断交 L 层,分项证据随 TODO 给出。
|
|
386
779
|
b = c['box']
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
score += 1 if 1.0 <= ar <= 8.0 else 0
|
|
392
|
-
score += 1 if c['n'] >= 2 else 0
|
|
393
|
-
logo_pool.append((score, c))
|
|
780
|
+
edge_x = min(b.get('x', 0), max(canvas_w - (b.get('x', 0) + (b.get('w') or 0)), 0))
|
|
781
|
+
edge_y = min(b.get('y', 0), max(canvas_h - (b.get('y', 0) + (b.get('h') or 0)), 0))
|
|
782
|
+
corner = (edge_x / canvas_w) + (edge_y / canvas_h) # 越小越贴角
|
|
783
|
+
logo_pool.append((corner, c))
|
|
394
784
|
else:
|
|
395
785
|
rejected.append((c, '内容区图片(占宽 %.0f%%,出现 %d 次)' % (c['w_pct'], c['n'])))
|
|
396
786
|
|
|
@@ -404,46 +794,528 @@ def draft_assets(d, outdir, bg_needed=(), cover_media=None, bg_under=None):
|
|
|
404
794
|
from PIL import Image
|
|
405
795
|
im = Image.open(os.path.join(outdir, row['out'])).convert('RGB')
|
|
406
796
|
b = c['box']
|
|
407
|
-
sx, sy = im.width / float(canvas_w), im.height / float(
|
|
797
|
+
sx, sy = im.width / float(canvas_w), im.height / float(canvas_h)
|
|
408
798
|
crop = im.crop((int(b.get('x', 0) * sx), int(b.get('y', 0) * sy),
|
|
409
799
|
max(int((b.get('x', 0) + b.get('w', 1)) * sx), 1),
|
|
410
800
|
max(int((b.get('y', 0) + b.get('h', 1)) * sy), 1))).resize((16, 16))
|
|
411
801
|
raw = crop.tobytes()
|
|
412
802
|
px = [raw[i:i + 3] for i in range(0, len(raw), 3)]
|
|
413
|
-
return 'light' if sum(lum(p) for p in px) / len(px) >
|
|
803
|
+
return 'light' if sum(lum(p) for p in px) / len(px) > LUM_MID else 'dark'
|
|
414
804
|
except Exception:
|
|
415
805
|
return None
|
|
416
806
|
|
|
417
|
-
|
|
418
|
-
|
|
807
|
+
# 贴角是品牌标识的定义性特征:离两边都超过画布 1/4 的重复小图,更可能是页内装饰。
|
|
808
|
+
# 这不是「多少分算 logo」那种凑出来的分数线——它直接来自「贴角」这个判据本身。
|
|
809
|
+
LOGO_CORNER_MAX = 0.5 # edge_x/W + edge_y/H,两边各 25% 即到上限
|
|
810
|
+
logo_pool.sort(key=lambda kv: (kv[0], -kv[1]['n']))
|
|
811
|
+
if logo_pool and logo_pool[0][0] > LOGO_CORNER_MAX:
|
|
812
|
+
todos.append('没有贴角的重复小图(最接近的一张离画布边 %.0f%%),本模板可能没有 logo;'
|
|
813
|
+
'确认后要么从联系表挑一张补进 manifest,要么在 gaps 写明模板无品牌标识'
|
|
814
|
+
% (logo_pool[0][0] * 50))
|
|
815
|
+
logo_pool = []
|
|
816
|
+
for i, (corner, c) in enumerate(logo_pool):
|
|
419
817
|
b = c['box']
|
|
420
|
-
if i == 0
|
|
818
|
+
if i == 0:
|
|
421
819
|
assets.append({'id': 'logo-primary', 'kind': 'logo', 'role': None, 'src': c,
|
|
422
820
|
'use_full': False, 'on_bg': on_bg_of(c)})
|
|
423
|
-
todos.append('看联系表确认 `%s
|
|
821
|
+
todos.append('看联系表确认 `%s` 真是品牌 logo(%.0fx%.0f @ %.0f,%.0f,出现 %d 次,'
|
|
822
|
+
'离画布边 %.0f%%,是所有小图里最贴角的一张);'
|
|
424
823
|
'不是就把 manifest 的 logo-primary 换成别的候选或整条删掉'
|
|
425
|
-
% (c['file'], b.get('w', 0), b.get('h', 0), b.get('x', 0), b.get('y', 0),
|
|
824
|
+
% (c['file'], b.get('w', 0), b.get('h', 0), b.get('x', 0), b.get('y', 0),
|
|
825
|
+
c['n'], corner * 50))
|
|
826
|
+
else:
|
|
827
|
+
rejected.append((c, '重复小图(%.0fx%.0f @ %.0f,%.0f),贴角程度 %.0f%% 不如首选'
|
|
828
|
+
% (b.get('w', 0), b.get('h', 0), b.get('x', 0), b.get('y', 0),
|
|
829
|
+
corner * 50)))
|
|
830
|
+
|
|
831
|
+
# 体量预算:包内资产总量超 20MB 直接 FAIL(V2-6)。`use_full` 的原图是唯一可能
|
|
832
|
+
# 单张爆预算的东西(未压缩的封面级大图可以单张达到数十 MB),所以在草案期就先丢 full,
|
|
833
|
+
# 不要留给 L 层去撞门禁再回修。
|
|
834
|
+
PACK_BUDGET = 20 * 1024 * 1024
|
|
835
|
+
est = sum(min(a['src'].get('bytes') or 0, ASSET_WARN_SINGLE) for a in assets)
|
|
836
|
+
for a in sorted([x for x in assets if x['use_full']],
|
|
837
|
+
key=lambda x: -(x['src'].get('bytes') or 0)):
|
|
838
|
+
orig = a['src'].get('bytes') or 0
|
|
839
|
+
if est + orig > PACK_BUDGET * 0.9:
|
|
840
|
+
a['use_full'] = False
|
|
841
|
+
todos.append('`%s` 的原图 %.1fMB 会把包撑过 20MB 上限,草案已只保留压缩版;'
|
|
842
|
+
'确实需要原图就改走 url 承载' % (a['id'], orig / 1024.0 / 1024))
|
|
426
843
|
else:
|
|
427
|
-
|
|
428
|
-
% (b.get('w', 0), b.get('h', 0), b.get('x', 0), b.get('y', 0))))
|
|
844
|
+
est += orig
|
|
429
845
|
|
|
846
|
+
if over_cap_bgs:
|
|
847
|
+
todos.append('模板有 %d 张内容页背景超出 %d 张上限(%s);用到它们的页型在 layouts.md 里'
|
|
848
|
+
'不会有 background,需要就手工补进 manifest 并删掉不重要的那几张'
|
|
849
|
+
% (len(over_cap_bgs), BG_CONTENT_CAP,
|
|
850
|
+
'、'.join(c['file'] for c in over_cap_bgs[:5])))
|
|
430
851
|
if not any(a['role'] == 'cover' for a in assets):
|
|
431
852
|
todos.append('没定出封面底图——从联系表挑一张补进 manifest(role: cover),或在 gaps 写明模板无封面主视觉')
|
|
432
853
|
copy_logo_candidates(outdir, logo_pool)
|
|
433
|
-
return assets, rejected, todos
|
|
854
|
+
return assets, rejected, todos, alias, {c['media']: c for c in kept}
|
|
434
855
|
|
|
435
856
|
|
|
436
857
|
# ---------------------------------------------------------------- 版式聚类
|
|
437
858
|
DECOR_MIN = 40.0
|
|
438
859
|
|
|
860
|
+
# 版式名 → role(模板自己按页型命名时直接用它,别再猜)。
|
|
861
|
+
# 英文词按整词匹配:裸子串会让短词吃掉长词——`end` 一度把 `agenda`、`Appendix`、
|
|
862
|
+
# `Trends Section` 全判成 closing,表里 `agenda -> section` 那条永远轮不到。
|
|
863
|
+
ROLE_BY_WORD = [('封面', 'cover'), ('cover', 'cover'), ('首页', 'cover'),
|
|
864
|
+
('title slide', 'cover'), ('标题幻灯片', 'cover'),
|
|
865
|
+
('封底', 'closing'), ('尾页', 'closing'), ('结束', 'closing'),
|
|
866
|
+
('致谢', 'closing'), ('谢谢', 'closing'), ('end', 'closing'),
|
|
867
|
+
('thank you', 'closing'), ('closing', 'closing'),
|
|
868
|
+
('章节', 'section'), ('目录', 'section'), ('过渡', 'section'),
|
|
869
|
+
('section', 'section'), ('agenda', 'section'),
|
|
870
|
+
('section header', 'section'), ('节标题', 'section'),
|
|
871
|
+
('金句', 'quote'), ('问句', 'quote'), ('引言', 'quote'), ('quote', 'quote'),
|
|
872
|
+
('空白', 'blank'), ('blank', 'blank')]
|
|
873
|
+
PH_TO_TYPE = {'title': 'title', 'ctrTitle': 'title', 'subTitle': 'subtitle',
|
|
874
|
+
'body': 'body', 'pic': 'pic', 'clipArt': 'pic', 'tbl': 'table',
|
|
875
|
+
'chart': 'chart', 'media': 'media', 'dgm': 'pic',
|
|
876
|
+
'sldNum': 'slide-number', 'ftr': 'footer', 'dt': 'footer'}
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
def role_of_name(name):
|
|
880
|
+
"""版式名 → role。认不出返回 None,由调用方降置信度并留 TODO——不要静默当 content。
|
|
881
|
+
|
|
882
|
+
词表只覆盖中英文;换一种语言命名的模板会整份认不出。那时全落 content 且机检照过,
|
|
883
|
+
消费端拿到的是「每一页都是内容页」,封面/章节/结束页的语义整个丢掉且无处可查。
|
|
884
|
+
"""
|
|
885
|
+
low = (name or '').lower()
|
|
886
|
+
for word, role in ROLE_BY_WORD:
|
|
887
|
+
if word.isascii():
|
|
888
|
+
if re.search(r'(?<![a-z])%s(?![a-z])' % re.escape(word), low):
|
|
889
|
+
return role
|
|
890
|
+
elif word in low:
|
|
891
|
+
return role
|
|
892
|
+
return None
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
def clean_layout_name(name):
|
|
896
|
+
"""`1_内容-左右排版(无副标题)` → `内容-左右排版(无副标题)`。"""
|
|
897
|
+
return re.sub(r'^\d+[_\-\s]*', '', (name or '').strip()) or '未命名版式'
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
def is_bleed(s):
|
|
901
|
+
return (s.get('kind') == 'pic' and (s.get('w_pct') or 0) >= 95
|
|
902
|
+
and (s.get('h_pct') or 0) >= 95)
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
def top_bleed_media(shapes):
|
|
906
|
+
"""一串形状里最上层的满屏图。
|
|
907
|
+
|
|
908
|
+
OOXML 的 spTree 是绘制序,靠后的画在上面。一个版式常叠两张满屏图——通用底纹在
|
|
909
|
+
下、这一页的主视觉在上——所以看得见的是最后那张。取第一张会拿到底纹,实测让
|
|
910
|
+
章节页的深蓝主视觉被换成了另一张鲜蓝底纹,成品与原稿完全不是一个颜色。
|
|
911
|
+
"""
|
|
912
|
+
out = None
|
|
913
|
+
for s in shapes:
|
|
914
|
+
if is_bleed(s) and s.get('media'):
|
|
915
|
+
out = s['media']
|
|
916
|
+
return out
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
def slot_overlaps(slots):
|
|
920
|
+
"""同一页型里坐标互相重叠的槽对。只报事实,不改坐标——坐标是从模板量的。"""
|
|
921
|
+
out = []
|
|
922
|
+
for i in range(len(slots)):
|
|
923
|
+
for j in range(i + 1, len(slots)):
|
|
924
|
+
a, b = slots[i].get('box'), slots[j].get('box')
|
|
925
|
+
if not (a and b):
|
|
926
|
+
continue
|
|
927
|
+
ox = min(a[0] + a[2], b[0] + b[2]) - max(a[0], b[0])
|
|
928
|
+
oy = min(a[1] + a[3], b[1] + b[3]) - max(a[1], b[1])
|
|
929
|
+
if ox > 0 and oy > 0:
|
|
930
|
+
out.append('%s×%s 叠 %dx%d' % (slots[i].get('role'), slots[j].get('role'),
|
|
931
|
+
round(ox), round(oy)))
|
|
932
|
+
return out
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
def css_number(value, digits=3):
|
|
936
|
+
"""CSS 数值稳定格式:整数不带小数,其余去掉无意义尾零。"""
|
|
937
|
+
number = round(float(value), digits)
|
|
938
|
+
if number == int(number):
|
|
939
|
+
return str(int(number))
|
|
940
|
+
return ('%.*f' % (digits, number)).rstrip('0').rstrip('.')
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
def slot_style(s):
|
|
944
|
+
"""占位符自带的排版样式,统一转成可直接写进 HTML style 的 CSS 声明串。
|
|
945
|
+
|
|
946
|
+
样式可能在三层:lstStyle.lvl1pPr(版式占位符常用)、段落 defRPr(Mac Office
|
|
947
|
+
导出把大量属性写在这一层)、段落 pPr(对齐)。逐层兜底,缺一层就往下取。
|
|
948
|
+
|
|
949
|
+
`box` 是布局几何,继续由 slot 独立承载;其余渲染属性不再泄漏成 size / color /
|
|
950
|
+
align / insets_px 等 PPTX 中间字段。下划线开头的键仅供 draft 内部统计,emit_layouts
|
|
951
|
+
不会写进消费者产物。
|
|
952
|
+
"""
|
|
953
|
+
txt = s.get('text') or {}
|
|
954
|
+
ls = dict((txt.get('lstStyle') or {}).get('lvl1pPr') or {})
|
|
955
|
+
# 四层逐级兜底,按 OOXML 的就近原则:run rPr → 段落 defRPr → 段落 pPr → lstStyle。
|
|
956
|
+
# 只枚举前几层会整份漏掉——有的导出器把字号全写在 run rPr 上,lstStyle 一个都没有。
|
|
957
|
+
for para in (txt.get('paragraphs') or []):
|
|
958
|
+
srcs = [r.get('rPr') or {} for r in (para.get('runs') or [])]
|
|
959
|
+
srcs.append(para.get('defRPr') or {})
|
|
960
|
+
srcs.append({k: v for k, v in para.items() if k not in ('runs', 'defRPr')})
|
|
961
|
+
for src in srcs:
|
|
962
|
+
for k, v in (src or {}).items():
|
|
963
|
+
if v is not None:
|
|
964
|
+
ls.setdefault(k, v)
|
|
965
|
+
if ls.get('sz_px'):
|
|
966
|
+
break
|
|
967
|
+
if not ls.get('sz_px'):
|
|
968
|
+
# 仍无声明:退到整形状里出现过的最大字号(generic walk),仍是文件里的值
|
|
969
|
+
anysz = shape_sz(s)
|
|
970
|
+
if anysz:
|
|
971
|
+
ls['sz_px'] = anysz
|
|
972
|
+
body = txt.get('bodyPr') or {}
|
|
973
|
+
css = []
|
|
974
|
+
out = {}
|
|
975
|
+
insets = body.get('insets_px') or {}
|
|
976
|
+
if insets:
|
|
977
|
+
css.append('box-sizing: border-box')
|
|
978
|
+
css.append('padding: %spx %spx %spx %spx' % (
|
|
979
|
+
css_number(insets.get('tIns', 0) or 0),
|
|
980
|
+
css_number(insets.get('rIns', 0) or 0),
|
|
981
|
+
css_number(insets.get('bIns', 0) or 0),
|
|
982
|
+
css_number(insets.get('lIns', 0) or 0),
|
|
983
|
+
))
|
|
984
|
+
if ls.get('sz_px'):
|
|
985
|
+
size = round(ls['sz_px'])
|
|
986
|
+
css.append('font-size: %dpx' % size)
|
|
987
|
+
out['_font_size'] = size
|
|
988
|
+
weight = ls.get('weight') or (700 if ls.get('bold') else None)
|
|
989
|
+
if weight:
|
|
990
|
+
css.append('font-weight: %s' % weight)
|
|
991
|
+
out['_font_weight'] = weight
|
|
992
|
+
if ls.get('italic'):
|
|
993
|
+
css.append('font-style: italic')
|
|
994
|
+
decorations = []
|
|
995
|
+
if ls.get('underline'):
|
|
996
|
+
decorations.append('underline')
|
|
997
|
+
if ls.get('strike'):
|
|
998
|
+
decorations.append('line-through')
|
|
999
|
+
if decorations:
|
|
1000
|
+
css.append('text-decoration: %s' % ' '.join(decorations))
|
|
1001
|
+
if ls.get('spc_px') is not None:
|
|
1002
|
+
css.append('letter-spacing: %spx' % css_number(ls['spc_px']))
|
|
1003
|
+
col = (ls.get('color') or {}).get('resolved')
|
|
1004
|
+
if col:
|
|
1005
|
+
css.append('color: %s' % col)
|
|
1006
|
+
out['_color'] = col
|
|
1007
|
+
else:
|
|
1008
|
+
# 占位符的字色也可以是 gradFill(章节页的大号序号常这么做)。解析层已经把
|
|
1009
|
+
# stops 和角度记全了,这里只取单色就会整条丢掉,消费端只能自己编一个平色。
|
|
1010
|
+
# 与 decor 同一约定:css 是可直接写进 style 的声明串。
|
|
1011
|
+
f = ls.get('fill') or {}
|
|
1012
|
+
if f.get('type') == 'gradient':
|
|
1013
|
+
g = _load_query()._css_gradient(f)
|
|
1014
|
+
if g:
|
|
1015
|
+
css += ['background-image: %s' % g, '-webkit-background-clip: text',
|
|
1016
|
+
'background-clip: text', 'color: transparent']
|
|
1017
|
+
align = ls.get('algn')
|
|
1018
|
+
if align:
|
|
1019
|
+
css.append('text-align: %s' % {
|
|
1020
|
+
'l': 'left', 'ctr': 'center', 'r': 'right', 'just': 'justify',
|
|
1021
|
+
}.get(align, align))
|
|
1022
|
+
line_spacing = ls.get('lnSpc') or {}
|
|
1023
|
+
if line_spacing.get('mult'):
|
|
1024
|
+
css.append('line-height: %s' % css_number(line_spacing['mult'] * 1.2))
|
|
1025
|
+
elif line_spacing.get('px'):
|
|
1026
|
+
css.append('line-height: %spx' % css_number(line_spacing['px']))
|
|
1027
|
+
anchor = body.get('anchor')
|
|
1028
|
+
if anchor in ('ctr', 'b'):
|
|
1029
|
+
css += ['display: flex', 'flex-direction: column',
|
|
1030
|
+
'justify-content: %s' % {'ctr': 'center', 'b': 'flex-end'}[anchor]]
|
|
1031
|
+
if body.get('rot'):
|
|
1032
|
+
try:
|
|
1033
|
+
degrees = float(body['rot']) / 60000.0
|
|
1034
|
+
css.append('rotate: %sdeg' % css_number(degrees))
|
|
1035
|
+
except (TypeError, ValueError):
|
|
1036
|
+
pass
|
|
1037
|
+
if css:
|
|
1038
|
+
out['css'] = '; '.join(css)
|
|
1039
|
+
return out
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
def instance_override(shapes, slide_part, slots, bgm, cW, cH, composites=None):
|
|
1043
|
+
"""实例页覆盖版式:版式是骨架,实例页才是设计师最终摆定的样子。
|
|
1044
|
+
|
|
1045
|
+
版式底图常是多个版式共用的通用底纹,实例页可能另铺主视觉大图;标题占位符的框高
|
|
1046
|
+
也常被实例页放大以容纳多行。只读版式的包会让消费端拿到错的底图和装不下字的框,
|
|
1047
|
+
只能自己缩字号。
|
|
1048
|
+
"""
|
|
1049
|
+
ins = [s for s in shapes if s.get('part') == slide_part]
|
|
1050
|
+
if not ins:
|
|
1051
|
+
return slots, bgm
|
|
1052
|
+
bgm = (composites or {}).get(slide_part) or top_bleed_media(ins) or bgm
|
|
1053
|
+
texts = []
|
|
1054
|
+
for s in ins:
|
|
1055
|
+
b = s.get('box') or {}
|
|
1056
|
+
if not (b.get('w') and b.get('h')) or not shape_text(s):
|
|
1057
|
+
continue
|
|
1058
|
+
texts.append({'sz': shape_sz(s), 'box': b, 'style': slot_style(s)})
|
|
1059
|
+
texts.sort(key=lambda x: -x['sz'])
|
|
1060
|
+
# 按字号大小依次顶替版式的文字槽(版式槽已按 y 排过,字号序更贴合语义层级)
|
|
1061
|
+
tslots = [s for s in slots if s['type'] != 'pic']
|
|
1062
|
+
for slot, ins_t in zip(sorted(tslots, key=lambda s: -(s.get('sz') or 0)), texts):
|
|
1063
|
+
b = ins_t['box']
|
|
1064
|
+
slot['box'] = [round(b.get('x', 0)), round(b.get('y', 0)),
|
|
1065
|
+
round(b.get('w', 0)), round(b.get('h', 0))]
|
|
1066
|
+
slot['sz'] = ins_t['sz']
|
|
1067
|
+
slot.update(ins_t['style'] or {})
|
|
1068
|
+
return slots, bgm
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
def layouts_from_template(d, shapes, cW, cH):
|
|
1072
|
+
"""form=3:模板自己用 slideLayout 声明了页型,直接读版式层。
|
|
1073
|
+
|
|
1074
|
+
拿样张聚类只能得到「样张数」个 archetype——模板往往只放 1-2 张样张,
|
|
1075
|
+
真正的页型全在版式里。模板常见只放个位数样张却声明几十个语义版式,按样张聚类
|
|
1076
|
+
只能得到「样张数」个 archetype,消费端搭页时大半无版式可抄,只能自己编。
|
|
1077
|
+
"""
|
|
1078
|
+
by_part = defaultdict(list)
|
|
1079
|
+
for s in shapes:
|
|
1080
|
+
if (s.get('layer') == 'layout' and s.get('kind') == 'sp'
|
|
1081
|
+
and (s.get('box') or {}).get('w') and (s.get('ph') or shape_text(s))):
|
|
1082
|
+
by_part[s['part']].append(s)
|
|
1083
|
+
bg_of_layout = {}
|
|
1084
|
+
composites = d.get('background_composites') or {}
|
|
1085
|
+
for s in shapes:
|
|
1086
|
+
if s.get('layer') == 'layout' and is_bleed(s) and s.get('media'):
|
|
1087
|
+
bg_of_layout[s['part']] = s['media'] # 靠后者在上层,最后一张才是看得见的
|
|
1088
|
+
topo = d.get('theme_topology') or {}
|
|
1089
|
+
theme_of_master = {m['master']: m.get('theme_label')
|
|
1090
|
+
for m in (topo.get('per_master') or [])}
|
|
1091
|
+
master_of = (d.get('reference_graph') or {}).get('master_of_layout') or {}
|
|
1092
|
+
# 只在版式恰好被 1 张实例页使用时才拿实例覆盖:多张实例共用一个版式时,
|
|
1093
|
+
# 谁都不代表版式本身,硬挑一张会把别页的构图当成页型
|
|
1094
|
+
lay_of_slide = (d.get('reference_graph') or {}).get('layout_of_slide') or {}
|
|
1095
|
+
used_n = Counter(lay_of_slide.values())
|
|
1096
|
+
slide_of_layout = {lp: sp for sp, lp in lay_of_slide.items() if used_n[lp] == 1}
|
|
1097
|
+
default_theme = topo.get('default')
|
|
1098
|
+
multi = len(topo.get('themes') or []) > 1
|
|
1099
|
+
|
|
1100
|
+
rows = []
|
|
1101
|
+
for l in d.get('layouts') or []:
|
|
1102
|
+
phs = [s for s in by_part.get(l['part'], []) if (s.get('box') or {}).get('w')]
|
|
1103
|
+
if not phs:
|
|
1104
|
+
continue
|
|
1105
|
+
theme = theme_of_master.get(master_of.get(l['part']))
|
|
1106
|
+
phs.sort(key=lambda s: ((s['box'].get('y') or 0), (s['box'].get('x') or 0)))
|
|
1107
|
+
slots, seen_kind = [], set()
|
|
1108
|
+
for s in phs:
|
|
1109
|
+
t = PH_TO_TYPE.get((s['ph'] or {}).get('type'), 'body')
|
|
1110
|
+
if t in ('slide-number', 'footer') and not shape_text(s):
|
|
1111
|
+
continue # 空 chrome 占位符不是实际元素
|
|
1112
|
+
b = s['box']
|
|
1113
|
+
role = t if t in ('title', 'subtitle', 'footer', 'slide-number') else 'body'
|
|
1114
|
+
if t == 'title' and 'title' in seen_kind:
|
|
1115
|
+
role, t = 'subtitle', 'subtitle'
|
|
1116
|
+
seen_kind.add(t)
|
|
1117
|
+
row = {'role': role, 'type': t, 'sz': shape_sz(s),
|
|
1118
|
+
'box': [round(b.get('x', 0)), round(b.get('y', 0)),
|
|
1119
|
+
round(b.get('w', 0)), round(b.get('h', 0))],
|
|
1120
|
+
'txt': shape_text(s) or (s.get('name') or '')[:24]}
|
|
1121
|
+
row.update(slot_style(s))
|
|
1122
|
+
if t == 'body':
|
|
1123
|
+
ph = s.get('ph') or {}
|
|
1124
|
+
row.update({
|
|
1125
|
+
'_needs_role': True,
|
|
1126
|
+
'_source_layer': 'layout',
|
|
1127
|
+
'_placeholder': '%s/%s' % (
|
|
1128
|
+
ph.get('type') or '-', ph.get('idx') or '-'),
|
|
1129
|
+
})
|
|
1130
|
+
slots.append(row)
|
|
1131
|
+
# 非满屏的图片元素(logo / 联名标 / 装饰)——它们逐版式换位置换尺寸,
|
|
1132
|
+
# 必须按版式落进 slots,压成一条全局「固定位」规则就会撞标题。
|
|
1133
|
+
bgm = composites.get(l['part']) or bg_of_layout.get(l['part'])
|
|
1134
|
+
for s in shapes:
|
|
1135
|
+
if s['part'] != l['part'] or s.get('kind') != 'pic' or not s.get('media'):
|
|
1136
|
+
continue
|
|
1137
|
+
if s['media'] == bgm or (s.get('w_pct', 0) >= 95 and s.get('h_pct', 0) >= 95):
|
|
1138
|
+
continue
|
|
1139
|
+
b = s.get('box') or {}
|
|
1140
|
+
if not b.get('w'):
|
|
1141
|
+
continue
|
|
1142
|
+
slots.append({'role': 'logo', 'type': 'pic', 'sz': 0, 'txt': '',
|
|
1143
|
+
'media': s['media'],
|
|
1144
|
+
'box': [round(b.get('x', 0)), round(b.get('y', 0)),
|
|
1145
|
+
round(b.get('w', 0)), round(b.get('h', 0))]})
|
|
1146
|
+
if not slots:
|
|
1147
|
+
continue
|
|
1148
|
+
inst = slide_of_layout.get(l['part'])
|
|
1149
|
+
if inst:
|
|
1150
|
+
slots, bgm = instance_override(
|
|
1151
|
+
shapes, inst, slots, bgm, cW, cH, composites)
|
|
1152
|
+
taken = {tuple(s['box']) for s in slots}
|
|
1153
|
+
decor = collect_decor(shapes, inst or l['part'], taken, (cW, cH))
|
|
1154
|
+
named_role = role_of_name(l.get('name'))
|
|
1155
|
+
rows.append({'zh': clean_layout_name(l.get('name')),
|
|
1156
|
+
'role': named_role or 'content', 'role_guessed': named_role is None,
|
|
1157
|
+
'slots': slots, 'decor': decor, 'bg_raw': bgm,
|
|
1158
|
+
'theme': theme, 'part': l['part'],
|
|
1159
|
+
'used': l.get('used_by_slides') or 0})
|
|
1160
|
+
|
|
1161
|
+
# 同名版式在 dark/light 两套 master 下各有一份——按名字归一,优先默认主题那份
|
|
1162
|
+
best = {}
|
|
1163
|
+
for r in rows:
|
|
1164
|
+
k = r['zh']
|
|
1165
|
+
cur = best.get(k)
|
|
1166
|
+
if cur is None or (r['theme'] == default_theme and cur['theme'] != default_theme) \
|
|
1167
|
+
or (r['used'] > cur['used']):
|
|
1168
|
+
best[k] = r
|
|
1169
|
+
picked = sorted(best.values(), key=lambda r: (
|
|
1170
|
+
['cover', 'section', 'quote', 'content', 'closing', 'blank'].index(r['role'])
|
|
1171
|
+
if r['role'] in ('cover', 'section', 'quote', 'content', 'closing', 'blank') else 9,
|
|
1172
|
+
-r['used'], r['part']))
|
|
1173
|
+
|
|
1174
|
+
used_key = Counter()
|
|
1175
|
+
arch = []
|
|
1176
|
+
for r in picked:
|
|
1177
|
+
used_key[r['role']] += 1
|
|
1178
|
+
n = used_key[r['role']]
|
|
1179
|
+
key = r['role'] if n == 1 else '%s-%d' % (r['role'], n)
|
|
1180
|
+
m_no = re.search(r'slideLayout(\d+)\.xml$', r['part'])
|
|
1181
|
+
arch.append({'name': key, 'zh': r['zh'], 'role': r['role'], 'bg': None,
|
|
1182
|
+
'role_guessed': r.get('role_guessed'),
|
|
1183
|
+
'bg_raw': r['bg_raw'], 'slots': r['slots'],
|
|
1184
|
+
'decor': r.get('decor') or [], 'pages': [],
|
|
1185
|
+
'rep': None, 'rep_layout': int(m_no.group(1)) if m_no else None,
|
|
1186
|
+
# 版式名认不出 role 时不装作有把握:置信度降到 low,让 L 层看图定
|
|
1187
|
+
'pic_n': 0, 'confidence': 'low' if r.get('role_guessed') else 'high',
|
|
1188
|
+
'theme': r['theme'] if multi else None,
|
|
1189
|
+
'source': 'layout:' + r['part'].split('/')[-1]})
|
|
1190
|
+
return arch
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
_QUERY = []
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
def _load_query():
|
|
1197
|
+
"""复用 query.py 的 OOXML→CSS 渲染,不再写第二份。"""
|
|
1198
|
+
if not _QUERY:
|
|
1199
|
+
import importlib.util
|
|
1200
|
+
spec = importlib.util.spec_from_file_location('_q', os.path.join(HERE, 'query.py'))
|
|
1201
|
+
mod = importlib.util.module_from_spec(spec)
|
|
1202
|
+
spec.loader.exec_module(mod)
|
|
1203
|
+
_QUERY.append(mod)
|
|
1204
|
+
return _QUERY[0]
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
def collect_decor(shapes, part, taken_boxes, canvas, limit=10):
|
|
1208
|
+
"""页面上撑起版式骨架、但不含文字的形状(圆形图标托、卡片、分隔线)。
|
|
1209
|
+
|
|
1210
|
+
只给文字框的坐标,消费端看到的是「一段说明悬在半空、上方一片空白」,只能自己编
|
|
1211
|
+
容器,编出来的形状与模板无关。这些形状必须进包。
|
|
1212
|
+
"""
|
|
1213
|
+
q = _load_query()
|
|
1214
|
+
cW, cH = canvas
|
|
1215
|
+
out = []
|
|
1216
|
+
for s in shapes:
|
|
1217
|
+
if s.get('part') != part or s.get('kind') != 'sp':
|
|
1218
|
+
continue
|
|
1219
|
+
if any(r.get('text', '').strip()
|
|
1220
|
+
for para in ((s.get('text') or {}).get('paragraphs') or [])
|
|
1221
|
+
for r in (para.get('runs') or [])):
|
|
1222
|
+
continue # 有文字的已经作为 slot 出过
|
|
1223
|
+
b = s.get('box') or {}
|
|
1224
|
+
w, h = b.get('w') or 0, b.get('h') or 0
|
|
1225
|
+
if not (w or h):
|
|
1226
|
+
continue # 零尺寸形状渲染不出任何东西
|
|
1227
|
+
if canvas_coverage(b, cW, cH) >= FULLSCREEN_COVERAGE:
|
|
1228
|
+
continue # 满屏底,属 background
|
|
1229
|
+
box = [round(b.get('x', 0)), round(b.get('y', 0)), round(w), round(h)]
|
|
1230
|
+
if tuple(box) in taken_boxes:
|
|
1231
|
+
continue
|
|
1232
|
+
css = q._recipe_css(s.get('fill'), s.get('line'),
|
|
1233
|
+
[s.get('radius_px')] if s.get('radius_px') else [], s.get('effects'))
|
|
1234
|
+
# 声明要落成单行:含换行的声明会被下游的行式解析器从换行处截断,
|
|
1235
|
+
# 且只记 PARSE-WARN 不 FAIL,整包照常出厂——带着半条渲染不出来的 CSS
|
|
1236
|
+
css = [re.sub(r'\s*\n\s*', ' ', c.split('\x00')[0]).strip() for c in css if c]
|
|
1237
|
+
if not css:
|
|
1238
|
+
continue # 无填充无描边无阴影 = 看不见,不占篇幅
|
|
1239
|
+
out.append({'box': box, 'geom': (s.get('geom') or {}).get('prst') or 'rect',
|
|
1240
|
+
'css': '; '.join(css), 'area': max(w * h, w, h)})
|
|
1241
|
+
# 按面积降序取前 limit 条:撑起版式的结构性形状总在最前,零星噪点自然落在截断线外,
|
|
1242
|
+
# 不需要再设一个「多小算噪点」的尺寸门槛(那种门槛会误杀 1px 分隔线)。
|
|
1243
|
+
out.sort(key=lambda d: -d['area'])
|
|
1244
|
+
note_truncation('装饰形状', limit, len(out), '按面积降序保留,剩下的多是零星小件',
|
|
1245
|
+
part.split('/')[-1])
|
|
1246
|
+
return out[:limit] # 同款不同位置都要留,位置本身是版式信息
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
def placeholder_key(shape):
|
|
1250
|
+
ph = shape.get('ph') or {}
|
|
1251
|
+
if not ph:
|
|
1252
|
+
return None
|
|
1253
|
+
return (ph.get('type') or 'body', str(ph.get('idx') or ''))
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
def merge_dict(base, override):
|
|
1257
|
+
"""把实例页的非空声明叠到版式声明上;空实例占位符继续继承版式事实。"""
|
|
1258
|
+
out = copy.deepcopy(base or {})
|
|
1259
|
+
for key, value in (override or {}).items():
|
|
1260
|
+
if value is None or value == []:
|
|
1261
|
+
continue
|
|
1262
|
+
if isinstance(value, dict) and isinstance(out.get(key), dict):
|
|
1263
|
+
out[key] = merge_dict(out[key], value)
|
|
1264
|
+
else:
|
|
1265
|
+
out[key] = copy.deepcopy(value)
|
|
1266
|
+
return out
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
def inherited_text_shapes(layout_shapes, slide_shapes):
|
|
1270
|
+
"""返回实例页可用的文字形状,并补齐其引用版式中的占位符几何与样式。"""
|
|
1271
|
+
layout_text = []
|
|
1272
|
+
for shape in layout_shapes:
|
|
1273
|
+
if shape.get('kind') != 'sp' or not (shape.get('box') or {}).get('w'):
|
|
1274
|
+
continue
|
|
1275
|
+
ph = shape.get('ph') or {}
|
|
1276
|
+
ph_type = ph.get('type')
|
|
1277
|
+
if shape_text(shape) or (ph and ph_type not in ('ftr', 'dt', 'sldNum')):
|
|
1278
|
+
layout_text.append(shape)
|
|
1279
|
+
by_placeholder = {placeholder_key(s): s for s in layout_text if placeholder_key(s)}
|
|
1280
|
+
used = set()
|
|
1281
|
+
out = []
|
|
1282
|
+
for shape in slide_shapes:
|
|
1283
|
+
if shape.get('kind') != 'sp':
|
|
1284
|
+
continue
|
|
1285
|
+
key = placeholder_key(shape)
|
|
1286
|
+
base = by_placeholder.get(key)
|
|
1287
|
+
if base:
|
|
1288
|
+
merged = merge_dict(base, shape)
|
|
1289
|
+
merged['text'] = merge_dict(base.get('text'), shape.get('text'))
|
|
1290
|
+
if not shape_text(shape):
|
|
1291
|
+
merged['text']['paragraphs'] = copy.deepcopy(
|
|
1292
|
+
(base.get('text') or {}).get('paragraphs') or [])
|
|
1293
|
+
used.add(key)
|
|
1294
|
+
out.append((merged, 'slide+layout'))
|
|
1295
|
+
elif (shape.get('box') or {}).get('w') and shape_text(shape):
|
|
1296
|
+
out.append((shape, 'slide'))
|
|
1297
|
+
for shape in layout_text:
|
|
1298
|
+
key = placeholder_key(shape)
|
|
1299
|
+
if key not in used:
|
|
1300
|
+
out.append((shape, 'layout'))
|
|
1301
|
+
return out
|
|
1302
|
+
|
|
439
1303
|
|
|
440
1304
|
def draft_layouts(d, outdir):
|
|
441
|
-
|
|
1305
|
+
with open(os.path.join(outdir, 'ref', 'shapes.json'), encoding='utf-8') as stream:
|
|
1306
|
+
shapes = json.load(stream)['shapes']
|
|
442
1307
|
cW, cH = d['canvas']['px']
|
|
1308
|
+
if (d.get('form_hint') or {}).get('form') == 3:
|
|
1309
|
+
arch = layouts_from_template(d, shapes, cW, cH)
|
|
1310
|
+
if len(arch) >= 3:
|
|
1311
|
+
return arch, [], []
|
|
443
1312
|
by_slide = defaultdict(list)
|
|
1313
|
+
by_layout = defaultdict(list)
|
|
444
1314
|
for s in shapes:
|
|
445
1315
|
if s.get('layer') == 'slide':
|
|
446
1316
|
by_slide[s['part']].append(s)
|
|
1317
|
+
elif s.get('layer') == 'layout':
|
|
1318
|
+
by_layout[s['part']].append(s)
|
|
447
1319
|
|
|
448
1320
|
bg_of_slide, layout_of_slide = {}, {}
|
|
449
1321
|
for s in d.get('slides', []):
|
|
@@ -451,55 +1323,76 @@ def draft_layouts(d, outdir):
|
|
|
451
1323
|
bg_of_slide[s['part']] = json.dumps(bg, sort_keys=True) if isinstance(bg, dict) else bg
|
|
452
1324
|
layout_of_slide[s['part']] = s.get('layout')
|
|
453
1325
|
# 版式层的满屏底图(form=2 常态:底图挂在 layout 上)
|
|
1326
|
+
composites = d.get('background_composites') or {}
|
|
454
1327
|
bg_of_layout = {}
|
|
455
1328
|
for s in shapes:
|
|
456
|
-
if
|
|
457
|
-
|
|
458
|
-
bg_of_layout.setdefault(s['part'], s.get('media'))
|
|
1329
|
+
if s.get('layer') == 'layout' and is_bleed(s) and s.get('media'):
|
|
1330
|
+
bg_of_layout[s['part']] = s['media']
|
|
459
1331
|
|
|
460
1332
|
pages = []
|
|
461
1333
|
for part, sh in sorted(by_slide.items(), key=lambda kv: slide_no(kv[0])):
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
bg_media = s.get('media')
|
|
466
|
-
break
|
|
1334
|
+
layout_part = layout_of_slide.get(part)
|
|
1335
|
+
layout_shapes = by_layout.get(layout_part) or []
|
|
1336
|
+
bg_media = top_bleed_media(sh)
|
|
467
1337
|
if bg_media is None:
|
|
468
|
-
bg_media = bg_of_layout.get(
|
|
1338
|
+
bg_media = bg_of_layout.get(layout_part)
|
|
1339
|
+
rendered_bg = (composites.get(part)
|
|
1340
|
+
or composites.get(layout_part)
|
|
1341
|
+
or bg_media)
|
|
469
1342
|
texts = []
|
|
470
|
-
for s in sh:
|
|
471
|
-
|
|
472
|
-
continue
|
|
473
|
-
txt = shape_text(s)
|
|
474
|
-
if not txt:
|
|
475
|
-
continue
|
|
1343
|
+
for s, source_layer in inherited_text_shapes(layout_shapes, sh):
|
|
1344
|
+
txt = shape_text(s) or (s.get('name') or '')[:24]
|
|
476
1345
|
b = s.get('box') or {}
|
|
477
1346
|
if b.get('w', 0) < DECOR_MIN or b.get('h', 0) < 16:
|
|
478
1347
|
continue
|
|
479
|
-
|
|
1348
|
+
ph = s.get('ph') or {}
|
|
1349
|
+
ph_type = ph.get('type')
|
|
1350
|
+
direct_type = PH_TO_TYPE.get(ph_type, 'body')
|
|
1351
|
+
texts.append({
|
|
1352
|
+
'sz': shape_sz(s),
|
|
1353
|
+
'box': b,
|
|
1354
|
+
'txt': txt,
|
|
1355
|
+
'style': slot_style(s),
|
|
1356
|
+
'direct_type': direct_type,
|
|
1357
|
+
'needs_role': direct_type == 'body',
|
|
1358
|
+
'source_layer': source_layer,
|
|
1359
|
+
'placeholder': '%s/%s' % (ph_type or '-', ph.get('idx') or '-'),
|
|
1360
|
+
})
|
|
480
1361
|
texts.sort(key=lambda t: (-t['sz'], t['box'].get('y', 0)))
|
|
481
|
-
|
|
1362
|
+
visible_shapes = layout_shapes + sh
|
|
1363
|
+
pics = [s for s in visible_shapes if s.get('kind') == 'pic' and s.get('w_pct', 0) < 95]
|
|
1364
|
+
# 小图元素(logo / 角标 / 装饰)逐页记位置,供 archetype 落 slots
|
|
1365
|
+
marks = [{'media': s['media'], 'box': s['box']} for s in pics
|
|
1366
|
+
if s.get('media') and (s.get('box') or {}).get('w') and s.get('w_pct', 0) < 30]
|
|
482
1367
|
pages.append({'part': part, 'no': slide_no(part), 'bg_media': bg_media,
|
|
1368
|
+
'rendered_bg': rendered_bg,
|
|
483
1369
|
'bg_color': bg_of_slide.get(part), 'texts': texts, 'pic_n': len(pics),
|
|
484
|
-
'shape_n': len(
|
|
1370
|
+
'marks': marks, 'shape_n': len(visible_shapes), 'layout': layout_part})
|
|
485
1371
|
|
|
486
|
-
|
|
1372
|
+
# 页型的**角色**(封面 / 章节页 / 内容页……)不在这里判:那是看图才能下的结论,
|
|
1373
|
+
# 交给读得到重建图的模型。脚本只做客观归并——同一张底图 + 文字块数量相近的页
|
|
1374
|
+
# 归成一组,档位按本 deck 自己的分布切,不用「字号 ≥60 就是章节页」这类固定数。
|
|
1375
|
+
ns = sorted(len(p['texts']) for p in pages) or [0]
|
|
1376
|
+
q1, q2 = ns[len(ns) // 3], ns[len(ns) * 2 // 3]
|
|
1377
|
+
|
|
1378
|
+
def density_band(p):
|
|
487
1379
|
n = len(p['texts'])
|
|
488
|
-
|
|
489
|
-
if p['no'] == 1:
|
|
490
|
-
return 'cover'
|
|
491
|
-
if n <= 3 and top >= 60:
|
|
492
|
-
return 'section'
|
|
493
|
-
if n >= 8 or p['pic_n'] >= 4:
|
|
494
|
-
return 'content-dense'
|
|
495
|
-
return 'content'
|
|
1380
|
+
return 0 if n <= q1 else (1 if n <= q2 else 2)
|
|
496
1381
|
|
|
497
1382
|
groups = defaultdict(list)
|
|
498
1383
|
for p in pages:
|
|
499
|
-
|
|
1384
|
+
if p['no'] == 1:
|
|
1385
|
+
# 首页单独成组:它是 deck 唯一的入口页,版面通常和后面任何一页都不同,
|
|
1386
|
+
# 并进别的组就会被代表页顶掉、坐标全丢。这只是不合并,不代表它是封面。
|
|
1387
|
+
groups[('__first__', -1)] = [p]
|
|
1388
|
+
continue
|
|
1389
|
+
groups[(p['bg_media'] or p['bg_color'] or 'none', density_band(p))].append(p)
|
|
500
1390
|
|
|
501
1391
|
ranked = sorted(groups.items(), key=lambda kv: (-len(kv[1]), kv[1][0]['no']))
|
|
502
|
-
|
|
1392
|
+
# 首页所在的组一定收——deck 的第一页是模板的门面,孤例也不能被名额挤掉。
|
|
1393
|
+
# 这只保证它进包,它是不是封面由看图的人定。
|
|
1394
|
+
first = [g for g in ranked if g[0][0] == '__first__']
|
|
1395
|
+
kept = first + [g for g in ranked if g not in first and len(g[1]) >= 2][:8 - len(first)]
|
|
503
1396
|
for g in ranked: # 名额没用满就把最大的孤例页也收进来
|
|
504
1397
|
if len(kept) >= 8:
|
|
505
1398
|
break
|
|
@@ -508,35 +1401,78 @@ def draft_layouts(d, outdir):
|
|
|
508
1401
|
leftover = sorted(p['no'] for g in ranked if g not in kept for p in g[1])
|
|
509
1402
|
|
|
510
1403
|
archetypes = []
|
|
511
|
-
|
|
512
|
-
for (bg_raw, kind), ps in kept:
|
|
1404
|
+
for gi, ((bg_raw, _band), ps) in enumerate(kept, 1):
|
|
513
1405
|
rep = max(ps, key=lambda p: len(p['texts']))
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
1406
|
+
if bg_raw == '__first__':
|
|
1407
|
+
bg_raw = rep['bg_media'] or rep['bg_color'] or 'none'
|
|
1408
|
+
rendered_bg = rep.get('rendered_bg')
|
|
1409
|
+
if rendered_bg:
|
|
1410
|
+
bg_raw = rendered_bg
|
|
1411
|
+
name = 'layout-%d' % gi
|
|
1412
|
+
# 标题按「位置 + 跨度」认,不按字号——big-number 类的巨号数值常比标题还大
|
|
1413
|
+
# 标题 = 该页最靠上的那批文本里最宽的一块。不按「画布前 28%」这类固定比例切:
|
|
1414
|
+
# 版心靠下的模板会整页认不出标题。以该页自身的文本框分布定「靠上」。
|
|
1415
|
+
ys = sorted(t['box'].get('y', 0) for t in rep['texts'])
|
|
1416
|
+
y_cut = ys[max(len(ys) // 4, 0)] if ys else 0
|
|
1417
|
+
band = [t for t in rep['texts'] if t['box'].get('y', 1e9) <= y_cut]
|
|
1418
|
+
title = max(band, key=lambda t: (t['box'].get('w', 0), t['sz'])) if band else (
|
|
520
1419
|
max(rep['texts'], key=lambda t: t['sz']) if rep['texts'] else None)
|
|
521
1420
|
rest = [t for t in rep['texts'] if t is not title]
|
|
522
1421
|
rest.sort(key=lambda t: (t['box'].get('y', 0), t['box'].get('x', 0)))
|
|
523
1422
|
ordered = ([title] if title else []) + rest
|
|
524
1423
|
slots = []
|
|
525
|
-
for i, t in enumerate(ordered
|
|
1424
|
+
for i, t in enumerate(ordered):
|
|
526
1425
|
b = t['box']
|
|
527
|
-
if t
|
|
1426
|
+
if t.get('needs_role'):
|
|
1427
|
+
role = typ = 'body'
|
|
1428
|
+
elif t.get('direct_type') in ('title', 'subtitle', 'footer', 'slide-number'):
|
|
1429
|
+
role = typ = t['direct_type']
|
|
1430
|
+
elif t is title:
|
|
528
1431
|
role = typ = 'title'
|
|
529
|
-
elif (title and i == 1
|
|
530
|
-
|
|
1432
|
+
elif (title and i == 1
|
|
1433
|
+
# 副标题 = 紧跟在标题下方、与标题左对齐的那一块。三个量都相对标题
|
|
1434
|
+
# 自身:绝对 px 门槛在大字号排版的模板上会整片认不出来。
|
|
1435
|
+
and abs(b.get('x', 0) - title['box'].get('x', 0)) <= title['box'].get('h', 0)
|
|
531
1436
|
and 0 <= b.get('y', 0) - (title['box'].get('y', 0)
|
|
532
|
-
+ title['box'].get('h', 0))
|
|
1437
|
+
+ title['box'].get('h', 0))
|
|
1438
|
+
<= title['box'].get('h', 0) * 2):
|
|
533
1439
|
role = typ = 'subtitle'
|
|
534
1440
|
else:
|
|
535
1441
|
role = typ = 'body'
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
1442
|
+
row = {'role': role, 'box': [round(b.get('x', 0)), round(b.get('y', 0)),
|
|
1443
|
+
round(b.get('w', 0)), round(b.get('h', 0))],
|
|
1444
|
+
'type': typ, 'sz': t['sz'], 'txt': t['txt']}
|
|
1445
|
+
row.update(t.get('style') or {})
|
|
1446
|
+
if t.get('needs_role'):
|
|
1447
|
+
row.update({
|
|
1448
|
+
'_needs_role': True,
|
|
1449
|
+
'_source_layer': t.get('source_layer'),
|
|
1450
|
+
'_placeholder': t.get('placeholder'),
|
|
1451
|
+
})
|
|
1452
|
+
slots.append(row)
|
|
1453
|
+
# 代表页上的小图元素按位置去重后落 slots(同一 logo 在不同页型位置不同)
|
|
1454
|
+
seen_mark = set()
|
|
1455
|
+
for mk in rep.get('marks') or []:
|
|
1456
|
+
b = mk['box']
|
|
1457
|
+
key = (mk['media'], round(b.get('x', 0)), round(b.get('y', 0)))
|
|
1458
|
+
if key in seen_mark:
|
|
1459
|
+
continue
|
|
1460
|
+
seen_mark.add(key)
|
|
1461
|
+
slots.append({'role': 'logo', 'type': 'pic', 'sz': 0, 'txt': '',
|
|
1462
|
+
'media': mk['media'],
|
|
1463
|
+
'box': [round(b.get('x', 0)), round(b.get('y', 0)),
|
|
1464
|
+
round(b.get('w', 0)), round(b.get('h', 0))]})
|
|
1465
|
+
taken = {tuple(s['box']) for s in slots}
|
|
1466
|
+
decor = []
|
|
1467
|
+
seen_decor = set()
|
|
1468
|
+
for source_part in (rep.get('layout'), rep['part']):
|
|
1469
|
+
for item in collect_decor(shapes, source_part, taken, (cW, cH)):
|
|
1470
|
+
key = (tuple(item['box']), item['geom'], item['css'])
|
|
1471
|
+
if key not in seen_decor:
|
|
1472
|
+
seen_decor.add(key)
|
|
1473
|
+
decor.append(item)
|
|
539
1474
|
archetypes.append({'name': name, 'bg': None, 'bg_raw': bg_raw, 'slots': slots,
|
|
1475
|
+
'decor': decor,
|
|
540
1476
|
'pages': sorted(p['no'] for p in ps), 'rep': rep['no'],
|
|
541
1477
|
'pic_n': rep['pic_n'],
|
|
542
1478
|
'confidence': 'high' if len(ps) >= 3 else
|
|
@@ -547,12 +1483,15 @@ def draft_layouts(d, outdir):
|
|
|
547
1483
|
# ---------------------------------------------------------------- 联系表
|
|
548
1484
|
def layout_sheet(outdir, archetypes, path):
|
|
549
1485
|
"""把各 archetype 的代表页光栅出来拼成一张——版式命名得看得见页面。"""
|
|
550
|
-
|
|
1486
|
+
use_layout = all(a.get('rep') is None for a in archetypes)
|
|
1487
|
+
reps = [a.get('rep_layout') if use_layout else a.get('rep') for a in archetypes]
|
|
1488
|
+
reps = [x for x in reps if x is not None]
|
|
551
1489
|
if not reps:
|
|
552
1490
|
return None
|
|
553
1491
|
import subprocess
|
|
554
1492
|
r = subprocess.run([sys.executable, os.path.join(HERE, 'render_pages.py'), outdir,
|
|
555
|
-
'--pages', '
|
|
1493
|
+
'--pages', 'layouts' if use_layout else 'slides',
|
|
1494
|
+
'--only', ','.join(map(str, reps)), '--no-html'],
|
|
556
1495
|
capture_output=True, text=True)
|
|
557
1496
|
png_dir = os.path.join(outdir, 'ref', 'rebuild', 'png')
|
|
558
1497
|
if r.returncode or not os.path.isdir(png_dir):
|
|
@@ -570,14 +1509,19 @@ def layout_sheet(outdir, archetypes, path):
|
|
|
570
1509
|
for i, a in enumerate(archetypes):
|
|
571
1510
|
x = pad + (i % cols) * (cw + pad)
|
|
572
1511
|
y = pad + (i // cols) * (ch + pad + lab)
|
|
573
|
-
|
|
1512
|
+
no = a.get('rep_layout') if use_layout else a.get('rep')
|
|
1513
|
+
f = os.path.join(png_dir, '%s-%s.png' % ('layout' if use_layout else 'slide', no))
|
|
574
1514
|
if os.path.exists(f):
|
|
575
1515
|
im = Image.open(f).convert('RGB')
|
|
576
1516
|
im.thumbnail((cw, ch))
|
|
577
1517
|
sheet.paste(im, (x, y))
|
|
578
1518
|
dr.rectangle([x, y, x + cw, y + ch], outline=(120, 120, 128))
|
|
579
|
-
|
|
580
|
-
|
|
1519
|
+
# 标注只写 ASCII——Pillow 默认字体没有 CJK 字形,中文会渲染成方框
|
|
1520
|
+
dr.text((x + 2, y + ch + 5), '[%s] %s bg=%s'
|
|
1521
|
+
% (a['name'],
|
|
1522
|
+
('layout %s' % a.get('rep_layout')) if use_layout
|
|
1523
|
+
else ('slide %s x%d pages' % (a.get('rep'), len(a['pages']))),
|
|
1524
|
+
a.get('bg') or '-'),
|
|
581
1525
|
fill=(20, 20, 24))
|
|
582
1526
|
sheet.save(path, optimize=True)
|
|
583
1527
|
return path
|
|
@@ -589,7 +1533,7 @@ def contact_sheet(outdir, cands, path):
|
|
|
589
1533
|
except Exception:
|
|
590
1534
|
return None
|
|
591
1535
|
cell, pad, cols = 220, 20, 4
|
|
592
|
-
items = cands
|
|
1536
|
+
items = cands # 上限由调用方定,编号与 BRIEF 表格一一对应
|
|
593
1537
|
if not items:
|
|
594
1538
|
return None
|
|
595
1539
|
rows = (len(items) + cols - 1) // cols
|
|
@@ -669,20 +1613,32 @@ def emit_frontmatter(d, tokens, fonts, roles, anchors, gaps, ldir):
|
|
|
669
1613
|
edge = {}
|
|
670
1614
|
for p in pads:
|
|
671
1615
|
edge.setdefault(p['edge'], p['px'])
|
|
672
|
-
|
|
1616
|
+
# 四边都测出来才写 spacing / safe-area。缺一边就整段不写,并在 gaps 说明——
|
|
1617
|
+
# 拿另一套模板的边距当默认值,会让消费端按一个从没在本模板出现过的网格排版。
|
|
1618
|
+
edges_full = all(edge.get(k) is not None for k in ('top', 'right', 'bottom', 'left'))
|
|
1619
|
+
if edges_full:
|
|
673
1620
|
L.append('spacing:')
|
|
674
1621
|
L.append(' page-padding: {top: %s, right: %s, bottom: %s, left: %s}'
|
|
675
|
-
% (edge
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
1622
|
+
% (edge['top'], edge['right'], edge['bottom'], edge['left']))
|
|
1623
|
+
# rounded.card 是全局 token,只能表达全档共同的一档圆角。多个非零档位或零/非零
|
|
1624
|
+
# 混用时,圆角属于 layouts.md 里的局部形状事实,压成一个值会把直角容器也圆角化。
|
|
1625
|
+
radii = d.get('radii_census') or []
|
|
1626
|
+
if len(radii) == 1 and radii[0]['px'] >= 1:
|
|
1627
|
+
top = radii[0]
|
|
680
1628
|
L.append('rounded:')
|
|
681
1629
|
L.append(' card: %dpx' % round(top['px']))
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
1630
|
+
if edges_full:
|
|
1631
|
+
L.append('safe-area:')
|
|
1632
|
+
L.append(' content: {top: %s, right: %s, bottom: %s, left: %s, applies-to: [content]}'
|
|
1633
|
+
% (edge['top'], edge['right'], edge['bottom'], edge['left']))
|
|
1634
|
+
L.append(' confidence: medium')
|
|
1635
|
+
else:
|
|
1636
|
+
gaps = list(gaps) + ['本模板没测出四边都稳定的页边距(普查到 %s),'
|
|
1637
|
+
'因此不给 spacing / safe-area:按各页型 slot 的实际坐标排版,'
|
|
1638
|
+
'不要自造统一边距。'
|
|
1639
|
+
% ('、'.join('%s=%s' % (k, edge[k]) for k in
|
|
1640
|
+
('top', 'right', 'bottom', 'left') if edge.get(k) is not None)
|
|
1641
|
+
or '一边都没有')]
|
|
686
1642
|
L.append('anchors:')
|
|
687
1643
|
for aid, typ, desc in anchors:
|
|
688
1644
|
L.append(' - {id: %s, type: %s, desc: "%s"}' % (aid, typ, desc))
|
|
@@ -692,131 +1648,548 @@ def emit_frontmatter(d, tokens, fonts, roles, anchors, gaps, ldir):
|
|
|
692
1648
|
write(os.path.join(ldir, 'frontmatter.yaml'), '\n'.join(L) + '\n')
|
|
693
1649
|
|
|
694
1650
|
|
|
695
|
-
def
|
|
696
|
-
|
|
697
|
-
|
|
1651
|
+
def draft_flow(a, facts, canvas):
|
|
1652
|
+
"""从结构事实推出「区带」草案:一页 = 若干竖直区带,高度由内容决定。
|
|
1653
|
+
|
|
1654
|
+
绝对坐标只能表达「模板样张那份内容摆在哪」。真实内容长度不同,上面的区带一变高,
|
|
1655
|
+
下面的就该整体下移——这件事在一张坐标表里表达不出来,只能靠消费端自己算,而它
|
|
1656
|
+
算错的方向有两个:估小了压穿下一块,估大了留一片空。
|
|
1657
|
+
|
|
1658
|
+
这里只出草案,最终用绝对还是流式由看得到重建图的人定。
|
|
1659
|
+
"""
|
|
1660
|
+
cW, cH = canvas
|
|
1661
|
+
# 装饰件也算进来:很多模板的版式层只有几个占位符,真正撑起版面的是卡片容器
|
|
1662
|
+
# (在 decor 里)。只看 slots 会把一页的主体结构整个漏掉。
|
|
1663
|
+
slots = [s for s in a['slots'] if s.get('box')]
|
|
1664
|
+
fixed_roles = {'logo', 'slide-number', 'page-number', 'header', 'footer'}
|
|
1665
|
+
fixed = [s for s in slots if s.get('role') in fixed_roles]
|
|
1666
|
+
content_slots = [s for s in slots if s.get('role') not in fixed_roles]
|
|
1667
|
+
containers = [{'role': 'container', 'type': 'decor', 'box': dcr['box'],
|
|
1668
|
+
'css': dcr.get('css')} for dcr in (a.get('decor') or [])]
|
|
1669
|
+
items = group_flow_cards(content_slots, containers)
|
|
1670
|
+
if len(items) < 2:
|
|
1671
|
+
return None
|
|
1672
|
+
items.sort(key=lambda s: (s['box'][1], s['box'][0]))
|
|
1673
|
+
gaps = [items[i + 1]['box'][1] - (items[i]['box'][1] + items[i]['box'][3])
|
|
1674
|
+
for i in range(len(items) - 1)]
|
|
1675
|
+
pos = [g for g in gaps if g > 0]
|
|
1676
|
+
if not pos:
|
|
1677
|
+
return None
|
|
1678
|
+
# 区带边界 = 间距分布里的最大空档。同一区带内部的间距(网格行距之类)总是明显
|
|
1679
|
+
# 小于区带之间的间距,用本页自己的分布切,不设固定阈值。
|
|
1680
|
+
cut = _gap_cut(pos, min(pos), max(pos)) if len(pos) > 1 else pos[0]
|
|
1681
|
+
regions, cur = [], [items[0]]
|
|
1682
|
+
for i, g in enumerate(gaps):
|
|
1683
|
+
if g >= cut:
|
|
1684
|
+
regions.append(cur)
|
|
1685
|
+
cur = []
|
|
1686
|
+
cur.append(items[i + 1])
|
|
1687
|
+
regions.append(cur)
|
|
1688
|
+
|
|
1689
|
+
out = []
|
|
1690
|
+
for reg in regions:
|
|
1691
|
+
if not reg:
|
|
1692
|
+
continue
|
|
1693
|
+
# 同一区带里 y 接近的算一行;每行元素数一致且 >1 就是网格
|
|
1694
|
+
rows, cr = [], [reg[0]]
|
|
1695
|
+
for s in reg[1:]:
|
|
1696
|
+
if abs(s['box'][1] - cr[-1]['box'][1]) <= max(s['box'][3], 1) * 0.5:
|
|
1697
|
+
cr.append(s)
|
|
1698
|
+
else:
|
|
1699
|
+
rows.append(cr)
|
|
1700
|
+
cr = [s]
|
|
1701
|
+
rows.append(cr)
|
|
1702
|
+
widths = {len(r) for r in rows}
|
|
1703
|
+
if len(rows) >= 1 and widths == {len(rows[0])} and len(rows[0]) > 1:
|
|
1704
|
+
cols = len(rows[0])
|
|
1705
|
+
xs = sorted(s['box'][0] for s in rows[0])
|
|
1706
|
+
col_gap = round((xs[1] - xs[0]) - rows[0][0]['box'][2]) if cols > 1 else 0
|
|
1707
|
+
row_gap = 0
|
|
1708
|
+
if len(rows) > 1:
|
|
1709
|
+
row_gap = round(rows[1][0]['box'][1]
|
|
1710
|
+
- (rows[0][0]['box'][1] + rows[0][0]['box'][3]))
|
|
1711
|
+
out.append({'kind': 'grid', 'cols': cols, 'gap': [max(col_gap, 0), max(row_gap, 0)],
|
|
1712
|
+
'items': rows[0]})
|
|
1713
|
+
elif len(rows) == len(reg):
|
|
1714
|
+
# 每行一个元素 = 真的竖着排
|
|
1715
|
+
inner = 0
|
|
1716
|
+
if len(reg) > 1:
|
|
1717
|
+
inner = round(reg[1]['box'][1] - (reg[0]['box'][1] + reg[0]['box'][3]))
|
|
1718
|
+
out.append({'kind': 'stack', 'gap': max(inner, 0), 'items': reg})
|
|
1719
|
+
else:
|
|
1720
|
+
# 每行元素数不一致(比如左列两张、右列一张跨两行)。硬说成 stack 会让消费端
|
|
1721
|
+
# 以为它们是竖排的,比不给还糟。如实说这块推不出规整结构,按坐标摆。
|
|
1722
|
+
out.append({'kind': 'free', 'items': reg})
|
|
1723
|
+
if fixed:
|
|
1724
|
+
out.append({'kind': 'free', 'items': fixed})
|
|
1725
|
+
if len(out) < 2:
|
|
1726
|
+
return None
|
|
1727
|
+
lefts = [s['box'][0] for s in items]
|
|
1728
|
+
rights = [s['box'][0] + s['box'][2] for s in items]
|
|
1729
|
+
return {'top': items[0]['box'][1], 'margin': [min(lefts), cW - max(rights)],
|
|
1730
|
+
'gap': round(cut), 'regions': out}
|
|
1731
|
+
|
|
1732
|
+
|
|
1733
|
+
def box_contains(outer, inner):
|
|
1734
|
+
return (outer[0] <= inner[0] and outer[1] <= inner[1]
|
|
1735
|
+
and outer[0] + outer[2] >= inner[0] + inner[2]
|
|
1736
|
+
and outer[1] + outer[3] >= inner[1] + inner[3])
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
def boxes_overlap(a, b):
|
|
1740
|
+
return (min(a[0] + a[2], b[0] + b[2]) > max(a[0], b[0])
|
|
1741
|
+
and min(a[1] + a[3], b[1] + b[3]) > max(a[1], b[1]))
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
def overlap_ratio(outer, inner):
|
|
1745
|
+
width = min(outer[0] + outer[2], inner[0] + inner[2]) - max(outer[0], inner[0])
|
|
1746
|
+
height = min(outer[1] + outer[3], inner[1] + inner[3]) - max(outer[1], inner[1])
|
|
1747
|
+
if width <= 0 or height <= 0 or inner[2] <= 0 or inner[3] <= 0:
|
|
1748
|
+
return 0
|
|
1749
|
+
return width * height / (inner[2] * inner[3])
|
|
1750
|
+
|
|
1751
|
+
|
|
1752
|
+
def group_flow_cards(slots, containers):
|
|
1753
|
+
"""把并列卡片容器及其文字组成一层 group,避免拍平成多列元素。"""
|
|
1754
|
+
candidates = []
|
|
1755
|
+
for container in containers:
|
|
1756
|
+
children = [slot for slot in slots if box_contains(container['box'], slot['box'])]
|
|
1757
|
+
if len(children) >= 2:
|
|
1758
|
+
candidates.append((container, children))
|
|
1759
|
+
selected = []
|
|
1760
|
+
for container, children in sorted(
|
|
1761
|
+
candidates, key=lambda pair: pair[0]['box'][2] * pair[0]['box'][3]):
|
|
1762
|
+
if not any(boxes_overlap(container['box'], other['box']) for other, _ in selected):
|
|
1763
|
+
selected.append((container, children))
|
|
1764
|
+
if len(selected) < 2:
|
|
1765
|
+
return slots + containers
|
|
1766
|
+
|
|
1767
|
+
grouped_slots = {id(slot) for _, children in selected for slot in children}
|
|
1768
|
+
nested_by_container = {}
|
|
1769
|
+
for container, _ in selected:
|
|
1770
|
+
nested_by_container[id(container)] = [
|
|
1771
|
+
other for other in containers
|
|
1772
|
+
if other is not container and overlap_ratio(container['box'], other['box']) >= 0.9
|
|
1773
|
+
]
|
|
1774
|
+
grouped_containers = {
|
|
1775
|
+
id(container)
|
|
1776
|
+
for container, _ in selected
|
|
1777
|
+
for container in [container] + nested_by_container[id(container)]
|
|
1778
|
+
}
|
|
1779
|
+
out = [slot for slot in slots if id(slot) not in grouped_slots]
|
|
1780
|
+
out += [container for container in containers if id(container) not in grouped_containers]
|
|
1781
|
+
for container, children in selected:
|
|
1782
|
+
children = children + nested_by_container[id(container)]
|
|
1783
|
+
children = sorted(children, key=lambda slot: (slot['box'][1], slot['box'][0]))
|
|
1784
|
+
gaps = [children[i + 1]['box'][1]
|
|
1785
|
+
- (children[i]['box'][1] + children[i]['box'][3])
|
|
1786
|
+
for i in range(len(children) - 1)]
|
|
1787
|
+
outer = container['box']
|
|
1788
|
+
insets = [
|
|
1789
|
+
min(child['box'][1] - outer[1] for child in children),
|
|
1790
|
+
min(outer[0] + outer[2] - child['box'][0] - child['box'][2] for child in children),
|
|
1791
|
+
min(outer[1] + outer[3] - child['box'][1] - child['box'][3] for child in children),
|
|
1792
|
+
min(child['box'][0] - outer[0] for child in children),
|
|
1793
|
+
]
|
|
1794
|
+
padding = max(0, round(min(insets)))
|
|
1795
|
+
css = container.get('css') or ''
|
|
1796
|
+
if padding:
|
|
1797
|
+
css = '; '.join(part for part in (
|
|
1798
|
+
css.rstrip('; '), 'box-sizing: border-box', 'padding: %dpx' % padding) if part)
|
|
1799
|
+
out.append({
|
|
1800
|
+
'role': 'group',
|
|
1801
|
+
'type': 'group',
|
|
1802
|
+
'box': outer,
|
|
1803
|
+
'css': css,
|
|
1804
|
+
'gap': max(0, round(min(gaps))) if gaps else 0,
|
|
1805
|
+
'items': children,
|
|
1806
|
+
})
|
|
1807
|
+
return out
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
def structure_facts(archetypes, d, shapes):
|
|
1811
|
+
"""每个页型的**结构事实**:栅格、垂直间距序列、容器样式配方、样张里的实际字数。
|
|
1812
|
+
|
|
1813
|
+
这些是判「该用绝对坐标还是流式」的依据,脚本只测不判:
|
|
1814
|
+
- 栅格拟合好不好,决定这页是不是一个规整的多列区带
|
|
1815
|
+
- 垂直间距序列里的突变点,就是区带的边界(网格内部 24、区带之间 110)
|
|
1816
|
+
- 样张字数说明这个框是按几行内容设计的——框高本身看不出这件事
|
|
1817
|
+
"""
|
|
1818
|
+
q = _load_query()
|
|
1819
|
+
by_part = defaultdict(list)
|
|
1820
|
+
for s in shapes:
|
|
1821
|
+
by_part[s.get('part')].append(s)
|
|
1822
|
+
|
|
1823
|
+
# 容器样式配方:跨全档聚类一次,记出现次数与跨页数,供判断「哪些是共性风格」
|
|
1824
|
+
groups = {}
|
|
1825
|
+
for s in shapes:
|
|
1826
|
+
fill, line, fx = s.get('fill'), s.get('line'), s.get('effects')
|
|
1827
|
+
if not fill and not line and not fx:
|
|
1828
|
+
continue
|
|
1829
|
+
if isinstance(fill, dict) and fill.get('type') == 'image':
|
|
1830
|
+
continue
|
|
1831
|
+
k = q._sig(fill, line, fx)
|
|
1832
|
+
if k[0] == 'none' and k[1] == 'none' and not k[2]:
|
|
1833
|
+
continue
|
|
1834
|
+
g = groups.setdefault(k, {'n': 0, 'parts': set(), 'radii': [],
|
|
1835
|
+
'fill': fill, 'line': line, 'fx': fx, 'shapes': set()})
|
|
1836
|
+
g['n'] += 1
|
|
1837
|
+
g['parts'].add(s.get('part'))
|
|
1838
|
+
g['radii'].append(s.get('radius_px') or 0)
|
|
1839
|
+
g['shapes'].add(id(s))
|
|
1840
|
+
ranked = sorted(groups.values(), key=lambda g: -g['n'])
|
|
1841
|
+
recipe_id = {}
|
|
1842
|
+
recipes = []
|
|
1843
|
+
for i, g in enumerate(ranked, 1):
|
|
1844
|
+
rid = 'r%d' % i
|
|
1845
|
+
css = [re.sub(r'\s*\n\s*', ' ', c.split('\x00')[0]).strip()
|
|
1846
|
+
for c in q._recipe_css(g['fill'], g['line'], g['radii'], g['fx']) if c]
|
|
1847
|
+
recipes.append({'id': rid, 'n': g['n'], 'pages': len(g['parts']),
|
|
1848
|
+
'css': '; '.join(css)})
|
|
1849
|
+
for sid in g['shapes']:
|
|
1850
|
+
recipe_id[sid] = rid
|
|
1851
|
+
|
|
1852
|
+
grids = (d.get('spacing_candidates') or {}).get('grids') or []
|
|
1853
|
+
grid_by_part = defaultdict(list)
|
|
1854
|
+
for gd in grids:
|
|
1855
|
+
grid_by_part[gd.get('part')].append(gd)
|
|
1856
|
+
|
|
1857
|
+
out = {}
|
|
1858
|
+
for a in archetypes:
|
|
1859
|
+
part = None
|
|
1860
|
+
if a.get('source', '').startswith('layout:'):
|
|
1861
|
+
part = 'ppt/slideLayouts/' + a['source'].split(':', 1)[1]
|
|
1862
|
+
elif a.get('rep'):
|
|
1863
|
+
part = 'ppt/slides/slide%d.xml' % a['rep']
|
|
1864
|
+
boxes = [s['box'] for s in a['slots']] + [x['box'] for x in (a.get('decor') or [])]
|
|
1865
|
+
boxes.sort(key=lambda b: b[1])
|
|
1866
|
+
gaps = [boxes[i + 1][1] - (boxes[i][1] + boxes[i][3]) for i in range(len(boxes) - 1)]
|
|
1867
|
+
chars = [(s['box'], len(s.get('txt') or '')) for s in a['slots'] if s.get('txt')]
|
|
1868
|
+
used = []
|
|
1869
|
+
for s in by_part.get(part, []):
|
|
1870
|
+
rid = recipe_id.get(id(s))
|
|
1871
|
+
if rid and rid not in used:
|
|
1872
|
+
used.append(rid)
|
|
1873
|
+
out[a['name']] = {'grids': grid_by_part.get(part) or [], 'gaps': gaps,
|
|
1874
|
+
'chars': chars, 'recipes': used}
|
|
1875
|
+
return out, recipes
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
def emit_layouts(archetypes, ldir, busy_hints=None, facts=None, recipes=None):
|
|
1879
|
+
prefilled = sum(1 for a in archetypes if a.get('zh'))
|
|
1880
|
+
L = ['# 判断单草案 —— package.py 读它产出 layouts.md,deck 的版式坐标从 layouts.md 读。',
|
|
1881
|
+
'# 只改 names / roles / text_roles / layout_modes / bg_rules 五段(都是扁平键值,'
|
|
1882
|
+
'改完 package.py 自动并回各页型)。',
|
|
1883
|
+
'# 下面 layouts 段是普查数值,一个字都不要动——改它容易连带删掉 slots/confidence。']
|
|
1884
|
+
if prefilled:
|
|
1885
|
+
L.append('# names 已按模板自带的版式名填好 %d 条,读一遍确认表意即可,通常不用改。' % prefilled)
|
|
1886
|
+
if recipes:
|
|
1887
|
+
L.append('# 容器样式配方(按出现次数排;跨页数多 = 共性风格,只在一处出现的多半不是):')
|
|
1888
|
+
for r in recipes[:8]:
|
|
1889
|
+
L.append('# %s 出现 %d 次 / 跨 %d 处 %s' % (r['id'], r['n'], r['pages'], r['css']))
|
|
1890
|
+
L.append('names:')
|
|
698
1891
|
for a in archetypes:
|
|
699
|
-
|
|
1892
|
+
if a.get('zh'):
|
|
1893
|
+
# 模板自己给版式起了名(form=3),直接用——比看图起名准,也省掉一轮判断
|
|
1894
|
+
L.append(' %s: %s' % (a['name'], q(a['zh'])))
|
|
1895
|
+
else:
|
|
1896
|
+
L.append(' %s: TODO中文名(代表页 %s,共 %d 页)'
|
|
1897
|
+
% (a['name'], a['rep'], len(a['pages'])))
|
|
1898
|
+
# 角色(封面 / 章节页 / 内容页……)是看图才能下的结论,脚本不猜。模板自己按页型
|
|
1899
|
+
# 命名时用它的标注,否则连同客观事实一起摆出来,由看得到重建图的你来定。
|
|
1900
|
+
need_role = [a for a in archetypes if not a.get('role')]
|
|
1901
|
+
if need_role:
|
|
1902
|
+
L.append('roles: # 取值 cover|section|content|quote|closing|blank|custom')
|
|
1903
|
+
for a in need_role:
|
|
1904
|
+
szs = sorted({round(s['sz']) for s in a['slots'] if s.get('sz')}, reverse=True)
|
|
1905
|
+
L.append(' %s: TODO角色 # 代表页 %s,共 %d 页;文字块 %d 个,字号 %s;'
|
|
1906
|
+
'图片 %d 张%s'
|
|
1907
|
+
% (a['name'], a['rep'], len(a['pages']),
|
|
1908
|
+
len([s for s in a['slots'] if not s.get('asset')]),
|
|
1909
|
+
'/'.join(str(x) for x in szs[:5]) or '未声明',
|
|
1910
|
+
a.get('pic_n') or 0, ';有满屏底图' if a.get('bg_raw') else ''))
|
|
1911
|
+
text_role_ids = {}
|
|
1912
|
+
for a in archetypes:
|
|
1913
|
+
index = 0
|
|
1914
|
+
for slot in a.get('slots') or []:
|
|
1915
|
+
if not slot.get('_needs_role'):
|
|
1916
|
+
continue
|
|
1917
|
+
index += 1
|
|
1918
|
+
text_role_ids[id(slot)] = '%s-text-%d' % (a['name'], index)
|
|
1919
|
+
if text_role_ids:
|
|
1920
|
+
L.append('text_roles: # 取值 title|subtitle|header|footer|body;只改角色,不删槽')
|
|
1921
|
+
for a in archetypes:
|
|
1922
|
+
for slot in a.get('slots') or []:
|
|
1923
|
+
role_id = text_role_ids.get(id(slot))
|
|
1924
|
+
if not role_id:
|
|
1925
|
+
continue
|
|
1926
|
+
L.append(' %s: TODO文本角色 # 来源 %s;占位符 %s;样例 %s;'
|
|
1927
|
+
'box %s;字号 %s;css %s'
|
|
1928
|
+
% (role_id, slot.get('_source_layer') or '-',
|
|
1929
|
+
slot.get('_placeholder') or '-', q(slot.get('txt') or ''),
|
|
1930
|
+
slot.get('box'), round(slot.get('sz') or 0),
|
|
1931
|
+
q(slot.get('css') or '未声明')))
|
|
1932
|
+
flow_archetypes = [a for a in archetypes if a.get('flow')]
|
|
1933
|
+
if flow_archetypes:
|
|
1934
|
+
L.append('layout_modes: # 取值 flow|slots;内容会变的内容页优先 flow,固定构图页用 slots')
|
|
1935
|
+
for a in flow_archetypes:
|
|
1936
|
+
L.append(' %s: TODO布局模式 # 依据见 layouts 段该页型上方的结构事实' % a['name'])
|
|
1937
|
+
# 禁放区是**背景图**的属性,不是页型的属性——按背景资产分组,页型再多也不涨
|
|
1938
|
+
bgs = []
|
|
1939
|
+
for a in archetypes:
|
|
1940
|
+
if a['bg'] and a['bg'] not in bgs:
|
|
1941
|
+
bgs.append(a['bg'])
|
|
1942
|
+
if bgs:
|
|
1943
|
+
L.append('bg_rules:')
|
|
1944
|
+
for bg in bgs:
|
|
1945
|
+
users = [a['name'] for a in archetypes if a['bg'] == bg]
|
|
1946
|
+
L.append(' %s: # 用它的页型:%s' % (bg, ', '.join(users)))
|
|
1947
|
+
hint = (busy_hints or {}).get(bg)
|
|
1948
|
+
if hint:
|
|
1949
|
+
L.append(' # 图像局部对比度:中位 %s、九分位 %s;%s'
|
|
1950
|
+
% (hint['median'], hint['p90'],
|
|
1951
|
+
('更花的一片在 %s' % hint['busy']) if hint.get('busy')
|
|
1952
|
+
else hint.get('why', '')))
|
|
1953
|
+
# text_safe 不是判断题:模板自己已经把文字放在哪儿写死了。取用这张背景的
|
|
1954
|
+
# 所有页型的槽与装饰件的外接并集即可——让人看图猜只会猜得更松,把模板从不
|
|
1955
|
+
# 放字的区域也划进安全区,这个字段就白设了。
|
|
1956
|
+
boxes = [s['box'] for a in archetypes if a['bg'] == bg for s in a['slots']] + \
|
|
1957
|
+
[dcr['box'] for a in archetypes if a['bg'] == bg for dcr in (a.get('decor') or [])]
|
|
1958
|
+
if boxes:
|
|
1959
|
+
x0 = min(b[0] for b in boxes)
|
|
1960
|
+
y0 = min(b[1] for b in boxes)
|
|
1961
|
+
x1 = max(b[0] + b[2] for b in boxes)
|
|
1962
|
+
y1 = max(b[1] + b[3] for b in boxes)
|
|
1963
|
+
L.append(' text_safe: [%d, %d, %d, %d] # 由该背景各页型的槽位并集算出'
|
|
1964
|
+
% (x0, y0, x1 - x0, y1 - y0))
|
|
1965
|
+
else:
|
|
1966
|
+
L.append(' text_safe: TODO安全文字区[x,y,w,h](该背景下没有任何槽位可依据)')
|
|
1967
|
+
L.append(' avoid: TODO禁放区列表;无禁放区写 [],有则写 [{box: [x,y,w,h], reason: "..."}]')
|
|
1968
|
+
L.append(' pairing_rule: "TODO这张背景上标题/正文/图表要避让哪些区域"')
|
|
700
1969
|
L.append('layouts:')
|
|
701
1970
|
for a in archetypes:
|
|
1971
|
+
fx = (facts or {}).get(a['name']) or {}
|
|
1972
|
+
if fx:
|
|
1973
|
+
# 结构事实:判「这页该用绝对坐标还是流式」的依据。脚本只测不判。
|
|
1974
|
+
for gd in (fx.get('grids') or [])[:2]:
|
|
1975
|
+
c, r = gd.get('cols') or {}, gd.get('rows') or {}
|
|
1976
|
+
L.append(' # 栅格:%s 列%s%s' % (
|
|
1977
|
+
c.get('n'), ' @%gpx 步距方差 %.2f' % (c.get('pitch') or 0, c.get('sd') or 0)
|
|
1978
|
+
if c.get('regular') else '(列不规整)',
|
|
1979
|
+
',行 %s' % (('%d @%gpx' % (r.get('n') or 0, r.get('pitch') or 0))
|
|
1980
|
+
if r.get('regular') else '不规整')))
|
|
1981
|
+
if fx.get('gaps'):
|
|
1982
|
+
L.append(' # 垂直间距:%s(突变处即区带边界)'
|
|
1983
|
+
% '、'.join(str(int(g)) for g in fx['gaps'][:10]))
|
|
1984
|
+
if fx.get('chars'):
|
|
1985
|
+
L.append(' # 样张字数:%s'
|
|
1986
|
+
% '、'.join('%s=%d字' % (b, n) for b, n in fx['chars'][:6]))
|
|
1987
|
+
if fx.get('recipes'):
|
|
1988
|
+
L.append(' # 命中配方:%s' % '、'.join(fx['recipes'][:4]))
|
|
1989
|
+
# 槽与槽在坐标上重叠:PPT 里占位符互相压是常态(文字 valign 居中、样张只有一行,
|
|
1990
|
+
# 看不出来),照抄坐标做成 HTML 后内容一变长就撞。实测封面 title 框比 subtitle
|
|
1991
|
+
# 的顶还低 41px,两行标题直接压在副标题上。这里只报事实,怎么让开由你定。
|
|
1992
|
+
ov = slot_overlaps(a.get('slots') or [])
|
|
1993
|
+
if ov:
|
|
1994
|
+
L.append(' # 槽位重叠:%s(模板里靠文字居中不显形,内容变长会撞)'
|
|
1995
|
+
% '、'.join(ov[:3]))
|
|
702
1996
|
L.append(' %s:' % a['name'])
|
|
703
|
-
|
|
1997
|
+
if a.get('role'):
|
|
1998
|
+
L.append(' role: %s' % a['role'])
|
|
704
1999
|
if a['bg']:
|
|
705
2000
|
L.append(' background: %s' % a['bg'])
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
L.append('
|
|
2001
|
+
fl = a.get('flow')
|
|
2002
|
+
if fl:
|
|
2003
|
+
L.append(' flow:')
|
|
2004
|
+
L.append(' top: %d' % fl['top'])
|
|
2005
|
+
L.append(' margin: [%d, %d]' % tuple(fl['margin']))
|
|
2006
|
+
L.append(' gap: %d' % fl['gap'])
|
|
2007
|
+
L.append(' regions:')
|
|
2008
|
+
for r in fl['regions']:
|
|
2009
|
+
if r['kind'] == 'grid':
|
|
2010
|
+
L.append(' - kind: grid')
|
|
2011
|
+
L.append(' cols: %d' % r['cols'])
|
|
2012
|
+
L.append(' gap: [%d, %d]' % tuple(r['gap']))
|
|
2013
|
+
elif r['kind'] == 'free':
|
|
2014
|
+
L.append(' - kind: free # 推不出规整结构,按 slots 的坐标摆')
|
|
2015
|
+
else:
|
|
2016
|
+
L.append(' - kind: stack')
|
|
2017
|
+
L.append(' gap: %d' % r['gap'])
|
|
2018
|
+
L.append(' items:')
|
|
2019
|
+
for s in r['items']:
|
|
2020
|
+
if s.get('type') == 'group':
|
|
2021
|
+
L.append(' - role: group')
|
|
2022
|
+
L.append(' gap: %d' % s['gap'])
|
|
2023
|
+
if s.get('css'):
|
|
2024
|
+
L.append(' css: "%s"'
|
|
2025
|
+
% str(s['css']).replace('"', "'"))
|
|
2026
|
+
L.append(' items:')
|
|
2027
|
+
for child in s['items']:
|
|
2028
|
+
role_id = text_role_ids.get(id(child))
|
|
2029
|
+
if role_id:
|
|
2030
|
+
L.append(' # text-role: %s' % role_id)
|
|
2031
|
+
if child.get('type') == 'decor':
|
|
2032
|
+
L.append(' - {role: container, css: "%s"}'
|
|
2033
|
+
% str(child.get('css') or '').replace('"', "'"))
|
|
2034
|
+
continue
|
|
2035
|
+
extra = ''
|
|
2036
|
+
if child.get('css') is not None:
|
|
2037
|
+
extra += ', css: "%s"' % str(child['css']).replace('"', "'")
|
|
2038
|
+
if child.get('asset'):
|
|
2039
|
+
extra += ', asset: %s' % child['asset']
|
|
2040
|
+
L.append(' - {role: %s, type: %s%s}'
|
|
2041
|
+
% (child['role'], child['type'], extra))
|
|
2042
|
+
continue
|
|
2043
|
+
role_id = text_role_ids.get(id(s))
|
|
2044
|
+
if role_id:
|
|
2045
|
+
L.append(' # text-role: %s' % role_id)
|
|
2046
|
+
# free 区带按坐标摆,而 slots 会被删掉,所以坐标必须写在这里
|
|
2047
|
+
bx = ', box: %s' % s['box'] if r['kind'] == 'free' else ''
|
|
2048
|
+
if s.get('type') == 'decor':
|
|
2049
|
+
L.append(' - {role: container%s, css: "%s"}'
|
|
2050
|
+
% (bx, (s.get('css') or '').replace('"', "'")))
|
|
2051
|
+
continue
|
|
2052
|
+
extra = bx
|
|
2053
|
+
if s.get('css') is not None:
|
|
2054
|
+
# CSS 串一律加引号:里面的逗号/冒号在 flow map 里是分隔符
|
|
2055
|
+
extra += ', css: "%s"' % str(s['css']).replace('"', "'")
|
|
2056
|
+
if s.get('asset'):
|
|
2057
|
+
extra += ', asset: %s' % s['asset']
|
|
2058
|
+
L.append(' - {role: %s, type: %s%s}' % (s['role'], s['type'], extra))
|
|
709
2059
|
L.append(' slots:')
|
|
710
2060
|
for s in a['slots']:
|
|
711
|
-
|
|
2061
|
+
role_id = text_role_ids.get(id(s))
|
|
2062
|
+
if role_id:
|
|
2063
|
+
L.append(' # text-role: %s' % role_id)
|
|
2064
|
+
extra = ''
|
|
2065
|
+
if s.get('asset'):
|
|
2066
|
+
extra += ', asset: %s' % s['asset']
|
|
2067
|
+
if s.get('css') is not None:
|
|
2068
|
+
extra += ', css: "%s"' % str(s['css']).replace('"', "'")
|
|
2069
|
+
L.append(' - {role: %s, box: %s, type: %s%s}'
|
|
2070
|
+
% (s['role'], s['box'], s['type'], extra))
|
|
2071
|
+
if a.get('decor'):
|
|
2072
|
+
L.append(' decor:')
|
|
2073
|
+
for dcr in a['decor']:
|
|
2074
|
+
L.append(' - {box: %s, geom: %s, css: "%s"}'
|
|
2075
|
+
% (dcr['box'], dcr['geom'], dcr['css'].replace('"', "'")))
|
|
712
2076
|
L.append(' confidence: %s' % a.get('confidence', 'medium'))
|
|
713
2077
|
write(os.path.join(ldir, 'layouts.yaml'), '\n'.join(L) + '\n')
|
|
714
2078
|
|
|
715
2079
|
|
|
716
|
-
def emit_body(d, tokens, fonts, roles, assets, archetypes, exceptions, ldir):
|
|
2080
|
+
def emit_body(d, tokens, fonts, roles, assets, archetypes, exceptions, cusage, ldir):
|
|
2081
|
+
"""design.md 正文。
|
|
2082
|
+
|
|
2083
|
+
每条规则只出现一次——同一条散在 Fast Path / Usage / Background Safety /
|
|
2084
|
+
Hard Rules 各写一遍时措辞必然漂移,消费端无法判断哪份权威。
|
|
2085
|
+
坐标、字号、色值、资产位置的权威都在 layouts.md;本文件只给色板、字体栈与纪律。
|
|
2086
|
+
"""
|
|
717
2087
|
canvas = d['canvas']['px']
|
|
718
2088
|
cover = next((a for a in assets if a['id'] == 'bg-cover'), None)
|
|
719
2089
|
logo = next((a for a in assets if a['kind'] == 'logo'), None)
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
'
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
'1. **挑版式** —— 打开 `layouts.md`,按用途选一个 archetype,`slots[].box` 的 `[x, y, w, h]` 是 %dx%d 画布上的绝对像素,直接照搬,不要自己排版;同时遵守该 archetype 的 `text_safe` 和 `avoid`。'
|
|
768
|
-
% (canvas[0], canvas[1])]
|
|
769
|
-
if assets:
|
|
770
|
-
L.append('2. **铺资产** —— 背景和标识只用 `assets/` 里的文件,见下表;不要自造渐变或重画 logo。背景必须和版式配对,文字必须留在安全区内。')
|
|
771
|
-
else:
|
|
772
|
-
L.append('2. **铺背景** —— 本包无图片资产,背景用 `colors` 里的底色。')
|
|
773
|
-
L += ['3. **填色与字** —— 颜色只从 frontmatter 的 `colors` 取,字号只从 `typography` 取。', '']
|
|
2090
|
+
imp, webs = import_line(fonts)
|
|
2091
|
+
sidecar = '`layouts.md`'
|
|
2092
|
+
|
|
2093
|
+
L = ['## Overview', '',
|
|
2094
|
+
'TODO: 两三句话讲清这套模板的性格与适用场景——看过联系表和页面重建图之后再写。', '']
|
|
2095
|
+
L.append(('模板自带 %d 种版式,页型、坐标和 CSS 样式都直读自版式层。'
|
|
2096
|
+
% len(archetypes)) if (d.get('form_hint') or {}).get('form') == 3 else
|
|
2097
|
+
('%d 页样张归纳出 %d 种页型。' % (d['counts']['slides'], len(archetypes))))
|
|
2098
|
+
L += ['', '## Usage', '',
|
|
2099
|
+
'搭一页 PPT 六步,中间四步的数据都在 %s:' % sidecar, '']
|
|
2100
|
+
L += ['1. **定画布** —— 舞台按 `layouts.md` 的 `canvas` 设成 %d×%d,'
|
|
2101
|
+
'别套用默认尺寸:源模板的长宽比不一定是 16:9,套错了整页坐标全偏。'
|
|
2102
|
+
'舞台尺寸改不了时,整体等比缩放 `min(舞台宽/%d, 舞台高/%d)` 后居中留白——'
|
|
2103
|
+
'逐轴拉伸会把圆压成椭圆、把字挤扁。' % (canvas[0], canvas[1], canvas[0], canvas[1]),
|
|
2104
|
+
'2. **挑页型** —— 在 %s 里按用途选一个 archetype(清单见下面 Layouts 段)。'
|
|
2105
|
+
'页数多于页型时,挑最接近的一个原样套用它的 slot:用不到的槽删掉,'
|
|
2106
|
+
'内容比槽多就按同类槽的间距等距加,**坐标一律沿用该页型给的那套,不要自己另起网格**。'
|
|
2107
|
+
% sidecar,
|
|
2108
|
+
'3. **按页型给的形态落元素** —— 页型给 `flow` 就用流式,给 `slots` 就用绝对,'
|
|
2109
|
+
'两者只会出现一个。'
|
|
2110
|
+
'**flow**:整块用一个纵向 flex 容器,`top` 是它的起始 y,`margin` 是左右边距,'
|
|
2111
|
+
'`gap` 是区带之间的间距;`regions` 从上往下依次排,**每个区带的高度由它自己的'
|
|
2112
|
+
'内容决定,不要写死高度**——上面的区带内容变多时,下面的自然被推下去,这正是'
|
|
2113
|
+
'这套表达要解决的事。区带内部:`kind: grid` 用 `grid-template-columns: repeat(cols, 1fr)` '
|
|
2114
|
+
'配 `gap: [行间距, 列间距]`;`kind: stack` 用纵向 flex 配 `gap`;`kind: free` '
|
|
2115
|
+
'按 item 自带的 `box` 绝对定位。`grid` 里的 `role: group` 是一张卡片:'
|
|
2116
|
+
'group 的 `css` 用于外层容器,内部 `items` 按顺序纵向排布并使用 group 的 `gap`。'
|
|
2117
|
+
'每个 `role: container` 的项是容器,把它的 `css` 逐项原样写进 style,内容放进去;'
|
|
2118
|
+
'其中没有 `border-radius` 就按 `0`,不得自行补圆角。',
|
|
2119
|
+
'4. **按 slot 落元素(页型给的是 slots 时)** —— 每个 slot 渲染成一个绝对定位元素:`box` 是 '
|
|
2120
|
+
'`[x, y, w, h]`(%dx%d 画布上的绝对像素),机械展开成 `left/top/width/height`;'
|
|
2121
|
+
'slot 的 `css` 是模板排版属性已转译好的声明串,原样写进 style,不要另选字号、'
|
|
2122
|
+
'内边距、颜色或对齐。'
|
|
2123
|
+
'带 `asset` 的 slot 是图片元素(logo、角标),把该资产放在它自己的 `box` 里;'
|
|
2124
|
+
'这个页型没有 `asset` 槽,这一页就不出现该资产。' % (canvas[0], canvas[1]),
|
|
2125
|
+
'5. **铺装饰几何** —— 页型的 `decor` 是这一页的图形骨架(图标托底的圆、'
|
|
2126
|
+
'卡片、分隔线):每条渲染成一个绝对定位空元素,`box` 给位置,`css` 逐项原样写进 '
|
|
2127
|
+
'style;没有 `border-radius` 就按 `0`。只有 `geom: ellipse` 另加 '
|
|
2128
|
+
'`border-radius: 50%`。它们压在背景之上、slot 之下,'
|
|
2129
|
+
'落在 slot 上的图标正是靠它们托住。',
|
|
2130
|
+
'6. **落实全局设计** —— `design.md` frontmatter 的 `colors`、`typography`、'
|
|
2131
|
+
'`spacing`、`rounded`、`components` 是全局 token;用 CSS variables、类名或内联'
|
|
2132
|
+
'样式承载。局部 slot / decor 的 `css` 优先,不能再解释成另一套视觉系统。'
|
|
2133
|
+
'字体使用 Typography 的完整栈与降级,不在运行时安装字体或依赖。',
|
|
2134
|
+
'7. **保持标题结构** —— 有合适页型可参考时,沿用该页型已有的标题层级与局部 '
|
|
2135
|
+
'`css`;只渲染该页型已有的文字槽,背景中已经可见的固定标题不再创建文本,'
|
|
2136
|
+
'页型没有 `subtitle` 槽就不新增副标题。没有合适参考时,按本包整体视觉组织标题。']
|
|
774
2137
|
if assets:
|
|
775
|
-
L += ['
|
|
776
|
-
|
|
777
|
-
'
|
|
778
|
-
|
|
779
|
-
|
|
2138
|
+
L += ['', '资产文件(背景由页型的 `background` 字段指定,'
|
|
2139
|
+
'图片资产的位置由该页型 `slots` 里带 `asset` 的槽给出):', '',
|
|
2140
|
+
'{{ASSET_TABLE}}', '',
|
|
2141
|
+
'将包内 `assets/` 复制到项目内相对目录,再引用复制后的路径;最终 HTML 不引用'
|
|
2142
|
+
'抽取工作目录或本机绝对路径。附件只提供 `assetRoot` / `assetPaths` 时,把'
|
|
2143
|
+
'`assetRoot` 当作不透明前缀,只拼接清单中声明的相对路径。']
|
|
2144
|
+
L += ['', '文字与容器的外接矩形落在该页型 `background` 对应的 `text_safe` 内,'
|
|
2145
|
+
'避开 `avoid` 列出的区域(两者都在 %s 的 `backgrounds` 段)。内容装不下时换页型或拆页。'
|
|
2146
|
+
% sidecar, '',
|
|
780
2147
|
'## Colors', '', '| token | 值 | 用途 |', '|---|---|---|']
|
|
781
|
-
USE = {'surface': '页面与卡片主底色', 'surface-alt': '次级底色,分区/强调区块的浅底',
|
|
782
|
-
'ink': '正文与标题文字色', 'ink-muted': '次级文字色,说明与标签',
|
|
783
|
-
'primary': '主强调色:图表主序列、关键数字、行动点',
|
|
784
|
-
'accent': '副强调色,多与 primary 组成渐变',
|
|
785
|
-
'accent-2': '渐变与图表的第二落点色', 'accent-3': '渐变收尾色,用量最少',
|
|
786
|
-
'neutral': '中性弱化色:分隔线、次要标签'}
|
|
787
2148
|
for name, r in tokens:
|
|
788
|
-
L.append('| `%s` | `%s` | %s |'
|
|
789
|
-
|
|
2149
|
+
L.append('| `%s` | `%s` | %s |'
|
|
2150
|
+
% (name, r['hex'], usage_phrase(cusage.get(r['hex'].upper()))))
|
|
790
2151
|
L += ['', '## Typography', '']
|
|
791
2152
|
for f in fonts[:2]:
|
|
792
2153
|
L.append('- **%s** —— 栈 `%s`%s' % (
|
|
793
2154
|
f['names'][0], font_css(f['stack']),
|
|
794
2155
|
',源为商业/内部字体无 web 分发源,按气质降级到 %s' % f['stack'][1]
|
|
795
2156
|
if len(f['stack']) > 1 else ''))
|
|
796
|
-
L += ['', '字号轴:' + '、'.join('%s %dpx' % (k, round(v['sz_px'])) for k, v in roles.items())
|
|
2157
|
+
L += ['', '字号轴:' + '、'.join('%s %dpx' % (k, round(v['sz_px'])) for k, v in roles.items())
|
|
2158
|
+
+ '。slot 自带 `css` 时以其中的 `font-size` 为准;没有 slot CSS 的新增层级,'
|
|
2159
|
+
'复用轴上最接近的一档。', '',
|
|
797
2160
|
'字体加载(**HARD REQUIREMENT:下面这行 @import 原样写入全局样式首行,禁止替换为 '
|
|
798
2161
|
'fonts.googleapis.com 或其他域**):', '', '```', imp, '```', '',
|
|
799
|
-
'镜像只保证 wght 400
|
|
800
|
-
'系统字体 PingFang SC / Microsoft YaHei
|
|
801
|
-
'## Layouts', '',
|
|
802
|
-
'
|
|
803
|
-
|
|
804
|
-
L += ['', '## Hard Rules', '']
|
|
2162
|
+
'镜像只保证 wght 400 一档,更粗的字重由浏览器合成,字重不能作为唯一区分手段;'
|
|
2163
|
+
'系统字体 PingFang SC / Microsoft YaHei 置于栈末保底,中文场景负字距清零。', '',
|
|
2164
|
+
'## Layouts', '', '页型清单如下,每个页型的 slots、background、'
|
|
2165
|
+
'禁放区都在 %s:' % sidecar, '', '{{LAYOUT_LIST}}',
|
|
2166
|
+
'', '## Hard Rules', '']
|
|
805
2167
|
if cover:
|
|
806
|
-
L.append('-
|
|
807
|
-
% (canvas[0], canvas[1]))
|
|
2168
|
+
L.append('- 封面页铺满 `bg-cover`,整幅覆盖 %dx%d 画布。' % (canvas[0], canvas[1]))
|
|
808
2169
|
if any(a['role'] == 'content' for a in assets):
|
|
809
|
-
L.append('-
|
|
2170
|
+
L.append('- 内容页的背景由该页型的 `background` 字段指定,整幅铺满。')
|
|
810
2171
|
if logo:
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
2172
|
+
# 点名哪几个页型带 logo。只说「位置去 slots 里查」的话,读起来像是每个页型都有
|
|
2173
|
+
# 这个槽、去查就行——而「不放」是靠该页型 slots 里缺这一项来表达的,要消费端
|
|
2174
|
+
# 自己做否定式推理才能得出。正面点名比让它去发现缺席可靠。
|
|
2175
|
+
with_logo = [a['name'] for a in archetypes
|
|
2176
|
+
if any(str(s.get('asset') or '') == logo['id'] for s in a['slots'])]
|
|
2177
|
+
L.append('- `%s` 只出现在这些页型上:%s;其余页型不放。位置取该页型 `slots` 里 '
|
|
2178
|
+
'`role: logo` 那一项的 `box`,原样使用该文件、保持原比例。'
|
|
2179
|
+
% (logo['id'], '、'.join('`%s`' % x for x in with_logo) or '(无)'))
|
|
2180
|
+
L += ['- 坐标、字号、色值、资产位置以 %s 为准;本文件的 Colors / Typography 是可用值的清单。'
|
|
2181
|
+
% sidecar,
|
|
2182
|
+
'- 强调色族以 Colors 和 %s 的 slot CSS 为主;必要时可以使用 Colors 之外的颜色,'
|
|
2183
|
+
'但不能形成与模板主色竞争的第二强调色。' % sidecar,
|
|
2184
|
+
'- 新增颜色应与模板整体的色相、明度和饱和度关系协调。允许新增中性色、低彩度辅助色'
|
|
2185
|
+
'或局部语义色表达正负、风险、警告、状态、图表序列,但保持辅助层级;'
|
|
2186
|
+
'只要新色通过高饱和、高对比、大面积或跨页重复获得主视觉权重,'
|
|
2187
|
+
'或被用于标题、关键数字、图表主序列、卡片底色或渐变,就属于新的强调色,改用模板'
|
|
2188
|
+
'强调色族的深浅、透明度,或改用线型、纹理、标签区分。',
|
|
2189
|
+
'- 交付前逐页检查:色板、字体、版式、背景、资产和本段规则均来自本风格包;'
|
|
2190
|
+
'页面无资源加载失败、内容溢出或画幅裁切。',
|
|
2191
|
+
'- 本包里的数值就是普查结果,照用即可,无需重新统计颜色、字体或版式。',
|
|
2192
|
+
'- 风格包以文本形式(zip 摘要等)到手时,直接用摘要里 design.md / layouts.md 的文本。',
|
|
820
2193
|
'', '## Exceptions', '']
|
|
821
2194
|
if exceptions:
|
|
822
2195
|
L += ['- ' + e for e in exceptions]
|
|
@@ -828,31 +2201,57 @@ def emit_body(d, tokens, fonts, roles, assets, archetypes, exceptions, ldir):
|
|
|
828
2201
|
|
|
829
2202
|
def emit_brief(d, ctx, ldir):
|
|
830
2203
|
(tokens, rest, fonts, roles, assets, rejected, todos, archetypes, cands, sheet,
|
|
831
|
-
leftover, lsheet) = ctx
|
|
2204
|
+
leftover, lsheet, sheet_n) = ctx
|
|
832
2205
|
canvas = d['canvas']['px']
|
|
833
|
-
L = ['#
|
|
2206
|
+
L = ['# 抽取简报(第 1/3 步产物;改完草案跑 package.py 出包)', '',
|
|
834
2207
|
'源:`%s` 画布 %dx%d %d 页 / %d 版式 主题 %s form=%s'
|
|
835
2208
|
% (d['source']['filename'], canvas[0], canvas[1], d['counts']['slides'],
|
|
836
2209
|
d['counts']['layouts'], d['theme_topology']['themes'],
|
|
837
2210
|
d['form_hint']['form']), '',
|
|
838
2211
|
'## 待判断(草案里已标 TODO,逐条改掉)', '']
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
2212
|
+
# 待判断清单从草案实时扫 TODO 生成,不写死:写死的清单会和草案对不上——
|
|
2213
|
+
# 既漏掉后加的段(模型读到一半才发现还有活),又在草案已预填时还催人去填。
|
|
2214
|
+
HINT = {'manifest.yaml': '看两张图定气质',
|
|
2215
|
+
'layouts.yaml': '看 layout-sheet.png;layouts 段本身不要动',
|
|
2216
|
+
'body.md': 'Colors 用途列草案已填好,觉得不对再改'}
|
|
2217
|
+
for fn in ('manifest.yaml', 'body.md', 'layouts.yaml', 'frontmatter.yaml'):
|
|
2218
|
+
path = os.path.join(ldir, fn)
|
|
2219
|
+
if not os.path.exists(path):
|
|
2220
|
+
continue
|
|
2221
|
+
keys = []
|
|
2222
|
+
for line in open(path, encoding='utf-8'):
|
|
2223
|
+
if 'TODO' not in line:
|
|
2224
|
+
continue
|
|
2225
|
+
m = re.match(r'\s*[-#]?\s*([\w-]+):', line)
|
|
2226
|
+
keys.append(m.group(1) if m else line.strip()[:24])
|
|
2227
|
+
if not keys:
|
|
2228
|
+
continue
|
|
2229
|
+
seen, uniq = set(), []
|
|
2230
|
+
for k in keys:
|
|
2231
|
+
if k not in seen:
|
|
2232
|
+
seen.add(k)
|
|
2233
|
+
uniq.append(k)
|
|
2234
|
+
hint = HINT.get(fn)
|
|
2235
|
+
L.append('- `%s` %d 处:%s%s'
|
|
2236
|
+
% (fn, len(keys), '、'.join(uniq[:6]) + ('…' if len(uniq) > 6 else ''),
|
|
2237
|
+
'(%s)' % hint if hint else ''))
|
|
2238
|
+
for t in todos:
|
|
844
2239
|
L.append('- ' + t)
|
|
845
2240
|
L += ['', '## 联系表(一次看完所有候选图)', '',
|
|
846
|
-
'`l-out/contact-sheet.png` ——
|
|
2241
|
+
'`l-out/contact-sheet.png` —— 图格编号对应下表前几行;看完再决定 logo / 封面归属。' if sheet
|
|
847
2242
|
else '(Pillow 不可用,未生成联系表;逐张看 `media-out/`)', '',
|
|
848
2243
|
'| # | 文件 | 尺寸 | 出现 | 满屏 | 页 | 草案判定 |', '|---|---|---|---|---|---|---|']
|
|
849
2244
|
decided = {a['src']['file']: a['id'] for a in assets}
|
|
850
2245
|
why = {c['file']: r for c, r in rejected}
|
|
851
|
-
for i, c in enumerate(cands
|
|
2246
|
+
for i, c in enumerate(cands, 1):
|
|
852
2247
|
L.append('| %d | `%s` | %sx%s | %d | %s | %s | %s |' % (
|
|
853
2248
|
i, c['file'], c['probe'].get('w') or '?', c['probe'].get('h') or '?', c['n'],
|
|
854
2249
|
'Y' if c['fullscreen'] else '', ','.join(map(str, c['slides'][:6])) or 'layout',
|
|
855
2250
|
decided.get(c['file']) or ('✗ ' + why.get(c['file'], '未采纳'))))
|
|
2251
|
+
if len(cands) > sheet_n:
|
|
2252
|
+
L.append('')
|
|
2253
|
+
L.append('拼版图只含前 %d 张(第 %d 行之后的没有图格)。要看后面某张,'
|
|
2254
|
+
'按文件名直接看 `media-out/`。' % (sheet_n, sheet_n))
|
|
856
2255
|
L += ['', '## 颜色(草案 token 已写进 frontmatter.yaml)', '',
|
|
857
2256
|
'| token | hex | 出现 |', '|---|---|---|']
|
|
858
2257
|
for name, r in tokens:
|
|
@@ -878,7 +2277,7 @@ def emit_brief(d, ctx, ldir):
|
|
|
878
2277
|
if leftover:
|
|
879
2278
|
L += ['', '未归入 archetype 的页:%s —— 都是单页孤例,需要就自己补一个 archetype。'
|
|
880
2279
|
% ', '.join(map(str, leftover))]
|
|
881
|
-
L += ['', '各 archetype 的 slot
|
|
2280
|
+
L += ['', '各 archetype 的 slot 原文(据此起中文页型名,并在 text_roles 判断文本角色):', '']
|
|
882
2281
|
for a in archetypes:
|
|
883
2282
|
L.append('- `%s`(第 %s 页,覆盖 %s)' % (a['name'], a['rep'], a['pages']))
|
|
884
2283
|
for s in a['slots']:
|
|
@@ -898,20 +2297,94 @@ def main(argv=None):
|
|
|
898
2297
|
ldir = os.path.join(outdir, 'l-out')
|
|
899
2298
|
os.makedirs(ldir, exist_ok=True)
|
|
900
2299
|
|
|
901
|
-
|
|
2300
|
+
all_shapes = json.load(open(os.path.join(outdir, 'ref', 'shapes.json'),
|
|
2301
|
+
encoding='utf-8'))['shapes']
|
|
2302
|
+
cusage = color_usage(all_shapes, d)
|
|
2303
|
+
tokens, rest, rows = draft_colors(d, cusage)
|
|
902
2304
|
fonts = draft_fonts(d)
|
|
903
2305
|
archetypes, pages, leftover = draft_layouts(d, outdir)
|
|
2306
|
+
# 封面底图:form=3 的页型键就是角色名(cover/section/...),直接按名字取。
|
|
2307
|
+
# form=2 按样张聚类,键是 layout-1..N,永远匹配不上 'cover'——实测 vo-lite 因此
|
|
2308
|
+
# 一张 role: cover 都没有,封面主视觉被标成 bg-content-1,消费端拿不到封面资产,
|
|
2309
|
+
# design.md 的「封面底图必用 cover 资产」这条硬规则无从满足。回退到覆盖第 1 页的
|
|
2310
|
+
# 那个页型:deck 的第 1 页就是封面,这是版式无关的事实。
|
|
904
2311
|
cover_media = next((a['bg_raw'] for a in archetypes if a['name'] == 'cover'), None)
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
2312
|
+
if not cover_media:
|
|
2313
|
+
cover_media = next((a['bg_raw'] for a in archetypes
|
|
2314
|
+
if 1 in (a.get('pages') or ())), None)
|
|
2315
|
+
exported_media = {m['media'] for m in d.get('media', []) if m.get('exported')}
|
|
2316
|
+
bg_needed = {a['bg_raw'] for a in archetypes if a['bg_raw'] in exported_media}
|
|
2317
|
+
bg_under = {p['no']: p.get('rendered_bg') or p['bg_media'] for p in pages}
|
|
2318
|
+
assets, rejected, todos, alias, pool = draft_assets(d, outdir, bg_needed, cover_media, bg_under)
|
|
908
2319
|
media_to_asset = {a['src']['media']: a['id'] for a in assets}
|
|
2320
|
+
for m, w in (alias or {}).items():
|
|
2321
|
+
if w in media_to_asset:
|
|
2322
|
+
media_to_asset.setdefault(m, media_to_asset[w])
|
|
2323
|
+
|
|
2324
|
+
# 版式里那些贴在装饰容器上的小图(图标托底圆里的图标之类):不进包的话,消费端只看到
|
|
2325
|
+
# 一个空圆,只能自己编图形。它们是版式的一部分,按 icon 收进来。
|
|
2326
|
+
ICON_CAP = 12
|
|
2327
|
+
ICON_BUDGET = 3 * 1024 * 1024 # 图标是小件,占包体不该超过背景
|
|
2328
|
+
cW, cH = d['canvas']['px']
|
|
2329
|
+
icon_i, icon_bytes = 0, 0
|
|
2330
|
+
for a in archetypes:
|
|
2331
|
+
for s in a['slots']:
|
|
2332
|
+
m = s.get('media')
|
|
2333
|
+
if not m or media_to_asset.get(m) or media_to_asset.get(alias.get(m, m)):
|
|
2334
|
+
continue
|
|
2335
|
+
c = pool.get(alias.get(m, m)) or pool.get(m)
|
|
2336
|
+
if not c or not c.get('out') or icon_i >= ICON_CAP:
|
|
2337
|
+
continue
|
|
2338
|
+
if icon_bytes + (c.get('bytes') or 0) > ICON_BUDGET:
|
|
2339
|
+
continue
|
|
2340
|
+
if s['box'][2] > cW * 0.25 or s['box'][3] > cH * 0.25:
|
|
2341
|
+
continue # 不是图标,是内容配图,交给消费端自备
|
|
2342
|
+
icon_i += 1
|
|
2343
|
+
icon_bytes += c.get('bytes') or 0
|
|
2344
|
+
aid = 'icon-%d' % icon_i
|
|
2345
|
+
assets.append({'id': aid, 'kind': 'icon', 'role': None, 'src': c, 'use_full': False})
|
|
2346
|
+
media_to_asset[c['media']] = aid
|
|
2347
|
+
media_to_asset[m] = aid
|
|
2348
|
+
dropped_slots = []
|
|
909
2349
|
for a in archetypes:
|
|
910
2350
|
a['bg'] = media_to_asset.get(a['bg_raw'])
|
|
2351
|
+
# 版式自带的图片元素:映射到资产 id。映射不到时**保留槽位但不写 asset**——
|
|
2352
|
+
# 删掉整条槽,消费端看到的是一个没有图标的托底圆,和图标不进包是同一个失败模式,
|
|
2353
|
+
# 而且它连「这里本来有东西」都不知道。
|
|
2354
|
+
keep = []
|
|
2355
|
+
for s in a['slots']:
|
|
2356
|
+
if s.get('media'):
|
|
2357
|
+
aid = media_to_asset.get(s['media'])
|
|
2358
|
+
if not aid:
|
|
2359
|
+
s['role'] = 'icon'
|
|
2360
|
+
s.pop('media', None)
|
|
2361
|
+
dropped_slots.append((a['name'], s['box']))
|
|
2362
|
+
keep.append(s)
|
|
2363
|
+
continue
|
|
2364
|
+
s['asset'] = aid
|
|
2365
|
+
# role 跟着资产走:图标槽写成 logo 会让消费端把它当品牌标识,每页都摆一个
|
|
2366
|
+
s['role'] = next((x['kind'] for x in assets if x['id'] == aid), s['role'])
|
|
2367
|
+
keep.append(s)
|
|
2368
|
+
a['slots'] = keep
|
|
911
2369
|
roles = draft_scale(d, archetypes)
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
2370
|
+
slot_added = cover_slot_colors(tokens, archetypes, rows, cusage)
|
|
2371
|
+
# 进包的资产必须全部上联系表。BRIEF 让 L 层「看联系表确认 logo / 封面归属」,
|
|
2372
|
+
# 表上没有的东西它只会从表里另挑一张顶上去。封面主视觉按定义只出现在封面那一页
|
|
2373
|
+
# (n=1),按出现次数排序时排在最末——实测被 cands[:12] 截掉,模型于是把 bg-cover
|
|
2374
|
+
# 换成了已经在用的内容页背景,封面与内容页字节相同,封面主视觉整个丢失。
|
|
2375
|
+
decided_c = sorted([a['src'] for a in assets], key=lambda c: (-c['n'], c['file']))
|
|
2376
|
+
other_c = sorted([c for c, _ in rejected], key=lambda c: (-c['n'], c['file']))
|
|
2377
|
+
cands, seen_file = [], set()
|
|
2378
|
+
for c in decided_c + other_c: # 同一张图可能有多条候选记录(不同位置各一条)
|
|
2379
|
+
if c['file'] not in seen_file:
|
|
2380
|
+
seen_file.add(c['file'])
|
|
2381
|
+
cands.append(c)
|
|
2382
|
+
# 表列全部候选,拼版图只拼前几张:两者成本差着数量级。表是文字,60 行也几乎不占
|
|
2383
|
+
# 上下文,却是模型唯一能知道「存在这张图」的地方——名额砍在这里,被误判成未采纳的
|
|
2384
|
+
# 图连翻案的机会都没有。拼版图是要「看」的,60 格就是 4 列×15 行、降采样后每格
|
|
2385
|
+
# 糊成一团,那个上限才有意义。
|
|
2386
|
+
sheet_items = cands[:max(SHEET_CAP, len(decided_c))]
|
|
2387
|
+
sheet = contact_sheet(outdir, sheet_items, os.path.join(ldir, 'contact-sheet.png'))
|
|
915
2388
|
lsheet = layout_sheet(outdir, archetypes, os.path.join(ldir, 'layout-sheet.png'))
|
|
916
2389
|
|
|
917
2390
|
anchors = draft_anchors(d, tokens, fonts, roles, assets, archetypes)
|
|
@@ -919,25 +2392,79 @@ def main(argv=None):
|
|
|
919
2392
|
for c, why in rejected:
|
|
920
2393
|
if '近全透明' in why:
|
|
921
2394
|
gaps.append('母版/版式里的 %s 是%s,不是设计资产,任何情况下不要当背景用。' % (c['file'], why))
|
|
922
|
-
|
|
923
|
-
|
|
2395
|
+
elif '不是背景' in why:
|
|
2396
|
+
gaps.append('%s 在模板里铺满整页,但%s;那几页的真实背景是幻灯片自身的底色,'
|
|
2397
|
+
'需要时按 Colors 里的 surface 铺纯色。' % (c['file'], why))
|
|
2398
|
+
by_kind = {}
|
|
2399
|
+
for kind, kept, total, advice, where in _TRUNCATED:
|
|
2400
|
+
e = by_kind.setdefault(kind, {'kept': 0, 'total': 0, 'advice': advice, 'where': []})
|
|
2401
|
+
e['kept'] += kept
|
|
2402
|
+
e['total'] += total
|
|
2403
|
+
if where:
|
|
2404
|
+
e['where'].append(where)
|
|
2405
|
+
for kind, e in by_kind.items():
|
|
2406
|
+
at = ('(%s)' % '、'.join(e['where'][:6])) if e['where'] else ''
|
|
2407
|
+
gaps.append('%s%s按名额截断:普查到 %d 个,包内留了 %d 个%s。'
|
|
2408
|
+
% (kind, at, e['total'], e['kept'],
|
|
2409
|
+
';' + e['advice'] if e['advice'] else ''))
|
|
2410
|
+
if dropped_slots:
|
|
2411
|
+
gaps.append('这些图标槽的源图没有随包分发(超出图标配额或不适合进包):%s。'
|
|
2412
|
+
'槽位保留了坐标,渲染时留空或用中性占位,不要自造图形去填。'
|
|
2413
|
+
% '、'.join('%s %s' % (n, b) for n, b in dropped_slots[:8]))
|
|
2414
|
+
# 「没命中映射表」不等于「装不上」:降级目标本身(Noto Sans SC 之类)和 Office 出厂体
|
|
2415
|
+
# 都不在 match 列里,但它们本来就可用。真正危险的是**既没命中、又不是已知可用字体**的
|
|
2416
|
+
# 那种——design.md 的字体栈里留着一个消费端装不上的商业字体名,且没有任何降级说明。
|
|
2417
|
+
web_ok = {norm(x) for fam in parse_fallback_table() for x in fam['fallback']}
|
|
2418
|
+
web_ok |= {norm(x.strip().strip('"')) for x in SYS_FALLBACK.split(',')}
|
|
2419
|
+
for f in fonts:
|
|
2420
|
+
if f.get('mapped'):
|
|
924
2421
|
gaps.append('源字体 %s 无 web 授权源,已按 font-fallback 表降级到 %s;字形细节与原稿有差异。'
|
|
925
2422
|
% (f['names'][0], f['stack'][1]))
|
|
2423
|
+
elif norm(f['names'][0]) in OFFICE_DEFAULT_FONTS_NORM:
|
|
2424
|
+
gaps.append('%s 是 Office 出厂字体,多半是模板里没清干净的残留而非设计选型;'
|
|
2425
|
+
'按正文/标题的实际气质挑替代体,不要照抄它。' % f['names'][0])
|
|
2426
|
+
elif norm(f['names'][0]) not in web_ok:
|
|
2427
|
+
gaps.append('源字体 %s 不在 font-fallback 表里,字体栈只有原名,消费端很可能装不上;'
|
|
2428
|
+
'按气质挑一个有 web 分发源的近似体补进栈,不要照抄原名。' % f['names'][0])
|
|
2429
|
+
nosize = [(a['name'], s['box']) for a in archetypes for s in a['slots']
|
|
2430
|
+
if not s.get('asset') and not s.get('_font_size')]
|
|
2431
|
+
if nosize:
|
|
2432
|
+
gaps.append('这些文字槽在源文件任何层级都没有字号声明(都不是占位符,是普通文本框,'
|
|
2433
|
+
'继承源是 presentation.xml 的 defaultTextStyle,本抽取按约定不解继承链):'
|
|
2434
|
+
'%s。用 typography 里最接近的档位,不要自造新档。'
|
|
2435
|
+
% '、'.join('%s %s' % (n, b) for n, b in nosize[:6]))
|
|
2436
|
+
|
|
926
2437
|
if leftover:
|
|
927
2438
|
exceptions.append('源 deck 第 %s 页是单页孤例,没有归纳成 archetype;需要类似构图时按最接近的页型改。'
|
|
928
2439
|
% '、'.join(map(str, leftover)))
|
|
929
2440
|
|
|
930
2441
|
emit_manifest(d, assets, ldir)
|
|
931
2442
|
emit_frontmatter(d, tokens, fonts, roles, anchors, gaps, ldir)
|
|
932
|
-
|
|
933
|
-
|
|
2443
|
+
# 每张背景量一次局部对比度,作为「哪里不能压文字」的客观依据摆进判断单。
|
|
2444
|
+
# 只报测到的数,不替人填 avoid——哪块算主体、要不要避让,是看图才能定的。
|
|
2445
|
+
busy_hints = {}
|
|
2446
|
+
for a in assets:
|
|
2447
|
+
if a['kind'] != 'background' or not a['src'].get('out'):
|
|
2448
|
+
continue
|
|
2449
|
+
r = bg_busy_map(os.path.join(outdir, a['src']['out']), (cW, cH))
|
|
2450
|
+
if r:
|
|
2451
|
+
busy_hints[a['id']] = r
|
|
2452
|
+
facts, recipes = structure_facts(archetypes, d, all_shapes)
|
|
2453
|
+
for a in archetypes:
|
|
2454
|
+
a['flow'] = draft_flow(a, facts.get(a['name']) or {}, (cW, cH))
|
|
2455
|
+
emit_layouts(archetypes, ldir, busy_hints, facts, recipes)
|
|
2456
|
+
emit_body(d, tokens, fonts, roles, assets, archetypes, exceptions, cusage, ldir)
|
|
934
2457
|
emit_brief(d, (tokens, rest, fonts, roles, assets, rejected, todos, archetypes, cands, sheet,
|
|
935
|
-
leftover, lsheet), ldir)
|
|
2458
|
+
leftover, lsheet, len(sheet_items)), ldir)
|
|
936
2459
|
|
|
937
|
-
|
|
938
|
-
|
|
2460
|
+
# 这几行落在模型判断「skill 是不是做完了」的那一刻。只报数就会被读成「包已生成」,
|
|
2461
|
+
# 于是判断和打包整段被跳过,deck 拿不到任何版式坐标。所以这里报进度与下一条命令。
|
|
2462
|
+
print('第 1/3 步完成,判断单草案 -> %s' % ldir)
|
|
2463
|
+
print(' 待你确认:资产 %d(%s) 版式 %d 色 %d 字体 %d'
|
|
939
2464
|
% (len(assets), ', '.join(x['id'] for x in assets), len(archetypes), len(tokens), len(fonts)))
|
|
940
|
-
print('
|
|
2465
|
+
print(' 第 2 步 读 l-out/BRIEF.md 与 contact-sheet.png,改掉草案里的 TODO')
|
|
2466
|
+
print(' 第 3 步 package.py 产出 design.md + layouts.md —— deck 的版式坐标只从这两份读')
|
|
2467
|
+
sys.stdout.flush()
|
|
941
2468
|
return 0
|
|
942
2469
|
|
|
943
2470
|
|