@yft-design/engine 0.0.5 → 0.0.7
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.js +4 -2
- package/dist/core/warpMesh.d.ts +75 -0
- package/dist/core/warpMesh.js +469 -0
- package/dist/export/svgExport.d.ts +11 -5
- package/dist/export/svgExport.js +17 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/render/GLTextureCache.d.ts +31 -8
- package/dist/render/GLTextureCache.js +51 -20
- package/dist/render/SceneRenderer.js +10 -0
- package/dist/render/TextRenderer.d.ts +12 -0
- package/dist/render/TextRenderer.js +55 -2
- package/dist/render/psdWarpText.d.ts +28 -0
- package/dist/render/psdWarpText.js +212 -0
- package/dist/render/warpText.d.ts +13 -0
- package/dist/render/warpText.js +8 -6
- package/package.json +1 -1
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
* 工作集 vs 512MiB 预算,每帧强逐 ~280MB 再全量重传,帧渲染 2.5~5s 永不
|
|
11
11
|
* 收敛;预算抬到覆盖工作集后同场景 3ms/帧——A/B 定谳)。孤儿/换页残留
|
|
12
12
|
* 不再被 get 命中即沉到 LRU 头,下一次插入压力先逐它们,预算仍长期生效。
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* - **帧界保护(插入压力三防线,批次 321 补丁)**:渲染中插入路径的淘汰依次
|
|
14
|
+
* 受 ①手势期冻结(markFrame(gestureActive))②近帧宽限(evictGraceFrames
|
|
15
|
+
* 帧内 touch 过的不逐——句柄可能已被批渲染器捕获,保留式帧让活动工作集
|
|
16
|
+
* 间歇不 touch)③代价感知(先逐 <32MiB 小条目,耗尽才动大条目)拦护;
|
|
17
|
+
* 全被拦下时允许留驻超额——颠簸 = 永不可用,留驻 = 一次性上传后稳定,
|
|
18
|
+
* 是显式取舍(细节见 evictIfNeeded 头注)
|
|
16
19
|
* - 字节口径:宽×高×4(RGBA8),mipmap 源 ×4/3(三级以上链约数)
|
|
17
20
|
*
|
|
18
21
|
* Phase 4 动态源(动画 GIF 单帧缓冲 / HTMLVideoElement):
|
|
@@ -29,6 +32,9 @@ export interface GLTextureCacheOptions {
|
|
|
29
32
|
budgetBytes?: number;
|
|
30
33
|
/** 条数上限(防小纹理海量条目绕过字节预算);缺省 2048 */
|
|
31
34
|
maxEntries?: number;
|
|
35
|
+
/** 插入压力淘汰的近帧宽限(帧数):lastFrame 距当前帧不足此值的条目跳过
|
|
36
|
+
* 淘汰。缺省 30。1 = 仅本帧(旧行为)。 */
|
|
37
|
+
evictGraceFrames?: number;
|
|
32
38
|
}
|
|
33
39
|
export interface TextureCacheStats {
|
|
34
40
|
entries: number;
|
|
@@ -46,6 +52,8 @@ export declare class GLTextureCache {
|
|
|
46
52
|
private readonly cache;
|
|
47
53
|
private budgetBytes;
|
|
48
54
|
private maxEntries;
|
|
55
|
+
private evictGraceFrames;
|
|
56
|
+
private gestureActive;
|
|
49
57
|
private frameStamp;
|
|
50
58
|
private frameTouches;
|
|
51
59
|
private evictions;
|
|
@@ -55,8 +63,10 @@ export declare class GLTextureCache {
|
|
|
55
63
|
/** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
|
|
56
64
|
* 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
|
|
57
65
|
* 「逐出→重传」死循环(同头注),淘汰统一改由插入压力驱动
|
|
58
|
-
* (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU
|
|
59
|
-
|
|
66
|
+
* (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU 头保证。
|
|
67
|
+
* gestureActive(指针手势进行中):本帧插入压力淘汰整体冻结(见
|
|
68
|
+
* evictIfNeeded 头注的手势期防线) */
|
|
69
|
+
markFrame(gestureActive?: boolean): void;
|
|
60
70
|
/** 累计逐出计数(批次 223 重落保留式回退门):逐出删除纹理句柄会使快照命令
|
|
61
71
|
* 里引用的句柄失效——计数变化即作废保留式快照走全量帧 */
|
|
62
72
|
get evictionCount(): number;
|
|
@@ -65,11 +75,24 @@ export declare class GLTextureCache {
|
|
|
65
75
|
get(source: TextureSource): WebGLTexture | null;
|
|
66
76
|
/**
|
|
67
77
|
* 预算淘汰(仅插入路径/setBudget 调用):从最旧端逐条淘汰到 reserveBytes
|
|
68
|
-
* 可容纳。protectCurrentFrame=true
|
|
69
|
-
*
|
|
70
|
-
*
|
|
78
|
+
* 可容纳。protectCurrentFrame=true(渲染中插入路径)三道防线(思阳素材
|
|
79
|
+
* 431.9MiB PSD 拖动每步 2.2s 定谳后的批次 321 补丁——保留式帧只重推脏节点,
|
|
80
|
+
* 活动大图整段不 touch,插入压力会把刚用过的大图逐出,下一全量帧 490MiB
|
|
81
|
+
* 级重传):
|
|
82
|
+
* ① 手势期冻结——markFrame(gestureActive) 期间插入压力整体 no-op(拖动/
|
|
83
|
+
* 缩放/旋转中绝不逐出;烘焙小纹理持续插入照常,超额留驻=头注取舍);
|
|
84
|
+
* ② 近帧宽限——距当前帧不足 evictGraceFrames(缺省 30)的条目跳过:非
|
|
85
|
+
* 手势期的活动工作集(动画/编辑间歇 touch)不被插入压力逐出;真孤儿
|
|
86
|
+
* (远旧帧号沉底)照逐,预算长期收敛性不变;
|
|
87
|
+
* ③ 代价感知——先逐小条目(< BIG_ENTRY_BYTES),小条目耗尽才动大条目:
|
|
88
|
+
* 逐出恢复代价 ∝ 条目字节数(小纹理重传无感,全幅大图重传秒级),偶发
|
|
89
|
+
* 结算优先牺牲无感的小条目。
|
|
90
|
+
* 全被防线拦下时允许临时超额(正确性优先)。false(setBudget 显式调压):
|
|
91
|
+
* 强制淘汰——调用点在帧间,无批次持有句柄,三道防线均不适用。
|
|
71
92
|
*/
|
|
72
93
|
private evictIfNeeded;
|
|
94
|
+
/** 从 LRU 最旧端逐一条目;allowBig=false 跳过大条目(代价感知第一轮) */
|
|
95
|
+
private evictOldestEligible;
|
|
73
96
|
/**
|
|
74
97
|
* 动态源内容更新后重传(GIF 换帧 / 视频新帧)。仅对已缓存源生效——
|
|
75
98
|
* 未创建过的源由下一次 get() 全量上传;纹理对象不变,调用方无需重取。
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
* 工作集 vs 512MiB 预算,每帧强逐 ~280MB 再全量重传,帧渲染 2.5~5s 永不
|
|
11
11
|
* 收敛;预算抬到覆盖工作集后同场景 3ms/帧——A/B 定谳)。孤儿/换页残留
|
|
12
12
|
* 不再被 get 命中即沉到 LRU 头,下一次插入压力先逐它们,预算仍长期生效。
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* - **帧界保护(插入压力三防线,批次 321 补丁)**:渲染中插入路径的淘汰依次
|
|
14
|
+
* 受 ①手势期冻结(markFrame(gestureActive))②近帧宽限(evictGraceFrames
|
|
15
|
+
* 帧内 touch 过的不逐——句柄可能已被批渲染器捕获,保留式帧让活动工作集
|
|
16
|
+
* 间歇不 touch)③代价感知(先逐 <32MiB 小条目,耗尽才动大条目)拦护;
|
|
17
|
+
* 全被拦下时允许留驻超额——颠簸 = 永不可用,留驻 = 一次性上传后稳定,
|
|
18
|
+
* 是显式取舍(细节见 evictIfNeeded 头注)
|
|
16
19
|
* - 字节口径:宽×高×4(RGBA8),mipmap 源 ×4/3(三级以上链约数)
|
|
17
20
|
*
|
|
18
21
|
* Phase 4 动态源(动画 GIF 单帧缓冲 / HTMLVideoElement):
|
|
@@ -25,11 +28,17 @@
|
|
|
25
28
|
*/
|
|
26
29
|
const DEFAULT_BUDGET_BYTES = 512 * 1024 * 1024;
|
|
27
30
|
const DEFAULT_MAX_ENTRIES = 2048;
|
|
31
|
+
const DEFAULT_EVICT_GRACE_FRAMES = 30;
|
|
32
|
+
/** 代价感知门槛:≥32MiB 的条目视为大条目,插入压力先耗尽小条目才逐它
|
|
33
|
+
* (全幅位图纹理逐出后全量重传是秒级,小烘焙纹理重传无感) */
|
|
34
|
+
const BIG_ENTRY_BYTES = 32 * 1024 * 1024;
|
|
28
35
|
export class GLTextureCache {
|
|
29
36
|
gl;
|
|
30
37
|
cache = new Map();
|
|
31
38
|
budgetBytes;
|
|
32
39
|
maxEntries;
|
|
40
|
+
evictGraceFrames;
|
|
41
|
+
gestureActive = false;
|
|
33
42
|
frameStamp = 0;
|
|
34
43
|
frameTouches = 0;
|
|
35
44
|
evictions = 0;
|
|
@@ -39,14 +48,18 @@ export class GLTextureCache {
|
|
|
39
48
|
this.gl = gl;
|
|
40
49
|
this.budgetBytes = options.budgetBytes ?? DEFAULT_BUDGET_BYTES;
|
|
41
50
|
this.maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
51
|
+
this.evictGraceFrames = options.evictGraceFrames ?? DEFAULT_EVICT_GRACE_FRAMES;
|
|
42
52
|
}
|
|
43
53
|
/** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
|
|
44
54
|
* 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
|
|
45
55
|
* 「逐出→重传」死循环(同头注),淘汰统一改由插入压力驱动
|
|
46
|
-
* (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU
|
|
47
|
-
|
|
56
|
+
* (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU 头保证。
|
|
57
|
+
* gestureActive(指针手势进行中):本帧插入压力淘汰整体冻结(见
|
|
58
|
+
* evictIfNeeded 头注的手势期防线) */
|
|
59
|
+
markFrame(gestureActive = false) {
|
|
48
60
|
this.frameStamp += 1;
|
|
49
61
|
this.frameTouches = 0;
|
|
62
|
+
this.gestureActive = gestureActive;
|
|
50
63
|
}
|
|
51
64
|
/** 累计逐出计数(批次 223 重落保留式回退门):逐出删除纹理句柄会使快照命令
|
|
52
65
|
* 里引用的句柄失效——计数变化即作废保留式快照走全量帧 */
|
|
@@ -105,30 +118,48 @@ export class GLTextureCache {
|
|
|
105
118
|
}
|
|
106
119
|
/**
|
|
107
120
|
* 预算淘汰(仅插入路径/setBudget 调用):从最旧端逐条淘汰到 reserveBytes
|
|
108
|
-
* 可容纳。protectCurrentFrame=true
|
|
109
|
-
*
|
|
110
|
-
*
|
|
121
|
+
* 可容纳。protectCurrentFrame=true(渲染中插入路径)三道防线(思阳素材
|
|
122
|
+
* 431.9MiB PSD 拖动每步 2.2s 定谳后的批次 321 补丁——保留式帧只重推脏节点,
|
|
123
|
+
* 活动大图整段不 touch,插入压力会把刚用过的大图逐出,下一全量帧 490MiB
|
|
124
|
+
* 级重传):
|
|
125
|
+
* ① 手势期冻结——markFrame(gestureActive) 期间插入压力整体 no-op(拖动/
|
|
126
|
+
* 缩放/旋转中绝不逐出;烘焙小纹理持续插入照常,超额留驻=头注取舍);
|
|
127
|
+
* ② 近帧宽限——距当前帧不足 evictGraceFrames(缺省 30)的条目跳过:非
|
|
128
|
+
* 手势期的活动工作集(动画/编辑间歇 touch)不被插入压力逐出;真孤儿
|
|
129
|
+
* (远旧帧号沉底)照逐,预算长期收敛性不变;
|
|
130
|
+
* ③ 代价感知——先逐小条目(< BIG_ENTRY_BYTES),小条目耗尽才动大条目:
|
|
131
|
+
* 逐出恢复代价 ∝ 条目字节数(小纹理重传无感,全幅大图重传秒级),偶发
|
|
132
|
+
* 结算优先牺牲无感的小条目。
|
|
133
|
+
* 全被防线拦下时允许临时超额(正确性优先)。false(setBudget 显式调压):
|
|
134
|
+
* 强制淘汰——调用点在帧间,无批次持有句柄,三道防线均不适用。
|
|
111
135
|
*/
|
|
112
136
|
evictIfNeeded(reserveBytes, protectCurrentFrame) {
|
|
113
137
|
if (this.disposed)
|
|
114
138
|
return;
|
|
139
|
+
if (protectCurrentFrame && this.gestureActive)
|
|
140
|
+
return;
|
|
115
141
|
while (this.trackedBytes + reserveBytes > this.budgetBytes || this.cache.size >= this.maxEntries) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (protectCurrentFrame && entry.lastFrame === this.frameStamp)
|
|
119
|
-
continue;
|
|
120
|
-
this.gl.deleteTexture(entry.tex);
|
|
121
|
-
this.cache.delete(source);
|
|
122
|
-
this.trackedBytes -= entry.bytes;
|
|
123
|
-
this.evictions += 1;
|
|
124
|
-
evicted = true;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
// 无可逐条目(全被帧界保护,或缓存已空仍超预算——reserveBytes 本身超限)
|
|
142
|
+
const evicted = this.evictOldestEligible(protectCurrentFrame, false) || this.evictOldestEligible(protectCurrentFrame, true);
|
|
143
|
+
// 无可逐条目(全被宽限/尺寸防线拦下,或缓存已空仍超预算——reserveBytes 本身超限)
|
|
128
144
|
if (!evicted)
|
|
129
145
|
return;
|
|
130
146
|
}
|
|
131
147
|
}
|
|
148
|
+
/** 从 LRU 最旧端逐一条目;allowBig=false 跳过大条目(代价感知第一轮) */
|
|
149
|
+
evictOldestEligible(protectCurrentFrame, allowBig) {
|
|
150
|
+
for (const [source, entry] of this.cache) {
|
|
151
|
+
if (protectCurrentFrame && this.frameStamp - entry.lastFrame < this.evictGraceFrames)
|
|
152
|
+
continue;
|
|
153
|
+
if (!allowBig && entry.bytes >= BIG_ENTRY_BYTES)
|
|
154
|
+
continue;
|
|
155
|
+
this.gl.deleteTexture(entry.tex);
|
|
156
|
+
this.cache.delete(source);
|
|
157
|
+
this.trackedBytes -= entry.bytes;
|
|
158
|
+
this.evictions += 1;
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
132
163
|
/**
|
|
133
164
|
* 动态源内容更新后重传(GIF 换帧 / 视频新帧)。仅对已缓存源生效——
|
|
134
165
|
* 未创建过的源由下一次 get() 全量上传;纹理对象不变,调用方无需重取。
|
|
@@ -5,6 +5,7 @@ import { imageFiltersKey, parseImageFilters } from '../core/imageFilters';
|
|
|
5
5
|
import { imageCornerRadius, rectCornerRadii } from '../core/roundedRect';
|
|
6
6
|
import { AnimatedNode, GroupNode, MaskNode, PuzzleNode, rasterMaskSrc, textBitmapFillAlpha } from '../model/scene';
|
|
7
7
|
import { warpTextKind } from './warpText';
|
|
8
|
+
import { activePsdTextWarp } from '../core/warpMesh';
|
|
8
9
|
import { arcTextKind } from '../model/arcLayout';
|
|
9
10
|
import { GLIsolator } from './GLIsolate';
|
|
10
11
|
import { GLBlender } from './GLBlend';
|
|
@@ -319,6 +320,15 @@ export class SceneRenderer {
|
|
|
319
320
|
this.text.renderWarpedText(node, warp);
|
|
320
321
|
return;
|
|
321
322
|
}
|
|
323
|
+
// 批次 365 PSD 文字变形:分派序在 renderSrc 位图(上分支)与 warp 三族之后
|
|
324
|
+
// ——TextImage 编辑转正(防线删 renderSrc、type 落 Textbox)后 raw.psdWarp
|
|
325
|
+
// 仍在场 → 参数化网格变形接管(「编辑后仍保持变形」);纯文本回退层带
|
|
326
|
+
// psdWarp 立即原生变形。被编辑的本节点走常规管线(PS 同构:编辑未变形文本)
|
|
327
|
+
const psdWarp = activePsdTextWarp(node.raw);
|
|
328
|
+
if (psdWarp && node !== this.host.editingNode) {
|
|
329
|
+
this.text.renderPsdWarpedText(node, psdWarp);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
322
332
|
// P4-5b 弧形/圆形文本:ArcText/CircleText 逐字摆位(curvature=0 也走摆位
|
|
323
333
|
// 机——radius=1e5 的近直渲染);双实现(GPU 批次 4)——逐字图集 quad /
|
|
324
334
|
// 整图烘焙,zoom×dpr 供桶分派。被编辑的本节点走常规管线。分派在
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 不可做模块级缓存。编辑态门控(变形文本在编辑中走常规管线)留在
|
|
9
9
|
* SceneRenderer 的分派分支。
|
|
10
10
|
*/
|
|
11
|
+
import type { PsdTextWarpParams } from '../core/warpMesh';
|
|
11
12
|
import type { SceneNode, TextNode } from '../model/scene';
|
|
12
13
|
import { GlyphAtlas } from './GlyphAtlas';
|
|
13
14
|
import { QuadBatch } from './QuadBatch';
|
|
@@ -19,6 +20,9 @@ export declare class TextRenderer {
|
|
|
19
20
|
private readonly glyphAtlas;
|
|
20
21
|
/** 变形文本烘焙缓存(P4-5a:节点 → {sig, tex, w, h}) */
|
|
21
22
|
private warpBakes;
|
|
23
|
+
/** PSD 变形文本烘焙缓存(批次 365:节点 → {sig, tex, w, h, offX, offY}——
|
|
24
|
+
* 变形输出窗一般不对称于对象中心,quad 定位携带中心偏移) */
|
|
25
|
+
private psdWarpBakes;
|
|
22
26
|
/** 弧形/圆形文本烘焙缓存(P4-5b:节点 → {sig, tex, w, h}) */
|
|
23
27
|
private arcBakes;
|
|
24
28
|
/** 虚线文本描边烘焙缓存(run 级栅格化;签名 = 文本+布局+描边+桶) */
|
|
@@ -38,6 +42,14 @@ export declare class TextRenderer {
|
|
|
38
42
|
invalidateNodeBakes(node: SceneNode): void;
|
|
39
43
|
/** 变形文本渲染(P4-5a):烘焙整图 quad(logicalW×logicalH 居中于对象中心) */
|
|
40
44
|
renderWarpedText(node: TextNode, kind: WarpKind): void;
|
|
45
|
+
/**
|
|
46
|
+
* PSD 变形文本渲染(批次 365):renderSrc 位图优先链的编辑后承接——转正防线
|
|
47
|
+
* 删 renderSrc 后 raw.psdWarp 在场 → 布局盒重排 + 15 样式网格变形烘焙单 quad
|
|
48
|
+
* (bakePsdWarpText:Patchy 前向格点 + 逐 cell 逆双线性)。签名键与 warp 族
|
|
49
|
+
* 同源 + psdWarp 参数 JSON + 排版扩展键(charSpacing/lineHeight/vertical——
|
|
50
|
+
* 转正后重排的文本这些键都会改墨迹)。
|
|
51
|
+
*/
|
|
52
|
+
renderPsdWarpedText(node: TextNode, params: PsdTextWarpParams): void;
|
|
41
53
|
/**
|
|
42
54
|
* 弧形/圆形文本渲染(P4-5b):双实现分发(GPU 迁移批次 4)——
|
|
43
55
|
* 逐字图集 quad(缩放桶重栅格化,放大始终清晰)/ 整图烘焙 quad(Canvas 参考
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* SceneRenderer 的分派分支。
|
|
10
10
|
*/
|
|
11
11
|
import { parseColor } from '../core/color';
|
|
12
|
-
import { multiply } from '../core/mat2d';
|
|
12
|
+
import { composeMatrix, multiply } from '../core/mat2d';
|
|
13
13
|
import { parsePsdEffects, psdEffectsKey } from '../core/psdEffects';
|
|
14
14
|
import { isArcGlyphEnabled } from '../engineFlag';
|
|
15
15
|
import { charJitterY, drawParagraphPrefix, fontDeclaration, graphemeSplit, lineDecorationRuns, maxCharJitterY, resolveStrokeDecl, verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
|
|
@@ -18,6 +18,7 @@ import { bakeScrollText, scrollTextDecl } from './scrollText';
|
|
|
18
18
|
import { bakeTextHighlight, planTextHighlight } from './textHighlight';
|
|
19
19
|
import { drawVerticalGlyph, glyphStyleAt, verticalGlyphOps } from './verticalText';
|
|
20
20
|
import { bakeWarpedText } from './warpText';
|
|
21
|
+
import { bakePsdWarpText } from './psdWarpText';
|
|
21
22
|
import { bakeArcText, glyphStyleOf } from './arcText';
|
|
22
23
|
import { computeArcTextLayout } from '../model/arcLayout';
|
|
23
24
|
import { createTexture2D } from './textureUpload';
|
|
@@ -50,6 +51,9 @@ export class TextRenderer {
|
|
|
50
51
|
glyphAtlas;
|
|
51
52
|
/** 变形文本烘焙缓存(P4-5a:节点 → {sig, tex, w, h}) */
|
|
52
53
|
warpBakes = new WeakMap();
|
|
54
|
+
/** PSD 变形文本烘焙缓存(批次 365:节点 → {sig, tex, w, h, offX, offY}——
|
|
55
|
+
* 变形输出窗一般不对称于对象中心,quad 定位携带中心偏移) */
|
|
56
|
+
psdWarpBakes = new WeakMap();
|
|
53
57
|
/** 弧形/圆形文本烘焙缓存(P4-5b:节点 → {sig, tex, w, h}) */
|
|
54
58
|
arcBakes = new WeakMap();
|
|
55
59
|
/** 虚线文本描边烘焙缓存(run 级栅格化;签名 = 文本+布局+描边+桶) */
|
|
@@ -71,7 +75,7 @@ export class TextRenderer {
|
|
|
71
75
|
* 烘焙随节点 GC,与既有 sig 更换/删除路径同语义)。
|
|
72
76
|
*/
|
|
73
77
|
invalidateNodeBakes(node) {
|
|
74
|
-
for (const bakes of [this.warpBakes, this.arcBakes, this.textDashBakes, this.scrollBakes, this.highlightBakes]) {
|
|
78
|
+
for (const bakes of [this.warpBakes, this.psdWarpBakes, this.arcBakes, this.textDashBakes, this.scrollBakes, this.highlightBakes]) {
|
|
75
79
|
const bake = bakes.get(node);
|
|
76
80
|
if (bake?.tex)
|
|
77
81
|
this.gl.deleteTexture(bake.tex);
|
|
@@ -119,6 +123,55 @@ export class TextRenderer {
|
|
|
119
123
|
}
|
|
120
124
|
this.batch.pushQuad(node.matrix, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
121
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* PSD 变形文本渲染(批次 365):renderSrc 位图优先链的编辑后承接——转正防线
|
|
128
|
+
* 删 renderSrc 后 raw.psdWarp 在场 → 布局盒重排 + 15 样式网格变形烘焙单 quad
|
|
129
|
+
* (bakePsdWarpText:Patchy 前向格点 + 逐 cell 逆双线性)。签名键与 warp 族
|
|
130
|
+
* 同源 + psdWarp 参数 JSON + 排版扩展键(charSpacing/lineHeight/vertical——
|
|
131
|
+
* 转正后重排的文本这些键都会改墨迹)。
|
|
132
|
+
*/
|
|
133
|
+
renderPsdWarpedText(node, params) {
|
|
134
|
+
const fxDecls = parsePsdEffects(node.raw.effects, { text: true });
|
|
135
|
+
const sig = [
|
|
136
|
+
node.raw.type,
|
|
137
|
+
node.raw.text,
|
|
138
|
+
JSON.stringify(node.raw.psdWarp ?? null),
|
|
139
|
+
node.raw.fontSize,
|
|
140
|
+
node.raw.fontFamily,
|
|
141
|
+
node.raw.fontWeight,
|
|
142
|
+
node.raw.fontStyle,
|
|
143
|
+
node.raw.width,
|
|
144
|
+
node.raw.height,
|
|
145
|
+
node.raw.lineHeight,
|
|
146
|
+
node.raw.charSpacing,
|
|
147
|
+
node.raw.vertical === true ? 1 : 0,
|
|
148
|
+
node.raw.fill,
|
|
149
|
+
node.raw.stroke,
|
|
150
|
+
node.raw.strokeWidth,
|
|
151
|
+
JSON.stringify(node.raw.styles ?? null),
|
|
152
|
+
JSON.stringify(node.raw.paragraph ?? null),
|
|
153
|
+
fxDecls ? psdEffectsKey(fxDecls) : ''
|
|
154
|
+
].join(';');
|
|
155
|
+
let bake = this.psdWarpBakes.get(node);
|
|
156
|
+
if (bake && bake.sig !== sig) {
|
|
157
|
+
this.gl.deleteTexture(bake.tex);
|
|
158
|
+
bake = undefined;
|
|
159
|
+
}
|
|
160
|
+
if (!bake) {
|
|
161
|
+
const result = bakePsdWarpText(node, params, fxDecls);
|
|
162
|
+
if (!result) {
|
|
163
|
+
this.psdWarpBakes.set(node, undefined);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const tex = createTexture2D(this.gl, result.canvas);
|
|
167
|
+
if (!tex)
|
|
168
|
+
return;
|
|
169
|
+
bake = { sig, tex, w: result.logicalW, h: result.logicalH, offX: result.offsetX, offY: result.offsetY };
|
|
170
|
+
this.psdWarpBakes.set(node, bake);
|
|
171
|
+
}
|
|
172
|
+
const m = bake.offX !== 0 || bake.offY !== 0 ? multiply(node.matrix, composeMatrix({ translateX: bake.offX, translateY: bake.offY })) : node.matrix;
|
|
173
|
+
this.batch.pushQuad(m, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
174
|
+
}
|
|
122
175
|
/**
|
|
123
176
|
* 弧形/圆形文本渲染(P4-5b):双实现分发(GPU 迁移批次 4)——
|
|
124
177
|
* 逐字图集 quad(缩放桶重栅格化,放大始终清晰)/ 整图烘焙 quad(Canvas 参考
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PSD 文字变形(Warp Text)CPU 烘焙(批次 365)——core/warpMesh 的 15 样式控制
|
|
3
|
+
* 网格 × Patchy「前向格点 + 逐 cell 闭式逆双线性」重采样(4px 提交级 cell,
|
|
4
|
+
* first-writer-wins 折叠语义)。
|
|
5
|
+
*
|
|
6
|
+
* 消费链(SceneRenderer 分派序):TextImage 位图态 renderSrc 单 quad 优先(导入
|
|
7
|
+
* 保真)→ 编辑转正防线删 renderSrc 后 raw.psdWarp 在场 → 本件接管(「编辑后仍
|
|
8
|
+
* 保持变形」);纯文本回退层(导入无图层像素)带 psdWarp 立即原生变形。变形作用
|
|
9
|
+
* 于布局盒(PS bounds 盒语义——PS 每次重排自行重推盒,本件同样按节点当前盒实时
|
|
10
|
+
* 求值不落盘);重采样窗口裁到墨迹(Patchy wt_* 同款——近空盒的 Bernstein 外推
|
|
11
|
+
* 会把格点分辨率饿死在墨迹之外)。
|
|
12
|
+
*
|
|
13
|
+
* 脚手架与 render/warpText.ts 同源:run 渲染(CACHE_DPR=2 中心原点系)+ PSD 特效
|
|
14
|
+
* 合成(compositeWarpEffects)→ alpha>10 墨迹扫描 → 网格变形重采样 → putImageData。
|
|
15
|
+
* 输出 = 变形窗口外接矩形 + 画布中心相对对象中心的逻辑偏移(变形输出窗一般不对称
|
|
16
|
+
* 于对象中心——quad/SVG 定位须携带,arch 族的恒居中约定在此不成立)。
|
|
17
|
+
*/
|
|
18
|
+
import { type PsdTextWarpParams } from '../core/warpMesh';
|
|
19
|
+
import type { TextNode } from '../model/scene';
|
|
20
|
+
import type { PsdEffectsDecls } from '../core/psdEffects';
|
|
21
|
+
import { type WarpBake } from './warpText';
|
|
22
|
+
/** PSD 变形烘焙产物:WarpBake 契约 + 输出窗中心的逻辑偏移(quad 定位用) */
|
|
23
|
+
export interface PsdWarpBake extends WarpBake {
|
|
24
|
+
offsetX: number;
|
|
25
|
+
offsetY: number;
|
|
26
|
+
}
|
|
27
|
+
/** PSD 变形文本整图烘焙(输出窗 = 变形后墨迹范围 + 1px AA 余量,中心偏移随行) */
|
|
28
|
+
export declare const bakePsdWarpText: (node: TextNode, params: PsdTextWarpParams, decls?: PsdEffectsDecls | null) => PsdWarpBake | null;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PSD 文字变形(Warp Text)CPU 烘焙(批次 365)——core/warpMesh 的 15 样式控制
|
|
3
|
+
* 网格 × Patchy「前向格点 + 逐 cell 闭式逆双线性」重采样(4px 提交级 cell,
|
|
4
|
+
* first-writer-wins 折叠语义)。
|
|
5
|
+
*
|
|
6
|
+
* 消费链(SceneRenderer 分派序):TextImage 位图态 renderSrc 单 quad 优先(导入
|
|
7
|
+
* 保真)→ 编辑转正防线删 renderSrc 后 raw.psdWarp 在场 → 本件接管(「编辑后仍
|
|
8
|
+
* 保持变形」);纯文本回退层(导入无图层像素)带 psdWarp 立即原生变形。变形作用
|
|
9
|
+
* 于布局盒(PS bounds 盒语义——PS 每次重排自行重推盒,本件同样按节点当前盒实时
|
|
10
|
+
* 求值不落盘);重采样窗口裁到墨迹(Patchy wt_* 同款——近空盒的 Bernstein 外推
|
|
11
|
+
* 会把格点分辨率饿死在墨迹之外)。
|
|
12
|
+
*
|
|
13
|
+
* 脚手架与 render/warpText.ts 同源:run 渲染(CACHE_DPR=2 中心原点系)+ PSD 特效
|
|
14
|
+
* 合成(compositeWarpEffects)→ alpha>10 墨迹扫描 → 网格变形重采样 → putImageData。
|
|
15
|
+
* 输出 = 变形窗口外接矩形 + 画布中心相对对象中心的逻辑偏移(变形输出窗一般不对称
|
|
16
|
+
* 于对象中心——quad/SVG 定位须携带,arch 族的恒居中约定在此不成立)。
|
|
17
|
+
*/
|
|
18
|
+
import { buildWarpSurfaceGridOverWindow, evaluateWarpMesh, generatePsdWarpMesh, invertBilinearCell } from '../core/warpMesh';
|
|
19
|
+
import { compositeWarpEffects, renderTextRuns, renderVerticalRuns, warpEffectExtentPad } from './warpText';
|
|
20
|
+
const CACHE_DPR = 2;
|
|
21
|
+
/** 提交级 cell 尺寸(逻辑像素 ×CACHE_DPR——Patchy bake_warp_into_layer 同款 4px) */
|
|
22
|
+
const MAX_CELL_DOC_PIXELS = 4 * CACHE_DPR;
|
|
23
|
+
const MAX_CELLS = 384;
|
|
24
|
+
/** 探针趟:窗口参数区间经网格前向映射 + 盒→源画布仿射后的输出范围(设备像素) */
|
|
25
|
+
const probeOutputExtent = (mesh, u0, u1, v0, v1, meshToSource) => {
|
|
26
|
+
let minX = Infinity;
|
|
27
|
+
let maxX = -Infinity;
|
|
28
|
+
let minY = Infinity;
|
|
29
|
+
let maxY = -Infinity;
|
|
30
|
+
const probe = 8;
|
|
31
|
+
for (let row = 0; row <= probe; row++) {
|
|
32
|
+
const v = v0 + ((v1 - v0) * row) / probe;
|
|
33
|
+
for (let column = 0; column <= probe; column++) {
|
|
34
|
+
const u = u0 + ((u1 - u0) * column) / probe;
|
|
35
|
+
const surface = evaluateWarpMesh(mesh, u, v);
|
|
36
|
+
const x = meshToSource[0] * surface.x + meshToSource[2] * surface.y + meshToSource[4];
|
|
37
|
+
const y = meshToSource[1] * surface.x + meshToSource[3] * surface.y + meshToSource[5];
|
|
38
|
+
minX = Math.min(minX, x);
|
|
39
|
+
maxX = Math.max(maxX, x);
|
|
40
|
+
minY = Math.min(minY, y);
|
|
41
|
+
maxY = Math.max(maxY, y);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { minX, maxX, minY, maxY };
|
|
45
|
+
};
|
|
46
|
+
/** PSD 变形文本整图烘焙(输出窗 = 变形后墨迹范围 + 1px AA 余量,中心偏移随行) */
|
|
47
|
+
export const bakePsdWarpText = (node, params, decls = null) => {
|
|
48
|
+
const layout = node.textLayout;
|
|
49
|
+
const fontSize = Number(node.raw.fontSize) || 40;
|
|
50
|
+
const boxW = typeof node.raw.width === 'number' ? node.raw.width : layout.width;
|
|
51
|
+
const boxH = typeof node.raw.height === 'number' ? node.raw.height : layout.height;
|
|
52
|
+
if (!(boxW > 0) || !(boxH > 0))
|
|
53
|
+
return null;
|
|
54
|
+
const padding = fontSize * 0.6;
|
|
55
|
+
const baseTextWidth = Math.max(layout.width, boxW, fontSize);
|
|
56
|
+
const baseTextHeight = Math.max(boxH, fontSize);
|
|
57
|
+
const fxPad = decls ? warpEffectExtentPad(decls) : 0;
|
|
58
|
+
const sourceW = Math.ceil(baseTextWidth + padding * 2 + fxPad * 2);
|
|
59
|
+
const sourceH = Math.ceil(baseTextHeight + padding * 2 + fxPad * 2);
|
|
60
|
+
const cacheW = sourceW * CACHE_DPR;
|
|
61
|
+
const cacheH = sourceH * CACHE_DPR;
|
|
62
|
+
if (!(cacheW > 0) || !(cacheH > 0) || cacheW > 8192 || cacheH > 8192)
|
|
63
|
+
return null;
|
|
64
|
+
const mesh = generatePsdWarpMesh(params, boxW, boxH);
|
|
65
|
+
if (!mesh)
|
|
66
|
+
return null;
|
|
67
|
+
// 源渲染:中心原点系 ×CACHE_DPR(盒居中于画布中心——对象中心即画布中心)
|
|
68
|
+
const canvas = document.createElement('canvas');
|
|
69
|
+
canvas.width = cacheW;
|
|
70
|
+
canvas.height = cacheH;
|
|
71
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
72
|
+
if (!ctx)
|
|
73
|
+
return null;
|
|
74
|
+
ctx.setTransform(CACHE_DPR, 0, 0, CACHE_DPR, cacheW / 2, cacheH / 2);
|
|
75
|
+
if (node.raw.vertical === true)
|
|
76
|
+
renderVerticalRuns(ctx, node);
|
|
77
|
+
else
|
|
78
|
+
renderTextRuns(ctx, node);
|
|
79
|
+
compositeWarpEffects(ctx, node, decls);
|
|
80
|
+
// 墨迹扫描(alpha > 10,warpText 同阈值)——重采样窗口裁到墨迹
|
|
81
|
+
const img = ctx.getImageData(0, 0, cacheW, cacheH);
|
|
82
|
+
const px = new Uint32Array(img.data.buffer);
|
|
83
|
+
let minX = cacheW;
|
|
84
|
+
let maxX = 0;
|
|
85
|
+
let minY = cacheH;
|
|
86
|
+
let maxY = 0;
|
|
87
|
+
let hasText = false;
|
|
88
|
+
for (let row = 0; row < cacheH; row++) {
|
|
89
|
+
for (let col = 0; col < cacheW; col++) {
|
|
90
|
+
if (((px[row * cacheW + col] >>> 24) & 0xff) > 10) {
|
|
91
|
+
hasText = true;
|
|
92
|
+
if (col < minX)
|
|
93
|
+
minX = col;
|
|
94
|
+
if (col > maxX)
|
|
95
|
+
maxX = col;
|
|
96
|
+
if (row < minY)
|
|
97
|
+
minY = row;
|
|
98
|
+
if (row > maxY)
|
|
99
|
+
maxY = row;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!hasText)
|
|
104
|
+
return null;
|
|
105
|
+
const srcX0 = minX;
|
|
106
|
+
const srcY0 = minY;
|
|
107
|
+
const srcW = maxX + 1 - minX;
|
|
108
|
+
const srcH = maxY + 1 - minY;
|
|
109
|
+
// 盒(mesh 空间 [0,boxW]×[0,boxH])→ 源画布设备像素的仿射(盒居中于画布)
|
|
110
|
+
const cx0 = ((sourceW - boxW) / 2) * CACHE_DPR;
|
|
111
|
+
const cy0 = ((sourceH - boxH) / 2) * CACHE_DPR;
|
|
112
|
+
const meshToSource = [CACHE_DPR, 0, 0, CACHE_DPR, cx0, cy0];
|
|
113
|
+
// 墨迹窗口(源设备像素)→ mesh 参数区间(可越 [0,1]——Bernstein 外推覆盖出盒墨迹)
|
|
114
|
+
const windowLeft = (srcX0 - cx0) / CACHE_DPR;
|
|
115
|
+
const windowRight = (srcX0 + srcW - cx0) / CACHE_DPR;
|
|
116
|
+
const windowTop = (srcY0 - cy0) / CACHE_DPR;
|
|
117
|
+
const windowBottom = (srcY0 + srcH - cy0) / CACHE_DPR;
|
|
118
|
+
const u0 = windowLeft / boxW;
|
|
119
|
+
const u1 = windowRight / boxW;
|
|
120
|
+
const v0 = windowTop / boxH;
|
|
121
|
+
const v1 = windowBottom / boxH;
|
|
122
|
+
// 输出窗:变形后窗口的设备范围 + 1px AA 余量
|
|
123
|
+
const extent = probeOutputExtent(mesh, u0, u1, v0, v1, meshToSource);
|
|
124
|
+
const outLeft = Math.floor(extent.minX) - 1;
|
|
125
|
+
const outTop = Math.floor(extent.minY) - 1;
|
|
126
|
+
const outW = Math.max(1, Math.ceil(extent.maxX + 1) - outLeft);
|
|
127
|
+
const outH = Math.max(1, Math.ceil(extent.maxY + 1) - outTop);
|
|
128
|
+
if (outW > 8192 || outH > 8192)
|
|
129
|
+
return null;
|
|
130
|
+
// 格点仿射:mesh → 输出画布像素(源仿射平移 -outLeft/-outTop)
|
|
131
|
+
const grid = buildWarpSurfaceGridOverWindow(mesh, 0, 0, boxW, boxH, windowLeft, windowTop, windowRight, windowBottom, srcW, srcH, [CACHE_DPR, 0, 0, CACHE_DPR, cx0 - outLeft, cy0 - outTop], MAX_CELL_DOC_PIXELS, MAX_CELLS);
|
|
132
|
+
if (!grid)
|
|
133
|
+
return null;
|
|
134
|
+
// 逐 cell 光栅化:cell 四边形 bbox 内逐像素闭式逆双线性 → (s,t) → 源像素双线性
|
|
135
|
+
// 采样;first-writer-wins(折叠处首写者胜,Patchy resample_warped_rgba8 同语义)
|
|
136
|
+
const out = ctx.createImageData(outW, outH);
|
|
137
|
+
const outPx = new Uint32Array(out.data.buffer);
|
|
138
|
+
const covered = new Uint8Array(outW * outH);
|
|
139
|
+
const sample = (fx, fy) => {
|
|
140
|
+
const x = Math.min(srcW - 1, Math.max(0, fx));
|
|
141
|
+
const y = Math.min(srcH - 1, Math.max(0, fy));
|
|
142
|
+
const x0 = Math.floor(x);
|
|
143
|
+
const y0 = Math.floor(y);
|
|
144
|
+
const x1 = Math.min(srcW - 1, x0 + 1);
|
|
145
|
+
const y1 = Math.min(srcH - 1, y0 + 1);
|
|
146
|
+
const tx = x - x0;
|
|
147
|
+
const ty = y - y0;
|
|
148
|
+
const a = px[(srcY0 + y0) * cacheW + (srcX0 + x0)];
|
|
149
|
+
const b = px[(srcY0 + y0) * cacheW + (srcX0 + x1)];
|
|
150
|
+
const c = px[(srcY0 + y1) * cacheW + (srcX0 + x1)];
|
|
151
|
+
const d = px[(srcY0 + y1) * cacheW + (srcX0 + x0)];
|
|
152
|
+
const aA = (a >>> 24) & 0xff;
|
|
153
|
+
const bA = (b >>> 24) & 0xff;
|
|
154
|
+
const cA = (c >>> 24) & 0xff;
|
|
155
|
+
const dA = (d >>> 24) & 0xff;
|
|
156
|
+
if (aA <= 10 && bA <= 10 && cA <= 10 && dA <= 10)
|
|
157
|
+
return 0;
|
|
158
|
+
const lerp = (v0, v1, t) => v0 + (v1 - v0) * t;
|
|
159
|
+
const r = Math.round(lerp(lerp(a & 0xff, b & 0xff, tx), lerp(d & 0xff, c & 0xff, tx), ty));
|
|
160
|
+
const g = Math.round(lerp(lerp((a >>> 8) & 0xff, (b >>> 8) & 0xff, tx), lerp((d >>> 8) & 0xff, (c >>> 8) & 0xff, tx), ty));
|
|
161
|
+
const bl = Math.round(lerp(lerp((a >>> 16) & 0xff, (b >>> 16) & 0xff, tx), lerp((d >>> 16) & 0xff, (c >>> 16) & 0xff, tx), ty));
|
|
162
|
+
const al = Math.round(lerp(lerp(aA, bA, tx), lerp(dA, cA, tx), ty));
|
|
163
|
+
return (al << 24) | (bl << 16) | (g << 8) | r;
|
|
164
|
+
};
|
|
165
|
+
for (let row = 0; row + 1 < grid.rows; row++) {
|
|
166
|
+
for (let column = 0; column + 1 < grid.columns; column++) {
|
|
167
|
+
const i00 = row * grid.columns + column;
|
|
168
|
+
const i10 = i00 + 1;
|
|
169
|
+
const i01 = i00 + grid.columns;
|
|
170
|
+
const i11 = i01 + 1;
|
|
171
|
+
const x00 = grid.docXs[i00];
|
|
172
|
+
const y00 = grid.docYs[i00];
|
|
173
|
+
const x10 = grid.docXs[i10];
|
|
174
|
+
const y10 = grid.docYs[i10];
|
|
175
|
+
const x11 = grid.docXs[i11];
|
|
176
|
+
const y11 = grid.docYs[i11];
|
|
177
|
+
const x01 = grid.docXs[i01];
|
|
178
|
+
const y01 = grid.docYs[i01];
|
|
179
|
+
const cellMinX = Math.max(0, Math.floor(Math.min(x00, x10, x11, x01)));
|
|
180
|
+
const cellMaxX = Math.min(outW - 1, Math.ceil(Math.max(x00, x10, x11, x01)));
|
|
181
|
+
const cellMinY = Math.max(0, Math.floor(Math.min(y00, y10, y11, y01)));
|
|
182
|
+
const cellMaxY = Math.min(outH - 1, Math.ceil(Math.max(y00, y10, y11, y01)));
|
|
183
|
+
for (let py = cellMinY; py <= cellMaxY; py++) {
|
|
184
|
+
for (let pxCur = cellMinX; pxCur <= cellMaxX; pxCur++) {
|
|
185
|
+
const index = py * outW + pxCur;
|
|
186
|
+
if (covered[index])
|
|
187
|
+
continue;
|
|
188
|
+
const st = invertBilinearCell(pxCur + 0.5, py + 0.5, x00, y00, x10, y10, x11, y11, x01, y01);
|
|
189
|
+
if (!st)
|
|
190
|
+
continue;
|
|
191
|
+
covered[index] = 1;
|
|
192
|
+
const { s, t } = st;
|
|
193
|
+
// 源坐标 = 四角源坐标的双线性(格点源坐标即 fraction×size,规则网格)
|
|
194
|
+
const sx = (1 - s) * (1 - t) * grid.sourceXs[i00] + s * (1 - t) * grid.sourceXs[i10] + s * t * grid.sourceXs[i11] + (1 - s) * t * grid.sourceXs[i01];
|
|
195
|
+
const sy = (1 - s) * (1 - t) * grid.sourceYs[i00] + s * (1 - t) * grid.sourceYs[i10] + s * t * grid.sourceYs[i11] + (1 - s) * t * grid.sourceYs[i01];
|
|
196
|
+
outPx[index] = sample(sx, sy);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const outCanvas = document.createElement('canvas');
|
|
202
|
+
outCanvas.width = outW;
|
|
203
|
+
outCanvas.height = outH;
|
|
204
|
+
const outCtx = outCanvas.getContext('2d');
|
|
205
|
+
if (!outCtx)
|
|
206
|
+
return null;
|
|
207
|
+
outCtx.putImageData(out, 0, 0);
|
|
208
|
+
// 输出画布中心相对对象中心(源画布中心)的逻辑偏移
|
|
209
|
+
const offsetX = (outLeft + outW / 2) / CACHE_DPR - sourceW / 2;
|
|
210
|
+
const offsetY = (outTop + outH / 2) / CACHE_DPR - sourceH / 2;
|
|
211
|
+
return { canvas: outCanvas, logicalW: outW / CACHE_DPR, logicalH: outH / CACHE_DPR, offsetX, offsetY };
|
|
212
|
+
};
|
|
@@ -25,6 +25,9 @@ export declare const warpTextKind: (raw: {
|
|
|
25
25
|
type?: unknown;
|
|
26
26
|
warpStrength?: unknown;
|
|
27
27
|
}) => WarpKind | null;
|
|
28
|
+
/** 文本 run(同样式连续段)逐 run 画到 ctx(中心原点本地系,×CACHE_DPR)。
|
|
29
|
+
* 批次 365 起导出:psdWarpText 烘焙复用(PSD 变形文本的未变形源渲染同脚手架) */
|
|
30
|
+
export declare const renderTextRuns: (ctx: CanvasRenderingContext2D, node: TextNode) => void;
|
|
28
31
|
export interface WarpBake {
|
|
29
32
|
canvas: HTMLCanvasElement;
|
|
30
33
|
logicalW: number;
|
|
@@ -44,8 +47,18 @@ export declare const bakeWarpShadowLayer: (decls: PsdDropShadowDecl[], source: H
|
|
|
44
47
|
w: number;
|
|
45
48
|
h: number;
|
|
46
49
|
} | null;
|
|
50
|
+
/** 变形特效合成(fabric _renderText 同序:投影垫底 → run 文本 → solidFill → stroke)。
|
|
51
|
+
* ctx 为变形烘焙画布上下文(中心原点本地系 ×CACHE_DPR);投影在 run 之后合成,
|
|
52
|
+
* 用 destination-over 落到已有文本之下。批次 365 起导出(psdWarpText 复用) */
|
|
53
|
+
export declare const compositeWarpEffects: (ctx: CanvasRenderingContext2D, node: TextNode, decls: PsdEffectsDecls | null) => void;
|
|
47
54
|
/** 变形文本整图烘焙(本地中心系 logicalW×logicalH,内容居中) */
|
|
48
55
|
export declare const bakeWarpedText: (node: TextNode, kind: WarpKind, decls?: PsdEffectsDecls | null) => WarpBake | null;
|
|
56
|
+
/** 竖排逐字彩色渲染(shadowBake.drawTextGlyphs 竖排分支的彩色版):摆位/
|
|
57
|
+
* 姿态(verticalGlyphOps + drawVerticalGlyph)与 K-line jitter 同剪影口径,
|
|
58
|
+
* fill/stroke 逐字覆写与 renderTextRuns 同语义(fill 覆写 ?? 对象级、
|
|
59
|
+
* 描边 resolveStrokeDecl;paintFirst 逐字粒度不区分——竖排 quad 管线同款)。
|
|
60
|
+
* 批次 365 起导出(psdWarpText 竖排分支复用) */
|
|
61
|
+
export declare const renderVerticalRuns: (ctx: CanvasRenderingContext2D, node: TextNode) => void;
|
|
49
62
|
/**
|
|
50
63
|
* 常规/竖排文本 + PSD 特效整图烘焙(SVG 导出位图路径):横排复用
|
|
51
64
|
* renderTextRuns、竖排 renderVerticalRuns,特效层 compositeWarpEffects 合成
|
package/dist/render/warpText.js
CHANGED
|
@@ -34,8 +34,9 @@ export const warpTextKind = (raw) => {
|
|
|
34
34
|
return null;
|
|
35
35
|
};
|
|
36
36
|
const CACHE_DPR = 2;
|
|
37
|
-
/** 文本 run(同样式连续段)逐 run 画到 ctx(中心原点本地系,×CACHE_DPR
|
|
38
|
-
|
|
37
|
+
/** 文本 run(同样式连续段)逐 run 画到 ctx(中心原点本地系,×CACHE_DPR)。
|
|
38
|
+
* 批次 365 起导出:psdWarpText 烘焙复用(PSD 变形文本的未变形源渲染同脚手架) */
|
|
39
|
+
export const renderTextRuns = (ctx, node) => {
|
|
39
40
|
const layout = node.textLayout;
|
|
40
41
|
const style = node.textStyle;
|
|
41
42
|
const baseStroke = node.textStroke;
|
|
@@ -149,8 +150,8 @@ export const bakeWarpShadowLayer = (decls, source, rs) => {
|
|
|
149
150
|
};
|
|
150
151
|
/** 变形特效合成(fabric _renderText 同序:投影垫底 → run 文本 → solidFill → stroke)。
|
|
151
152
|
* ctx 为变形烘焙画布上下文(中心原点本地系 ×CACHE_DPR);投影在 run 之后合成,
|
|
152
|
-
* 用 destination-over
|
|
153
|
-
const compositeWarpEffects = (ctx, node, decls) => {
|
|
153
|
+
* 用 destination-over 落到已有文本之下。批次 365 起导出(psdWarpText 复用) */
|
|
154
|
+
export const compositeWarpEffects = (ctx, node, decls) => {
|
|
154
155
|
if (!decls)
|
|
155
156
|
return;
|
|
156
157
|
if (decls.dropShadows.length === 0 && decls.solidFills.length === 0 && decls.strokes.length === 0)
|
|
@@ -309,8 +310,9 @@ export const bakeWarpedText = (node, kind, decls = null) => {
|
|
|
309
310
|
/** 竖排逐字彩色渲染(shadowBake.drawTextGlyphs 竖排分支的彩色版):摆位/
|
|
310
311
|
* 姿态(verticalGlyphOps + drawVerticalGlyph)与 K-line jitter 同剪影口径,
|
|
311
312
|
* fill/stroke 逐字覆写与 renderTextRuns 同语义(fill 覆写 ?? 对象级、
|
|
312
|
-
* 描边 resolveStrokeDecl;paintFirst 逐字粒度不区分——竖排 quad 管线同款)。
|
|
313
|
-
|
|
313
|
+
* 描边 resolveStrokeDecl;paintFirst 逐字粒度不区分——竖排 quad 管线同款)。
|
|
314
|
+
* 批次 365 起导出(psdWarpText 竖排分支复用) */
|
|
315
|
+
export const renderVerticalRuns = (ctx, node) => {
|
|
314
316
|
const layout = node.textLayout;
|
|
315
317
|
const style = node.textStyle;
|
|
316
318
|
const baseStroke = node.textStroke;
|