@yft-design/engine 0.0.0-stage → 0.0.1
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 +39 -2
- package/dist/EngineCanvas.d.ts +500 -0
- package/dist/EngineCanvas.js +927 -0
- package/dist/core/canvasPerf.d.ts +23 -0
- package/dist/core/canvasPerf.js +170 -0
- package/dist/core/color.d.ts +52 -0
- package/dist/core/color.js +107 -0
- package/dist/core/distanceField.d.ts +15 -0
- package/dist/core/distanceField.js +92 -0
- package/dist/core/events.d.ts +34 -0
- package/dist/core/events.js +52 -0
- package/dist/core/gradient.d.ts +97 -0
- package/dist/core/gradient.js +175 -0
- package/dist/core/imageFilters.d.ts +150 -0
- package/dist/core/imageFilters.js +330 -0
- package/dist/core/mat2d.d.ts +151 -0
- package/dist/core/mat2d.js +241 -0
- package/dist/core/pathData.d.ts +53 -0
- package/dist/core/pathData.js +926 -0
- package/dist/core/pattern.d.ts +38 -0
- package/dist/core/pattern.js +40 -0
- package/dist/core/point.d.ts +59 -0
- package/dist/core/point.js +119 -0
- package/dist/core/psdEffects.d.ts +126 -0
- package/dist/core/psdEffects.js +158 -0
- package/dist/core/roundedRect.d.ts +62 -0
- package/dist/core/roundedRect.js +163 -0
- package/dist/core/shadow.d.ts +51 -0
- package/dist/core/shadow.js +47 -0
- package/dist/core/snap.d.ts +232 -0
- package/dist/core/snap.js +793 -0
- package/dist/core/stroke.d.ts +41 -0
- package/dist/core/stroke.js +44 -0
- package/dist/core/triangulate.d.ts +24 -0
- package/dist/core/triangulate.js +118 -0
- package/dist/debug/canvasInspection.d.ts +92 -0
- package/dist/debug/canvasInspection.js +113 -0
- package/dist/debug/pixelDiff.d.ts +22 -0
- package/dist/debug/pixelDiff.js +64 -0
- package/dist/debug/seed.d.ts +473 -0
- package/dist/debug/seed.js +3803 -0
- package/dist/decoders/gif2sprite.d.ts +9 -0
- package/dist/decoders/gif2sprite.js +84 -0
- package/dist/decoders/webp2sprite.d.ts +22 -0
- package/dist/decoders/webp2sprite.js +133 -0
- package/dist/engineFlag.d.ts +72 -0
- package/dist/engineFlag.js +86 -0
- package/dist/export/SceneExporter.d.ts +92 -0
- package/dist/export/SceneExporter.js +280 -0
- package/dist/export/glExport.d.ts +66 -0
- package/dist/export/glExport.js +79 -0
- package/dist/export/svgExport.d.ts +277 -0
- package/dist/export/svgExport.js +1790 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +48 -0
- package/dist/interact/animationPlayback.d.ts +125 -0
- package/dist/interact/animationPlayback.js +344 -0
- package/dist/interact/canvasInteractions.d.ts +50 -0
- package/dist/interact/canvasInteractions.js +150 -0
- package/dist/interact/cropSession.d.ts +123 -0
- package/dist/interact/cropSession.js +526 -0
- package/dist/interact/dblClick.d.ts +51 -0
- package/dist/interact/dblClick.js +106 -0
- package/dist/interact/expandSession.d.ts +107 -0
- package/dist/interact/expandSession.js +281 -0
- package/dist/interact/hotkeyActions.d.ts +16 -0
- package/dist/interact/hotkeyActions.js +41 -0
- package/dist/interact/pathSession.d.ts +141 -0
- package/dist/interact/pathSession.js +480 -0
- package/dist/interact/pointer.d.ts +106 -0
- package/dist/interact/pointer.js +1594 -0
- package/dist/interact/pointerTablePuzzle.d.ts +100 -0
- package/dist/interact/pointerTablePuzzle.js +358 -0
- package/dist/interact/pointerTransform.d.ts +86 -0
- package/dist/interact/pointerTransform.js +440 -0
- package/dist/interact/pointerTypes.d.ts +577 -0
- package/dist/interact/pointerTypes.js +96 -0
- package/dist/interact/snapGuide.d.ts +127 -0
- package/dist/interact/snapGuide.js +376 -0
- package/dist/interact/tableCellEditing.d.ts +61 -0
- package/dist/interact/tableCellEditing.js +198 -0
- package/dist/interact/tableInteraction.d.ts +55 -0
- package/dist/interact/tableInteraction.js +212 -0
- package/dist/interact/textEditing.d.ts +77 -0
- package/dist/interact/textEditing.js +410 -0
- package/dist/interact/warpFacade.d.ts +36 -0
- package/dist/interact/warpFacade.js +51 -0
- package/dist/interact/warpSession.d.ts +191 -0
- package/dist/interact/warpSession.js +582 -0
- package/dist/interact/wheelScroll.d.ts +62 -0
- package/dist/interact/wheelScroll.js +72 -0
- package/dist/model/alphaHit.d.ts +59 -0
- package/dist/model/alphaHit.js +262 -0
- package/dist/model/animation.d.ts +228 -0
- package/dist/model/animation.js +510 -0
- package/dist/model/arcLayout.d.ts +54 -0
- package/dist/model/arcLayout.js +307 -0
- package/dist/model/arcTextTransform.d.ts +7 -0
- package/dist/model/arcTextTransform.js +87 -0
- package/dist/model/compatEvents.d.ts +135 -0
- package/dist/model/compatEvents.js +73 -0
- package/dist/model/compatObject.d.ts +716 -0
- package/dist/model/compatObject.js +1579 -0
- package/dist/model/cropEdit.d.ts +118 -0
- package/dist/model/cropEdit.js +497 -0
- package/dist/model/document.d.ts +294 -0
- package/dist/model/document.js +572 -0
- package/dist/model/expandEdit.d.ts +93 -0
- package/dist/model/expandEdit.js +161 -0
- package/dist/model/fabricPrimitives.d.ts +156 -0
- package/dist/model/fabricPrimitives.js +9 -0
- package/dist/model/filler.d.ts +53 -0
- package/dist/model/filler.js +1 -0
- package/dist/model/groupAssemble.d.ts +7 -0
- package/dist/model/groupAssemble.js +98 -0
- package/dist/model/groupChildMove.d.ts +46 -0
- package/dist/model/groupChildMove.js +145 -0
- package/dist/model/groupResize.d.ts +78 -0
- package/dist/model/groupResize.js +108 -0
- package/dist/model/handles.d.ts +40 -0
- package/dist/model/handles.js +29 -0
- package/dist/model/imageMaskBake.d.ts +75 -0
- package/dist/model/imageMaskBake.js +136 -0
- package/dist/model/lineConstruct.d.ts +13 -0
- package/dist/model/lineConstruct.js +79 -0
- package/dist/model/maskCropEdit.d.ts +64 -0
- package/dist/model/maskCropEdit.js +90 -0
- package/dist/model/pathBackground.d.ts +51 -0
- package/dist/model/pathBackground.js +196 -0
- package/dist/model/pathConstruct.d.ts +27 -0
- package/dist/model/pathConstruct.js +55 -0
- package/dist/model/pathEdit.d.ts +114 -0
- package/dist/model/pathEdit.js +378 -0
- package/dist/model/puzzleEdit.d.ts +136 -0
- package/dist/model/puzzleEdit.js +742 -0
- package/dist/model/puzzleLayout.d.ts +91 -0
- package/dist/model/puzzleLayout.js +143 -0
- package/dist/model/scene.d.ts +1004 -0
- package/dist/model/scene.js +2841 -0
- package/dist/model/schema.d.ts +290 -0
- package/dist/model/schema.js +13 -0
- package/dist/model/shapePath.d.ts +14 -0
- package/dist/model/shapePath.js +136 -0
- package/dist/model/tableEdit.d.ts +196 -0
- package/dist/model/tableEdit.js +751 -0
- package/dist/model/tableFacade.d.ts +6 -0
- package/dist/model/tableFacade.js +808 -0
- package/dist/model/tableLayout.d.ts +85 -0
- package/dist/model/tableLayout.js +193 -0
- package/dist/model/textLayout.d.ts +357 -0
- package/dist/model/textLayout.js +822 -0
- package/dist/render/GLBlend.d.ts +40 -0
- package/dist/render/GLBlend.js +270 -0
- package/dist/render/GLContext.d.ts +25 -0
- package/dist/render/GLContext.js +48 -0
- package/dist/render/GLIsolate.d.ts +46 -0
- package/dist/render/GLIsolate.js +188 -0
- package/dist/render/GLTextureCache.d.ts +86 -0
- package/dist/render/GLTextureCache.js +187 -0
- package/dist/render/GlyphAtlas.d.ts +151 -0
- package/dist/render/GlyphAtlas.js +404 -0
- package/dist/render/MeshBatch.d.ts +123 -0
- package/dist/render/MeshBatch.js +416 -0
- package/dist/render/QuadBatch.d.ts +138 -0
- package/dist/render/QuadBatch.js +490 -0
- package/dist/render/SceneRenderer.d.ts +186 -0
- package/dist/render/SceneRenderer.js +700 -0
- package/dist/render/SourceManager.d.ts +121 -0
- package/dist/render/SourceManager.js +505 -0
- package/dist/render/TextRenderer.d.ts +140 -0
- package/dist/render/TextRenderer.js +795 -0
- package/dist/render/arcText.d.ts +40 -0
- package/dist/render/arcText.js +187 -0
- package/dist/render/batchOrder.d.ts +105 -0
- package/dist/render/batchOrder.js +168 -0
- package/dist/render/blendMode.d.ts +35 -0
- package/dist/render/blendMode.js +142 -0
- package/dist/render/clipMaskPainter.d.ts +17 -0
- package/dist/render/clipMaskPainter.js +121 -0
- package/dist/render/fontInvalidation.d.ts +25 -0
- package/dist/render/fontInvalidation.js +77 -0
- package/dist/render/fontInvalidationController.d.ts +76 -0
- package/dist/render/fontInvalidationController.js +114 -0
- package/dist/render/frameOverlay.d.ts +62 -0
- package/dist/render/frameOverlay.js +124 -0
- package/dist/render/framePipeline.d.ts +99 -0
- package/dist/render/framePipeline.js +95 -0
- package/dist/render/gpuFilterPasses.d.ts +25 -0
- package/dist/render/gpuFilterPasses.js +883 -0
- package/dist/render/gpuFx.d.ts +136 -0
- package/dist/render/gpuFx.js +614 -0
- package/dist/render/gpuImageFilters.d.ts +59 -0
- package/dist/render/gpuImageFilters.js +289 -0
- package/dist/render/gpuShadow.d.ts +52 -0
- package/dist/render/gpuShadow.js +289 -0
- package/dist/render/gradientRamp.d.ts +45 -0
- package/dist/render/gradientRamp.js +74 -0
- package/dist/render/imageEffects.d.ts +123 -0
- package/dist/render/imageEffects.js +390 -0
- package/dist/render/maskRender.d.ts +92 -0
- package/dist/render/maskRender.js +224 -0
- package/dist/render/progressiveLoad.d.ts +45 -0
- package/dist/render/progressiveLoad.js +86 -0
- package/dist/render/psdEffectPainter.d.ts +34 -0
- package/dist/render/psdEffectPainter.js +309 -0
- package/dist/render/puzzleClamp.d.ts +28 -0
- package/dist/render/puzzleClamp.js +30 -0
- package/dist/render/retainedFrame.d.ts +85 -0
- package/dist/render/retainedFrame.js +193 -0
- package/dist/render/ruler.d.ts +90 -0
- package/dist/render/ruler.js +287 -0
- package/dist/render/scrollText.d.ts +65 -0
- package/dist/render/scrollText.js +261 -0
- package/dist/render/selectionOverlay.d.ts +318 -0
- package/dist/render/selectionOverlay.js +921 -0
- package/dist/render/shaders.d.ts +38 -0
- package/dist/render/shaders.js +314 -0
- package/dist/render/shadowBake.d.ts +43 -0
- package/dist/render/shadowBake.js +202 -0
- package/dist/render/shadowPainter.d.ts +13 -0
- package/dist/render/shadowPainter.js +80 -0
- package/dist/render/sharedGpuPainters.d.ts +25 -0
- package/dist/render/sharedGpuPainters.js +40 -0
- package/dist/render/sourceHydration.d.ts +12 -0
- package/dist/render/sourceHydration.js +48 -0
- package/dist/render/strokeBake.d.ts +85 -0
- package/dist/render/strokeBake.js +515 -0
- package/dist/render/strokePainter.d.ts +28 -0
- package/dist/render/strokePainter.js +119 -0
- package/dist/render/strokeSdf.d.ts +35 -0
- package/dist/render/strokeSdf.js +74 -0
- package/dist/render/svgRaster.d.ts +46 -0
- package/dist/render/svgRaster.js +71 -0
- package/dist/render/tableOverlay.d.ts +38 -0
- package/dist/render/tableOverlay.js +233 -0
- package/dist/render/textHighlight.d.ts +117 -0
- package/dist/render/textHighlight.js +380 -0
- package/dist/render/textureUpload.d.ts +18 -0
- package/dist/render/textureUpload.js +26 -0
- package/dist/render/verticalText.d.ts +38 -0
- package/dist/render/verticalText.js +63 -0
- package/dist/render/warpText.d.ts +58 -0
- package/dist/render/warpText.js +380 -0
- package/dist/render/workspaceBackdrop.d.ts +35 -0
- package/dist/render/workspaceBackdrop.js +71 -0
- package/dist/render/workspaceChecker.d.ts +54 -0
- package/dist/render/workspaceChecker.js +170 -0
- package/dist/render/workspaceGlow.d.ts +51 -0
- package/dist/render/workspaceGlow.js +171 -0
- package/package.json +39 -3
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文字划重点(批次62):应用定制 Textbox._renderHighlight(主仓
|
|
3
|
+
* extension/object/Textbox.ts 1466-1767)的引擎承接。
|
|
4
|
+
*
|
|
5
|
+
* 数据面:raw.texts = [{ text, highlight?: { type:'svg', svgInfo } }]——compat 面
|
|
6
|
+
* setTexts 直写已久(数据持久化供 fabric 模式往返),本模块补引擎渲染消费。
|
|
7
|
+
*
|
|
8
|
+
* 两段式:
|
|
9
|
+
* 1. highlightRuns / planTextHighlight —— 纯函数(jsdom 可测):段 → 视觉行/
|
|
10
|
+
* 字符盒区间切分(fabric 索引数学逐行复刻,含行尾虚拟游标盒)→ 本地系
|
|
11
|
+
* 绘制计划(变换矩阵 + 画笔参数 + 出血余量)。
|
|
12
|
+
* 2. bakeTextHighlight —— 浏览器面:按计划在 canvas2d 上 Path2D 绘制(fabric
|
|
13
|
+
* 同一光栅器语义,线帽/拐角不设值=canvas 缺省 butt/miter,fabric
|
|
14
|
+
* _renderHighlight 亦不设置——TextMark 配置里的 round 不生效是双栈共同 quirk)。
|
|
15
|
+
*
|
|
16
|
+
* 已知边界:
|
|
17
|
+
* - 竖排(raw.vertical)不承接——fabric 侧行/列 charBounds 语义存疑,登记缺口;
|
|
18
|
+
* - 阴影/PSD 特效剪影不含划重点墨迹(fabric _renderHighlight 在阴影域外,同构);
|
|
19
|
+
* - SVG 导出序列化面不消费 texts(双栈同侪)。
|
|
20
|
+
*/
|
|
21
|
+
import { getBoundsOfPath, parsePathData } from '../core/pathData';
|
|
22
|
+
/**
|
|
23
|
+
* 应用定制 _measureLine 的行尾游标盒(主仓 Textbox.ts 1319-1325):
|
|
24
|
+
* left = 末字盒 left+width、宽 0、height = 对象级 fontSize。fabric 整行段的
|
|
25
|
+
* width = curCharBoxs[end].left − startBox.left 依赖它(原生 fabric 无此盒,
|
|
26
|
+
* 越界抛错被 try/catch 吞成全跳——应用补盒后整行段是主路径)。
|
|
27
|
+
*/
|
|
28
|
+
export const trailingCharBox = (line, objectFontSize) => {
|
|
29
|
+
const boxes = line.boxes;
|
|
30
|
+
if (boxes.length === 0)
|
|
31
|
+
return { left: 0, width: 0, kernedWidth: 0, height: objectFontSize };
|
|
32
|
+
const last = boxes[boxes.length - 1];
|
|
33
|
+
return { left: last.left + last.width, width: 0, kernedWidth: 0, height: objectFontSize };
|
|
34
|
+
};
|
|
35
|
+
/** 行内取盒:越界仅允许 == length(尾盒),再越界返回 null(调用方跳过该 run) */
|
|
36
|
+
const boxAt = (line, i, objectFontSize) => {
|
|
37
|
+
if (i < 0)
|
|
38
|
+
return null;
|
|
39
|
+
if (i < line.boxes.length)
|
|
40
|
+
return line.boxes[i];
|
|
41
|
+
if (i === line.boxes.length)
|
|
42
|
+
return trailingCharBox(line, objectFontSize);
|
|
43
|
+
return null;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 段 → 视觉行/盒区间切分(fabric _renderHighlight 1480-1610 复刻)。
|
|
47
|
+
*
|
|
48
|
+
* 索引语义(与 fabric 同名变量一一对应):
|
|
49
|
+
* - indexLineMap / index2IndexOfLine:grapheme 平铺序 → (视觉行号, 行内盒序);
|
|
50
|
+
* - fullTextToLineIndexMap:text 的 **code unit** → grapheme 平铺序('\n' → -1;
|
|
51
|
+
* 计数器按 code unit 递增——代理对字符双耗 grapheme 槽位的漂移是 fabric
|
|
52
|
+
* 原 quirk,复刻不修)。
|
|
53
|
+
*
|
|
54
|
+
* 守卫同 fabric:Σ段长 ≠ text.length(code unit)整跳;非 svg highlight 跳段;
|
|
55
|
+
* '\n' 单独段只推 idx。fabric 对查表越界段有 start=0 兜底/no-end-index 跳过的
|
|
56
|
+
* 杂路(仅双重换行等病态段触达),此处统一按跳过处理(正常 UI 不会生成)。
|
|
57
|
+
*/
|
|
58
|
+
export const highlightRuns = (text, layout, texts) => {
|
|
59
|
+
if (!Array.isArray(texts) || texts.length === 0)
|
|
60
|
+
return [];
|
|
61
|
+
let total = 0;
|
|
62
|
+
for (const t of texts) {
|
|
63
|
+
if (!t || typeof t.text !== 'string')
|
|
64
|
+
return [];
|
|
65
|
+
total += t.text.length;
|
|
66
|
+
}
|
|
67
|
+
if (total !== text.length)
|
|
68
|
+
return [];
|
|
69
|
+
const indexLineMap = [];
|
|
70
|
+
const index2IndexOfLine = [];
|
|
71
|
+
for (let line = 0; line < layout.lines.length; line++) {
|
|
72
|
+
const n = layout.lines[line].graphemes.length;
|
|
73
|
+
for (let i = 0; i < n; i++) {
|
|
74
|
+
index2IndexOfLine.push(i);
|
|
75
|
+
indexLineMap.push(line);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const fullTextToLineIndexMap = [];
|
|
79
|
+
let lineTextIndex = 0;
|
|
80
|
+
for (let i = 0; i < text.length; i++) {
|
|
81
|
+
if (text[i] === '\n') {
|
|
82
|
+
fullTextToLineIndexMap.push(-1);
|
|
83
|
+
}
|
|
84
|
+
else if (lineTextIndex < indexLineMap.length) {
|
|
85
|
+
fullTextToLineIndexMap.push(lineTextIndex);
|
|
86
|
+
lineTextIndex++;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
fullTextToLineIndexMap.push(-1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const runs = [];
|
|
93
|
+
const flatAt = (codeUnitIdx) => {
|
|
94
|
+
const mapped = fullTextToLineIndexMap[codeUnitIdx];
|
|
95
|
+
if (mapped === undefined || mapped === -1 || mapped >= indexLineMap.length)
|
|
96
|
+
return -1;
|
|
97
|
+
return mapped;
|
|
98
|
+
};
|
|
99
|
+
let idx = 0;
|
|
100
|
+
for (const tObj of texts) {
|
|
101
|
+
if (tObj.text.length === 0)
|
|
102
|
+
continue;
|
|
103
|
+
if (tObj.text === '\n') {
|
|
104
|
+
idx += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (!tObj.highlight || tObj.highlight.type !== 'svg' || !tObj.highlight.svgInfo) {
|
|
108
|
+
idx += tObj.text.length;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const info = tObj.highlight.svgInfo;
|
|
112
|
+
const mappedStartIdx = flatAt(idx);
|
|
113
|
+
if (mappedStartIdx === -1) {
|
|
114
|
+
idx += tObj.text.length;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
let startLineIndex = indexLineMap[mappedStartIdx];
|
|
118
|
+
let startIdx = 0;
|
|
119
|
+
let lastValidLineIndex = startLineIndex;
|
|
120
|
+
let lastValidCharIdx = 0;
|
|
121
|
+
// exclusiveEnd = fabric 的 i(换行/跨行 flush)或段长(尾 flush)——
|
|
122
|
+
// `startIdx < i` 守卫是段内 '\n' 紧跟换行边界的唯一分界(fabric 1552/1574:
|
|
123
|
+
// 换行 flush 只推 startIdx 起至 i 前的已积累段,空段不推)
|
|
124
|
+
const flush = (exclusiveEnd) => {
|
|
125
|
+
if (startIdx >= exclusiveEnd)
|
|
126
|
+
return;
|
|
127
|
+
const startFlat = flatAt(idx + startIdx);
|
|
128
|
+
const lastFlat = flatAt(idx + lastValidCharIdx);
|
|
129
|
+
if (startFlat === -1 || lastFlat === -1)
|
|
130
|
+
return;
|
|
131
|
+
runs.push({
|
|
132
|
+
lineIndex: lastValidLineIndex,
|
|
133
|
+
start: index2IndexOfLine[startFlat],
|
|
134
|
+
end: index2IndexOfLine[lastFlat] + 1,
|
|
135
|
+
info
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
for (let i = 0; i < tObj.text.length; i++) {
|
|
139
|
+
const mappedIdx = flatAt(idx + i);
|
|
140
|
+
if (mappedIdx === -1) {
|
|
141
|
+
// fabric 1551-1565:段内 '\n'(映射 -1)——已累积部分按所在行截断成段
|
|
142
|
+
flush(i);
|
|
143
|
+
startIdx = i + 1;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const curLineIndex = indexLineMap[mappedIdx];
|
|
147
|
+
if (curLineIndex !== startLineIndex) {
|
|
148
|
+
// fabric 1573-1588:跨行边界——前段按 lastValidLineIndex 截断
|
|
149
|
+
flush(i);
|
|
150
|
+
startIdx = i;
|
|
151
|
+
startLineIndex = curLineIndex;
|
|
152
|
+
}
|
|
153
|
+
lastValidLineIndex = curLineIndex;
|
|
154
|
+
lastValidCharIdx = i;
|
|
155
|
+
}
|
|
156
|
+
flush(tObj.text.length);
|
|
157
|
+
idx += tObj.text.length;
|
|
158
|
+
}
|
|
159
|
+
return runs;
|
|
160
|
+
};
|
|
161
|
+
/** fabric getAlignedTranslateY(1657-1666)逐式复刻 */
|
|
162
|
+
const alignedTranslateY = (targetTop, targetHeight, boxTop, rawBoxHeight, scale, alignVertical) => {
|
|
163
|
+
const boxHeight = rawBoxHeight || targetHeight;
|
|
164
|
+
if (alignVertical === 'bottom')
|
|
165
|
+
return targetTop + targetHeight - (boxTop + boxHeight) * scale;
|
|
166
|
+
if (alignVertical === 'top')
|
|
167
|
+
return targetTop - boxTop * scale;
|
|
168
|
+
return targetTop + (targetHeight - boxHeight * scale) / 2 - boxTop * scale;
|
|
169
|
+
};
|
|
170
|
+
const boundsOfPath = (d) => {
|
|
171
|
+
const commands = parsePathData(d);
|
|
172
|
+
if (!commands)
|
|
173
|
+
return null;
|
|
174
|
+
const b = getBoundsOfPath(commands);
|
|
175
|
+
if (!b)
|
|
176
|
+
return null;
|
|
177
|
+
return { left: b.left, top: b.top, width: b.right - b.left, height: b.bottom - b.top };
|
|
178
|
+
};
|
|
179
|
+
/** fabric getFirstSingleHighlightSubPath(1634-1656):取首子路径并补闭合 */
|
|
180
|
+
const firstSingleSubPath = (rawPath) => {
|
|
181
|
+
const subPaths = rawPath
|
|
182
|
+
.split(/[Zz]/)
|
|
183
|
+
.map((p) => p.trim())
|
|
184
|
+
.filter((p) => p.length > 0);
|
|
185
|
+
if (subPaths.length === 0)
|
|
186
|
+
return null;
|
|
187
|
+
const p = subPaths[0];
|
|
188
|
+
return p.endsWith('Z') || p.endsWith('z') ? p : `${p} Z`;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* 绘制计划:runs → 本地中心系 op 列表 + 出血余量。
|
|
192
|
+
*
|
|
193
|
+
* 本地系与字形管线同构:lineLeft = −layout.width/2 + line.leftOffset、
|
|
194
|
+
* 行顶 y = contentTopY + line.top(contentTopY = −dims.y/2,可能深于
|
|
195
|
+
* −layout.height/2——盒被 mt/mb 抬高时内容块上移,计划不假设居中)。
|
|
196
|
+
*
|
|
197
|
+
* span 模式(fabric 1722-1762):整段拉伸——scaleX = 段宽/path宽、
|
|
198
|
+
* scaleY = 行字高/boxHeight(top/bottom 档按 pathBottom 参考高重算)、
|
|
199
|
+
* translate 使 path 盒对齐段矩形左上(alignVertical 三档)。
|
|
200
|
+
* isSingle 模式(fabric 1667-1719):首子路径逐字重复——uniformScale =
|
|
201
|
+
* min(字宽/path宽, 字高/pathHeight)×svgInfo.scale、水平居中、跳空白字;
|
|
202
|
+
* bottom 档走 fabric 特有的 cTop+cHeight−box.top×s 式(非 getAlignedTranslateY)。
|
|
203
|
+
*/
|
|
204
|
+
export const planTextHighlight = (text, layout, texts, contentTopY, objectFontSize) => {
|
|
205
|
+
const runs = highlightRuns(text, layout, texts);
|
|
206
|
+
if (runs.length === 0)
|
|
207
|
+
return null;
|
|
208
|
+
const ops = [];
|
|
209
|
+
// 真实墨迹累计包围盒(本地中心系)——pad 由其对内容盒的溢出量导出(批次62修:
|
|
210
|
+
// isSingle scale>1 时墨迹超出字盒,如 mock 逐字圆点 scale 1.3 直径 104 超出 80
|
|
211
|
+
// 字盒上下各 12px;原「isFill 零出血」口径把溢出弧线切在画布边缘)
|
|
212
|
+
const ink = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
213
|
+
// op 墨迹包围盒:path 盒经 translate+scale 变换 + 描边出血(各轴独立)
|
|
214
|
+
const extendInk = (op, box) => {
|
|
215
|
+
const hx = op.isFill ? 0 : ((op.strokeWidth || 0) * Math.abs(op.scaleX)) / 2;
|
|
216
|
+
const hy = op.isFill ? 0 : ((op.strokeWidth || 0) * Math.abs(op.scaleY)) / 2;
|
|
217
|
+
const x0 = op.translateX + box.left * op.scaleX - hx;
|
|
218
|
+
const y0 = op.translateY + box.top * op.scaleY - hy;
|
|
219
|
+
const x1 = op.translateX + (box.left + box.width) * op.scaleX + hx;
|
|
220
|
+
const y1 = op.translateY + (box.top + box.height) * op.scaleY + hy;
|
|
221
|
+
if (x0 < ink.minX)
|
|
222
|
+
ink.minX = x0;
|
|
223
|
+
if (y0 < ink.minY)
|
|
224
|
+
ink.minY = y0;
|
|
225
|
+
if (x1 > ink.maxX)
|
|
226
|
+
ink.maxX = x1;
|
|
227
|
+
if (y1 > ink.maxY)
|
|
228
|
+
ink.maxY = y1;
|
|
229
|
+
};
|
|
230
|
+
for (const run of runs) {
|
|
231
|
+
const line = layout.lines[run.lineIndex];
|
|
232
|
+
if (!line)
|
|
233
|
+
continue;
|
|
234
|
+
const info = run.info;
|
|
235
|
+
const rawPath = typeof info.path === 'string' ? info.path : '';
|
|
236
|
+
if (!rawPath)
|
|
237
|
+
continue;
|
|
238
|
+
const alignVertical = info.alignVertical || 'center';
|
|
239
|
+
const isFill = info.isFill === true;
|
|
240
|
+
const strokeWidth = info.strokeWidth || 0;
|
|
241
|
+
const lineLeft = -layout.width / 2 + line.leftOffset;
|
|
242
|
+
const top = contentTopY + line.top;
|
|
243
|
+
const startBox = boxAt(line, run.start, objectFontSize);
|
|
244
|
+
if (!startBox)
|
|
245
|
+
continue;
|
|
246
|
+
if (info.isSingle === true) {
|
|
247
|
+
// 首子路径逐字重复
|
|
248
|
+
const subD = firstSingleSubPath(rawPath);
|
|
249
|
+
if (!subD)
|
|
250
|
+
continue;
|
|
251
|
+
const box = boundsOfPath(subD);
|
|
252
|
+
if (!box || !Number.isFinite(box.width) || !Number.isFinite(box.height))
|
|
253
|
+
continue;
|
|
254
|
+
const path2dSource = subD;
|
|
255
|
+
for (let j = run.start; j < run.end; j++) {
|
|
256
|
+
const ch = line.graphemes[j];
|
|
257
|
+
if (!ch || /^\s$/.test(ch))
|
|
258
|
+
continue;
|
|
259
|
+
const charBox = boxAt(line, j, objectFontSize);
|
|
260
|
+
const nextBox = boxAt(line, j + 1, objectFontSize);
|
|
261
|
+
if (!charBox)
|
|
262
|
+
continue;
|
|
263
|
+
const cLeft = lineLeft + charBox.left;
|
|
264
|
+
const cTop = top;
|
|
265
|
+
const cWidth = charBox.kernedWidth || charBox.width || (nextBox ? nextBox.left : charBox.left) - charBox.left;
|
|
266
|
+
const cHeight = charBox.height;
|
|
267
|
+
let boxHeight = box.height;
|
|
268
|
+
if (!boxHeight)
|
|
269
|
+
boxHeight = cHeight;
|
|
270
|
+
const scaleXCandidate = box.width ? cWidth / box.width : 1;
|
|
271
|
+
const scaleYCandidate = boxHeight ? cHeight / boxHeight : 1;
|
|
272
|
+
const scale = info.scale || 1;
|
|
273
|
+
const uniformScale = Math.min(scaleXCandidate, scaleYCandidate) * scale;
|
|
274
|
+
const scaledW = (box.width || 0) * uniformScale;
|
|
275
|
+
const translateX = cLeft + (cWidth - scaledW) / 2 - box.left * uniformScale;
|
|
276
|
+
const translateY = alignVertical === 'bottom' ? cTop + cHeight - box.top * uniformScale : alignedTranslateY(cTop, cHeight, box.top, boxHeight, uniformScale, alignVertical);
|
|
277
|
+
const op = {
|
|
278
|
+
d: path2dSource,
|
|
279
|
+
translateX,
|
|
280
|
+
translateY,
|
|
281
|
+
scaleX: uniformScale,
|
|
282
|
+
scaleY: uniformScale,
|
|
283
|
+
isFill,
|
|
284
|
+
fill: info.fill || '#9FFFFC',
|
|
285
|
+
stroke: info.stroke || '#9FFFFC',
|
|
286
|
+
strokeWidth
|
|
287
|
+
};
|
|
288
|
+
ops.push(op);
|
|
289
|
+
extendInk(op, box);
|
|
290
|
+
}
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
// span 整段拉伸
|
|
294
|
+
const endBox = boxAt(line, run.end, objectFontSize);
|
|
295
|
+
if (!endBox)
|
|
296
|
+
continue;
|
|
297
|
+
const left = lineLeft + startBox.left;
|
|
298
|
+
const width = endBox.left - startBox.left;
|
|
299
|
+
const height = startBox.height;
|
|
300
|
+
const box = boundsOfPath(rawPath);
|
|
301
|
+
if (!box || !Number.isFinite(box.width) || !Number.isFinite(box.height) || box.width === 0)
|
|
302
|
+
continue;
|
|
303
|
+
let boxHeight = box.height;
|
|
304
|
+
if (!boxHeight)
|
|
305
|
+
boxHeight = height;
|
|
306
|
+
const scaleX = width / box.width;
|
|
307
|
+
let scaleY = height / boxHeight;
|
|
308
|
+
const translateX = left - box.left * scaleX;
|
|
309
|
+
let translateY = alignedTranslateY(top, height, box.top, boxHeight, scaleY, alignVertical);
|
|
310
|
+
if (alignVertical === 'bottom' || alignVertical === 'top') {
|
|
311
|
+
const pathBottom = box.top + boxHeight;
|
|
312
|
+
const referenceHeight = pathBottom > 0 ? pathBottom : boxHeight || 1;
|
|
313
|
+
scaleY = height / referenceHeight;
|
|
314
|
+
translateY = alignedTranslateY(top, height, box.top, boxHeight, scaleY, alignVertical);
|
|
315
|
+
}
|
|
316
|
+
if (!box.height)
|
|
317
|
+
translateY += height / 2;
|
|
318
|
+
const op = {
|
|
319
|
+
d: rawPath,
|
|
320
|
+
translateX,
|
|
321
|
+
translateY,
|
|
322
|
+
scaleX,
|
|
323
|
+
scaleY,
|
|
324
|
+
isFill,
|
|
325
|
+
fill: info.fill || '#9FFFFC',
|
|
326
|
+
stroke: info.stroke || '#9FFFFC',
|
|
327
|
+
strokeWidth
|
|
328
|
+
};
|
|
329
|
+
ops.push(op);
|
|
330
|
+
extendInk(op, box);
|
|
331
|
+
}
|
|
332
|
+
if (ops.length === 0)
|
|
333
|
+
return null;
|
|
334
|
+
// pad = 墨迹溢出内容盒 [−w/2, w/2] × [contentTopY, contentTopY+h] 的量(四向
|
|
335
|
+
// 取大——画布是单矩形);无溢出保底 2px(AA 余量)。左溢出 = −half − minX
|
|
336
|
+
// (盒左缘是 −half——曾写反成 half − minX,贴盒左缘的段恒溢出 2×half)
|
|
337
|
+
const half = layout.width / 2;
|
|
338
|
+
const finite = Number.isFinite(ink.minX) && Number.isFinite(ink.minY);
|
|
339
|
+
const padX = finite ? Math.max(2, -half - ink.minX, ink.maxX - half) : 2;
|
|
340
|
+
const padY = finite ? Math.max(2, contentTopY - ink.minY, ink.maxY - (contentTopY + layout.height)) : 2;
|
|
341
|
+
return { ops, padX, padY };
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* canvas2d 烘焙:计划 → 纹理源。画布覆盖本地矩形
|
|
345
|
+
* [−(layout.width/2+padX), +] × [contentTopY−padY, contentTopY+layout.height+padY]
|
|
346
|
+
* (y 向锚内容块顶——盒抬高时 quad 由调用方按 contentTopY 偏心推送)。
|
|
347
|
+
* scale = 分桶(同字形/虚线烘焙口径,超采样防放大糊)。
|
|
348
|
+
*/
|
|
349
|
+
export const bakeTextHighlight = (plan, layout, contentTopY, scale) => {
|
|
350
|
+
const logicalW = Math.ceil(layout.width + plan.padX * 2);
|
|
351
|
+
const logicalH = Math.ceil(layout.height + plan.padY * 2);
|
|
352
|
+
if (!(logicalW > 0) || !(logicalH > 0) || logicalW > 8192 || logicalH > 8192)
|
|
353
|
+
return null;
|
|
354
|
+
const canvas = document.createElement('canvas');
|
|
355
|
+
canvas.width = Math.ceil(logicalW * scale);
|
|
356
|
+
canvas.height = Math.ceil(logicalH * scale);
|
|
357
|
+
const ctx = canvas.getContext('2d');
|
|
358
|
+
if (!ctx)
|
|
359
|
+
return null;
|
|
360
|
+
ctx.setTransform(scale, 0, 0, scale, 0, 0);
|
|
361
|
+
// 本地中心系 → 画布:x + logicalW/2;y − contentTopY + padY(锚内容块顶)
|
|
362
|
+
ctx.translate(layout.width / 2 + plan.padX, plan.padY - contentTopY);
|
|
363
|
+
for (const op of plan.ops) {
|
|
364
|
+
const path = new Path2D(op.d);
|
|
365
|
+
ctx.save();
|
|
366
|
+
ctx.translate(op.translateX, op.translateY);
|
|
367
|
+
ctx.scale(op.scaleX, op.scaleY);
|
|
368
|
+
if (op.isFill) {
|
|
369
|
+
ctx.fillStyle = op.fill;
|
|
370
|
+
ctx.fill(path);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
ctx.lineWidth = op.strokeWidth;
|
|
374
|
+
ctx.strokeStyle = op.stroke;
|
|
375
|
+
ctx.stroke(path);
|
|
376
|
+
}
|
|
377
|
+
ctx.restore();
|
|
378
|
+
}
|
|
379
|
+
return { canvas, logicalW, logicalH };
|
|
380
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GL 纹理上传工具(从 EngineCanvas 收编的样板,调用序逐处同构):
|
|
3
|
+
* createTexture → bindTexture → texImage2D(RGBA/UNSIGNED_BYTE) →
|
|
4
|
+
* (generateMipmap) → MIN_FILTER → MAG_FILTER → WRAP_S/T。
|
|
5
|
+
*
|
|
6
|
+
* 实际只有 3 种参数组合:缺省(LINEAR + CLAMP,位图/烘焙画布)、
|
|
7
|
+
* mipmap(阴影类烘焙,MIN=LINEAR_MIPMAP_LINEAR)、mipmap+repeat
|
|
8
|
+
* (图案纹理唯一——WebGL2 NPOT 可 REPEAT)。createTexture 失败返回
|
|
9
|
+
* null,调用点原有 null 守卫语义不变。不收编 GLTextureCache.get
|
|
10
|
+
* (FLIP_Y 语境)与 GLIsolator.ensureSize(null 数据重载)。
|
|
11
|
+
*/
|
|
12
|
+
export interface TextureUploadOptions {
|
|
13
|
+
/** generateMipmap + MIN_FILTER=LINEAR_MIPMAP_LINEAR(缺省 LINEAR) */
|
|
14
|
+
mipmap?: boolean;
|
|
15
|
+
/** wrap = REPEAT(缺省 CLAMP_TO_EDGE) */
|
|
16
|
+
repeat?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const createTexture2D: (gl: WebGL2RenderingContext, source: TexImageSource, options?: TextureUploadOptions) => WebGLTexture | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GL 纹理上传工具(从 EngineCanvas 收编的样板,调用序逐处同构):
|
|
3
|
+
* createTexture → bindTexture → texImage2D(RGBA/UNSIGNED_BYTE) →
|
|
4
|
+
* (generateMipmap) → MIN_FILTER → MAG_FILTER → WRAP_S/T。
|
|
5
|
+
*
|
|
6
|
+
* 实际只有 3 种参数组合:缺省(LINEAR + CLAMP,位图/烘焙画布)、
|
|
7
|
+
* mipmap(阴影类烘焙,MIN=LINEAR_MIPMAP_LINEAR)、mipmap+repeat
|
|
8
|
+
* (图案纹理唯一——WebGL2 NPOT 可 REPEAT)。createTexture 失败返回
|
|
9
|
+
* null,调用点原有 null 守卫语义不变。不收编 GLTextureCache.get
|
|
10
|
+
* (FLIP_Y 语境)与 GLIsolator.ensureSize(null 数据重载)。
|
|
11
|
+
*/
|
|
12
|
+
export const createTexture2D = (gl, source, options = {}) => {
|
|
13
|
+
const tex = gl.createTexture();
|
|
14
|
+
if (!tex)
|
|
15
|
+
return null;
|
|
16
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
17
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
18
|
+
if (options.mipmap)
|
|
19
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
20
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, options.mipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
|
|
21
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
22
|
+
const wrap = options.repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
23
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap);
|
|
24
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap);
|
|
25
|
+
return tex;
|
|
26
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 竖排文本的 canvas 逐字绘制助手(P4-5c)。
|
|
3
|
+
*
|
|
4
|
+
* shadowBake 剪影与 TextRenderer 虚线描边烘焙共用——两处都以 canvas2d 复刻
|
|
5
|
+
* 应用 Textbox `_renderStr` 的竖排分支(内部坐标系:行沿 +x 行进、经对象
|
|
6
|
+
* angle:90 的通用矩阵转竖,引擎不做任何角度特判)。quad 管线
|
|
7
|
+
* (renderGlyphPass)不在此列——四类姿态在 GL 侧用矩阵等价实现。
|
|
8
|
+
*
|
|
9
|
+
* textOffsetY 隔字抖动不在此列(调用方以 charJitterY 平移 op.y——横排/
|
|
10
|
+
* 竖排四姿态共用,fabric _renderStr 2714-2757 口径)。
|
|
11
|
+
*/
|
|
12
|
+
import type { TextNode } from '../model/scene';
|
|
13
|
+
import { type TextLineLayout, type TextStyleProps } from '../model/textLayout';
|
|
14
|
+
export interface VerticalGlyphOp {
|
|
15
|
+
ch: string;
|
|
16
|
+
/** symbol/cjk 类:锚点平移 + rotate(−π/2) 后在原点绘制;否则平画 */
|
|
17
|
+
rotated: boolean;
|
|
18
|
+
/** rotated ? 锚点坐标 : fillText 直画原点 */
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 单行竖排逐字摆位(fabric _renderChars 2459-2478 笔位 + _renderStr
|
|
24
|
+
* 2711-2743 姿态)。lineLeft/baselineY 为该行行首 x 与基线 y(对象中心系);
|
|
25
|
+
* style/charSpacing 为对象级样式(逐字 fontSize 覆写用于锚点偏移)。
|
|
26
|
+
*/
|
|
27
|
+
export declare const verticalGlyphOps: (line: TextLineLayout, lineLeft: number, baselineY: number, style: TextStyleProps, charSpacing: number) => VerticalGlyphOp[];
|
|
28
|
+
/** 按摆位画一个竖排字符(fill/stroke 二选一;font/描边参数由调用方预设) */
|
|
29
|
+
export declare const drawVerticalGlyph: (ctx: CanvasRenderingContext2D, op: VerticalGlyphOp, method: "fillText" | "strokeText") => void;
|
|
30
|
+
/** 逐字字体四件套解析(glyph pass / bakes 同口径的覆写合并) */
|
|
31
|
+
export declare const glyphStyleAt: (style: TextStyleProps, o: {
|
|
32
|
+
fontSize?: number;
|
|
33
|
+
fontFamily?: string;
|
|
34
|
+
fontWeight?: string | number;
|
|
35
|
+
fontStyle?: string;
|
|
36
|
+
} | undefined) => TextStyleProps;
|
|
37
|
+
/** TextNode 是否竖排(引擎唯一判定源:vertical === true,无角度特判) */
|
|
38
|
+
export declare const isVerticalText: (node: TextNode) => boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 竖排文本的 canvas 逐字绘制助手(P4-5c)。
|
|
3
|
+
*
|
|
4
|
+
* shadowBake 剪影与 TextRenderer 虚线描边烘焙共用——两处都以 canvas2d 复刻
|
|
5
|
+
* 应用 Textbox `_renderStr` 的竖排分支(内部坐标系:行沿 +x 行进、经对象
|
|
6
|
+
* angle:90 的通用矩阵转竖,引擎不做任何角度特判)。quad 管线
|
|
7
|
+
* (renderGlyphPass)不在此列——四类姿态在 GL 侧用矩阵等价实现。
|
|
8
|
+
*
|
|
9
|
+
* textOffsetY 隔字抖动不在此列(调用方以 charJitterY 平移 op.y——横排/
|
|
10
|
+
* 竖排四姿态共用,fabric _renderStr 2714-2757 口径)。
|
|
11
|
+
*/
|
|
12
|
+
import { verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
|
|
13
|
+
/**
|
|
14
|
+
* 单行竖排逐字摆位(fabric _renderChars 2459-2478 笔位 + _renderStr
|
|
15
|
+
* 2711-2743 姿态)。lineLeft/baselineY 为该行行首 x 与基线 y(对象中心系);
|
|
16
|
+
* style/charSpacing 为对象级样式(逐字 fontSize 覆写用于锚点偏移)。
|
|
17
|
+
*/
|
|
18
|
+
export const verticalGlyphOps = (line, lineLeft, baselineY, style, charSpacing) => {
|
|
19
|
+
const ops = [];
|
|
20
|
+
const vSpacing = charSpacing ? (style.fontSize * charSpacing) / 1000 : 0;
|
|
21
|
+
let penV = 0;
|
|
22
|
+
for (let i = 0; i < line.graphemes.length; i++) {
|
|
23
|
+
const g = line.graphemes[i];
|
|
24
|
+
const box = line.boxes[i];
|
|
25
|
+
const fontSize = line.charStyles[i]?.fontSize ?? style.fontSize;
|
|
26
|
+
const klass = verticalCharClass(g);
|
|
27
|
+
if (klass === 'latin' || klass === 'bracket') {
|
|
28
|
+
// 拉丁画位前移 kerned−width(fabric signWidth),括号原样平画
|
|
29
|
+
ops.push({ ch: g, rotated: false, x: lineLeft + penV + (klass === 'latin' ? box.kernedWidth - box.width : 0), y: baselineY });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
ops.push({ ch: g, rotated: true, x: lineLeft + penV + verticalAnchorShiftX(fontSize), y: baselineY + verticalAnchorShiftY(klass, box, fontSize) });
|
|
33
|
+
}
|
|
34
|
+
penV += verticalRenderAdvance(g, box, vSpacing);
|
|
35
|
+
}
|
|
36
|
+
return ops;
|
|
37
|
+
};
|
|
38
|
+
/** 按摆位画一个竖排字符(fill/stroke 二选一;font/描边参数由调用方预设) */
|
|
39
|
+
export const drawVerticalGlyph = (ctx, op, method) => {
|
|
40
|
+
if (!op.rotated) {
|
|
41
|
+
ctx[method](op.ch, op.x, op.y);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
ctx.save();
|
|
45
|
+
ctx.translate(op.x, op.y);
|
|
46
|
+
ctx.rotate(-Math.PI / 2);
|
|
47
|
+
ctx[method](op.ch, 0, 0);
|
|
48
|
+
ctx.restore();
|
|
49
|
+
};
|
|
50
|
+
/** 逐字字体四件套解析(glyph pass / bakes 同口径的覆写合并) */
|
|
51
|
+
export const glyphStyleAt = (style, o) => {
|
|
52
|
+
if (!o || (o.fontSize === undefined && o.fontFamily === undefined && o.fontWeight === undefined && o.fontStyle === undefined))
|
|
53
|
+
return style;
|
|
54
|
+
return {
|
|
55
|
+
...style,
|
|
56
|
+
fontSize: o.fontSize ?? style.fontSize,
|
|
57
|
+
fontFamily: o.fontFamily ?? style.fontFamily,
|
|
58
|
+
fontWeight: o.fontWeight ?? style.fontWeight,
|
|
59
|
+
fontStyle: o.fontStyle ?? style.fontStyle
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/** TextNode 是否竖排(引擎唯一判定源:vertical === true,无角度特判) */
|
|
63
|
+
export const isVerticalText = (node) => node.raw.vertical === true;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 变形文本烘焙(main-webgl2 Phase 4 P4-5a):ArchText/WaistText/FlagText 的
|
|
3
|
+
* 像素变形——main 流程同构:文本 run 渲染到离屏画布(cacheDpr=2、中心定位,
|
|
4
|
+
* Arch 正强度顶部预留 archRise/2)→ alpha>10 边界扫描(centerX/textHalfWidth/
|
|
5
|
+
* contentBottom)→ 按列纵向形变(Arch/Waist:scaleY 反向采样;Flag:正弦波
|
|
6
|
+
* 垂直位移)→ 整图 quad(logicalW×logicalH 居中于对象中心)。
|
|
7
|
+
*
|
|
8
|
+
* 内核为 main CPU 路径逐式移植(GL shader 同式——bilinear 采样差异亚像素级);
|
|
9
|
+
* 逐字样式支持 fill/font/stroke(装饰线不进 warp 烘焙,种子规避)。
|
|
10
|
+
*
|
|
11
|
+
* PSD 特效(批次 39):fabric 的变形离屏调 super._render → _renderText 内联
|
|
12
|
+
* 投影/填充/描边效果层——特效进离屏、随列形变一起扭曲(引擎此前变形分支早退
|
|
13
|
+
* 跳过 renderPsdEffects + 烘焙不含特效 = 「变形文本的特效没有生效」)。本文件
|
|
14
|
+
* 在 run 渲染后、边界扫描前合成特效层(顺序同 fabric:投影垫底 destination-over
|
|
15
|
+
* → 文本 run → solidFill 盖字面 → stroke 最上),复用直排文本特效的纯 canvas
|
|
16
|
+
* 烘焙件(buildTextEffectSource/bakePsdSolidFill/bakePsdStrokes——摆位公式与
|
|
17
|
+
* renderTextRuns 同源);投影走本地无矩阵变体(bakePsdShadow 带 node.matrix
|
|
18
|
+
* 世界系,变形合成需要本地未缩放口径——整块 quad 随后统一携带对象矩阵)。
|
|
19
|
+
* 边界扫描 therefore 含特效墨(与 fabric 逐式一致——它也扫 super._render 产物)。
|
|
20
|
+
*/
|
|
21
|
+
import type { TextNode } from '../model/scene';
|
|
22
|
+
import type { PsdDropShadowDecl, PsdEffectsDecls } from '../core/psdEffects';
|
|
23
|
+
export type WarpKind = 'arch' | 'waist' | 'flag';
|
|
24
|
+
export declare const warpTextKind: (raw: {
|
|
25
|
+
type?: unknown;
|
|
26
|
+
warpStrength?: unknown;
|
|
27
|
+
}) => WarpKind | null;
|
|
28
|
+
export interface WarpBake {
|
|
29
|
+
canvas: HTMLCanvasElement;
|
|
30
|
+
logicalW: number;
|
|
31
|
+
logicalH: number;
|
|
32
|
+
}
|
|
33
|
+
/** 特效外扩余量(逻辑单位):描边 outside 全宽/center 半宽、投影 blur×2+偏移、
|
|
34
|
+
* 填充层偏移——变形/弧形烘焙画布须容纳(fabric 离屏 padding=fontSize 比例不含
|
|
35
|
+
* 特效,其画布按文本实际 bbox 预留较大 buffer 不裁;引擎 logicalW/H 从布局盒推,
|
|
36
|
+
* 不外扩会被画布边缘硬裁)。批次 64 起弧形烘焙共用 */
|
|
37
|
+
export declare const warpEffectExtentPad: (decls: PsdEffectsDecls) => number;
|
|
38
|
+
/** 投影本地烘焙(无矩阵/未缩放口径):bakePsdShadow 的本地变体——效果层进
|
|
39
|
+
* 变形/弧形合成系,随后的整块 quad 统一携带对象矩阵,此处带 node.matrix 会双重
|
|
40
|
+
* 变换。层序/擦除源本体与 bakePsdShadow 逐式一致(数组序、destination-out)。
|
|
41
|
+
* 批次 64 起弧形烘焙共用(源/输出几何通用,锚定由调用方自理) */
|
|
42
|
+
export declare const bakeWarpShadowLayer: (decls: PsdDropShadowDecl[], source: HTMLCanvasElement, rs: number) => {
|
|
43
|
+
canvas: HTMLCanvasElement;
|
|
44
|
+
w: number;
|
|
45
|
+
h: number;
|
|
46
|
+
} | null;
|
|
47
|
+
/** 变形文本整图烘焙(本地中心系 logicalW×logicalH,内容居中) */
|
|
48
|
+
export declare const bakeWarpedText: (node: TextNode, kind: WarpKind, decls?: PsdEffectsDecls | null) => WarpBake | null;
|
|
49
|
+
/**
|
|
50
|
+
* 常规/竖排文本 + PSD 特效整图烘焙(SVG 导出位图路径):横排复用
|
|
51
|
+
* renderTextRuns、竖排 renderVerticalRuns,特效层 compositeWarpEffects 合成
|
|
52
|
+
* (层序 fabric _renderText 同款:投影垫底 → 文本 → solidFill → stroke)。
|
|
53
|
+
* logical 尺寸 = node.dims + 特效外扩(warpEffectExtentPad),quad 居中于对象
|
|
54
|
+
* 中心——画布常规管线的特效走 GL 分层(psd.render),本件是导出专用的
|
|
55
|
+
* 「整对象位图化」口径(bakeWarpedText 的无形变版 + 竖排支持)。K-line
|
|
56
|
+
* jitter 越界裁剪为剪影源同款登记近似(buildTextEffectSource 头注)。
|
|
57
|
+
*/
|
|
58
|
+
export declare const bakeTextEffects: (node: TextNode, decls: PsdEffectsDecls | null) => WarpBake | null;
|