@yft-design/engine 0.0.10 → 0.0.11
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/dist/EngineCanvas.d.ts +6 -0
- package/dist/EngineCanvas.js +8 -0
- package/dist/debug/seed.d.ts +2 -1
- package/dist/debug/seed.js +8 -5
- package/dist/engineFlag.d.ts +12 -0
- package/dist/engineFlag.js +12 -0
- package/dist/export/svgExport.js +12 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interact/tableCellEditing.js +2 -1
- package/dist/model/scene.d.ts +1 -1
- package/dist/model/scene.js +4 -3
- package/dist/model/tableLayout.js +3 -2
- package/dist/model/textAlign.d.ts +37 -0
- package/dist/model/textAlign.js +36 -0
- package/dist/model/textLayout.d.ts +11 -4
- package/dist/model/textLayout.js +46 -26
- package/dist/render/QuadBatch.d.ts +14 -5
- package/dist/render/QuadBatch.js +66 -10
- package/dist/render/SceneRenderer.d.ts +10 -0
- package/dist/render/SceneRenderer.js +12 -0
- package/dist/render/TextRenderer.js +10 -4
- package/dist/render/imageEffects.d.ts +3 -1
- package/dist/render/imageEffects.js +30 -5
- package/dist/render/lineDecorationSdf.d.ts +63 -0
- package/dist/render/lineDecorationSdf.js +188 -0
- package/dist/render/scrollText.js +8 -3
- package/dist/render/segmentTable.d.ts +53 -0
- package/dist/render/segmentTable.js +117 -0
- package/dist/render/shaders.d.ts +4 -2
- package/dist/render/shaders.js +98 -7
- package/dist/render/strokeMiterOutline.d.ts +39 -0
- package/dist/render/strokeMiterOutline.js +224 -0
- package/dist/render/strokePainter.d.ts +11 -0
- package/dist/render/strokePainter.js +80 -7
- package/dist/render/strokeSdf.d.ts +34 -13
- package/dist/render/strokeSdf.js +177 -13
- package/package.json +1 -1
package/dist/render/QuadBatch.js
CHANGED
|
@@ -11,10 +11,16 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { bindPaintUniforms } from './gradientRamp';
|
|
13
13
|
import { QUAD_FRAG_SRC, QUAD_VERT_SRC, compileProgram } from './shaders';
|
|
14
|
-
|
|
14
|
+
import { SegmentTable } from './segmentTable';
|
|
15
|
+
/** 每实例 24 个 float:mat3x2(6) + dim(2) + uv(4) + color(4) + radius(2) + dash(3) + seg(3),96 字节。
|
|
15
16
|
* dash 三元(方向三第一刀,2026-10-13):(on, cycle, phase)——(0,0,0)=非 dash
|
|
16
|
-
* 实例,着色器 cycle≤0.5 跳过 dash
|
|
17
|
-
|
|
17
|
+
* 实例,着色器 cycle≤0.5 跳过 dash 门,填充/纹理路径零语义变化。
|
|
18
|
+
* seg 三元(方向三第二刀,2026-10-13):(rowBase, segCount, geomHash)——段表
|
|
19
|
+
* 寻址(uSegTex 行=实例槽位);(0,0,0)=非段表实例,着色器 segCount≤0 跳过
|
|
20
|
+
* 段循环。rowBase 是**槽位相关量**(不参与内容等价判定,命中缓存后按当前
|
|
21
|
+
* 槽位回写);segCount/geomHash 是内容量(进 ownerBlocks 等价性判定——几何
|
|
22
|
+
* 变化 → hash 变 → 判脏重传,段表行随之重写) */
|
|
23
|
+
const INSTANCE_FLOATS = 24;
|
|
18
24
|
/** view 矩阵上传 scratch(批次 221,语义见 MeshBatch.VIEW_SCRATCH 同注) */
|
|
19
25
|
const VIEW_SCRATCH = new Float32Array(9);
|
|
20
26
|
const INITIAL_CAPACITY = 4096;
|
|
@@ -28,7 +34,7 @@ export class QuadBatch {
|
|
|
28
34
|
order = null;
|
|
29
35
|
/** owner → 已在 GPU 缓冲的实例落位(批次 212 增量上传):同偏移同内容即净段 */
|
|
30
36
|
gpuRecords = new Map();
|
|
31
|
-
/** owner → 上次写入的实例数据块(批次 212):matrix/dims/uv/color/radius/dash 全等即 memcpy */
|
|
37
|
+
/** owner → 上次写入的实例数据块(批次 212):matrix/dims/uv/color/radius/dash/seg(hash) 全等即 memcpy */
|
|
32
38
|
ownerBlocks = new WeakMap();
|
|
33
39
|
/** 自上次 flush 起新入的段(owner 落位记录的消费单元;deferDraws 下跨命令累积) */
|
|
34
40
|
pendingSegments = [];
|
|
@@ -49,6 +55,9 @@ export class QuadBatch {
|
|
|
49
55
|
instanceData = new Float32Array(INITIAL_CAPACITY * INSTANCE_FLOATS);
|
|
50
56
|
/** 白色 1x1 纹理:纯色 quad 的采样源 */
|
|
51
57
|
whiteTexture = null;
|
|
58
|
+
/** 段表数据纹理(方向三第二刀):行=实例槽位,生命周期与实例块同源(见
|
|
59
|
+
* segmentTable.ts 头注);懒建(首个段表 push 时),失败永久回落 */
|
|
60
|
+
segmentTable = null;
|
|
52
61
|
instanceCount = 0;
|
|
53
62
|
currentTexture = null;
|
|
54
63
|
/** 当前 run 的程序化填充参数(null = 纯色/纹理 run;flush 时据此绑 uPaint* uniforms) */
|
|
@@ -103,6 +112,7 @@ export class QuadBatch {
|
|
|
103
112
|
attr(6, 4, 12); // aColor
|
|
104
113
|
attr(7, 2, 16); // aRadius(批次 98 圆角;0,0 = 直角快路)
|
|
105
114
|
attr(8, 3, 18); // aDash(方向三第一刀:on/cycle/phase;(0,0,0) = 非 dash 快路)
|
|
115
|
+
attr(9, 3, 21); // aSeg(方向三第二刀:rowBase/segCount/hash;(0,0,0) = 非段表快路)
|
|
106
116
|
gl.bindVertexArray(null);
|
|
107
117
|
gl.enable(gl.BLEND);
|
|
108
118
|
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
@@ -125,6 +135,8 @@ export class QuadBatch {
|
|
|
125
135
|
const gl = this.gl;
|
|
126
136
|
if (this.whiteTexture)
|
|
127
137
|
gl.deleteTexture(this.whiteTexture);
|
|
138
|
+
this.segmentTable?.dispose();
|
|
139
|
+
this.segmentTable = null;
|
|
128
140
|
if (this.instanceBuffer)
|
|
129
141
|
gl.deleteBuffer(this.instanceBuffer);
|
|
130
142
|
if (this.indexBuffer)
|
|
@@ -172,13 +184,15 @@ export class QuadBatch {
|
|
|
172
184
|
* 提交一个 quad。matrix 为场景系 objectOwnMatrix;dim 为 transformedDimensions。
|
|
173
185
|
* texture 传 null 时用白纹理纯色渲染。radius(批次 98 圆角,本地系 [rx, ry],
|
|
174
186
|
* 调用侧已按 fabric 口径钳制/解析)缺省直角。dash(方向三第一刀,本地系
|
|
175
|
-
* [on, cycle, phase])缺省 null=非 dash(槽位写 0,着色器跳过门)。
|
|
187
|
+
* [on, cycle, phase])缺省 null=非 dash(槽位写 0,着色器跳过门)。segments
|
|
188
|
+
* (方向三第二刀)= 段表内容(data/count/hash)——写入 aSeg 槽并把段数据
|
|
189
|
+
* 写入段表纹理行(行号=本实例槽位;同 owner 同 hash 去重,见 segmentTable)。
|
|
176
190
|
*
|
|
177
191
|
* owner(批次 212 增量上传):节点身份键——实例数据全等(matrix/dims/uv/
|
|
178
|
-
* color/radius
|
|
179
|
-
* flush 不再重传净段)。缺省恒走全量写入。
|
|
192
|
+
* color/radius/seg 内容量)且落位不变时 memcpy 复用并标段为净(帧内累积模型下
|
|
193
|
+
* 交错 flush 不再重传净段)。缺省恒走全量写入。
|
|
180
194
|
*/
|
|
181
|
-
pushQuad(matrix, dimX, dimY, color, texture, uv = [0, 0, 1, 1], radius = null, owner, dash) {
|
|
195
|
+
pushQuad(matrix, dimX, dimY, color, texture, uv = [0, 0, 1, 1], radius = null, owner, dash, segments) {
|
|
182
196
|
if (!this.valid)
|
|
183
197
|
return;
|
|
184
198
|
// 跨批次 z 序协调(批次 210 优化②):mesh 侧有更新的待发内容先出清
|
|
@@ -191,6 +205,7 @@ export class QuadBatch {
|
|
|
191
205
|
this.grow();
|
|
192
206
|
}
|
|
193
207
|
const o = this.instanceCount * INSTANCE_FLOATS;
|
|
208
|
+
const slot = this.instanceCount;
|
|
194
209
|
this.pushedTextures.add(texture);
|
|
195
210
|
const d = this.instanceData;
|
|
196
211
|
let contentDirty = true;
|
|
@@ -216,8 +231,15 @@ export class QuadBatch {
|
|
|
216
231
|
cached.c3 === color[3] &&
|
|
217
232
|
cached.dashOn === (dash ? dash[0] : 0) &&
|
|
218
233
|
cached.dashCycle === (dash ? dash[1] : 0) &&
|
|
219
|
-
cached.dashPhase === (dash ? dash[2] : 0)
|
|
234
|
+
cached.dashPhase === (dash ? dash[2] : 0) &&
|
|
235
|
+
cached.segCount === (segments ? segments.count : 0) &&
|
|
236
|
+
cached.segHash === (segments ? segments.hash : 0)) {
|
|
220
237
|
d.set(cached.block, o);
|
|
238
|
+
// aSeg 槽位相关字段(rowBase=当前槽位)不参与内容等价——命中后按本次
|
|
239
|
+
// 实参回写(block 里是旧槽位;count/hash 命中态恒等,回写幂等)
|
|
240
|
+
d[o + 21] = slot;
|
|
241
|
+
d[o + 22] = segments ? segments.count : 0;
|
|
242
|
+
d[o + 23] = segments ? segments.hash : 0;
|
|
221
243
|
contentDirty = false;
|
|
222
244
|
}
|
|
223
245
|
else {
|
|
@@ -242,6 +264,9 @@ export class QuadBatch {
|
|
|
242
264
|
d[o + 18] = dash ? dash[0] : 0;
|
|
243
265
|
d[o + 19] = dash ? dash[1] : 0;
|
|
244
266
|
d[o + 20] = dash ? dash[2] : 0;
|
|
267
|
+
d[o + 21] = slot;
|
|
268
|
+
d[o + 22] = segments ? segments.count : 0;
|
|
269
|
+
d[o + 23] = segments ? segments.hash : 0;
|
|
245
270
|
if (owner) {
|
|
246
271
|
this.ownerBlocks.set(owner, {
|
|
247
272
|
floatCount: INSTANCE_FLOATS,
|
|
@@ -266,10 +291,16 @@ export class QuadBatch {
|
|
|
266
291
|
dashOn: dash ? dash[0] : 0,
|
|
267
292
|
dashCycle: dash ? dash[1] : 0,
|
|
268
293
|
dashPhase: dash ? dash[2] : 0,
|
|
294
|
+
segCount: segments ? segments.count : 0,
|
|
295
|
+
segHash: segments ? segments.hash : 0,
|
|
269
296
|
block: this.instanceData.slice(o, o + INSTANCE_FLOATS)
|
|
270
297
|
});
|
|
271
298
|
}
|
|
272
299
|
}
|
|
300
|
+
// 段表行写入(方向三第二刀):与实例块同点双写——同 owner 同 hash 去重
|
|
301
|
+
// (槽位复用/内容变化必然触发重写,见 segmentTable.writeRow)
|
|
302
|
+
if (segments)
|
|
303
|
+
this.segmentTable?.writeRow(slot, owner ?? null, segments);
|
|
273
304
|
const record = owner ? this.gpuRecords.get(owner) : undefined;
|
|
274
305
|
const segDirty = contentDirty || !record || record.startFloat !== o || record.floatCount !== INSTANCE_FLOATS;
|
|
275
306
|
this.pendingSegments.push({ owner: owner ?? null, startFloat: o, floatCount: INSTANCE_FLOATS, dirty: segDirty });
|
|
@@ -339,6 +370,12 @@ export class QuadBatch {
|
|
|
339
370
|
gl.activeTexture(gl.TEXTURE0);
|
|
340
371
|
gl.bindTexture(gl.TEXTURE_2D, this.currentTexture ?? this.whiteTexture);
|
|
341
372
|
gl.uniform1i(uniforms.tex, 0);
|
|
373
|
+
// 段表绑 unit2(方向三第二刀):uTex=0/uFillTex=1 之外的独立通道;无段表
|
|
374
|
+
// 实例(segCount=0)不 fetch,占位白纹理即可
|
|
375
|
+
gl.activeTexture(gl.TEXTURE2);
|
|
376
|
+
gl.bindTexture(gl.TEXTURE_2D, this.segmentTable?.texture ?? this.whiteTexture);
|
|
377
|
+
gl.uniform1i(uniforms.segTex, 2);
|
|
378
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
342
379
|
// 程序化填充段:填充纹理绑 unit1(uniforms 绑定共用);纯色/纹理段显式归零
|
|
343
380
|
// (uniform 是 program 级持久态,上个填充段残留的 mode 会污染后续纯色 run)
|
|
344
381
|
bindPaintUniforms(gl, uniforms, this.currentGradient, 1);
|
|
@@ -349,7 +386,7 @@ export class QuadBatch {
|
|
|
349
386
|
this.invalidateOverlappingRecords(start, end);
|
|
350
387
|
}
|
|
351
388
|
this.pendingUploads = [];
|
|
352
|
-
// 实例属性指针平移到区间起点(
|
|
389
|
+
// 实例属性指针平移到区间起点(9 个实例属性同源单缓冲,一次平移)
|
|
353
390
|
const stride = INSTANCE_FLOATS * 4;
|
|
354
391
|
const off = this.drawnFrom * stride;
|
|
355
392
|
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, stride, off);
|
|
@@ -360,6 +397,7 @@ export class QuadBatch {
|
|
|
360
397
|
gl.vertexAttribPointer(6, 4, gl.FLOAT, false, stride, off + 12 * 4);
|
|
361
398
|
gl.vertexAttribPointer(7, 2, gl.FLOAT, false, stride, off + 16 * 4);
|
|
362
399
|
gl.vertexAttribPointer(8, 3, gl.FLOAT, false, stride, off + 18 * 4);
|
|
400
|
+
gl.vertexAttribPointer(9, 3, gl.FLOAT, false, stride, off + 21 * 4);
|
|
363
401
|
gl.drawElementsInstanced(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0, count);
|
|
364
402
|
this.drawnFrom = this.instanceCount;
|
|
365
403
|
// 落位记录推进:净段记录本就命中,脏段上传后对齐——跨帧同走位即续传
|
|
@@ -463,6 +501,10 @@ export class QuadBatch {
|
|
|
463
501
|
gl.activeTexture(gl.TEXTURE0);
|
|
464
502
|
gl.bindTexture(gl.TEXTURE_2D, cmd.texture ?? this.whiteTexture);
|
|
465
503
|
gl.uniform1i(uniforms.tex, 0);
|
|
504
|
+
gl.activeTexture(gl.TEXTURE2);
|
|
505
|
+
gl.bindTexture(gl.TEXTURE_2D, this.segmentTable?.texture ?? this.whiteTexture);
|
|
506
|
+
gl.uniform1i(uniforms.segTex, 2);
|
|
507
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
466
508
|
bindPaintUniforms(gl, uniforms, cmd.gradient, 1);
|
|
467
509
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.instanceBuffer);
|
|
468
510
|
const stride = INSTANCE_FLOATS * 4;
|
|
@@ -475,6 +517,7 @@ export class QuadBatch {
|
|
|
475
517
|
gl.vertexAttribPointer(6, 4, gl.FLOAT, false, stride, off + 12 * 4);
|
|
476
518
|
gl.vertexAttribPointer(7, 2, gl.FLOAT, false, stride, off + 16 * 4);
|
|
477
519
|
gl.vertexAttribPointer(8, 3, gl.FLOAT, false, stride, off + 18 * 4);
|
|
520
|
+
gl.vertexAttribPointer(9, 3, gl.FLOAT, false, stride, off + 21 * 4);
|
|
478
521
|
gl.drawElementsInstanced(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0, cmd.count);
|
|
479
522
|
}
|
|
480
523
|
grow() {
|
|
@@ -488,6 +531,19 @@ export class QuadBatch {
|
|
|
488
531
|
this.pendingUploads = [[0, this.instanceCount * INSTANCE_FLOATS]];
|
|
489
532
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.instanceBuffer);
|
|
490
533
|
gl.bufferData(gl.ARRAY_BUFFER, this.instanceData.byteLength, gl.DYNAMIC_DRAW);
|
|
534
|
+
// 段表行容量同步(方向三第二刀):纹理重分配即行内容失守——writeRow 的
|
|
535
|
+
// rowOwners 去重依赖「行内容=该 owner 当前内容」,失守后首个同槽位 push
|
|
536
|
+
// 不会重写 → 必须整表重分配并全量回传(ensureRows 内部 texImage2D 全量)
|
|
537
|
+
this.segmentTable?.ensureRows(this.instanceData.length / INSTANCE_FLOATS);
|
|
538
|
+
}
|
|
539
|
+
/** 段表健康门(方向三第二刀):懒建段表并保障行容量——失败(RGBA32F 不可
|
|
540
|
+
* 用/OOM)永久 false,strokePainter 对 polygon 族回落烘焙。非段表路径零成本 */
|
|
541
|
+
canPushSegments() {
|
|
542
|
+
if (!this.valid)
|
|
543
|
+
return false;
|
|
544
|
+
if (!this.segmentTable)
|
|
545
|
+
this.segmentTable = new SegmentTable(this.gl);
|
|
546
|
+
return this.segmentTable.ensureRows(this.instanceData.length / INSTANCE_FLOATS);
|
|
491
547
|
}
|
|
492
548
|
get drawnInstances() {
|
|
493
549
|
return this.instanceCount;
|
|
@@ -102,6 +102,16 @@ export declare class SceneRenderer {
|
|
|
102
102
|
* 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口——批次372 起
|
|
103
103
|
* 统一汇入 SettleScheduler(三画家消费同一窗口,语义见各画家头注) */
|
|
104
104
|
noteVptChange(): void;
|
|
105
|
+
/** 覆盖层拖拽会话交互标记(批次 386,蒙版工具栏把手拖图「不跟手」刀一):
|
|
106
|
+
* 宿主 DOM 层拖拽(蒙版中心/旋转/缩放把手族)不写视口,但 zoom 换档后的
|
|
107
|
+
* k 档 settle 补帧(描边/文本/PSD 特效/蒙版全家族按帧预算补齐)撞上拖拽
|
|
108
|
+
* 期会与其帧渲染交错出 100ms+ 长任务(实测 zoom→220ms 后抓把手:zoom2/4
|
|
109
|
+
* 拖拽窗 96/283ms 长任务、最大帧隙 117/167ms;稳态拖拽零长任务)。与 vpt
|
|
110
|
+
* 写点同享 SettleScheduler 手势窗:拖拽事件逐次标记 → k 档补帧保持 stale
|
|
111
|
+
* 让路,停手 160ms 后 settle 帧统一补齐。语义与 noteVptChange 等价,独立
|
|
112
|
+
* 命名只表「非视口交互源」——不触 hit 带(zoom 不变)不请求渲染(调用方
|
|
113
|
+
* 的属性写自带 requestRenderAll) */
|
|
114
|
+
noteExternalInteraction(): void;
|
|
105
115
|
/** 节点光栅蒙版纹理与屏幕 uv 摆放(组蒙版 + 形状族直挂蒙版——批次 178 泛化;
|
|
106
116
|
* 无 mask/未加载返回 null。数学只依赖 raw.mask/dims/matrix,节点族无差) */
|
|
107
117
|
private groupMask;
|
|
@@ -85,6 +85,18 @@ export class SceneRenderer {
|
|
|
85
85
|
noteVptChange() {
|
|
86
86
|
this.settle.noteInteraction();
|
|
87
87
|
}
|
|
88
|
+
/** 覆盖层拖拽会话交互标记(批次 386,蒙版工具栏把手拖图「不跟手」刀一):
|
|
89
|
+
* 宿主 DOM 层拖拽(蒙版中心/旋转/缩放把手族)不写视口,但 zoom 换档后的
|
|
90
|
+
* k 档 settle 补帧(描边/文本/PSD 特效/蒙版全家族按帧预算补齐)撞上拖拽
|
|
91
|
+
* 期会与其帧渲染交错出 100ms+ 长任务(实测 zoom→220ms 后抓把手:zoom2/4
|
|
92
|
+
* 拖拽窗 96/283ms 长任务、最大帧隙 117/167ms;稳态拖拽零长任务)。与 vpt
|
|
93
|
+
* 写点同享 SettleScheduler 手势窗:拖拽事件逐次标记 → k 档补帧保持 stale
|
|
94
|
+
* 让路,停手 160ms 后 settle 帧统一补齐。语义与 noteVptChange 等价,独立
|
|
95
|
+
* 命名只表「非视口交互源」——不触 hit 带(zoom 不变)不请求渲染(调用方
|
|
96
|
+
* 的属性写自带 requestRenderAll) */
|
|
97
|
+
noteExternalInteraction() {
|
|
98
|
+
this.settle.noteInteraction();
|
|
99
|
+
}
|
|
88
100
|
/** 节点光栅蒙版纹理与屏幕 uv 摆放(组蒙版 + 形状族直挂蒙版——批次 178 泛化;
|
|
89
101
|
* 无 mask/未加载返回 null。数学只依赖 raw.mask/dims/matrix,节点族无差) */
|
|
90
102
|
groupMask(node) {
|
|
@@ -12,7 +12,8 @@ import { parseColor } from '../core/color';
|
|
|
12
12
|
import { composeMatrix, multiply } from '../core/mat2d';
|
|
13
13
|
import { parsePsdEffects, psdEffectsKey } from '../core/psdEffects';
|
|
14
14
|
import { isArcGlyphEnabled } from '../engineFlag';
|
|
15
|
-
import { charJitterY, drawParagraphPrefix, fontDeclaration, graphemeSplit, lineDecorationRuns, maxCharJitterY, resolveStrokeDecl, verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
|
|
15
|
+
import { CJK_LINE_RE, charJitterY, drawParagraphPrefix, fontDeclaration, graphemeSplit, lineDecorationRuns, maxCharJitterY, resolveStrokeDecl, verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
|
|
16
|
+
import { TextAlignValues, isJustifyFamilyAlign, isStretchAlign } from '../model/textAlign';
|
|
16
17
|
import { glyphRasterPlan, pickZoomBucket } from './GlyphAtlas';
|
|
17
18
|
import { bakeScrollText, scrollTextDecl } from './scrollText';
|
|
18
19
|
import { bakeTextHighlight, planTextHighlight } from './textHighlight';
|
|
@@ -498,7 +499,8 @@ export class TextRenderer {
|
|
|
498
499
|
if (!baseStroke || strokeWidth <= 0)
|
|
499
500
|
return;
|
|
500
501
|
const charSpacing = Number(node.raw.charSpacing) || 0;
|
|
501
|
-
const justify =
|
|
502
|
+
const justify = isJustifyFamilyAlign(node.raw.textAlign);
|
|
503
|
+
const disperse = node.raw.textAlign === TextAlignValues.DISPERSE;
|
|
502
504
|
// K-line 抖动:奇字越出排版盒(峰值 fontSize·0.5),画布四向余量同步放宽防裁剪
|
|
503
505
|
const textOffsetY = Number(node.raw.textOffsetY) || 0;
|
|
504
506
|
const jitterPad = maxCharJitterY(textOffsetY, node.textStyle, layout.lines);
|
|
@@ -518,6 +520,7 @@ export class TextRenderer {
|
|
|
518
520
|
bucket,
|
|
519
521
|
charSpacing,
|
|
520
522
|
justify,
|
|
523
|
+
node.raw.textAlign,
|
|
521
524
|
node.raw.vertical === true,
|
|
522
525
|
textOffsetY,
|
|
523
526
|
JSON.stringify(node.raw.paragraph ?? null)
|
|
@@ -572,10 +575,13 @@ export class TextRenderer {
|
|
|
572
575
|
globalCharIndex += line.graphemes.length;
|
|
573
576
|
continue;
|
|
574
577
|
}
|
|
575
|
-
// run 分段:charSpacing 逐字;justify
|
|
578
|
+
// run 分段:charSpacing 逐字;justify/disperse 空格断段;纯 justify/
|
|
579
|
+
// disperse 的 CJK 行被逐字分布拉伸(textLayout fork 口径)→ run 必须逐字
|
|
580
|
+
// 断段(run 内自然步进会吃掉字间隙);样式(字体/描边/填充)变化断段;
|
|
576
581
|
// K-line 逐字断段(fabric _renderChars 2496:textOffsetY≠0 强制逐字出笔,奇字 y 各异)
|
|
577
582
|
// 列表前缀:行首 strokeText(fabric 前缀块)+ runX 起点平移前缀宽
|
|
578
583
|
//(首 run 的 runX 不再是 0——boxes[0].left 已被前缀平移打破恒 0 不变量)
|
|
584
|
+
const charWiseStretched = isStretchAlign(node.raw.textAlign) && line.graphemes.some((g) => CJK_LINE_RE.test(g));
|
|
579
585
|
let run = '';
|
|
580
586
|
let runX = line.prefix ? drawParagraphPrefix(ctx, line, originX + lineLeft, baselineY, { stroke: resolveStrokeDecl(baseStroke, line.charStyles[0]) }) : 0;
|
|
581
587
|
let runJitter = 0;
|
|
@@ -622,7 +628,7 @@ export class TextRenderer {
|
|
|
622
628
|
runJitter = charJitterY(textOffsetY, glyphStyle.fontSize, globalCharIndex + i);
|
|
623
629
|
}
|
|
624
630
|
run += line.graphemes[i];
|
|
625
|
-
if (charSpacing || textOffsetY !== 0 || (justify && /[ \t\r]/.test(line.graphemes[i])))
|
|
631
|
+
if (charSpacing || textOffsetY !== 0 || ((justify || disperse) && /[ \t\r]/.test(line.graphemes[i])) || charWiseStretched)
|
|
626
632
|
flush(i + 1);
|
|
627
633
|
}
|
|
628
634
|
flush(line.graphemes.length);
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* translate(w/2,h/2) 与 fabric percentage 变换自带的 (-w/2,-h/2) 相消。引擎
|
|
16
16
|
* 用同款 canvas 原生 createLinear/RadialGradient + setTransform(decl 空间)
|
|
17
17
|
* 绘制,与 main 同机制(两端都是 canvas2d 对同一声明的求值,插值口径天然
|
|
18
|
-
* 一致,无需 ramp)。
|
|
18
|
+
* 一致,无需 ramp)。UI 取色器产出的渐变无 gradientUnits 键判 pixels(coords
|
|
19
|
+
* 即画布像素刻度),填充矩形按画布逆像包围盒取覆盖(渐变按 paint 时 CTM 解释,
|
|
20
|
+
* 见 bakePsdSolidFill 渐变分支注——批次 388)。
|
|
19
21
|
* - 路径族投影(P3-5c):main 的 PathCommon.renderShadow——dropShadow[] 逐层
|
|
20
22
|
* `ctx.filter = drop-shadow(ox oy blur color)` + `_renderFill` 重画(**raw 偏移
|
|
21
23
|
* 无缩放补偿**——与图片族的 effectiveShadow 公式不同);投影先画、被填充
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* translate(w/2,h/2) 与 fabric percentage 变换自带的 (-w/2,-h/2) 相消。引擎
|
|
16
16
|
* 用同款 canvas 原生 createLinear/RadialGradient + setTransform(decl 空间)
|
|
17
17
|
* 绘制,与 main 同机制(两端都是 canvas2d 对同一声明的求值,插值口径天然
|
|
18
|
-
* 一致,无需 ramp)。
|
|
18
|
+
* 一致,无需 ramp)。UI 取色器产出的渐变无 gradientUnits 键判 pixels(coords
|
|
19
|
+
* 即画布像素刻度),填充矩形按画布逆像包围盒取覆盖(渐变按 paint 时 CTM 解释,
|
|
20
|
+
* 见 bakePsdSolidFill 渐变分支注——批次 388)。
|
|
19
21
|
* - 路径族投影(P3-5c):main 的 PathCommon.renderShadow——dropShadow[] 逐层
|
|
20
22
|
* `ctx.filter = drop-shadow(ox oy blur color)` + `_renderFill` 重画(**raw 偏移
|
|
21
23
|
* 无缩放补偿**——与图片族的 effectiveShadow 公式不同);投影先画、被填充
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
import { effectiveShadow } from '../core/shadow';
|
|
32
34
|
import { fillStyleForNode, traceShapeStrokePath } from './strokeBake';
|
|
33
35
|
import { drawTextGlyphs } from './shadowBake';
|
|
34
|
-
import { multiply } from '../core/mat2d';
|
|
36
|
+
import { multiply, invert, transformPoint } from '../core/mat2d';
|
|
35
37
|
import { binaryFromAlpha, computeDistances } from '../core/distanceField';
|
|
36
38
|
import { imageFiltersKey, parseImageFilters } from '../core/imageFilters';
|
|
37
39
|
import { AnimatedNode } from '../model/scene';
|
|
@@ -189,9 +191,32 @@ export const bakePsdSolidFill = (node, decl, source, rasterScale = 1, sourceRect
|
|
|
189
191
|
g.addColorStop(t, `rgba(${Math.round(s.color[0] * 255)}, ${Math.round(s.color[1] * 255)}, ${Math.round(s.color[2] * 255)}, ${s.color[3]})`);
|
|
190
192
|
}
|
|
191
193
|
ctx.fillStyle = g;
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
|
|
194
|
+
// 渐变按 paint 时的 CTM 解释(此刻的 m = decl→画布 变换)——填充矩形须在
|
|
195
|
+
// decl 空间覆盖画布 [0,cw]×[0,ch] 的逆像;渐变端点外按 canvas 规范钳到首/
|
|
196
|
+
// 末 stop,覆盖大于画布不改变取色语义。percentage(PSD/模板装载形态)=
|
|
197
|
+
// decl 单位方 [0,1]² 外扩(既有口径,存量渐变面零扰动);pixels(UI 取色器
|
|
198
|
+
// 产出,无 gradientUnits 键,coords 即画布像素刻度)此前沿用单位方
|
|
199
|
+
// fillRect(-2,-2,5,5)——identity 变换下只画左上 5×5 像素,经 destination-in
|
|
200
|
+
// 剪影遮罩后渐变整层丢失(批次 388「文本渐变填充不生效」根因)——改取画布
|
|
201
|
+
// 逆像包围盒(覆盖 offset/gradientTransform 的平移旋缩,外扩 2px)
|
|
202
|
+
if (d.gradientUnits === 'percentage') {
|
|
203
|
+
ctx.fillRect(-2, -2, 5, 5);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const inv = invert(m);
|
|
207
|
+
const corners = [transformPoint(inv, 0, 0), transformPoint(inv, cw, 0), transformPoint(inv, 0, ch), transformPoint(inv, cw, ch)];
|
|
208
|
+
if (corners.every((p) => isFinite(p.x) && isFinite(p.y))) {
|
|
209
|
+
const minX = Math.min(...corners.map((p) => p.x)) - 2;
|
|
210
|
+
const maxX = Math.max(...corners.map((p) => p.x)) + 2;
|
|
211
|
+
const minY = Math.min(...corners.map((p) => p.y)) - 2;
|
|
212
|
+
const maxY = Math.max(...corners.map((p) => p.y)) + 2;
|
|
213
|
+
ctx.fillRect(minX, minY, maxX - minX, maxY - minY);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// 奇异 gradientTransform 兜底:超大矩形(该变换下渐变退化整面单色,覆盖域无碍)
|
|
217
|
+
ctx.fillRect(-cw - ch, -cw - ch, (cw + ch) * 3, (cw + ch) * 3);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
195
220
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
196
221
|
}
|
|
197
222
|
else {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 线族装饰(Arrow/Dimension)的 SDF 直绘分片打包(方向三,批次 388,
|
|
3
|
+
* docs/2026-10-14_webgl2-sdf-line-decoration-blueprint.md)。
|
|
4
|
+
*
|
|
5
|
+
* 383 对 arrow/dimension「装饰头三角非纯折线,永走烘焙」的判决在 385 落地
|
|
6
|
+
* 段表填充模式(kind=4 mode 1 winding)后过时——实心三角头=三段闭合轮廓的
|
|
7
|
+
* 绕数填充。本模块把 bakeLineDecoration 的整元素 canvas 烘焙(sig 含连续
|
|
8
|
+
* k=zoom×dpr 的缩放连续重烘族)拆解为解析式分片:
|
|
9
|
+
*
|
|
10
|
+
* - Arrow:杆线片(端头所在端退缩 headH,line kind——butt/square 帽与两段
|
|
11
|
+
* dash 既有语义)+ 三角头片(tip=端点、向后 headH、±headW/2、sizeScale=
|
|
12
|
+
* √strokeWidth——段表填充,实心无笔宽语义 halfW 槽闲置);
|
|
13
|
+
* - Dimension:主线片(全描边语义:dash/cap/join/miter/uniform 补偿——line
|
|
14
|
+
* kind 既有)+ 端刻片×2(垂直主线、长 textFontSize、round 帽、宽
|
|
15
|
+
* strokeWidth、无 dash)——文本标签由 strokePainter 桶化小烘焙承接(唯一
|
|
16
|
+
* 残留,sig 含桶而非连续 k)。
|
|
17
|
+
*
|
|
18
|
+
* 几何公式**逐式照抄 bakeLineDecoration**(strokeBake.ts 同源——同一公式两处
|
|
19
|
+
* 实现是漂移地雷,lineDecorationSdf.spec 锁逐点相等)。坐标系:raw x1..y2 即
|
|
20
|
+
* 对象中心系(LineNode.localPoint 命中同口径);每片以自身 bbox 中心为 quad
|
|
21
|
+
* 中心(matrix=node.matrix∘T(center),片坐标=几何−中心)。
|
|
22
|
+
*/
|
|
23
|
+
import type { StrokeDecl } from '../core/stroke';
|
|
24
|
+
import { type StrokeSdfSegments } from './segmentTable';
|
|
25
|
+
export interface DecorationPiece {
|
|
26
|
+
/** 片 quad 中心(对象本地系)——pushQuad 矩阵=node.matrix∘T(center) */
|
|
27
|
+
centerX: number;
|
|
28
|
+
centerY: number;
|
|
29
|
+
/** aUv/shape 槽:line=(x1,y1,x2,y2)(片中心系)/填充片=(0,0,0,0) */
|
|
30
|
+
shape: [number, number, number, number];
|
|
31
|
+
/** aRadius 槽:[halfW, −code](填充片 halfW 闲置传 0) */
|
|
32
|
+
halfW: number;
|
|
33
|
+
code: number;
|
|
34
|
+
quadW: number;
|
|
35
|
+
quadH: number;
|
|
36
|
+
dash: readonly [number, number, number] | null;
|
|
37
|
+
segments: StrokeSdfSegments | null;
|
|
38
|
+
}
|
|
39
|
+
/** Dimension 文本标签 spec(bakeLineDecoration 文本段同式;w 由调用方以
|
|
40
|
+
* measureWidth 补齐——模块零 DOM 依赖) */
|
|
41
|
+
export interface LineDecoTextSpec {
|
|
42
|
+
text: string;
|
|
43
|
+
fontPx: number;
|
|
44
|
+
w: number;
|
|
45
|
+
h: number;
|
|
46
|
+
cx: number;
|
|
47
|
+
cy: number;
|
|
48
|
+
angle: number;
|
|
49
|
+
color: string;
|
|
50
|
+
bg: string;
|
|
51
|
+
follow: boolean;
|
|
52
|
+
pad: number;
|
|
53
|
+
}
|
|
54
|
+
export interface LineDecorationPieces {
|
|
55
|
+
pieces: DecorationPiece[];
|
|
56
|
+
/** Dimension 文本标签(桶化小烘焙承接);arrow 恒 null */
|
|
57
|
+
text: LineDecoTextSpec | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* eligibility 与分片打包:不合形态返回 null(调用方整元素回落烘焙——半解析半
|
|
61
|
+
* 烘焙的混血形态不做,383 原则)。几何源=raw.x1..y2(对象中心系)。
|
|
62
|
+
*/
|
|
63
|
+
export declare const lineDecorationPieces: (raw: Record<string, unknown>, decl: StrokeDecl, matrix: ReadonlyArray<number>, zoom: number, dpr: number) => LineDecorationPieces | null;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { isStrokeSdfDashEnabled, isStrokeSdfLineDecorationEnabled } from '../engineFlag';
|
|
2
|
+
import { segHash } from './segmentTable';
|
|
3
|
+
/** 描边码位段(与 strokeSdf.ts/shaders.ts 解码一致) */
|
|
4
|
+
const KIND_LINE = 2;
|
|
5
|
+
const KIND_SEGMENT_FILL = 4;
|
|
6
|
+
const CAP_INDEX = { butt: 0, round: 1, square: 2 };
|
|
7
|
+
/** AA 余量(设备像素折算本地单位)——与 strokeSdf.ts 同式(minAxis 最劣方向) */
|
|
8
|
+
const localPerDevicePxOf = (m, zoom, dpr) => {
|
|
9
|
+
const k = Math.max(1e-6, zoom * dpr);
|
|
10
|
+
const axis0 = Math.hypot(m[0], m[1]);
|
|
11
|
+
const axis1 = Math.hypot(m[2], m[3]);
|
|
12
|
+
const minAxis = Math.max(Math.min(axis0, axis1), 1e-6);
|
|
13
|
+
return { aa: 1 / (minAxis * k), minAxis };
|
|
14
|
+
};
|
|
15
|
+
/** dash 三元(两段 pattern butt/square 帽非 uniform——与 strokeSdf.ts line 放行同规;
|
|
16
|
+
* 不合形态返回 false 表示该线片不可直绘(调用方整元素回落) */
|
|
17
|
+
const lineDashTriple = (decl) => {
|
|
18
|
+
if (!decl.dashArray)
|
|
19
|
+
return { dash: null, ok: true };
|
|
20
|
+
if (!isStrokeSdfDashEnabled())
|
|
21
|
+
return { dash: null, ok: false };
|
|
22
|
+
if (decl.dashArray.length > 2)
|
|
23
|
+
return { dash: null, ok: false };
|
|
24
|
+
if (decl.lineCap !== 'butt' && decl.lineCap !== 'square')
|
|
25
|
+
return { dash: null, ok: false };
|
|
26
|
+
if (decl.uniform)
|
|
27
|
+
return { dash: null, ok: false };
|
|
28
|
+
const on = decl.dashArray[0];
|
|
29
|
+
const off = decl.dashArray.length > 1 ? decl.dashArray[1] : on;
|
|
30
|
+
if (on + off <= 0)
|
|
31
|
+
return { dash: null, ok: true };
|
|
32
|
+
return { dash: [on, on + off, decl.dashOffset], ok: true };
|
|
33
|
+
};
|
|
34
|
+
/** 线片打包(片中心系):中心=中点、quad=|dx|×|dy|+2×(带余量+AA)。uniform
|
|
35
|
+
* 笔宽带余量=halfW/minAxis(strokeSdf.ts 同式——着色器像素空间换算的最劣界) */
|
|
36
|
+
const linePiece = (x1, y1, x2, y2, halfW, capSlot, penUniform, dash, aa, minAxis) => {
|
|
37
|
+
const cx = (x1 + x2) / 2;
|
|
38
|
+
const cy = (y1 + y2) / 2;
|
|
39
|
+
const margin = penUniform ? halfW / minAxis : halfW;
|
|
40
|
+
const quadW = Math.abs(x2 - x1) + 2 * (margin + aa);
|
|
41
|
+
const quadH = Math.abs(y2 - y1) + 2 * (margin + aa);
|
|
42
|
+
return {
|
|
43
|
+
centerX: cx,
|
|
44
|
+
centerY: cy,
|
|
45
|
+
shape: [x1 - cx, y1 - cy, x2 - cx, y2 - cy],
|
|
46
|
+
halfW,
|
|
47
|
+
code: -(KIND_LINE + (capSlot << 3) + (penUniform ? 64 : 0)),
|
|
48
|
+
quadW,
|
|
49
|
+
quadH,
|
|
50
|
+
dash,
|
|
51
|
+
segments: null
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** 三角头片(段表填充):verts 三点闭合轮廓,quad=bbox+2×AA(实心无带余量) */
|
|
55
|
+
const trianglePiece = (verts, aa) => {
|
|
56
|
+
let minX = Infinity;
|
|
57
|
+
let minY = Infinity;
|
|
58
|
+
let maxX = -Infinity;
|
|
59
|
+
let maxY = -Infinity;
|
|
60
|
+
for (const v of verts) {
|
|
61
|
+
if (minX > v.x)
|
|
62
|
+
minX = v.x;
|
|
63
|
+
if (minY > v.y)
|
|
64
|
+
minY = v.y;
|
|
65
|
+
if (maxX < v.x)
|
|
66
|
+
maxX = v.x;
|
|
67
|
+
if (maxY < v.y)
|
|
68
|
+
maxY = v.y;
|
|
69
|
+
}
|
|
70
|
+
const cx = (minX + maxX) / 2;
|
|
71
|
+
const cy = (minY + maxY) / 2;
|
|
72
|
+
const loop = [verts[0], verts[1], verts[2], verts[0]];
|
|
73
|
+
const data = new Float32Array(3 * 4);
|
|
74
|
+
for (let i = 0; i < 3; i++) {
|
|
75
|
+
data[i * 4] = loop[i].x - cx;
|
|
76
|
+
data[i * 4 + 1] = loop[i].y - cy;
|
|
77
|
+
data[i * 4 + 2] = loop[i + 1].x - cx;
|
|
78
|
+
data[i * 4 + 3] = loop[i + 1].y - cy;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
centerX: cx,
|
|
82
|
+
centerY: cy,
|
|
83
|
+
shape: [0, 0, 0, 0],
|
|
84
|
+
halfW: 0,
|
|
85
|
+
code: -(KIND_SEGMENT_FILL + (1 << 3)),
|
|
86
|
+
quadW: maxX - minX + 2 * aa,
|
|
87
|
+
quadH: maxY - minY + 2 * aa,
|
|
88
|
+
dash: null,
|
|
89
|
+
segments: { data, count: 3, hash: segHash(data) }
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const readPoints = (raw) => {
|
|
93
|
+
const x1 = Number(raw.x1);
|
|
94
|
+
const y1 = Number(raw.y1);
|
|
95
|
+
const x2 = Number(raw.x2);
|
|
96
|
+
const y2 = Number(raw.y2);
|
|
97
|
+
if (!Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x2) || !Number.isFinite(y2))
|
|
98
|
+
return null;
|
|
99
|
+
if (x1 === x2 && y1 === y2)
|
|
100
|
+
return null;
|
|
101
|
+
return { x1, y1, x2, y2 };
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* eligibility 与分片打包:不合形态返回 null(调用方整元素回落烘焙——半解析半
|
|
105
|
+
* 烘焙的混血形态不做,383 原则)。几何源=raw.x1..y2(对象中心系)。
|
|
106
|
+
*/
|
|
107
|
+
export const lineDecorationPieces = (raw, decl, matrix, zoom, dpr) => {
|
|
108
|
+
const type = typeof raw.type === 'string' ? raw.type.toLowerCase() : '';
|
|
109
|
+
if (type !== 'arrow' && type !== 'dimension')
|
|
110
|
+
return null;
|
|
111
|
+
if (!isStrokeSdfLineDecorationEnabled())
|
|
112
|
+
return null;
|
|
113
|
+
const p = readPoints(raw);
|
|
114
|
+
if (!p)
|
|
115
|
+
return null;
|
|
116
|
+
if (decl.alignment !== 'center')
|
|
117
|
+
return null;
|
|
118
|
+
const { aa, minAxis } = localPerDevicePxOf(matrix, zoom, dpr);
|
|
119
|
+
const aaPx = 4 * aa;
|
|
120
|
+
const strokeWidth = decl.width;
|
|
121
|
+
const cos = (p.x2 - p.x1) / Math.hypot(p.x2 - p.x1, p.y2 - p.y1);
|
|
122
|
+
const sin = (p.y2 - p.y1) / Math.hypot(p.x2 - p.x1, p.y2 - p.y1);
|
|
123
|
+
if (type === 'arrow') {
|
|
124
|
+
const arrowW = Number(raw.arrowWidth) || 15;
|
|
125
|
+
const arrowH = Number(raw.arrowHeight) || 22.5;
|
|
126
|
+
const arrowType = raw.arrowType === 'start' || raw.arrowType === 'both' ? raw.arrowType : 'end';
|
|
127
|
+
const sizeScale = Math.sqrt(strokeWidth);
|
|
128
|
+
const headW = arrowW * sizeScale;
|
|
129
|
+
const headH = arrowH * sizeScale;
|
|
130
|
+
const atStart = arrowType === 'start' || arrowType === 'both';
|
|
131
|
+
const atEnd = arrowType === 'end' || arrowType === 'both';
|
|
132
|
+
const { dash, ok } = lineDashTriple(decl);
|
|
133
|
+
if (!ok)
|
|
134
|
+
return null;
|
|
135
|
+
// 杆线:端头所在端退缩 headH(bake 同式);帽=decl(butt 缺省)
|
|
136
|
+
const ax1 = p.x1 + cos * (atStart ? headH : 0);
|
|
137
|
+
const ay1 = p.y1 + sin * (atStart ? headH : 0);
|
|
138
|
+
const ax2 = p.x2 - cos * (atEnd ? headH : 0);
|
|
139
|
+
const ay2 = p.y2 - sin * (atEnd ? headH : 0);
|
|
140
|
+
const shaft = linePiece(ax1, ay1, ax2, ay2, strokeWidth / 2, CAP_INDEX[decl.lineCap] ?? 0, decl.uniform, dash, aaPx, minAxis);
|
|
141
|
+
const pieces = [shaft];
|
|
142
|
+
const head = (tipX, tipY, dirCos, dirSin) => {
|
|
143
|
+
const bx = tipX - dirCos * headH;
|
|
144
|
+
const by = tipY - dirSin * headH;
|
|
145
|
+
return trianglePiece([
|
|
146
|
+
{ x: tipX, y: tipY },
|
|
147
|
+
{ x: bx + -dirSin * (headW / 2), y: by + dirCos * (headW / 2) },
|
|
148
|
+
{ x: bx - -dirSin * (headW / 2), y: by - dirCos * (headW / 2) }
|
|
149
|
+
], aaPx);
|
|
150
|
+
};
|
|
151
|
+
if (atEnd)
|
|
152
|
+
pieces.push(head(p.x2, p.y2, cos, sin));
|
|
153
|
+
if (atStart)
|
|
154
|
+
pieces.push(head(p.x1, p.y1, -cos, -sin));
|
|
155
|
+
return { pieces, text: null };
|
|
156
|
+
}
|
|
157
|
+
// Dimension:主线全语义 + 端刻×2(round 帽短线)+ 文本 spec
|
|
158
|
+
const { dash, ok } = lineDashTriple(decl);
|
|
159
|
+
if (!ok)
|
|
160
|
+
return null;
|
|
161
|
+
const main = linePiece(p.x1, p.y1, p.x2, p.y2, strokeWidth / 2, CAP_INDEX[decl.lineCap] ?? 0, decl.uniform, dash, aaPx, minAxis);
|
|
162
|
+
const fontPx = Number(raw.textFontSize) || 50;
|
|
163
|
+
const nx = -sin;
|
|
164
|
+
const ny = cos;
|
|
165
|
+
const halfTick = fontPx / 2;
|
|
166
|
+
const tickA = linePiece(p.x1 - nx * halfTick, p.y1 - ny * halfTick, p.x1 + nx * halfTick, p.y1 + ny * halfTick, strokeWidth / 2, CAP_INDEX.round, false, null, aaPx, minAxis);
|
|
167
|
+
const tickB = linePiece(p.x2 - nx * halfTick, p.y2 - ny * halfTick, p.x2 + nx * halfTick, p.y2 + ny * halfTick, strokeWidth / 2, CAP_INDEX.round, false, null, aaPx, minAxis);
|
|
168
|
+
// 文本 spec(bakeLineDecoration 同式:measureWidth 由调用方注入——模块零 DOM 依赖)
|
|
169
|
+
const text = typeof raw.text === 'string' && raw.text.trim() ? raw.text : '50cm';
|
|
170
|
+
const pad = Number(raw.textPadding) || 4;
|
|
171
|
+
const offset = fontPx + strokeWidth / 2 + 5;
|
|
172
|
+
return {
|
|
173
|
+
pieces: [main, tickA, tickB],
|
|
174
|
+
text: {
|
|
175
|
+
text,
|
|
176
|
+
fontPx,
|
|
177
|
+
w: 0,
|
|
178
|
+
h: fontPx + pad * 2,
|
|
179
|
+
cx: (p.x1 + p.x2) / 2 + nx * offset,
|
|
180
|
+
cy: (p.y1 + p.y2) / 2 + ny * offset,
|
|
181
|
+
angle: Math.atan2(p.y2 - p.y1, p.x2 - p.x1),
|
|
182
|
+
color: typeof raw.textColor === 'string' ? raw.textColor : '#333333',
|
|
183
|
+
bg: typeof raw.textBackgroundColor === 'string' ? raw.textBackgroundColor : '#ffffff',
|
|
184
|
+
follow: raw.textFollowLine !== false,
|
|
185
|
+
pad
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
};
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
* 近似,parity 劣于 canvas 直出。offset 进签名:播放期逐帧重烘(量级同
|
|
21
21
|
* 动画族逐帧纹理重传),静止态恒缓存。
|
|
22
22
|
*/
|
|
23
|
-
import { drawParagraphPrefix, fontDeclaration, resolveStrokeDecl } from '../model/textLayout';
|
|
23
|
+
import { CJK_LINE_RE, drawParagraphPrefix, fontDeclaration, resolveStrokeDecl } from '../model/textLayout';
|
|
24
|
+
import { TextAlignValues, isJustifyFamilyAlign, isStretchAlign } from '../model/textAlign';
|
|
24
25
|
import { glyphStyleOf } from './arcText';
|
|
25
26
|
import { drawVerticalGlyph, verticalGlyphOps } from './verticalText';
|
|
26
27
|
/** 滚动声明解析:只认 ScrollText 类型(普通 textbox 带杂散字段不滚)。
|
|
@@ -212,7 +213,11 @@ const drawTextPass = (ctx, node, pass) => {
|
|
|
212
213
|
if (endIndex < line.boxes.length)
|
|
213
214
|
runX = line.boxes[endIndex].left;
|
|
214
215
|
};
|
|
215
|
-
const justify =
|
|
216
|
+
const justify = isJustifyFamilyAlign(raw.textAlign);
|
|
217
|
+
const disperse = raw.textAlign === TextAlignValues.DISPERSE;
|
|
218
|
+
// 纯 justify/disperse 的 CJK 行被逐字分布拉伸(textLayout fork 口径)→ run
|
|
219
|
+
// 必须逐字断段(与 TextRenderer.renderTextDashStroke 同语义)
|
|
220
|
+
const charWiseStretched = isStretchAlign(raw.textAlign) && line.graphemes.some((g) => CJK_LINE_RE.test(g));
|
|
216
221
|
for (let i = 0; i < line.graphemes.length; i++) {
|
|
217
222
|
const o = line.charStyles[i];
|
|
218
223
|
const gs = glyphStyleOf(style, o);
|
|
@@ -228,7 +233,7 @@ const drawTextPass = (ctx, node, pass) => {
|
|
|
228
233
|
runFill = fill;
|
|
229
234
|
}
|
|
230
235
|
run += line.graphemes[i];
|
|
231
|
-
if (charSpacing || (justify && /[ \t\r]/.test(line.graphemes[i])))
|
|
236
|
+
if (charSpacing || ((justify || disperse) && /[ \t\r]/.test(line.graphemes[i])) || charWiseStretched)
|
|
232
237
|
flush(i + 1);
|
|
233
238
|
}
|
|
234
239
|
flush(line.graphemes.length);
|