jpfun 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -11
- package/dist/converter/midi/convert.d.ts +50 -0
- package/dist/converter/midi/convert.js +700 -0
- package/dist/converter/midi/index.d.ts +5 -0
- package/dist/converter/midi/index.js +11 -0
- package/dist/converter/midi/json.d.ts +38 -0
- package/dist/converter/midi/json.js +1 -0
- package/dist/converter/midi/triplet.d.ts +30 -0
- package/dist/converter/midi/triplet.js +75 -0
- package/dist/converter/musicxml/dom.d.ts +25 -0
- package/dist/converter/musicxml/dom.js +65 -0
- package/dist/converter/musicxml/features.d.ts +51 -0
- package/dist/converter/musicxml/features.js +232 -0
- package/dist/converter/musicxml/index.d.ts +9 -0
- package/dist/converter/musicxml/index.js +1140 -0
- package/dist/converter/musicxml/model.d.ts +123 -0
- package/dist/converter/musicxml/model.js +1 -0
- package/dist/converter/source.d.ts +22 -0
- package/dist/converter/source.js +51 -0
- package/dist/core.d.ts +22 -0
- package/dist/core.js +22 -0
- package/dist/diagnostic.js +5 -2
- package/dist/fraction.d.ts +24 -0
- package/dist/fraction.js +132 -0
- package/dist/functions/ASTtypes.d.ts +51 -31
- package/dist/functions/ASTtypes.js +59 -38
- package/dist/functions/adjust/index.d.ts +2 -0
- package/dist/functions/adjust/index.js +193 -0
- package/dist/functions/arpeggio/index.d.ts +2 -0
- package/dist/functions/arpeggio/index.js +180 -0
- package/dist/functions/arpeggio/shape.d.ts +7 -0
- package/dist/functions/arpeggio/shape.js +122 -0
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +62 -25
- package/dist/functions/beam/auto.d.ts +1 -1
- package/dist/functions/beam/auto.js +33 -16
- package/dist/functions/beam/index.js +10 -6
- package/dist/functions/beam/layout.d.ts +4 -3
- package/dist/functions/beam/layout.js +43 -65
- package/dist/functions/box/index.js +37 -36
- package/dist/functions/br/index.js +10 -8
- package/dist/functions/dash/index.js +40 -7
- package/dist/functions/default.js +19 -8
- package/dist/functions/div/index.d.ts +16 -0
- package/dist/functions/div/index.js +45 -17
- package/dist/functions/dot/index.js +23 -25
- package/dist/functions/dyn/index.d.ts +2 -0
- package/dist/functions/dyn/index.js +242 -0
- package/dist/functions/grace/index.d.ts +8 -11
- package/dist/functions/grace/index.js +84 -79
- package/dist/functions/head/index.d.ts +2 -0
- package/dist/functions/head/index.js +496 -0
- package/dist/functions/key/index.js +98 -3
- package/dist/functions/meter/index.d.ts +2 -0
- package/dist/functions/meter/index.js +155 -0
- package/dist/functions/note/accidentals.d.ts +24 -3
- package/dist/functions/note/accidentals.js +31 -1
- package/dist/functions/note/index.js +106 -79
- package/dist/functions/note/noteNameFSM.js +52 -63
- package/dist/functions/page/index.d.ts +11 -2
- package/dist/functions/page/index.js +65 -4
- package/dist/functions/program/index.d.ts +2 -0
- package/dist/functions/program/index.js +30 -0
- package/dist/functions/set/index.js +43 -32
- package/dist/functions/stack/index.js +26 -22
- package/dist/functions/symbol/index.d.ts +31 -0
- package/dist/functions/symbol/index.js +139 -0
- package/dist/functions/symbol/ornament.d.ts +15 -0
- package/dist/functions/symbol/ornament.js +73 -0
- package/dist/functions/symbol/shape.d.ts +24 -0
- package/dist/functions/symbol/shape.js +52 -0
- package/dist/functions/symbol/symbols/accent.d.ts +2 -0
- package/dist/functions/symbol/symbols/accent.js +24 -0
- package/dist/functions/symbol/symbols/dc.d.ts +4 -0
- package/dist/functions/symbol/symbols/dc.js +82 -0
- package/dist/functions/symbol/symbols/ds.d.ts +2 -0
- package/dist/functions/symbol/symbols/ds.js +93 -0
- package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
- package/dist/functions/symbol/symbols/dynamics.js +168 -0
- package/dist/functions/symbol/symbols/fermata.d.ts +2 -0
- package/dist/functions/symbol/symbols/fermata.js +24 -0
- package/dist/functions/symbol/symbols/fine.d.ts +2 -0
- package/dist/functions/symbol/symbols/fine.js +12 -0
- package/dist/functions/symbol/symbols/mordent.d.ts +2 -0
- package/dist/functions/symbol/symbols/mordent.js +56 -0
- package/dist/functions/symbol/symbols/prall.d.ts +2 -0
- package/dist/functions/symbol/symbols/prall.js +42 -0
- package/dist/functions/symbol/symbols/segno.d.ts +4 -0
- package/dist/functions/symbol/symbols/segno.js +82 -0
- package/dist/functions/symbol/symbols/tr.d.ts +2 -0
- package/dist/functions/symbol/symbols/tr.js +71 -0
- package/dist/functions/tempo/glyph.d.ts +12 -0
- package/dist/functions/tempo/glyph.js +30 -0
- package/dist/functions/tempo/index.js +57 -4
- package/dist/functions/temporal.d.ts +138 -0
- package/dist/functions/temporal.js +101 -0
- package/dist/functions/text/index.js +86 -27
- package/dist/functions/tie/index.js +136 -152
- package/dist/functions/tuplet/index.d.ts +2 -0
- package/dist/functions/tuplet/index.js +218 -0
- package/dist/functions/up/index.d.ts +1 -0
- package/dist/functions/up/index.js +258 -182
- package/dist/functions/voice/index.js +203 -109
- package/dist/functions/volta/index.d.ts +2 -0
- package/dist/functions/volta/index.js +230 -0
- package/dist/iife/core.d.ts +1 -0
- package/dist/iife/core.js +3 -0
- package/dist/iife/from-midi.d.ts +1 -0
- package/dist/iife/from-midi.js +15 -0
- package/dist/iife/from-musicxml.d.ts +1 -0
- package/dist/iife/from-musicxml.js +3 -0
- package/dist/iife/full.d.ts +1 -0
- package/dist/iife/full.js +3 -0
- package/dist/index.d.ts +3 -17
- package/dist/index.js +3 -17
- package/dist/jpfun.core.min.js +153 -0
- package/dist/jpfun.from-midi.min.js +9 -0
- package/dist/jpfun.from-musicxml.min.js +12 -0
- package/dist/jpfun.min.js +166 -0
- package/dist/layout/default.js +2 -3
- package/dist/layout/engine.d.ts +6 -12
- package/dist/layout/engine.js +115 -64
- package/dist/layout/model.d.ts +12 -5
- package/dist/layout/model.js +31 -18
- package/dist/layout/page.js +5 -4
- package/dist/layout/path.d.ts +19 -0
- package/dist/layout/path.js +101 -0
- package/dist/layout/types.d.ts +71 -20
- package/dist/layout/types.js +3 -1
- package/dist/lowering/loweringContext.d.ts +20 -20
- package/dist/lowering/loweringContext.js +153 -101
- package/dist/lowering/track.d.ts +5 -9
- package/dist/lowering/track.js +7 -2
- package/dist/lowering/types.d.ts +26 -112
- package/dist/lowering/types.js +1 -92
- package/dist/parser/parse-utils/call-utils.d.ts +0 -2
- package/dist/parser/parse-utils/call-utils.js +0 -6
- package/dist/parser/parse-utils/note-utils.d.ts +8 -0
- package/dist/parser/parse-utils/note-utils.js +35 -13
- package/dist/parser/parse-utils/string-utils.d.ts +10 -0
- package/dist/parser/parse-utils/string-utils.js +24 -0
- package/dist/parser/parserContext.d.ts +11 -9
- package/dist/parser/parserContext.js +65 -55
- package/dist/parser/preprocess.js +17 -11
- package/dist/pipeline.d.ts +6 -5
- package/dist/pipeline.js +4 -5
- package/dist/playback/compile.d.ts +18 -0
- package/dist/playback/compile.js +414 -0
- package/dist/playback/event.d.ts +105 -0
- package/dist/playback/event.js +105 -0
- package/dist/playback/time.d.ts +14 -0
- package/dist/playback/time.js +81 -0
- package/dist/playback/types.d.ts +129 -0
- package/dist/playback/types.js +3 -0
- package/dist/render/canvas.d.ts +4 -4
- package/dist/render/canvas.js +20 -5
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.js +1 -0
- package/dist/render/paint.d.ts +8 -0
- package/dist/render/paint.js +101 -0
- package/dist/render/svg.d.ts +3 -3
- package/dist/render/svg.js +10 -8
- package/dist/render/text.d.ts +22 -0
- package/dist/render/text.js +42 -0
- package/dist/render/types.d.ts +1 -1
- package/grammar.md +132 -13
- package/package.json +19 -6
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
2
|
+
import { layoutHorizontalRegion } from "../../layout/model.js";
|
|
3
|
+
import { isVisualTemporalNode, TemporalNodeBase, } from "../temporal.js";
|
|
4
|
+
import { ParserContext, skipSpaces, skipSpacesBack } from "../../parser/parserContext.js";
|
|
5
|
+
import { ASTBraceNode, ASTFunctionNode, ASTNodeBase, } from "../ASTtypes.js";
|
|
6
|
+
import { KeyNode } from "../key/index.js";
|
|
7
|
+
import { MeterNode } from "../meter/index.js";
|
|
8
|
+
import { TempoNode } from "../tempo/index.js";
|
|
9
|
+
import { TextNode } from "../text/index.js";
|
|
10
|
+
const FIELD_SLOT = {
|
|
11
|
+
title: "center", subtitle: "center", author: "right",
|
|
12
|
+
signature: "left", tempo: "left", left: "left", center: "center", right: "right",
|
|
13
|
+
};
|
|
14
|
+
const TEXT_PRESET = {
|
|
15
|
+
title: [2, "center"], subtitle: [0.85, "center"], author: [0.8, "right"],
|
|
16
|
+
};
|
|
17
|
+
const ITEM_GAP_EM = 0.25;
|
|
18
|
+
const DEFAULT_GAP_PX = 5;
|
|
19
|
+
// 也决定居中精度:值越大弹簧越软,求解器按合力收敛后残留的坐标误差越大
|
|
20
|
+
const HEAD_STRETCH = 10_000;
|
|
21
|
+
function sugarRow(span, content) {
|
|
22
|
+
return content.length === 1 && content[0] instanceof ASTBraceNode
|
|
23
|
+
? content[0]
|
|
24
|
+
: new ASTBraceNode(span, content);
|
|
25
|
+
}
|
|
26
|
+
function findLineEnd(source, start, end = source.length) {
|
|
27
|
+
while (start < end && source[start] !== "\r" && source[start] !== "\n")
|
|
28
|
+
start++;
|
|
29
|
+
return start;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 让一个槽的两个边界代表它在弹簧链上应占的横向范围
|
|
33
|
+
*
|
|
34
|
+
* 先在本区间自然求解(宽度不限,因此更窄的 hook 已固化的布局原样保留),再移动边界:
|
|
35
|
+
* 侧槽的两个边界重合成一个点,center 的两个边界贴住内容的几何左右沿。
|
|
36
|
+
* 整段随即固化,最终求解合并成一根刚性列,而刚性列的宽度只取首末边界,
|
|
37
|
+
* 中间列的相对布局原样保留。
|
|
38
|
+
*/
|
|
39
|
+
function layoutHeadSlot({ columns, rows, start, end, X, fixed, options }, occupiesWidth) {
|
|
40
|
+
layoutHorizontalRegion(columns.slice(start, end + 1), rows, X.subarray(start, end + 1), fixed.subarray(start, end), Infinity, options);
|
|
41
|
+
let left = Infinity;
|
|
42
|
+
let right = -Infinity;
|
|
43
|
+
for (let c = start + 1; c < end; c++) {
|
|
44
|
+
for (let r = 0; r < rows; r++) {
|
|
45
|
+
left = Math.min(left, X[c] - columns[c][r].WL);
|
|
46
|
+
right = Math.max(right, X[c] + columns[c][r].WR);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (occupiesWidth && left <= right) {
|
|
50
|
+
X[start] = left;
|
|
51
|
+
X[end] = right;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
X[end] = X[start];
|
|
55
|
+
}
|
|
56
|
+
/** 行从上到下按 gap 排列;capture 让 Head 在同一遍测量里取得整组范围 */
|
|
57
|
+
function measureRows(members, gap, capture) {
|
|
58
|
+
const placements = [];
|
|
59
|
+
let top;
|
|
60
|
+
let cursor;
|
|
61
|
+
for (const extent of members) {
|
|
62
|
+
if (!extent) {
|
|
63
|
+
placements.push(null);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const offset = cursor === void 0 ? 0 : cursor + gap - extent.top;
|
|
67
|
+
placements.push({ offset, extent });
|
|
68
|
+
top ??= offset + extent.top;
|
|
69
|
+
cursor = offset + extent.bottom;
|
|
70
|
+
}
|
|
71
|
+
capture?.(top === void 0 || cursor === void 0 ? null : { top, bottom: cursor });
|
|
72
|
+
return placements;
|
|
73
|
+
}
|
|
74
|
+
class HeadBoundaryTemporal extends TemporalNodeBase {
|
|
75
|
+
members = [];
|
|
76
|
+
slots = [];
|
|
77
|
+
titleBottom = 0;
|
|
78
|
+
leftExtent = null;
|
|
79
|
+
rightExtent = null;
|
|
80
|
+
constructor(ast) {
|
|
81
|
+
super();
|
|
82
|
+
this.ast = ast;
|
|
83
|
+
this.initLayoutBox();
|
|
84
|
+
}
|
|
85
|
+
prepareLayout() { this.box.w = this.box.h = this.box.anchor = this.box.visualAxis = 0; }
|
|
86
|
+
prepareHorizontal(line) {
|
|
87
|
+
// 只由第一个边界协调一次整块 Head,避免六个边界重复改弹簧
|
|
88
|
+
if (this.slots.length > 0)
|
|
89
|
+
this.prepareHead(line);
|
|
90
|
+
}
|
|
91
|
+
onPlaced() {
|
|
92
|
+
if (this.slots.length > 0)
|
|
93
|
+
this.alignHead();
|
|
94
|
+
}
|
|
95
|
+
createTracks(slot) {
|
|
96
|
+
const { name, owner } = slot;
|
|
97
|
+
return {
|
|
98
|
+
laneKey: `head/rows/${owner.sourceSpan.start}/${name}`,
|
|
99
|
+
hostIndex: null,
|
|
100
|
+
measure: members => {
|
|
101
|
+
if (name === "center") {
|
|
102
|
+
const placements = measureRows(members, owner.gap);
|
|
103
|
+
const first = placements.find(placement => placement !== null);
|
|
104
|
+
this.titleBottom = first ? first.offset + first.extent.bottom : 0;
|
|
105
|
+
return placements;
|
|
106
|
+
}
|
|
107
|
+
return measureRows(members, owner.gap, extent => {
|
|
108
|
+
if (name === "left")
|
|
109
|
+
this.leftExtent = extent;
|
|
110
|
+
else
|
|
111
|
+
this.rightExtent = extent;
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
place: name === "center" ? undefined : () => {
|
|
115
|
+
const extent = name === "left" ? this.leftExtent : this.rightExtent;
|
|
116
|
+
if (!extent)
|
|
117
|
+
return this.titleBottom;
|
|
118
|
+
const leftHeight = this.leftExtent ? this.leftExtent.bottom - this.leftExtent.top : 0;
|
|
119
|
+
const rightHeight = this.rightExtent ? this.rightExtent.bottom - this.rightExtent.top : 0;
|
|
120
|
+
// 两侧共享底边;以较高侧定总高度,使它的顶部恰好贴标题底边
|
|
121
|
+
const targetBottom = this.titleBottom + Math.max(leftHeight, rightHeight);
|
|
122
|
+
return targetBottom - extent.bottom;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
prepareHead(line) {
|
|
127
|
+
if (this.members.some(node => isVisualTemporalNode(node) && node.layoutLine !== line.index)) {
|
|
128
|
+
throw new ErrorDiagnostic("E_HEAD_INTERNAL_BREAK", "@head 的内容不能跨谱面行", this.ast.owner.sourceSpan);
|
|
129
|
+
}
|
|
130
|
+
const [left, center, right] = this.slots;
|
|
131
|
+
// 最外侧不受墙的推力,两个点才能落在纸面边缘
|
|
132
|
+
left.start.springConfig.alpha_L = 0;
|
|
133
|
+
right.end.springConfig.alpha_R = 0;
|
|
134
|
+
// 串联弹簧的静长是两端之和、刚度由软端主导,所以只需 center 自己向两侧撑开
|
|
135
|
+
this.stretch(center.start, "L");
|
|
136
|
+
this.stretch(center.end, "R");
|
|
137
|
+
for (const slot of this.slots) {
|
|
138
|
+
line.registerHorizontalLayoutHook(slot.start, slot.end, context => layoutHeadSlot(context, slot === center));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
alignHead() {
|
|
142
|
+
// 全局列已经完成求解;这里不改 TimeColumn,只覆盖 left/right 主体的最终 box.x
|
|
143
|
+
// center 不参与后置重排,继续使用全局列坐标
|
|
144
|
+
const cells = new Map();
|
|
145
|
+
for (const member of this.members) {
|
|
146
|
+
if (!isVisualTemporalNode(member))
|
|
147
|
+
continue;
|
|
148
|
+
const cell = this.sideCellOf(member.ast);
|
|
149
|
+
if (!cell)
|
|
150
|
+
continue;
|
|
151
|
+
const members = cells.get(cell);
|
|
152
|
+
if (members)
|
|
153
|
+
members.push(member);
|
|
154
|
+
else
|
|
155
|
+
cells.set(cell, [member]);
|
|
156
|
+
}
|
|
157
|
+
const [left, , right] = this.slots;
|
|
158
|
+
this.packRows(left.ast, left.start.box.x, "left", cells);
|
|
159
|
+
this.packRows(right.ast, right.end.box.x, "right", cells);
|
|
160
|
+
}
|
|
161
|
+
stretch(node, side) {
|
|
162
|
+
const alpha = side === "L" ? "alpha_L" : "alpha_R";
|
|
163
|
+
const beta = side === "L" ? "beta_L" : "beta_R";
|
|
164
|
+
// alpha 撑开槽间空间;beta 反向缩放,避免弹簧刚度随 alpha 一起失控
|
|
165
|
+
node.springConfig[alpha] = node.springConfig[alpha] * HEAD_STRETCH;
|
|
166
|
+
node.springConfig[beta] = node.springConfig[beta] * 3 / HEAD_STRETCH;
|
|
167
|
+
}
|
|
168
|
+
packRows(slot, target, side, cells) {
|
|
169
|
+
const gap = this.ast.owner.size * ITEM_GAP_EM;
|
|
170
|
+
const fromLeft = side === "left";
|
|
171
|
+
const direction = fromLeft ? 1 : -1;
|
|
172
|
+
for (const row of slot.rows) {
|
|
173
|
+
const rowCells = row instanceof ASTBraceNode ? row.content : [row];
|
|
174
|
+
let cursor = target;
|
|
175
|
+
for (let index = fromLeft ? 0 : rowCells.length - 1; index >= 0 && index < rowCells.length; index += direction) {
|
|
176
|
+
const members = cells.get(rowCells[index]);
|
|
177
|
+
if (!members)
|
|
178
|
+
continue;
|
|
179
|
+
let left = Infinity;
|
|
180
|
+
let right = -Infinity;
|
|
181
|
+
for (const member of members) {
|
|
182
|
+
left = Math.min(left, member.box.x);
|
|
183
|
+
right = Math.max(right, member.box.x + member.box.w);
|
|
184
|
+
}
|
|
185
|
+
const offset = cursor - (fromLeft ? left : right);
|
|
186
|
+
for (const member of members)
|
|
187
|
+
member.box.x += offset;
|
|
188
|
+
// 复合单元先整体平移,再让其内部成员读取彼此的最终坐标
|
|
189
|
+
for (const member of members)
|
|
190
|
+
member.onPlaced?.();
|
|
191
|
+
cursor += direction * (right - left + gap);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** 找到成员所属侧栏行的顶层单元;复合节点内部成员会归回同一个直接子节点 */
|
|
196
|
+
sideCellOf(ast) {
|
|
197
|
+
let cell = ast;
|
|
198
|
+
while (cell.parent) {
|
|
199
|
+
const parent = cell.parent;
|
|
200
|
+
const slot = parent instanceof HeadSlotNode
|
|
201
|
+
? parent
|
|
202
|
+
: parent instanceof ASTBraceNode && parent.parent instanceof HeadSlotNode
|
|
203
|
+
? parent.parent
|
|
204
|
+
: null;
|
|
205
|
+
if (slot?.owner === this.ast.owner)
|
|
206
|
+
return slot.name === "center" ? null : cell;
|
|
207
|
+
cell = parent;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** 一个槽既是 AST 容器,也是把每个顶层行分配到独立 Track 的边界 */
|
|
213
|
+
class HeadSlotNode extends ASTNodeBase {
|
|
214
|
+
owner;
|
|
215
|
+
name;
|
|
216
|
+
rows;
|
|
217
|
+
constructor(span, owner, name, rows) {
|
|
218
|
+
super(span, owner);
|
|
219
|
+
this.owner = owner;
|
|
220
|
+
this.name = name;
|
|
221
|
+
this.rows = rows;
|
|
222
|
+
for (const row of this.rows)
|
|
223
|
+
row.parent = this;
|
|
224
|
+
}
|
|
225
|
+
// 零宽边界需要字号契约,但字号由 Head 统一冻结,不在三个槽里重复保存
|
|
226
|
+
get size() { return this.owner.size; }
|
|
227
|
+
get children() { return this.rows; }
|
|
228
|
+
timeFlowModel(ctx) {
|
|
229
|
+
if (this.rows.length === 0)
|
|
230
|
+
return null;
|
|
231
|
+
const head = ctx.getTemporalNodes(this.owner.slots[0])[0];
|
|
232
|
+
return {
|
|
233
|
+
mode: "parallel",
|
|
234
|
+
children: this.rows,
|
|
235
|
+
tracks: head.createTracks(this),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
loweringEnter() {
|
|
239
|
+
return [new HeadBoundaryTemporal(this)];
|
|
240
|
+
}
|
|
241
|
+
loweringExit() {
|
|
242
|
+
return [new HeadBoundaryTemporal(this)];
|
|
243
|
+
}
|
|
244
|
+
addRow(row) {
|
|
245
|
+
row.parent = this;
|
|
246
|
+
this.rows.push(row);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Head 布局建立在全局时序与布局协议上:
|
|
251
|
+
*
|
|
252
|
+
* 1. Head 是 left -> center -> right 的 sequence,保证三槽在全局列中的先后顺序;
|
|
253
|
+
* 每个槽再把第一层节点作为一组 parallel Track,形成多行。三槽使用不同 laneKey
|
|
254
|
+
* 独立测量行距;center 第一行的求解轴与宿主轴相同,left/right 整组在 place 阶段
|
|
255
|
+
* 平移到同一个底边,较高侧的顶部贴住 center 第一行的下侧。
|
|
256
|
+
*
|
|
257
|
+
* 例如 `@head(left={L1 L2 L3}, center={C1 C2}, right={R1})` 会形成:
|
|
258
|
+
*
|
|
259
|
+
* Head (sequence)
|
|
260
|
+
* +-- left (independent parallel Tracks)
|
|
261
|
+
* | +-- Track L1
|
|
262
|
+
* | +-- Track L2
|
|
263
|
+
* | `-- Track L3
|
|
264
|
+
* +-- center (independent parallel Tracks, axis(C1) = host axis)
|
|
265
|
+
* | +-- Track C1
|
|
266
|
+
* | `-- Track C2
|
|
267
|
+
* `-- right (independent parallel Tracks)
|
|
268
|
+
* `-- Track R1
|
|
269
|
+
*
|
|
270
|
+
* left/right 是两组不同 Track,但最终拥有相同的包围盒底边;任一侧的行高只影响
|
|
271
|
+
* 自己后续各行。槽参数的一层内容表示多行;若要让多个对象留在同一行,需再包
|
|
272
|
+
* 一层 brace,如 `left={{@key(C) @meter(4,4)}}`。center 为空时,较高侧从宿主轴
|
|
273
|
+
* 开始向下排列。
|
|
274
|
+
*
|
|
275
|
+
* 2. 每个槽在真实内容前后各产生一个零尺寸 Temporal。边界和每个真实 Temporal
|
|
276
|
+
* 都进入全局 TimeColumn;同一时刻只有 mergeKey 相同的跨轨事件才会合列,
|
|
277
|
+
* key、meter 等默认仍各自占列,并非一个 Head 槽只有一列。Track 只表达纵向行,
|
|
278
|
+
* 不取代横向列。Head 因此仍可行内使用或嵌套,box、tie 等 attachment 也沿用
|
|
279
|
+
* 正常生命周期。
|
|
280
|
+
* 3. 横向求解前,left.start 的回调把最外侧设为自由边、让 center 向两侧撑开,
|
|
281
|
+
* 并为三个槽各注册一个 layoutHeadSlot。每个槽的两个边界因此代表本块在弹簧链上
|
|
282
|
+
* 应占的横向范围:left/right 收缩成一个点,center 贴住内容的几何左右沿。
|
|
283
|
+
* 4. 于是链形如 `点 - 强弹簧 - center - 强弹簧 - 点`。两根强弹簧参数相同、压缩量
|
|
284
|
+
* 必然相等,两个点又被自由的墙对称顶在纸面两侧,因此 center 的几何中心精确落在
|
|
285
|
+
* 内容区中线,与两侧内容多宽、多少行无关。center 的求解坐标即最终坐标,不参与
|
|
286
|
+
* 后置重排。两个代价是刻意接受的:侧槽不占横向流,所以内容过宽时会与 center 的
|
|
287
|
+
* 第二行及以后重叠,引擎不再阻止;强弹簧靠“把整行撑到必然过满”成立,所以同一
|
|
288
|
+
* 谱面行上的普通内容会被挤到几乎没有间隙,行内 head 只适合极短的内容。
|
|
289
|
+
* 5. 纵向放置完成后,left.start 以两个点为准,按顶层 AST 单元重新写入两侧成员的
|
|
290
|
+
* box.x:left 向右、right 向左紧凑排列,单元间留 0.25em。因此 TimeColumn 拓扑
|
|
291
|
+
* 没有消失,但两侧最终 x 不再等于全局列锚点;复合内容整体平移。随后重新调用
|
|
292
|
+
* 成员的 `onPlaced`,使折叠成员同步最终坐标,attachment 再读取这些坐标生成几何。
|
|
293
|
+
*
|
|
294
|
+
* Head 只协调布局,不建立局部列或局部 attachment 系统。内部内容须为零时长,且不能主动换谱面行。
|
|
295
|
+
*/
|
|
296
|
+
class HeadFunction extends ASTFunctionNode {
|
|
297
|
+
static def = {
|
|
298
|
+
name: ["head"],
|
|
299
|
+
description: "提供左、中、右三块布局,常用于曲谱头部信息展示;也可用连续的 H.*: 行声明构造",
|
|
300
|
+
example: `@head(left={{@key(C) @meter(4,4)}}, center={@text(标题)}, right={@text(作者)})
|
|
301
|
+
语法糖:相邻的 H.*: 声明合并为一个 head,每条声明生成对应槽的一行;空行或普通内容结束组合
|
|
302
|
+
H.title: 标题 center 槽,预设大字号居中 Text
|
|
303
|
+
H.subtitle: 副标题 center 槽,预设小字号居中 Text
|
|
304
|
+
H.author: 作者 right 槽,预设小字号右对齐 Text
|
|
305
|
+
H.signature: 1=C 4/4 left 槽,同一行生成 Key 和 Meter
|
|
306
|
+
H.tempo: 94 left 槽,生成 Tempo
|
|
307
|
+
H.left: / H.center: / H.right: 接受对应槽的任意零时长 DSL 内容
|
|
308
|
+
以 @ 或 { 开头时按 DSL 解析,否则按该字段的裸文本规则生成 Text`,
|
|
309
|
+
allowExtraArgs: false,
|
|
310
|
+
args: [
|
|
311
|
+
{ name: "left", type: "content", default: "" },
|
|
312
|
+
{ name: "center", type: "content", default: "" },
|
|
313
|
+
{ name: "right", type: "content", default: "" },
|
|
314
|
+
{ name: "gap", type: "length", default: { value: DEFAULT_GAP_PX, unit: "px" } },
|
|
315
|
+
],
|
|
316
|
+
};
|
|
317
|
+
slots;
|
|
318
|
+
size;
|
|
319
|
+
gap;
|
|
320
|
+
createdBySugar = false;
|
|
321
|
+
get children() { return this.slots; }
|
|
322
|
+
timeFlowModel() {
|
|
323
|
+
return { mode: "sequence", children: this.slots };
|
|
324
|
+
}
|
|
325
|
+
static deSugarAtom(source, start, end) {
|
|
326
|
+
if (source[start] !== "H" || source[start + 1] !== ".")
|
|
327
|
+
return null;
|
|
328
|
+
let pos = start + 2;
|
|
329
|
+
while (pos < end && source[pos] >= "a" && source[pos] <= "z")
|
|
330
|
+
pos++;
|
|
331
|
+
const field = source.slice(start + 2, pos);
|
|
332
|
+
if (!Object.hasOwn(FIELD_SLOT, field) || source[pos] !== ":")
|
|
333
|
+
return null;
|
|
334
|
+
pos++;
|
|
335
|
+
const lineEnd = findLineEnd(source, pos, end);
|
|
336
|
+
const contentStart = skipSpaces(source, pos, lineEnd);
|
|
337
|
+
const explicitContent = source[contentStart] === "@" || source[contentStart] === "{";
|
|
338
|
+
// 裸文本整行归 Head 所有,直接越过可避免其中的 F 等字符被识别成音符
|
|
339
|
+
// 显式 DSL 仍从冒号后继续扫描,保留内部函数高亮
|
|
340
|
+
return {
|
|
341
|
+
next: explicitContent ? pos : lineEnd,
|
|
342
|
+
node: {
|
|
343
|
+
kind: "sugar",
|
|
344
|
+
data: { class: HeadFunction, field },
|
|
345
|
+
span: { start, end: pos },
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
static deSugarRelation(ctx, nodes, at) {
|
|
350
|
+
const sugar = nodes[at++];
|
|
351
|
+
if (sugar.data?.class !== HeadFunction)
|
|
352
|
+
return null;
|
|
353
|
+
const field = sugar.data.field;
|
|
354
|
+
let breakAt = at;
|
|
355
|
+
for (; breakAt < nodes.length; breakAt++) {
|
|
356
|
+
const node = nodes[breakAt];
|
|
357
|
+
if (typeof node === "number" && (ctx.source[node] === "\r" || ctx.source[node] === "\n"))
|
|
358
|
+
break;
|
|
359
|
+
if (typeof node !== "number" && node.kind === "sugar" && node.data?.class === HeadFunction)
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
const stop = nodes[breakAt];
|
|
363
|
+
// 裸文本在第一轮被整体越过,EOF 时 nodes 中没有末尾标记,需从源码恢复边界
|
|
364
|
+
let boundary;
|
|
365
|
+
if (typeof stop === "number")
|
|
366
|
+
boundary = stop;
|
|
367
|
+
else if (stop)
|
|
368
|
+
boundary = stop.span.start;
|
|
369
|
+
else if (breakAt > at) {
|
|
370
|
+
const last = nodes[breakAt - 1];
|
|
371
|
+
boundary = typeof last === "number" ? last + 1 : last.span.end;
|
|
372
|
+
}
|
|
373
|
+
else
|
|
374
|
+
boundary = findLineEnd(ctx.source, sugar.span.end);
|
|
375
|
+
const start = skipSpaces(ctx.source, sugar.span.end, boundary);
|
|
376
|
+
const last = skipSpacesBack(ctx.source, boundary - 1, start);
|
|
377
|
+
const span = { start, end: Math.max(start, last + 1) };
|
|
378
|
+
if (span.start >= span.end) {
|
|
379
|
+
throw new ErrorDiagnostic("E_HEAD_EMPTY_DECLARATION", `H.${field}: 后必须有内容`, sugar.span);
|
|
380
|
+
}
|
|
381
|
+
const text = ctx.source.slice(span.start, span.end).trim();
|
|
382
|
+
let parsed;
|
|
383
|
+
if (text.startsWith("@") || text.startsWith("{")) {
|
|
384
|
+
const sub = new ParserContext(ctx);
|
|
385
|
+
sub.makeNodes(nodes.slice(at, breakAt));
|
|
386
|
+
parsed = sub.nodes;
|
|
387
|
+
}
|
|
388
|
+
const previous = ctx.nodes.at(-1);
|
|
389
|
+
// 只有相邻的 H.* 声明合并;普通节点或空行都会切断组合
|
|
390
|
+
const head = previous instanceof HeadFunction && previous.createdBySugar
|
|
391
|
+
? previous
|
|
392
|
+
: new HeadFunction(sugar.span, new Map(), ctx, null);
|
|
393
|
+
head.createdBySugar = true;
|
|
394
|
+
head.addSugarRow(FIELD_SLOT[field], HeadFunction.parseSugarRow(ctx, field, span, text, parsed));
|
|
395
|
+
head.sourceSpan.end = span.end;
|
|
396
|
+
if (head !== previous)
|
|
397
|
+
ctx.pushNode(head);
|
|
398
|
+
if (typeof stop !== "number")
|
|
399
|
+
return breakAt;
|
|
400
|
+
let next = breakAt + 1;
|
|
401
|
+
if (ctx.source[stop] === "\r") {
|
|
402
|
+
const lf = nodes[next];
|
|
403
|
+
if (typeof lf === "number" && ctx.source[lf] === "\n")
|
|
404
|
+
next++;
|
|
405
|
+
}
|
|
406
|
+
return next;
|
|
407
|
+
}
|
|
408
|
+
static parseSugarRow(ctx, field, span, text, parsed) {
|
|
409
|
+
if (parsed !== void 0)
|
|
410
|
+
return sugarRow(span, parsed);
|
|
411
|
+
if (field === "signature") {
|
|
412
|
+
const match = /^(1\s*=\s*(\S+))\s+((\d+)\s*\/\s*(\d+))$/.exec(text);
|
|
413
|
+
if (!match)
|
|
414
|
+
throw new ErrorDiagnostic("E_HEAD_INVALID_SIGNATURE", "H.signature 的格式应为 1=C 4/4", span);
|
|
415
|
+
const keySpan = { start: span.start, end: span.start + match[1].length };
|
|
416
|
+
const meterSpan = { start: span.end - match[3].length, end: span.end };
|
|
417
|
+
return sugarRow(span, [
|
|
418
|
+
new KeyNode(keySpan, new Map([["tonality", match[2]]]), ctx, null),
|
|
419
|
+
new MeterNode(meterSpan, new Map([["num", Number(match[4])], ["den", Number(match[5])]]), ctx, null),
|
|
420
|
+
]);
|
|
421
|
+
}
|
|
422
|
+
if (field === "tempo") {
|
|
423
|
+
const bpm = Number(text);
|
|
424
|
+
if (!Number.isFinite(bpm) || bpm <= 0)
|
|
425
|
+
throw new ErrorDiagnostic("E_HEAD_INVALID_TEMPO", "H.tempo 后必须是正数", span);
|
|
426
|
+
return sugarRow(span, [new TempoNode(span, new Map([["bpm", bpm]]), ctx, null)]);
|
|
427
|
+
}
|
|
428
|
+
const args = new Map([[0, text]]);
|
|
429
|
+
const preset = TEXT_PRESET[field];
|
|
430
|
+
if (preset) {
|
|
431
|
+
args.set("size", { value: preset[0], unit: "em" });
|
|
432
|
+
args.set("align", preset[1]);
|
|
433
|
+
}
|
|
434
|
+
return sugarRow(span, [new TextNode(span, args, ctx, null)]);
|
|
435
|
+
}
|
|
436
|
+
constructor(span, args, ctx, parent = null) {
|
|
437
|
+
super(span, parent);
|
|
438
|
+
this.size = ctx.variables.fontsize;
|
|
439
|
+
this.gap = ctx.length2px(this.getArgValue(args, ctx)[3]);
|
|
440
|
+
const rows = (name, index) => {
|
|
441
|
+
const value = args.get(name) ?? args.get(index);
|
|
442
|
+
if (!(value instanceof ASTNodeBase))
|
|
443
|
+
return [];
|
|
444
|
+
return value instanceof ASTBraceNode ? value.content : [value];
|
|
445
|
+
};
|
|
446
|
+
this.slots = [
|
|
447
|
+
new HeadSlotNode(span, this, "left", rows("left", 0)),
|
|
448
|
+
new HeadSlotNode(span, this, "center", rows("center", 1)),
|
|
449
|
+
new HeadSlotNode(span, this, "right", rows("right", 2)),
|
|
450
|
+
];
|
|
451
|
+
}
|
|
452
|
+
loweringEnter(ctx) {
|
|
453
|
+
// 收集真实全局事件:退出时校验时值,放置后按 AST 行归属做横向对齐
|
|
454
|
+
const group = {
|
|
455
|
+
members: [],
|
|
456
|
+
onTemporal(node) { this.members.push(node); },
|
|
457
|
+
};
|
|
458
|
+
ctx.beginLoweringGroup(this, group);
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
461
|
+
loweringExit(ctx) {
|
|
462
|
+
const { members } = ctx.endLoweringGroup(this);
|
|
463
|
+
const head = ctx.getTemporalNodes(this.slots[0])[0];
|
|
464
|
+
head.members = members;
|
|
465
|
+
head.slots = this.slots.map(ast => {
|
|
466
|
+
const [start, end] = ctx.getTemporalNodes(ast);
|
|
467
|
+
return { ast, start, end };
|
|
468
|
+
});
|
|
469
|
+
for (const node of members) {
|
|
470
|
+
if (!node.T.isZero()) {
|
|
471
|
+
throw new ErrorDiagnostic("E_HEAD_NONZERO_DURATION", "@head 的内容必须全部为零时长", node.ast.sourceSpan);
|
|
472
|
+
}
|
|
473
|
+
if (node.breakBefore > 0) {
|
|
474
|
+
throw new ErrorDiagnostic("E_HEAD_INTERNAL_BREAK", "@head 的内部不能使用 @br;第一层内容已经表示视觉行", node.ast.sourceSpan);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return [];
|
|
478
|
+
}
|
|
479
|
+
addSugarRow(name, row) {
|
|
480
|
+
this.slots.find(slot => slot.name === name).addRow(row);
|
|
481
|
+
}
|
|
482
|
+
toString(source) {
|
|
483
|
+
const slots = this.slots
|
|
484
|
+
.filter(slot => slot.rows.length > 0)
|
|
485
|
+
.map(slot => {
|
|
486
|
+
const rows = slot.rows
|
|
487
|
+
.map(row => ` ${row.toString(source).replaceAll("\n", "\n ")}`)
|
|
488
|
+
.join("\n");
|
|
489
|
+
return ` ${slot.name}={\n${rows}\n }`;
|
|
490
|
+
});
|
|
491
|
+
if (this.gap !== DEFAULT_GAP_PX)
|
|
492
|
+
slots.push(` gap=${this.gap}px`);
|
|
493
|
+
return `@head(\n${slots.join(",\n")}\n)`;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
export const HeadNode = HeadFunction;
|
|
@@ -1,11 +1,41 @@
|
|
|
1
|
-
import { TemporalNodeBase } from "
|
|
1
|
+
import { DEFAULT_TONALITY, TemporalNodeBase } from "../temporal.js";
|
|
2
2
|
import { ASTFunctionNode } from "../ASTtypes.js";
|
|
3
|
+
import { Diagnostic, ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
|
|
4
|
+
import { parseNoteName } from "../note/noteNameFSM.js";
|
|
5
|
+
import { acc2Offset, NoteNameMap, tonality2Midi } from "../../parser/parse-utils/note-utils.js";
|
|
6
|
+
import { paintAccidental, placeAccidentals } from "../note/accidentals.js";
|
|
7
|
+
/**
|
|
8
|
+
* 把宽松的调性写法收敛成 tonality2Midi 认得的 [音名][最多一个 #b][绝对八度]
|
|
9
|
+
*
|
|
10
|
+
* 本来就合法就原样返回,彻底读不懂返回 null
|
|
11
|
+
* `C###` 这种超过一个变音记号的写法按实际音高换字母(→ D#4),落在黑键上则跟随原来的升降方向拼写
|
|
12
|
+
*/
|
|
13
|
+
function normalizeTonality(tonality) {
|
|
14
|
+
try {
|
|
15
|
+
tonality2Midi(tonality, 4);
|
|
16
|
+
return tonality;
|
|
17
|
+
}
|
|
18
|
+
catch { /* 落到下面归一化 */ }
|
|
19
|
+
const parsed = parseNoteName(tonality.replace(/^[a-g]/, letter => letter.toUpperCase()));
|
|
20
|
+
if (parsed instanceof Diagnostic)
|
|
21
|
+
return null;
|
|
22
|
+
const pitchClass = NoteNameMap[parsed.name];
|
|
23
|
+
if (pitchClass === undefined)
|
|
24
|
+
return null;
|
|
25
|
+
const offset = acc2Offset(parsed.acc ?? "", false);
|
|
26
|
+
const octave = parsed.absOctave ? parsed.octave ?? 4 : 4 + (parsed.octave ?? 0);
|
|
27
|
+
const midi = (octave + 1) * 12 + pitchClass + offset;
|
|
28
|
+
// NoteNameMap 里同一音高的升号拼写在前、降号在后,正好用来挑方向;数字音名不参与拼写
|
|
29
|
+
const spellings = Object.keys(NoteNameMap).filter(name => NoteNameMap[name] === ((midi % 12) + 12) % 12 && /^[A-G]/.test(name));
|
|
30
|
+
return (offset < 0 ? spellings.at(-1) : spellings[0]) + (Math.floor(midi / 12) - 1);
|
|
31
|
+
}
|
|
3
32
|
class KeyFunction extends ASTFunctionNode {
|
|
4
33
|
static def = {
|
|
5
34
|
name: ["key", "1"],
|
|
6
35
|
description: "设置时间线上的 1= 调性基准",
|
|
7
36
|
example: `@1(C4) 或 @key(F#3)
|
|
8
|
-
它不会修改 parser
|
|
37
|
+
它不会修改 parser 的局部变量,而是在时间固化阶段影响其后的数字音名解释
|
|
38
|
+
画出来的记号只含音名和升降号,不含八度;通常叠在音符上方书写:1 ^ @1(F#)`,
|
|
9
39
|
allowExtraArgs: false,
|
|
10
40
|
args: [
|
|
11
41
|
{
|
|
@@ -13,12 +43,38 @@ class KeyFunction extends ASTFunctionNode {
|
|
|
13
43
|
type: "string",
|
|
14
44
|
default: null,
|
|
15
45
|
},
|
|
46
|
+
{
|
|
47
|
+
name: "size",
|
|
48
|
+
type: "length",
|
|
49
|
+
default: {
|
|
50
|
+
value: 1,
|
|
51
|
+
unit: "em",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
16
54
|
],
|
|
17
55
|
};
|
|
18
56
|
tonality;
|
|
57
|
+
size;
|
|
58
|
+
font;
|
|
59
|
+
/** 只用于绘制:音名与升降号,八度不上谱 */
|
|
60
|
+
displayName;
|
|
61
|
+
displayAcc;
|
|
19
62
|
constructor(sourceSpan, args, ctx, parent = null) {
|
|
20
63
|
super(sourceSpan, parent);
|
|
21
|
-
[
|
|
64
|
+
const [tonality, size] = this.getArgValue(args, ctx);
|
|
65
|
+
this.font = ctx.variables.numberfont;
|
|
66
|
+
this.tonality = tonality;
|
|
67
|
+
this.size = ctx.length2px(size);
|
|
68
|
+
const normalized = normalizeTonality(tonality);
|
|
69
|
+
if (normalized !== tonality) {
|
|
70
|
+
if (ctx.variables.strict)
|
|
71
|
+
throw new ErrorDiagnostic("E_KEY_TONALITY", `@key 无法解析调性 "${tonality}"`, sourceSpan);
|
|
72
|
+
this.tonality = normalized ?? DEFAULT_TONALITY;
|
|
73
|
+
ctx.diagnostics.push(new WarningDiagnostic("W_KEY_TONALITY", `@key 的调性 "${tonality}" 不是规范写法,已自动切换到 ${this.tonality}`, sourceSpan));
|
|
74
|
+
}
|
|
75
|
+
// 归一化保证了格式是 [音名][最多一个 #b][八度]
|
|
76
|
+
this.displayName = this.tonality[0];
|
|
77
|
+
this.displayAcc = this.tonality[1] === "#" || this.tonality[1] === "b" ? this.tonality[1] : "";
|
|
22
78
|
}
|
|
23
79
|
loweringEnter() {
|
|
24
80
|
return [new KeyTemporalNode(this)];
|
|
@@ -28,12 +84,51 @@ class KeyFunction extends ASTFunctionNode {
|
|
|
28
84
|
}
|
|
29
85
|
}
|
|
30
86
|
export const KeyNode = KeyFunction;
|
|
87
|
+
const PREFIX = "1=";
|
|
31
88
|
class KeyTemporalNode extends TemporalNodeBase {
|
|
89
|
+
accidentals = [];
|
|
90
|
+
nameX = 0;
|
|
91
|
+
textBaselineY = 0;
|
|
92
|
+
/** 字号在解析时已经固化,样式随之不再变 */
|
|
93
|
+
style;
|
|
32
94
|
constructor(ast) {
|
|
33
95
|
super();
|
|
34
96
|
this.ast = ast;
|
|
97
|
+
this.style = {
|
|
98
|
+
fontSize: ast.size,
|
|
99
|
+
fontFamily: ast.font,
|
|
100
|
+
fill: "#000",
|
|
101
|
+
};
|
|
102
|
+
this.initLayoutBox();
|
|
35
103
|
}
|
|
36
104
|
onTimeState(state) {
|
|
37
105
|
state.keySignature = this.ast.tonality;
|
|
38
106
|
}
|
|
107
|
+
prepareLayout(context) {
|
|
108
|
+
const size = this.ast.size;
|
|
109
|
+
const style = this.style;
|
|
110
|
+
const prefix = context.textMeasurer.measureText(PREFIX, style);
|
|
111
|
+
const name = context.textMeasurer.measureText(this.ast.displayName, style);
|
|
112
|
+
const accidentalGap = size * 0.02;
|
|
113
|
+
const { placed, right, top } = placeAccidentals(this.ast.displayAcc, size, prefix.w, prefix.baseline, accidentalGap);
|
|
114
|
+
this.accidentals = placed;
|
|
115
|
+
// 升降号抬高后可能高过文字,整块下移把它装回盒子里
|
|
116
|
+
const shift = -top;
|
|
117
|
+
for (const p of placed)
|
|
118
|
+
p.y += shift;
|
|
119
|
+
this.nameX = right;
|
|
120
|
+
this.textBaselineY = shift + prefix.baseline;
|
|
121
|
+
this.box.w = right + name.w;
|
|
122
|
+
this.box.h = shift + Math.max(prefix.h, name.h);
|
|
123
|
+
// 与 @text 同规则:对齐点在第一个字符的中心
|
|
124
|
+
this.box.anchor = context.textMeasurer.measureText(PREFIX[0], style).w / 2;
|
|
125
|
+
this.box.visualAxis = this.box.h / 2;
|
|
126
|
+
}
|
|
127
|
+
paint(painter) {
|
|
128
|
+
const style = this.style;
|
|
129
|
+
painter.drawText(PREFIX, this.box.x, this.box.y + this.textBaselineY, style);
|
|
130
|
+
for (const placed of this.accidentals)
|
|
131
|
+
paintAccidental(painter, placed, this.box, "#000");
|
|
132
|
+
painter.drawText(this.ast.displayName, this.box.x + this.nameX, this.box.y + this.textBaselineY, style);
|
|
133
|
+
}
|
|
39
134
|
}
|