Spaces:
Running
Running
taurus: 字幕文字在底板内垂直居中(按字形墨迹校正)
Browse files- taurus/js/film.js +9 -4
taurus/js/film.js
CHANGED
|
@@ -17,14 +17,19 @@ export function createFilm() {
|
|
| 17 |
const a = Math.min(ease.smooth(seg(t, cur.t0 - .1, cur.t0 + .15)), 1 - ease.smooth(seg(t, cur.t1, cur.t1 + .2)));
|
| 18 |
const size = (P ? 48 : 42) * S, lines = wrapText(g, cur.text, P ? W * .82 : W * .62, size), lh = size * 1.45;
|
| 19 |
const cy = (P ? H * .885 : H * .9) - (lines.length - 1) * lh / 2;
|
| 20 |
-
g.save(); g.font = `600 ${size}px ${FONT.sans}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
g.save(); g.globalAlpha = a * .85;
|
| 22 |
const gr = g.createLinearGradient(W / 2 - w / 2, 0, W / 2 + w / 2, 0);
|
| 23 |
gr.addColorStop(0, 'rgba(8,16,14,0)'); gr.addColorStop(.15, 'rgba(8,16,14,.8)'); gr.addColorStop(.85, 'rgba(8,16,14,.8)'); gr.addColorStop(1, 'rgba(8,16,14,0)');
|
| 24 |
-
g.fillStyle = gr;
|
| 25 |
-
g.fillStyle = gilt(g, W / 2 - w * .3, 0, W / 2 + w * .3, 0, 'rose'); g.fillRect(W / 2 - w * .28, top, w * .56, 1.4 * S); g.fillRect(W / 2 - w * .28, top + hgt, w * .56, 1.4 * S);
|
| 26 |
g.restore();
|
| 27 |
-
lines.forEach((l, i) => text(g, l, W / 2, cy + i * lh, { size, font: FONT.sans, weight: 600, color: '#fff8ee', alpha: a, outline: 'rgba(10,14,12,.85)', outlineW: size * .12 }));
|
| 28 |
}
|
| 29 |
|
| 30 |
function hud(g, t, W, H, i) {
|
|
|
|
| 17 |
const a = Math.min(ease.smooth(seg(t, cur.t0 - .1, cur.t0 + .15)), 1 - ease.smooth(seg(t, cur.t1, cur.t1 + .2)));
|
| 18 |
const size = (P ? 48 : 42) * S, lines = wrapText(g, cur.text, P ? W * .82 : W * .62, size), lh = size * 1.45;
|
| 19 |
const cy = (P ? H * .885 : H * .9) - (lines.length - 1) * lh / 2;
|
| 20 |
+
g.save(); g.font = `600 ${size}px ${FONT.sans}`; g.textBaseline = 'middle';
|
| 21 |
+
const w = Math.max(...lines.map(l => g.measureText(l).width)) + 90 * S;
|
| 22 |
+
// 以字形实际墨迹(含标点)计算视觉中心,修正 middle 基线在中文字体上的偏移
|
| 23 |
+
const m = g.measureText(lines.join('') + '字'), dy = (m.actualBoundingBoxAscent - m.actualBoundingBoxDescent) / 2;
|
| 24 |
+
g.restore();
|
| 25 |
+
const padY = size * .42, top = cy - size / 2 - padY, hgt = (lines.length - 1) * lh + size + padY * 2;
|
| 26 |
g.save(); g.globalAlpha = a * .85;
|
| 27 |
const gr = g.createLinearGradient(W / 2 - w / 2, 0, W / 2 + w / 2, 0);
|
| 28 |
gr.addColorStop(0, 'rgba(8,16,14,0)'); gr.addColorStop(.15, 'rgba(8,16,14,.8)'); gr.addColorStop(.85, 'rgba(8,16,14,.8)'); gr.addColorStop(1, 'rgba(8,16,14,0)');
|
| 29 |
+
g.fillStyle = gr; g.fillRect(W / 2 - w / 2, top, w, hgt);
|
| 30 |
+
g.fillStyle = gilt(g, W / 2 - w * .3, 0, W / 2 + w * .3, 0, 'rose'); g.fillRect(W / 2 - w * .28, top, w * .56, 1.4 * S); g.fillRect(W / 2 - w * .28, top + hgt - 1.4 * S, w * .56, 1.4 * S);
|
| 31 |
g.restore();
|
| 32 |
+
lines.forEach((l, i) => text(g, l, W / 2, cy + i * lh + dy, { size, font: FONT.sans, weight: 600, color: '#fff8ee', alpha: a, outline: 'rgba(10,14,12,.85)', outlineW: size * .12 }));
|
| 33 |
}
|
| 34 |
|
| 35 |
function hud(g, t, W, H, i) {
|