@yft-design/engine 0.0.16 → 0.0.18
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 +23 -11
- package/dist/EngineCanvas.d.ts +0 -255
- package/dist/core/color.d.ts +0 -11
- package/dist/core/distanceField.d.ts +0 -13
- package/dist/core/events.d.ts +0 -25
- package/dist/core/gradient.d.ts +0 -47
- package/dist/core/homography.d.ts +0 -20
- package/dist/core/imageFilters.d.ts +0 -31
- package/dist/core/mat2d.d.ts +0 -62
- package/dist/core/pathData.d.ts +0 -36
- package/dist/core/pattern.d.ts +0 -14
- package/dist/core/point.d.ts +0 -14
- package/dist/core/psdEffects.d.ts +0 -48
- package/dist/core/roundedRect.d.ts +0 -48
- package/dist/core/shadow.d.ts +0 -23
- package/dist/core/snap.d.ts +0 -103
- package/dist/core/stroke.d.ts +0 -13
- package/dist/core/triangulate.d.ts +0 -31
- package/dist/core/warpMesh.d.ts +0 -38
- package/dist/debug/canvasInspection.d.ts +0 -20
- package/dist/debug/pixelDiff.d.ts +0 -7
- package/dist/debug/pixelDiff.js +1 -64
- package/dist/debug/seed.d.ts +0 -426
- package/dist/debug/seed.js +28 -3806
- package/dist/decoders/webp2sprite.d.ts +0 -16
- package/dist/engineFlag.d.ts +0 -76
- package/dist/export/SceneExporter.d.ts +0 -58
- package/dist/export/glExport.d.ts +0 -41
- package/dist/export/svgExport.d.ts +0 -181
- package/dist/index.d.ts +0 -13
- package/dist/index.js +1060 -64
- package/dist/interact/animationPlayback.d.ts +0 -62
- package/dist/interact/canvasInteractions.d.ts +1 -38
- package/dist/interact/cropSession.d.ts +0 -68
- package/dist/interact/dblClick.d.ts +0 -32
- package/dist/interact/expandSession.d.ts +0 -46
- package/dist/interact/hotkeyActions.d.ts +0 -12
- package/dist/interact/pageTransfer.d.ts +0 -2
- package/dist/interact/pathSession.d.ts +0 -42
- package/dist/interact/pointer.d.ts +0 -87
- package/dist/interact/pointerTablePuzzle.d.ts +0 -60
- package/dist/interact/pointerTransform.d.ts +0 -48
- package/dist/interact/pointerTypes.d.ts +6 -148
- package/dist/interact/snapGuide.d.ts +0 -68
- package/dist/interact/tableCellEditing.d.ts +0 -34
- package/dist/interact/tableInteraction.d.ts +0 -31
- package/dist/interact/textEditing.d.ts +0 -44
- package/dist/interact/warpFacade.d.ts +0 -5
- package/dist/interact/warpSession.d.ts +0 -55
- package/dist/interact/wheelScroll.d.ts +0 -42
- package/dist/model/alphaHit.d.ts +0 -51
- package/dist/model/animation.d.ts +0 -99
- package/dist/model/arcLayout.d.ts +0 -33
- package/dist/model/arcTextTransform.d.ts +0 -4
- package/dist/model/compatEvents.d.ts +12 -55
- package/dist/model/compatObject.d.ts +0 -360
- package/dist/model/cropEdit.d.ts +0 -60
- package/dist/model/document.d.ts +3 -158
- package/dist/model/elementTypes.d.ts +0 -47
- package/dist/model/expandEdit.d.ts +0 -36
- package/dist/model/fabricPrimitives.d.ts +0 -24
- package/dist/model/filler.d.ts +0 -12
- package/dist/model/groupAssemble.d.ts +0 -5
- package/dist/model/groupChildMove.d.ts +0 -37
- package/dist/model/groupResize.d.ts +0 -42
- package/dist/model/handles.d.ts +0 -24
- package/dist/model/imageMaskBake.d.ts +0 -50
- package/dist/model/lineConstruct.d.ts +0 -8
- package/dist/model/maskCropEdit.d.ts +0 -34
- package/dist/model/pathBackground.d.ts +0 -33
- package/dist/model/pathConstruct.d.ts +0 -24
- package/dist/model/pathEdit.d.ts +0 -55
- package/dist/model/puzzleEdit.d.ts +0 -66
- package/dist/model/puzzleLayout.d.ts +0 -31
- package/dist/model/scene.d.ts +0 -603
- package/dist/model/schema.d.ts +0 -48
- package/dist/model/shapePath.d.ts +0 -5
- package/dist/model/smartObjectBake.d.ts +0 -6
- package/dist/model/tableEdit.d.ts +0 -90
- package/dist/model/tableFacade.d.ts +0 -5
- package/dist/model/tableLayout.d.ts +0 -40
- package/dist/model/textAlign.d.ts +0 -22
- package/dist/model/textLayout.d.ts +0 -213
- package/dist/render/GLBlend.d.ts +0 -24
- package/dist/render/GLContext.d.ts +0 -11
- package/dist/render/GLIsolate.d.ts +0 -25
- package/dist/render/GLTextureCache.d.ts +0 -72
- package/dist/render/GlyphAtlas.d.ts +0 -98
- package/dist/render/MeshBatch.d.ts +0 -71
- package/dist/render/QuadBatch.d.ts +0 -87
- package/dist/render/SceneRenderer.d.ts +0 -137
- package/dist/render/SourceManager.d.ts +0 -82
- package/dist/render/TextRenderer.d.ts +0 -120
- package/dist/render/arcText.d.ts +0 -28
- package/dist/render/bakeGate.d.ts +0 -35
- package/dist/render/batchOrder.d.ts +0 -60
- package/dist/render/blendMode.d.ts +0 -27
- package/dist/render/clipMaskPainter.d.ts +32 -4
- package/dist/render/fontInvalidation.d.ts +0 -18
- package/dist/render/fontInvalidationController.d.ts +0 -52
- package/dist/render/frameOverlay.d.ts +0 -32
- package/dist/render/framePipeline.d.ts +0 -27
- package/dist/render/gpuFilterPasses.d.ts +0 -15
- package/dist/render/gpuFx.d.ts +0 -82
- package/dist/render/gpuImageFilters.d.ts +0 -41
- package/dist/render/gpuShadow.d.ts +0 -38
- package/dist/render/gradientRamp.d.ts +0 -14
- package/dist/render/imageEffects.d.ts +0 -99
- package/dist/render/lineDecorationSdf.d.ts +0 -32
- package/dist/render/maskRender.d.ts +0 -60
- package/dist/render/multiPage.d.ts +0 -91
- package/dist/render/progressiveLoad.d.ts +0 -27
- package/dist/render/psdEffectPainter.d.ts +0 -25
- package/dist/render/psdWarpText.d.ts +0 -19
- package/dist/render/puzzleClamp.d.ts +0 -15
- package/dist/render/renderEpoch.d.ts +0 -21
- package/dist/render/retainedFrame.d.ts +0 -36
- package/dist/render/ruler.d.ts +0 -36
- package/dist/render/screenClip.d.ts +0 -31
- package/dist/render/scrollText.d.ts +0 -46
- package/dist/render/segmentTable.d.ts +0 -30
- package/dist/render/selectionOverlay.d.ts +0 -203
- package/dist/render/settleScheduler.d.ts +0 -24
- package/dist/render/shaders.d.ts +4 -24
- package/dist/render/shadowBake.d.ts +0 -28
- package/dist/render/shadowPainter.d.ts +0 -8
- package/dist/render/sharedGpuPainters.d.ts +0 -13
- package/dist/render/sourceHydration.d.ts +0 -8
- package/dist/render/strokeBake.d.ts +0 -59
- package/dist/render/strokeMiterOutline.d.ts +0 -29
- package/dist/render/strokePainter.d.ts +0 -31
- package/dist/render/strokeSdf.d.ts +0 -52
- package/dist/render/svgRaster.d.ts +0 -34
- package/dist/render/tableOverlay.d.ts +0 -35
- package/dist/render/textHighlight.d.ts +0 -67
- package/dist/render/textureUpload.d.ts +0 -13
- package/dist/render/verticalText.d.ts +0 -21
- package/dist/render/warpText.d.ts +0 -48
- package/dist/render/workspaceBackdrop.d.ts +0 -22
- package/dist/render/workspaceChecker.d.ts +0 -34
- package/dist/render/workspaceGlow.d.ts +0 -38
- package/package.json +5 -3
- package/dist/EngineCanvas.js +0 -1202
- package/dist/core/canvasPerf.js +0 -170
- package/dist/core/color.js +0 -107
- package/dist/core/distanceField.js +0 -92
- package/dist/core/events.js +0 -80
- package/dist/core/gradient.js +0 -175
- package/dist/core/homography.js +0 -123
- package/dist/core/imageFilters.js +0 -330
- package/dist/core/mat2d.js +0 -241
- package/dist/core/pathData.js +0 -926
- package/dist/core/pattern.js +0 -40
- package/dist/core/point.js +0 -119
- package/dist/core/psdEffects.js +0 -158
- package/dist/core/roundedRect.js +0 -164
- package/dist/core/shadow.js +0 -47
- package/dist/core/snap.js +0 -793
- package/dist/core/stroke.js +0 -45
- package/dist/core/triangulate.js +0 -194
- package/dist/core/warpMesh.js +0 -469
- package/dist/debug/canvasInspection.js +0 -113
- package/dist/decoders/gif2sprite.js +0 -84
- package/dist/decoders/webp2sprite.js +0 -133
- package/dist/engineFlag.js +0 -104
- package/dist/export/SceneExporter.js +0 -286
- package/dist/export/glExport.js +0 -79
- package/dist/export/svgExport.js +0 -1803
- package/dist/interact/animationPlayback.js +0 -358
- package/dist/interact/canvasInteractions.js +0 -174
- package/dist/interact/cropSession.js +0 -526
- package/dist/interact/dblClick.js +0 -120
- package/dist/interact/expandSession.js +0 -281
- package/dist/interact/hotkeyActions.js +0 -41
- package/dist/interact/pageTransfer.js +0 -56
- package/dist/interact/pathSession.js +0 -480
- package/dist/interact/pointer.js +0 -1691
- package/dist/interact/pointerTablePuzzle.js +0 -358
- package/dist/interact/pointerTransform.js +0 -441
- package/dist/interact/pointerTypes.js +0 -96
- package/dist/interact/snapGuide.js +0 -377
- package/dist/interact/tableCellEditing.js +0 -206
- package/dist/interact/tableInteraction.js +0 -219
- package/dist/interact/textEditing.js +0 -423
- package/dist/interact/warpFacade.js +0 -51
- package/dist/interact/warpSession.js +0 -582
- package/dist/interact/wheelScroll.js +0 -100
- package/dist/model/alphaHit.js +0 -263
- package/dist/model/animation.js +0 -510
- package/dist/model/arcLayout.js +0 -308
- package/dist/model/arcTextTransform.js +0 -87
- package/dist/model/compatEvents.js +0 -73
- package/dist/model/compatObject.js +0 -1580
- package/dist/model/cropEdit.js +0 -497
- package/dist/model/document.js +0 -572
- package/dist/model/elementTypes.js +0 -119
- package/dist/model/expandEdit.js +0 -161
- package/dist/model/fabricPrimitives.js +0 -9
- package/dist/model/filler.js +0 -1
- package/dist/model/groupAssemble.js +0 -98
- package/dist/model/groupChildMove.js +0 -145
- package/dist/model/groupResize.js +0 -109
- package/dist/model/handles.js +0 -29
- package/dist/model/imageMaskBake.js +0 -136
- package/dist/model/lineConstruct.js +0 -79
- package/dist/model/maskCropEdit.js +0 -90
- package/dist/model/pathBackground.js +0 -196
- package/dist/model/pathConstruct.js +0 -55
- package/dist/model/pathEdit.js +0 -378
- package/dist/model/puzzleEdit.js +0 -742
- package/dist/model/puzzleLayout.js +0 -143
- package/dist/model/scene.js +0 -2930
- package/dist/model/schema.js +0 -13
- package/dist/model/shapePath.js +0 -136
- package/dist/model/smartObjectBake.js +0 -295
- package/dist/model/tableEdit.js +0 -751
- package/dist/model/tableFacade.js +0 -808
- package/dist/model/tableLayout.js +0 -194
- package/dist/model/textAlign.js +0 -36
- package/dist/model/textLayout.js +0 -842
- package/dist/render/GLBlend.js +0 -270
- package/dist/render/GLContext.js +0 -48
- package/dist/render/GLIsolate.js +0 -188
- package/dist/render/GLTextureCache.js +0 -224
- package/dist/render/GlyphAtlas.js +0 -412
- package/dist/render/MeshBatch.js +0 -416
- package/dist/render/QuadBatch.js +0 -561
- package/dist/render/SceneRenderer.js +0 -753
- package/dist/render/SourceManager.js +0 -523
- package/dist/render/TextRenderer.js +0 -854
- package/dist/render/arcText.js +0 -187
- package/dist/render/bakeGate.js +0 -32
- package/dist/render/batchOrder.js +0 -168
- package/dist/render/blendMode.js +0 -142
- package/dist/render/clipMaskPainter.js +0 -123
- package/dist/render/fontInvalidation.js +0 -77
- package/dist/render/fontInvalidationController.js +0 -119
- package/dist/render/frameOverlay.js +0 -124
- package/dist/render/framePipeline.js +0 -96
- package/dist/render/gpuFilterPasses.js +0 -883
- package/dist/render/gpuFx.js +0 -673
- package/dist/render/gpuImageFilters.js +0 -295
- package/dist/render/gpuShadow.js +0 -327
- package/dist/render/gradientRamp.js +0 -74
- package/dist/render/imageEffects.js +0 -415
- package/dist/render/lineDecorationSdf.js +0 -188
- package/dist/render/maskRender.js +0 -217
- package/dist/render/multiPage.js +0 -419
- package/dist/render/progressiveLoad.js +0 -86
- package/dist/render/psdEffectPainter.js +0 -333
- package/dist/render/psdWarpText.js +0 -212
- package/dist/render/puzzleClamp.js +0 -30
- package/dist/render/renderEpoch.js +0 -35
- package/dist/render/renderViewport.js +0 -18
- package/dist/render/retainedFrame.js +0 -192
- package/dist/render/ruler.js +0 -287
- package/dist/render/screenClip.js +0 -67
- package/dist/render/scrollText.js +0 -266
- package/dist/render/segmentTable.js +0 -117
- package/dist/render/selectionOverlay.js +0 -1008
- package/dist/render/settleScheduler.js +0 -51
- package/dist/render/shaders.js +0 -450
- package/dist/render/shadowBake.js +0 -203
- package/dist/render/shadowPainter.js +0 -93
- package/dist/render/sharedGpuPainters.js +0 -42
- package/dist/render/sourceHydration.js +0 -48
- package/dist/render/strokeBake.js +0 -515
- package/dist/render/strokeMiterOutline.js +0 -224
- package/dist/render/strokePainter.js +0 -207
- package/dist/render/strokeSdf.js +0 -261
- package/dist/render/svgRaster.js +0 -71
- package/dist/render/tableOverlay.js +0 -233
- package/dist/render/textHighlight.js +0 -380
- package/dist/render/textureUpload.js +0 -26
- package/dist/render/verticalText.js +0 -63
- package/dist/render/warpText.js +0 -382
- package/dist/render/workspaceBackdrop.js +0 -60
- package/dist/render/workspaceChecker.js +0 -170
- package/dist/render/workspaceGlow.js +0 -198
|
@@ -1,854 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 文本渲染管线(从 EngineCanvas 拆出,main-webgl2 重构)。
|
|
3
|
-
*
|
|
4
|
-
* 字形/背景高亮/装饰线/虚线描边(run 级烘焙)/变形文本整图烘焙,
|
|
5
|
-
* 与宿主的唯一跨层耦合是分桶用的 zoom×dpr——以参数注入,无需 host
|
|
6
|
-
* (分桶有效缩放在管线内再乘节点世界矩阵的对象 scale,见 glyphEffectiveScale)。
|
|
7
|
-
* 烘焙缓存(warpBakes/textDashBakes)随实例:GL 纹理属具体上下文,
|
|
8
|
-
* 不可做模块级缓存。编辑态门控(变形文本在编辑中走常规管线)留在
|
|
9
|
-
* SceneRenderer 的分派分支。
|
|
10
|
-
*/
|
|
11
|
-
import { parseColor } from '../core/color';
|
|
12
|
-
import { composeMatrix, multiply } from '../core/mat2d';
|
|
13
|
-
import { parsePsdEffects, psdEffectsKey } from '../core/psdEffects';
|
|
14
|
-
import { isArcGlyphEnabled } from '../engineFlag';
|
|
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';
|
|
17
|
-
import { glyphRasterPlan, pickZoomBucket } from './GlyphAtlas';
|
|
18
|
-
import { bakeScrollText, scrollTextDecl } from './scrollText';
|
|
19
|
-
import { bakeTextHighlight, planTextHighlight } from './textHighlight';
|
|
20
|
-
import { drawVerticalGlyph, glyphStyleAt, verticalGlyphOps } from './verticalText';
|
|
21
|
-
import { bakeWarpedText } from './warpText';
|
|
22
|
-
import { bakePsdWarpText } from './psdWarpText';
|
|
23
|
-
import { bakeArcText, glyphStyleOf } from './arcText';
|
|
24
|
-
import { computeArcTextLayout } from '../model/arcLayout';
|
|
25
|
-
import { createTexture2D } from './textureUpload';
|
|
26
|
-
/** 逐字 fill 解析缓存(同一颜色串高频复用) */
|
|
27
|
-
const charColorCache = new Map();
|
|
28
|
-
/**
|
|
29
|
-
* 字形分桶的有效缩放:zoom×dpr × 节点世界矩阵线性部分的较大奇异值。字形
|
|
30
|
-
* quad 随后被矩阵整体变换(表格/嵌套组的对象 scale 都在矩阵里),桶只看
|
|
31
|
-
* zoom 时纹理被对象 scale 线性放大发糊(缩放后的表格文本模糊根因)。非等比
|
|
32
|
-
* 取大轴超采样(小轴随 LINEAR 采样微缩,zoom 各向异性同口径);scale=1 时
|
|
33
|
-
* 与原口径逐位相等(既有 parity 基线不受影响)。
|
|
34
|
-
*/
|
|
35
|
-
const glyphEffectiveScale = (node, zoomX) => {
|
|
36
|
-
const s = node.worldScale;
|
|
37
|
-
return zoomX * Math.max(s.x, s.y, 1e-6);
|
|
38
|
-
};
|
|
39
|
-
const charFillColor = (fill, base) => {
|
|
40
|
-
let color = charColorCache.get(fill);
|
|
41
|
-
if (!color) {
|
|
42
|
-
const parsed = parseColor(fill);
|
|
43
|
-
color = [parsed[0], parsed[1], parsed[2], parsed[3]];
|
|
44
|
-
charColorCache.set(fill, color);
|
|
45
|
-
}
|
|
46
|
-
// 样式色 alpha 与对象 opacity(base[3] 已含)相乘,fabric 同语义
|
|
47
|
-
return [color[0], color[1], color[2], color[3] * base[3]];
|
|
48
|
-
};
|
|
49
|
-
export class TextRenderer {
|
|
50
|
-
gl;
|
|
51
|
-
batch;
|
|
52
|
-
glyphAtlas;
|
|
53
|
-
/** 变形文本烘焙缓存(P4-5a:节点 → {sig, tex, w, h}) */
|
|
54
|
-
warpBakes = new WeakMap();
|
|
55
|
-
/** PSD 变形文本烘焙缓存(批次 365:节点 → {sig, tex, w, h, offX, offY}——
|
|
56
|
-
* 变形输出窗一般不对称于对象中心,quad 定位携带中心偏移) */
|
|
57
|
-
psdWarpBakes = new WeakMap();
|
|
58
|
-
/** 弧形/圆形文本烘焙缓存(P4-5b:节点 → {sig, tex, w, h}) */
|
|
59
|
-
arcBakes = new WeakMap();
|
|
60
|
-
/** 虚线文本描边烘焙缓存(run 级栅格化;签名 = 文本+布局+描边+桶) */
|
|
61
|
-
textDashBakes = new WeakMap();
|
|
62
|
-
/** 滚动文本烘焙缓存(P5-6 余):签名含 offset——播放期逐帧重烘,静止态恒缓存 */
|
|
63
|
-
scrollBakes = new WeakMap();
|
|
64
|
-
/** 划重点烘焙缓存(批次62):签名 = 文本+布局键+texts JSON+桶+dims.y(盒抬高移位);
|
|
65
|
-
* centerY = 画布矩形本地系中心 y(x 居中、y 锚内容块顶——盒抬高时偏心) */
|
|
66
|
-
highlightBakes = new WeakMap();
|
|
67
|
-
constructor(gl, batch, glyphAtlas) {
|
|
68
|
-
this.gl = gl;
|
|
69
|
-
this.batch = batch;
|
|
70
|
-
this.glyphAtlas = glyphAtlas;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* 字体迟到失效:该节点四族烘焙整删(含 GL 纹理)。烘焙签名不含字体加载态,
|
|
74
|
-
* 回退字体栅格化的整图会留脏——由 EngineCanvas 对文档在册文本节点逐个调用
|
|
75
|
-
* (WeakMap 不可枚举,按节点删是唯一能显式回收纹理的形态;已离场节点的
|
|
76
|
-
* 烘焙随节点 GC,与既有 sig 更换/删除路径同语义)。
|
|
77
|
-
*/
|
|
78
|
-
invalidateNodeBakes(node) {
|
|
79
|
-
for (const bakes of [this.warpBakes, this.psdWarpBakes, this.arcBakes, this.textDashBakes, this.scrollBakes, this.highlightBakes]) {
|
|
80
|
-
const bake = bakes.get(node);
|
|
81
|
-
if (bake?.tex)
|
|
82
|
-
this.gl.deleteTexture(bake.tex);
|
|
83
|
-
bakes.delete(node);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/** 变形文本渲染(P4-5a):烘焙整图 quad(logicalW×logicalH 居中于对象中心) */
|
|
87
|
-
renderWarpedText(node, kind) {
|
|
88
|
-
// PSD 特效(批次 39):特效进变形烘焙(fabric 语义——特效随列形变一起扭曲);
|
|
89
|
-
// 键入签名保证特效增删/改参触发重烘(此前签名不含 effects,写入 raw 后命中
|
|
90
|
-
// 旧纹理 = 「变形文本的特效没有生效」);文本族口径(描边宽读 size.value、
|
|
91
|
-
// 对齐缺省 center)与 SceneRenderer.renderPsdEffects 同源
|
|
92
|
-
const fxDecls = parsePsdEffects(node.raw.effects, { text: true });
|
|
93
|
-
const sig = [
|
|
94
|
-
node.raw.type,
|
|
95
|
-
node.raw.text,
|
|
96
|
-
node.raw.warpStrength,
|
|
97
|
-
node.raw.fontSize,
|
|
98
|
-
node.raw.fontFamily,
|
|
99
|
-
node.raw.width,
|
|
100
|
-
node.raw.height,
|
|
101
|
-
node.raw.fill,
|
|
102
|
-
node.raw.stroke,
|
|
103
|
-
node.raw.strokeWidth,
|
|
104
|
-
JSON.stringify(node.raw.styles ?? null),
|
|
105
|
-
JSON.stringify(node.raw.paragraph ?? null),
|
|
106
|
-
fxDecls ? psdEffectsKey(fxDecls) : ''
|
|
107
|
-
].join(';');
|
|
108
|
-
let bake = this.warpBakes.get(node);
|
|
109
|
-
if (bake && bake.sig !== sig) {
|
|
110
|
-
this.gl.deleteTexture(bake.tex);
|
|
111
|
-
bake = undefined;
|
|
112
|
-
}
|
|
113
|
-
if (!bake) {
|
|
114
|
-
const result = bakeWarpedText(node, kind, fxDecls);
|
|
115
|
-
if (!result) {
|
|
116
|
-
this.warpBakes.set(node, undefined);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const tex = createTexture2D(this.gl, result.canvas);
|
|
120
|
-
if (!tex)
|
|
121
|
-
return;
|
|
122
|
-
bake = { sig, tex, w: result.logicalW, h: result.logicalH };
|
|
123
|
-
this.warpBakes.set(node, bake);
|
|
124
|
-
}
|
|
125
|
-
this.batch.pushQuad(node.matrix, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* PSD 变形文本渲染(批次 365):renderSrc 位图优先链的编辑后承接——转正防线
|
|
129
|
-
* 删 renderSrc 后 raw.psdWarp 在场 → 布局盒重排 + 15 样式网格变形烘焙单 quad
|
|
130
|
-
* (bakePsdWarpText:Patchy 前向格点 + 逐 cell 逆双线性)。签名键与 warp 族
|
|
131
|
-
* 同源 + psdWarp 参数 JSON + 排版扩展键(charSpacing/lineHeight/vertical——
|
|
132
|
-
* 转正后重排的文本这些键都会改墨迹)。
|
|
133
|
-
*/
|
|
134
|
-
renderPsdWarpedText(node, params) {
|
|
135
|
-
const fxDecls = parsePsdEffects(node.raw.effects, { text: true });
|
|
136
|
-
const sig = [
|
|
137
|
-
node.raw.type,
|
|
138
|
-
node.raw.text,
|
|
139
|
-
JSON.stringify(node.raw.psdWarp ?? null),
|
|
140
|
-
node.raw.fontSize,
|
|
141
|
-
node.raw.fontFamily,
|
|
142
|
-
node.raw.fontWeight,
|
|
143
|
-
node.raw.fontStyle,
|
|
144
|
-
node.raw.width,
|
|
145
|
-
node.raw.height,
|
|
146
|
-
node.raw.lineHeight,
|
|
147
|
-
node.raw.charSpacing,
|
|
148
|
-
node.raw.vertical === true ? 1 : 0,
|
|
149
|
-
node.raw.fill,
|
|
150
|
-
node.raw.stroke,
|
|
151
|
-
node.raw.strokeWidth,
|
|
152
|
-
JSON.stringify(node.raw.styles ?? null),
|
|
153
|
-
JSON.stringify(node.raw.paragraph ?? null),
|
|
154
|
-
fxDecls ? psdEffectsKey(fxDecls) : ''
|
|
155
|
-
].join(';');
|
|
156
|
-
let bake = this.psdWarpBakes.get(node);
|
|
157
|
-
if (bake && bake.sig !== sig) {
|
|
158
|
-
this.gl.deleteTexture(bake.tex);
|
|
159
|
-
bake = undefined;
|
|
160
|
-
}
|
|
161
|
-
if (!bake) {
|
|
162
|
-
const result = bakePsdWarpText(node, params, fxDecls);
|
|
163
|
-
if (!result) {
|
|
164
|
-
this.psdWarpBakes.set(node, undefined);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const tex = createTexture2D(this.gl, result.canvas);
|
|
168
|
-
if (!tex)
|
|
169
|
-
return;
|
|
170
|
-
bake = { sig, tex, w: result.logicalW, h: result.logicalH, offX: result.offsetX, offY: result.offsetY };
|
|
171
|
-
this.psdWarpBakes.set(node, bake);
|
|
172
|
-
}
|
|
173
|
-
const m = bake.offX !== 0 || bake.offY !== 0 ? multiply(node.matrix, composeMatrix({ translateX: bake.offX, translateY: bake.offY })) : node.matrix;
|
|
174
|
-
this.batch.pushQuad(m, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* 弧形/圆形文本渲染(P4-5b):双实现分发(GPU 迁移批次 4)——
|
|
178
|
-
* 逐字图集 quad(缩放桶重栅格化,放大始终清晰)/ 整图烘焙 quad(Canvas 参考
|
|
179
|
-
* 面,固定 2× 超采样)。语义锚点见 renderArcGlyphs 注释。
|
|
180
|
-
* 批次 64:带 PSD 特效时强制走烘焙(特效层进烘焙合成,warp 批次 39 同款;
|
|
181
|
-
* 逐字图集路径不消费 effects)。
|
|
182
|
-
*/
|
|
183
|
-
renderArcText(node, kind, zoomX) {
|
|
184
|
-
// 特效只承接投影/纯色填充/描边三族(纹理类 parsePsdEffects 即跳过,同 warp 口径)
|
|
185
|
-
const fxDecls = parsePsdEffects(node.raw.effects, { text: true });
|
|
186
|
-
const hasFx = !!fxDecls && (fxDecls.dropShadows.length > 0 || fxDecls.solidFills.length > 0 || fxDecls.strokes.length > 0);
|
|
187
|
-
if (isArcGlyphEnabled() && !hasFx) {
|
|
188
|
-
this.renderArcGlyphs(node, kind, zoomX);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
// 缩放桶(批次 64):烘焙按有效缩放重栅格化(textDash/scroll 同款),放大不糊
|
|
192
|
-
// ——固定 2× 在 zoom>2 线性放大发糊(GPU 逐字路径本就桶化,烘焙侧对齐口径)
|
|
193
|
-
const bucket = pickZoomBucket(glyphEffectiveScale(node, zoomX));
|
|
194
|
-
const sig = [
|
|
195
|
-
node.raw.type,
|
|
196
|
-
node.raw.text,
|
|
197
|
-
node.raw.curvature,
|
|
198
|
-
node.raw.circleSize,
|
|
199
|
-
node.raw.circleStartAngle,
|
|
200
|
-
node.raw.circleSweep,
|
|
201
|
-
node.raw.circleEccentricity,
|
|
202
|
-
node.raw.circleDirection,
|
|
203
|
-
node.raw.fontSize,
|
|
204
|
-
node.raw.fontFamily,
|
|
205
|
-
node.raw.fontWeight,
|
|
206
|
-
node.raw.fontStyle,
|
|
207
|
-
node.raw.lineHeight,
|
|
208
|
-
node.raw.textAlign,
|
|
209
|
-
node.raw.fill,
|
|
210
|
-
node.raw.stroke,
|
|
211
|
-
node.raw.strokeWidth,
|
|
212
|
-
node.raw.strokeVisible,
|
|
213
|
-
node.raw.paintFirst,
|
|
214
|
-
JSON.stringify(node.raw.styles ?? null),
|
|
215
|
-
fxDecls ? psdEffectsKey(fxDecls) : '',
|
|
216
|
-
bucket
|
|
217
|
-
].join(';');
|
|
218
|
-
let bake = this.arcBakes.get(node);
|
|
219
|
-
if (bake && bake.sig !== sig) {
|
|
220
|
-
this.gl.deleteTexture(bake.tex);
|
|
221
|
-
bake = undefined;
|
|
222
|
-
}
|
|
223
|
-
if (!bake) {
|
|
224
|
-
const result = bakeArcText(node, kind, fxDecls, bucket);
|
|
225
|
-
if (!result) {
|
|
226
|
-
this.arcBakes.set(node, undefined);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const tex = createTexture2D(this.gl, result.canvas);
|
|
230
|
-
if (!tex)
|
|
231
|
-
return;
|
|
232
|
-
bake = { sig, tex, w: result.logicalW, h: result.logicalH };
|
|
233
|
-
this.arcBakes.set(node, bake);
|
|
234
|
-
}
|
|
235
|
-
this.batch.pushQuad(node.matrix, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* 弧形/圆形文本逐字图集 quad(GPU 迁移批次 4):与 bakeArcText 的 Canvas 烘焙
|
|
239
|
-
* 同一锚定语义——每字在「字形系」(原点 = 摆位锚点,x 轴沿旋转后基线)按
|
|
240
|
-
* textAlign='center' + alphabetic 落笔:advance 中心对齐锚点、基线过锚点。
|
|
241
|
-
*
|
|
242
|
-
* cell 定位推导(metrics 均在栅格化空间,/scale 回文本空间):
|
|
243
|
-
* - textAlign='center' 等价于笔位(alignment point)左移 advance/2 →
|
|
244
|
-
* cell 左缘相对锚点 = (inkLeftPx − advancePx/2 − padPx)/scale
|
|
245
|
-
* - cell 顶缘相对锚点 = −(ascentPx + padPx)/scale(基线 = 锚点 y)
|
|
246
|
-
* - quad 中心 = 左/顶缘 + w/h 的一半;glyphMatrix =
|
|
247
|
-
* nodeMatrix ∘ T(锚点本地) ∘ R(摆位旋转) ∘ T(中心相对锚点)
|
|
248
|
-
* (锚点本地 = 弧形布局坐标 − contentOffset——Canvas 烘焙的
|
|
249
|
-
* ctx.translate(−contentOffset) 同构)
|
|
250
|
-
*
|
|
251
|
-
* 逐字 z 序照 bakeArcText 的 per-char 循环:paintFirst 决定该字 fill/stroke
|
|
252
|
-
* 先后(不是横排的两遍全局分层——弧形紧排时字符可交叠,跨字分层会改观感)。
|
|
253
|
-
* 栅格化走 GlyphAtlas 缩放桶(桶 ≥ 有效缩放 = zoom×dpr×对象 worldScale
|
|
254
|
-
* 超采样)——放大跨桶重栅格化保持锐利,这是相对固定 2× 烘焙的主要清晰度收益。
|
|
255
|
-
*/
|
|
256
|
-
renderArcGlyphs(node, kind, zoomX) {
|
|
257
|
-
const layout = computeArcTextLayout(node.textLayout, node.raw, node.textStyle.lineHeight ?? 1.16);
|
|
258
|
-
const bucket = pickZoomBucket(glyphEffectiveScale(node, zoomX));
|
|
259
|
-
const style = node.textStyle;
|
|
260
|
-
const baseStroke = node.textStroke;
|
|
261
|
-
const strokeOn = node.raw.strokeVisible === true;
|
|
262
|
-
const paintFirstStroke = node.paintFirst === 'stroke';
|
|
263
|
-
const objectFill = typeof node.raw.fill === 'string' ? node.raw.fill : '';
|
|
264
|
-
const nodeMatrix = node.matrix;
|
|
265
|
-
const base = [1, 1, 1, node.renderOpacity];
|
|
266
|
-
for (const p of layout.chars) {
|
|
267
|
-
const o = node.textLayout.lines[p.line]?.charStyles[p.index];
|
|
268
|
-
const glyphStyle = glyphStyleOf(style, o);
|
|
269
|
-
const fill = typeof o?.fill === 'string' && o.fill ? o.fill : objectFill;
|
|
270
|
-
const strokeDecl = strokeOn ? resolveStrokeDecl(baseStroke, o) : null;
|
|
271
|
-
const ax = p.x - layout.contentOffsetX;
|
|
272
|
-
const ay = p.y - layout.contentOffsetY;
|
|
273
|
-
const cos = Math.cos(p.rotation);
|
|
274
|
-
const sin = Math.sin(p.rotation);
|
|
275
|
-
const emit = (strokePass) => {
|
|
276
|
-
if (strokePass) {
|
|
277
|
-
if (!strokeDecl || strokeDecl.width <= 0)
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
else if (!fill) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
// cell 光栅封顶(模板 273 图集风暴):rs/scale 同源折算,视觉尺寸不变
|
|
284
|
-
const { rs, scale } = glyphRasterPlan(glyphStyle.fontSize, bucket);
|
|
285
|
-
const cell = this.glyphAtlas.get(glyphStyle, rs, p.char, strokePass ? strokeDecl : null);
|
|
286
|
-
if (!cell)
|
|
287
|
-
return;
|
|
288
|
-
const w = cell.wPx / scale;
|
|
289
|
-
const h = cell.hPx / scale;
|
|
290
|
-
const cx = (cell.inkLeftPx - cell.advancePx / 2 - cell.padPx) / scale + w / 2;
|
|
291
|
-
const cy = -(cell.ascentPx + cell.padPx) / scale + h / 2;
|
|
292
|
-
const color = charFillColor(strokePass ? strokeDecl.color : fill, base);
|
|
293
|
-
const glyphMatrix = multiply(nodeMatrix, multiply([1, 0, 0, 1, ax, ay], multiply([cos, sin, -sin, cos, 0, 0], [1, 0, 0, 1, cx, cy])));
|
|
294
|
-
this.batch.pushQuad(glyphMatrix, w, h, color, this.glyphAtlas.textureOf(cell), [cell.u0, cell.v0, cell.u1, cell.v1]);
|
|
295
|
-
};
|
|
296
|
-
if (paintFirstStroke) {
|
|
297
|
-
emit(true);
|
|
298
|
-
emit(false);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
emit(false);
|
|
302
|
-
emit(true);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* 文本提交:先铺整段背景高亮 run(fabric _renderTextLinesBackground 同语义:
|
|
308
|
-
* 同色相邻合并、行顶起 impl 高),再按 fabric `_render` 的 z 序提交——
|
|
309
|
-
* underline 在字形**之下**、overline/linethrough 在字形**之上**(与 paintFirst
|
|
310
|
-
* 无关,fabric 固定此序),中间按 `_renderText` 的 paintFirst 语义分两遍提交
|
|
311
|
-
* 字形——缺省先 fill 遍后 stroke 遍(描边压住填充外缘),paintFirst='stroke'
|
|
312
|
-
* 时相反(填充盖掉描边内半 = 视觉外描边)。
|
|
313
|
-
*
|
|
314
|
-
* 各层都是**整段文本**粒度,与 fabric 逐行的 fillText/strokeText/fillRect 循环
|
|
315
|
-
* 等价:同层内提交序即 z 序,跨层严格分层。
|
|
316
|
-
*
|
|
317
|
-
* 逐字符覆盖:charStyles[i] 的 fill 优先于对象 fill;字体四件套覆写改写栅格化
|
|
318
|
-
* 样式与栅格化字号(fabric renderChar 逐字 set font 同语义,图集键含字体声明,
|
|
319
|
-
* 天然分桶);stroke/strokeWidth 覆写决定该字取哪一层描边 cell(P2-3);
|
|
320
|
-
* underline/overline/linethrough/textDecorationThickness 覆写参与装饰 run
|
|
321
|
-
* 分段(P2-4,lineDecorationRuns)。
|
|
322
|
-
*
|
|
323
|
-
* quad 定位按 fabric 的字符渲染语义:penX = 行偏移 + charBox.left(含 kerning),
|
|
324
|
-
* 基线 y = 行基线;cell 含 pad(描边层为 miter 留白后的 pad),墨迹左/上由
|
|
325
|
-
* actualBoundingBox 对齐(亚像素由纹理线性采样承载)。
|
|
326
|
-
* 栅格化字号 = 逐字 fontSize×缩放桶(桶 ≥ 有效缩放 zoom×dpr×对象 worldScale,超采样)。
|
|
327
|
-
*/
|
|
328
|
-
renderTextGlyphs(node, zoomX) {
|
|
329
|
-
// P5-6 滚动文本:scrollEnabled 的 ScrollText 走烘焙管线(视口 clip + 双副本
|
|
330
|
-
// 横移);scrollEnabled=false 退化回常规路径(应用 super._renderTextFill 同构)
|
|
331
|
-
const scroll = scrollTextDecl(node.raw);
|
|
332
|
-
if (scroll?.enabled) {
|
|
333
|
-
this.renderScrollText(node, zoomX);
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const layout = node.textLayout;
|
|
337
|
-
const stroke = node.textStroke;
|
|
338
|
-
const needsFill = !!node.raw.fill || layout.lines.some((l) => l.charStyles.some((o) => o?.fill));
|
|
339
|
-
const bucket = pickZoomBucket(glyphEffectiveScale(node, zoomX));
|
|
340
|
-
this.renderTextBackgrounds(node);
|
|
341
|
-
this.renderTextDecorations(node, 'underline');
|
|
342
|
-
// 划重点(批次62):fabric _renderText 定制链首层——underline 之上、字形之下
|
|
343
|
-
this.renderTextHighlight(node, bucket);
|
|
344
|
-
// fabric _renderTextFill / _renderTextStroke 的整体跳过条件:无 fill 不跑 fill 遍、
|
|
345
|
-
// 无描边声明不跑 stroke 遍(逐字覆写可能独立成描边,故对象级为空也要看逐字)
|
|
346
|
-
if (stroke && node.paintFirst === 'stroke') {
|
|
347
|
-
this.renderGlyphPass(node, 'stroke', bucket);
|
|
348
|
-
if (needsFill)
|
|
349
|
-
this.renderGlyphPass(node, 'fill', bucket);
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
if (needsFill)
|
|
353
|
-
this.renderGlyphPass(node, 'fill', bucket);
|
|
354
|
-
if (stroke)
|
|
355
|
-
this.renderGlyphPass(node, 'stroke', bucket);
|
|
356
|
-
}
|
|
357
|
-
this.renderTextDecorations(node, 'overline');
|
|
358
|
-
this.renderTextDecorations(node, 'linethrough');
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* 滚动文本渲染(P5-6 余):应用只覆写 _renderTextFill/_renderTextStroke——
|
|
362
|
-
* 背景高亮与装饰线走 fabric 原路径(不滚也不裁,quirk 保持),z 序
|
|
363
|
-
* bg → underline → 滚动字形(烘焙 quad)→ overline → linethrough。
|
|
364
|
-
* 原生 shadow/PSD effects 仍由 SceneRenderer 在本入口外按静态块渲染
|
|
365
|
-
* (应用 effects 走 Textbox 自有链同样不随滚动;原生 shadow 在应用的
|
|
366
|
-
* clip 内跟随滚动——已知偏差,种子规避)。
|
|
367
|
-
*/
|
|
368
|
-
renderScrollText(node, zoomX) {
|
|
369
|
-
this.renderTextBackgrounds(node);
|
|
370
|
-
this.renderTextDecorations(node, 'underline');
|
|
371
|
-
const bucket = pickZoomBucket(glyphEffectiveScale(node, zoomX));
|
|
372
|
-
const raw = node.raw;
|
|
373
|
-
const sig = [
|
|
374
|
-
raw.text,
|
|
375
|
-
raw.width,
|
|
376
|
-
raw.height,
|
|
377
|
-
raw.fontSize,
|
|
378
|
-
raw.fontFamily,
|
|
379
|
-
raw.fontWeight,
|
|
380
|
-
raw.fontStyle,
|
|
381
|
-
raw.lineHeight,
|
|
382
|
-
raw.charSpacing,
|
|
383
|
-
raw.textAlign,
|
|
384
|
-
raw.splitByGrapheme,
|
|
385
|
-
raw.vertical,
|
|
386
|
-
typeof raw.fill === 'string' ? raw.fill : 'gradient',
|
|
387
|
-
raw.stroke,
|
|
388
|
-
raw.strokeWidth,
|
|
389
|
-
Array.isArray(raw.strokeDashArray) ? raw.strokeDashArray.join(',') : '',
|
|
390
|
-
raw.strokeDashOffset,
|
|
391
|
-
raw.paintFirst,
|
|
392
|
-
JSON.stringify(raw.styles ?? null),
|
|
393
|
-
raw.scrollDirection,
|
|
394
|
-
JSON.stringify(raw.paragraph ?? null),
|
|
395
|
-
node.scrollOffset.toFixed(3),
|
|
396
|
-
node.textTotalWidth.toFixed(3),
|
|
397
|
-
bucket
|
|
398
|
-
].join(';');
|
|
399
|
-
let bake = this.scrollBakes.get(node);
|
|
400
|
-
if (bake && bake.sig !== sig) {
|
|
401
|
-
this.gl.deleteTexture(bake.tex);
|
|
402
|
-
bake = undefined;
|
|
403
|
-
}
|
|
404
|
-
if (!bake) {
|
|
405
|
-
const result = bakeScrollText(node, bucket, node.scrollOffset);
|
|
406
|
-
if (!result) {
|
|
407
|
-
this.scrollBakes.set(node, undefined);
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const tex = createTexture2D(this.gl, result.canvas);
|
|
411
|
-
if (!tex)
|
|
412
|
-
return;
|
|
413
|
-
bake = { sig, tex, w: result.logicalW, h: result.logicalH };
|
|
414
|
-
this.scrollBakes.set(node, bake);
|
|
415
|
-
}
|
|
416
|
-
this.batch.pushQuad(node.matrix, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
417
|
-
this.renderTextDecorations(node, 'overline');
|
|
418
|
-
this.renderTextDecorations(node, 'linethrough');
|
|
419
|
-
}
|
|
420
|
-
/** 背景高亮 run(整段先铺,fabric _renderTextLinesBackground 在 _renderText 之前) */
|
|
421
|
-
renderTextBackgrounds(node) {
|
|
422
|
-
const layout = node.textLayout;
|
|
423
|
-
const nodeOpacity = node.renderOpacity;
|
|
424
|
-
const nodeMatrix = node.matrix;
|
|
425
|
-
const defaultBg = typeof node.raw.textBackgroundColor === 'string' ? node.raw.textBackgroundColor : '';
|
|
426
|
-
if (!defaultBg && !layout.lines.some((l) => l.charStyles.some((o) => o?.textBackgroundColor)))
|
|
427
|
-
return;
|
|
428
|
-
for (const line of layout.lines) {
|
|
429
|
-
const lineLeft = -layout.width / 2 + line.leftOffset;
|
|
430
|
-
const lineTopY = node.contentTopY + line.top;
|
|
431
|
-
const bgAt = (i) => line.charStyles[i]?.textBackgroundColor ?? defaultBg;
|
|
432
|
-
let runStart = 0;
|
|
433
|
-
let runWidth = 0;
|
|
434
|
-
let runColor = bgAt(0);
|
|
435
|
-
const flushBg = () => {
|
|
436
|
-
if (!runColor || runWidth <= 0)
|
|
437
|
-
return;
|
|
438
|
-
const x = lineLeft + line.boxes[runStart].left;
|
|
439
|
-
const color = parseColor(runColor);
|
|
440
|
-
const rgba = [color[0], color[1], color[2], color[3] * nodeOpacity];
|
|
441
|
-
const m = multiply(nodeMatrix, [1, 0, 0, 1, x + runWidth / 2, lineTopY + line.implHeight / 2]);
|
|
442
|
-
this.batch.pushQuad(m, runWidth, line.implHeight, rgba, null);
|
|
443
|
-
};
|
|
444
|
-
for (let i = 0; i < line.graphemes.length; i++) {
|
|
445
|
-
const current = bgAt(i);
|
|
446
|
-
if (current !== runColor) {
|
|
447
|
-
flushBg();
|
|
448
|
-
runStart = i;
|
|
449
|
-
runWidth = line.boxes[i].width;
|
|
450
|
-
runColor = current;
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
runWidth += line.boxes[i].kernedWidth;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
flushBg();
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* 装饰线 run(P2-4):lineDecorationRuns 产出线段,转纯色 quad。
|
|
461
|
-
* y 基准 = 行基线(run.y 已是基线相对量);颜色跟 run 起始字符的 fill ×
|
|
462
|
-
* 对象 opacity(与描边色同口径,不复用含 fill alpha 的 drawColor——后者
|
|
463
|
-
* 会把样式色自身的 alpha 再乘一次)。
|
|
464
|
-
*/
|
|
465
|
-
renderTextDecorations(node, type) {
|
|
466
|
-
const layout = node.textLayout;
|
|
467
|
-
const defaults = node.decorationDefaults;
|
|
468
|
-
const base = [1, 1, 1, node.renderOpacity];
|
|
469
|
-
const nodeMatrix = node.matrix;
|
|
470
|
-
for (const line of layout.lines) {
|
|
471
|
-
const runs = lineDecorationRuns(line, type, defaults);
|
|
472
|
-
if (runs.length === 0)
|
|
473
|
-
continue;
|
|
474
|
-
const lineLeft = -layout.width / 2 + line.leftOffset;
|
|
475
|
-
const baselineY = node.contentTopY + line.baseline;
|
|
476
|
-
for (const run of runs) {
|
|
477
|
-
const cx = lineLeft + run.x + run.width / 2;
|
|
478
|
-
const cy = baselineY + run.y + run.thickness / 2;
|
|
479
|
-
this.batch.pushQuad(multiply(nodeMatrix, [1, 0, 0, 1, cx, cy]), run.width, run.thickness, charFillColor(run.color, base), null);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
/** 对象级虚线描边(P3-2b 判定;逐字覆写无虚线字段,仅对象级) */
|
|
484
|
-
textHasDashStroke(node) {
|
|
485
|
-
return Array.isArray(node.raw.strokeDashArray) && node.raw.strokeDashArray.length > 0;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* 虚线文本描边(P3-2b):fabric `_renderTextStroke` 的同构烘焙——对象级
|
|
489
|
-
* setLineDash 一次 + `_renderTextCommon('strokeText')` 逐 run 出笔(相位在
|
|
490
|
-
* run 内连续)。分段语义同 `_renderChars`:charSpacing ≠ 0 逐字一段;
|
|
491
|
-
* justify 在空格处断段;其余按样式变化(字体声明/描边声明/填充色)分段。
|
|
492
|
-
*/
|
|
493
|
-
renderTextDashStroke(node, bucket) {
|
|
494
|
-
const layout = node.textLayout;
|
|
495
|
-
const style = node.textStyle;
|
|
496
|
-
const dash = node.raw.strokeDashArray;
|
|
497
|
-
const baseStroke = node.textStroke;
|
|
498
|
-
const strokeWidth = baseStroke ? baseStroke.width : 0;
|
|
499
|
-
if (!baseStroke || strokeWidth <= 0)
|
|
500
|
-
return;
|
|
501
|
-
const charSpacing = Number(node.raw.charSpacing) || 0;
|
|
502
|
-
const justify = isJustifyFamilyAlign(node.raw.textAlign);
|
|
503
|
-
const disperse = node.raw.textAlign === TextAlignValues.DISPERSE;
|
|
504
|
-
// K-line 抖动:奇字越出排版盒(峰值 fontSize·0.5),画布四向余量同步放宽防裁剪
|
|
505
|
-
const textOffsetY = Number(node.raw.textOffsetY) || 0;
|
|
506
|
-
const jitterPad = maxCharJitterY(textOffsetY, node.textStyle, layout.lines);
|
|
507
|
-
const pad = strokeWidth + 4 + Math.ceil(jitterPad);
|
|
508
|
-
const w = Math.ceil(layout.width + pad * 2);
|
|
509
|
-
const h = Math.ceil(layout.height + pad * 2);
|
|
510
|
-
if (!(w > 0) || !(h > 0) || w > 8192 || h > 8192)
|
|
511
|
-
return;
|
|
512
|
-
const sig = [
|
|
513
|
-
node.raw.text,
|
|
514
|
-
layout.width,
|
|
515
|
-
layout.height,
|
|
516
|
-
baseStroke.color,
|
|
517
|
-
baseStroke.width,
|
|
518
|
-
dash.join(','),
|
|
519
|
-
Number(node.raw.strokeDashOffset) || 0,
|
|
520
|
-
bucket,
|
|
521
|
-
charSpacing,
|
|
522
|
-
justify,
|
|
523
|
-
node.raw.textAlign,
|
|
524
|
-
node.raw.vertical === true,
|
|
525
|
-
textOffsetY,
|
|
526
|
-
JSON.stringify(node.raw.paragraph ?? null)
|
|
527
|
-
].join(';');
|
|
528
|
-
let bake = this.textDashBakes.get(node);
|
|
529
|
-
if (bake && bake.sig !== sig) {
|
|
530
|
-
this.gl.deleteTexture(bake.tex);
|
|
531
|
-
bake = undefined;
|
|
532
|
-
}
|
|
533
|
-
if (!bake) {
|
|
534
|
-
const canvas = document.createElement('canvas');
|
|
535
|
-
canvas.width = Math.ceil(w * bucket);
|
|
536
|
-
canvas.height = Math.ceil(h * bucket);
|
|
537
|
-
const ctx = canvas.getContext('2d');
|
|
538
|
-
if (!ctx)
|
|
539
|
-
return;
|
|
540
|
-
ctx.setTransform(bucket, 0, 0, bucket, 0, 0);
|
|
541
|
-
ctx.textBaseline = 'alphabetic';
|
|
542
|
-
ctx.setLineDash(dash);
|
|
543
|
-
ctx.lineDashOffset = Number(node.raw.strokeDashOffset) || 0;
|
|
544
|
-
ctx.lineJoin = (typeof node.raw.strokeLineJoin === 'string' ? node.raw.strokeLineJoin : 'miter');
|
|
545
|
-
ctx.lineCap = (typeof node.raw.strokeLineCap === 'string' ? node.raw.strokeLineCap : 'butt');
|
|
546
|
-
ctx.miterLimit = Number(node.raw.strokeMiterLimit) || 4;
|
|
547
|
-
const originX = layout.width / 2 + pad;
|
|
548
|
-
// 本地(中心系)→ 烘焙坐标:+h/2+pad;基线 = contentTopY + line.baseline
|
|
549
|
-
// (contentTopY 是中心系块顶(负值)——曾写反号致整块下移一个盒高)
|
|
550
|
-
const originY = layout.height / 2 + pad + node.contentTopY;
|
|
551
|
-
const vertical = node.raw.vertical === true;
|
|
552
|
-
let globalCharIndex = 0;
|
|
553
|
-
for (const line of layout.lines) {
|
|
554
|
-
const lineLeft = -layout.width / 2 + line.leftOffset;
|
|
555
|
-
const baselineY = originY + line.baseline;
|
|
556
|
-
if (vertical) {
|
|
557
|
-
// 列表前缀:列首出笔(不旋转、无 jitter),描边态随对象级 setLineDash
|
|
558
|
-
if (line.prefix) {
|
|
559
|
-
drawParagraphPrefix(ctx, line, originX + lineLeft, baselineY, { stroke: resolveStrokeDecl(baseStroke, line.charStyles[0]) });
|
|
560
|
-
}
|
|
561
|
-
// P4-5c 竖排:fabric vertical 强制逐字出笔(_renderChars 2454),虚线相位
|
|
562
|
-
// 逐 strokeText 各自重来——与参考面同 quirk,setLineDash 仍对象级一次
|
|
563
|
-
const ops = verticalGlyphOps(line, lineLeft, baselineY, style, charSpacing);
|
|
564
|
-
for (let i = 0; i < ops.length; i++) {
|
|
565
|
-
const strokeDecl = resolveStrokeDecl(baseStroke, line.charStyles[i]);
|
|
566
|
-
if (!strokeDecl || strokeDecl.width <= 0)
|
|
567
|
-
continue;
|
|
568
|
-
const glyphStyle = glyphStyleAt(style, line.charStyles[i]);
|
|
569
|
-
ctx.font = fontDeclaration(glyphStyle, glyphStyle.fontSize);
|
|
570
|
-
ctx.lineWidth = strokeDecl.width;
|
|
571
|
-
ctx.strokeStyle = strokeDecl.color;
|
|
572
|
-
// K-line:竖排锚点 y 平移(fabric charTop 加偏移后算锚点,同 glyph 口径)
|
|
573
|
-
drawVerticalGlyph(ctx, { ...ops[i], y: ops[i].y + charJitterY(textOffsetY, glyphStyle.fontSize, globalCharIndex + i) }, 'strokeText');
|
|
574
|
-
}
|
|
575
|
-
globalCharIndex += line.graphemes.length;
|
|
576
|
-
continue;
|
|
577
|
-
}
|
|
578
|
-
// run 分段:charSpacing 逐字;justify/disperse 空格断段;纯 justify/
|
|
579
|
-
// disperse 的 CJK 行被逐字分布拉伸(textLayout fork 口径)→ run 必须逐字
|
|
580
|
-
// 断段(run 内自然步进会吃掉字间隙);样式(字体/描边/填充)变化断段;
|
|
581
|
-
// K-line 逐字断段(fabric _renderChars 2496:textOffsetY≠0 强制逐字出笔,奇字 y 各异)
|
|
582
|
-
// 列表前缀:行首 strokeText(fabric 前缀块)+ runX 起点平移前缀宽
|
|
583
|
-
//(首 run 的 runX 不再是 0——boxes[0].left 已被前缀平移打破恒 0 不变量)
|
|
584
|
-
const charWiseStretched = isStretchAlign(node.raw.textAlign) && line.graphemes.some((g) => CJK_LINE_RE.test(g));
|
|
585
|
-
let run = '';
|
|
586
|
-
let runX = line.prefix ? drawParagraphPrefix(ctx, line, originX + lineLeft, baselineY, { stroke: resolveStrokeDecl(baseStroke, line.charStyles[0]) }) : 0;
|
|
587
|
-
let runJitter = 0;
|
|
588
|
-
let runFont = '';
|
|
589
|
-
let runStroke = null;
|
|
590
|
-
let runFill;
|
|
591
|
-
const flush = (endIndex) => {
|
|
592
|
-
if (!run)
|
|
593
|
-
return;
|
|
594
|
-
const decl = runStroke;
|
|
595
|
-
if (decl && decl.width > 0) {
|
|
596
|
-
ctx.font = runFont;
|
|
597
|
-
ctx.lineWidth = decl.width;
|
|
598
|
-
ctx.strokeStyle = decl.color;
|
|
599
|
-
ctx.strokeText(run, originX + lineLeft + runX, baselineY + runJitter);
|
|
600
|
-
}
|
|
601
|
-
run = '';
|
|
602
|
-
if (endIndex < line.boxes.length)
|
|
603
|
-
runX = line.boxes[endIndex].left;
|
|
604
|
-
};
|
|
605
|
-
for (let i = 0; i < line.graphemes.length; i++) {
|
|
606
|
-
const o = line.charStyles[i];
|
|
607
|
-
const hasFontOverride = o !== undefined && (o.fontSize !== undefined || o.fontFamily !== undefined || o.fontWeight !== undefined || o.fontStyle !== undefined);
|
|
608
|
-
const glyphStyle = hasFontOverride && o
|
|
609
|
-
? {
|
|
610
|
-
...style,
|
|
611
|
-
fontSize: o.fontSize ?? style.fontSize,
|
|
612
|
-
fontFamily: o.fontFamily ?? style.fontFamily,
|
|
613
|
-
fontWeight: o.fontWeight ?? style.fontWeight,
|
|
614
|
-
fontStyle: o.fontStyle ?? style.fontStyle
|
|
615
|
-
}
|
|
616
|
-
: style;
|
|
617
|
-
const font = fontDeclaration(glyphStyle, glyphStyle.fontSize);
|
|
618
|
-
const strokeDecl = resolveStrokeDecl(baseStroke, o);
|
|
619
|
-
const fill = o?.fill ?? '';
|
|
620
|
-
const prevStroke = runStroke;
|
|
621
|
-
if (run && (font !== runFont || strokeDecl?.color !== prevStroke?.color || strokeDecl?.width !== prevStroke?.width || fill !== runFill)) {
|
|
622
|
-
flush(i);
|
|
623
|
-
}
|
|
624
|
-
if (!run) {
|
|
625
|
-
runFont = font;
|
|
626
|
-
runStroke = strokeDecl;
|
|
627
|
-
runFill = fill;
|
|
628
|
-
runJitter = charJitterY(textOffsetY, glyphStyle.fontSize, globalCharIndex + i);
|
|
629
|
-
}
|
|
630
|
-
run += line.graphemes[i];
|
|
631
|
-
if (charSpacing || textOffsetY !== 0 || ((justify || disperse) && /[ \t\r]/.test(line.graphemes[i])) || charWiseStretched)
|
|
632
|
-
flush(i + 1);
|
|
633
|
-
}
|
|
634
|
-
flush(line.graphemes.length);
|
|
635
|
-
globalCharIndex += line.graphemes.length;
|
|
636
|
-
}
|
|
637
|
-
const tex = createTexture2D(this.gl, canvas);
|
|
638
|
-
if (!tex)
|
|
639
|
-
return;
|
|
640
|
-
bake = { sig, tex, w, h };
|
|
641
|
-
this.textDashBakes.set(node, bake);
|
|
642
|
-
}
|
|
643
|
-
// 整块 quad:烘焙是**本地空间**(区别于形状的场景空间烘焙)——quad 走完整
|
|
644
|
-
// 对象矩阵(旋转/缩放在矩阵上,曾误用恒等旋转致 kd5 变换链错位)
|
|
645
|
-
this.batch.pushQuad(node.matrix, bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* 划重点(批次62):raw.texts 的 svg highlight → 整块烘焙 quad。
|
|
649
|
-
*
|
|
650
|
-
* z 序 = fabric _renderText 定制链(bg → underline → **highlight** → 字形 →
|
|
651
|
-
* overline/linethrough),插槽在 renderTextGlyphs 内已排定。滚动文本在
|
|
652
|
-
* renderTextGlyphs 前置分支返回(UI 本就禁标,双栈同侪);竖排不承接
|
|
653
|
-
* (fabric 行/列 charBounds 语义存疑,登记已知缺口)。
|
|
654
|
-
*
|
|
655
|
-
* 烘焙画布 y 向锚内容块顶(contentTopY = −dims.y/2,盒抬高时块上移)——
|
|
656
|
-
* quad 不能像虚线烘焙那样直接走 node.matrix(其画布锚 -height/2 假设居中),
|
|
657
|
-
* 平移列按画布实际中心补偏心。
|
|
658
|
-
*/
|
|
659
|
-
renderTextHighlight(node, bucket) {
|
|
660
|
-
const raw = node.raw;
|
|
661
|
-
if (!Array.isArray(raw.texts) || raw.texts.length === 0)
|
|
662
|
-
return;
|
|
663
|
-
if (raw.vertical === true)
|
|
664
|
-
return;
|
|
665
|
-
const layout = node.textLayout;
|
|
666
|
-
const sig = [
|
|
667
|
-
raw.text,
|
|
668
|
-
layout.width,
|
|
669
|
-
layout.height,
|
|
670
|
-
raw.fontSize,
|
|
671
|
-
raw.fontFamily,
|
|
672
|
-
raw.fontWeight,
|
|
673
|
-
raw.fontStyle,
|
|
674
|
-
raw.lineHeight,
|
|
675
|
-
raw.charSpacing,
|
|
676
|
-
raw.textAlign,
|
|
677
|
-
raw.splitByGrapheme,
|
|
678
|
-
JSON.stringify(raw.styles ?? null),
|
|
679
|
-
node.dims.y,
|
|
680
|
-
JSON.stringify(raw.texts ?? null),
|
|
681
|
-
JSON.stringify(raw.paragraph ?? null),
|
|
682
|
-
bucket
|
|
683
|
-
].join(';');
|
|
684
|
-
let bake = this.highlightBakes.get(node);
|
|
685
|
-
if (bake && bake.sig !== sig) {
|
|
686
|
-
this.gl.deleteTexture(bake.tex);
|
|
687
|
-
bake = undefined;
|
|
688
|
-
}
|
|
689
|
-
if (!bake) {
|
|
690
|
-
const plan = planTextHighlight(raw.text ?? '', layout, raw.texts, node.contentTopY, node.textStyle.fontSize);
|
|
691
|
-
if (!plan) {
|
|
692
|
-
this.highlightBakes.set(node, undefined);
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
const result = bakeTextHighlight(plan, layout, node.contentTopY, bucket);
|
|
696
|
-
if (!result)
|
|
697
|
-
return;
|
|
698
|
-
const tex = createTexture2D(this.gl, result.canvas);
|
|
699
|
-
if (!tex)
|
|
700
|
-
return;
|
|
701
|
-
bake = { sig, tex, w: result.logicalW, h: result.logicalH, centerY: node.contentTopY - plan.padY + result.logicalH / 2 };
|
|
702
|
-
this.highlightBakes.set(node, bake);
|
|
703
|
-
}
|
|
704
|
-
// 画布矩形本地系 x 居中、y 锚 contentTopY−pad——quad 中心按画布实际中心补平移
|
|
705
|
-
this.batch.pushQuad(multiply(node.matrix, [1, 0, 0, 1, 0, bake.centerY]), bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
|
|
706
|
-
}
|
|
707
|
-
/** 单遍字形提交:pass='fill' 取填充层 cell、pass='stroke' 取描边层 cell */
|
|
708
|
-
renderGlyphPass(node, pass, bucket) {
|
|
709
|
-
// P3-2b 虚线描边:fabric 按 run 一次 strokeText(虚线相位在 run 内连续),
|
|
710
|
-
// 图集逐字形 cell 相位会逐字重来——改走 run 级烘焙(同 fabric 分段语义)
|
|
711
|
-
if (pass === 'stroke' && this.textHasDashStroke(node)) {
|
|
712
|
-
this.renderTextDashStroke(node, bucket);
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
const layout = node.textLayout;
|
|
716
|
-
const style = node.textStyle;
|
|
717
|
-
const nodeMatrix = node.matrix;
|
|
718
|
-
const nodeOpacity = node.renderOpacity;
|
|
719
|
-
// P3-3 已知缺口:文本的渐变填充尚未接入字形管线(需逐字形按对象空间位置采样
|
|
720
|
-
// ramp),暂以首 stop 实色 × opacity 近似——fabric 侧渲染完整渐变,种子场景
|
|
721
|
-
// 避免文本渐变;后续批次按 quad 渐变管线同机制接入
|
|
722
|
-
const paint = node.fillPaint;
|
|
723
|
-
const nodeColor = paint?.kind === 'gradient' ? [paint.decl.stops[0].color[0], paint.decl.stops[0].color[1], paint.decl.stops[0].color[2], paint.decl.stops[0].color[3] * nodeOpacity] : node.drawColor;
|
|
724
|
-
const hasFill = !!node.raw.fill;
|
|
725
|
-
const baseStroke = node.textStroke;
|
|
726
|
-
// 描边色 modulation 只乘对象 opacity(fabric globalAlpha 语义)——
|
|
727
|
-
// 不可借用 drawColor(它已含 fill 自身 alpha,会让半透明填充拖累描边不透明度)
|
|
728
|
-
const strokeBase = [1, 1, 1, nodeOpacity];
|
|
729
|
-
// P4-5c 竖排:CJK 族的 spacing 手动加(对象 fontSize 基数,fabric
|
|
730
|
-
// _getWidthOfCharSpacing——kernedWidth 已含 spacing 的只有拉丁不双算)
|
|
731
|
-
const vertical = node.raw.vertical === true;
|
|
732
|
-
const verticalCharSpacing = vertical && style.charSpacing ? (style.fontSize * style.charSpacing) / 1000 : 0;
|
|
733
|
-
// K-line 抖动(fabric _renderStr 2714-2757):全局奇偶按视觉行字素数跨行累计
|
|
734
|
-
const textOffsetY = Number(node.raw.textOffsetY) || 0;
|
|
735
|
-
let globalCharIndex = 0;
|
|
736
|
-
for (const line of layout.lines) {
|
|
737
|
-
const lineLeft = -layout.width / 2 + line.leftOffset;
|
|
738
|
-
const baselineY = node.contentTopY + line.baseline;
|
|
739
|
-
// 列表前缀(fabric _renderChars 前缀块):行首先画前缀再画正文;色/描边
|
|
740
|
-
// 取行首字符覆写 ?? 对象级(fabric fullDecl);无 K-line jitter(fabric 前缀
|
|
741
|
-
// 块直 fillText 不走 _renderStr);竖排同在列首出笔(不旋转)。z 序 = 行内
|
|
742
|
-
// 同趟先前缀后正文(无交叠,与 fabric 逐行前缀块同构)
|
|
743
|
-
if (line.prefix) {
|
|
744
|
-
if (pass === 'stroke') {
|
|
745
|
-
const strokeDecl = resolveStrokeDecl(baseStroke, line.charStyles[0]);
|
|
746
|
-
if (strokeDecl && strokeDecl.width > 0) {
|
|
747
|
-
this.pushPrefixGlyphs(node, line.prefix, lineLeft, baselineY, strokeDecl, charFillColor(strokeDecl.color, strokeBase), bucket);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
else {
|
|
751
|
-
const override = line.charStyles[0]?.fill;
|
|
752
|
-
if (override || hasFill) {
|
|
753
|
-
this.pushPrefixGlyphs(node, line.prefix, lineLeft, baselineY, null, override ? charFillColor(override, nodeColor) : nodeColor, bucket);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
// P4-5c vertical in-line glyph position: fabric _renderChars per-char accumulation (2459-2478)——
|
|
758
|
-
// latin advance = box.width (draw position shifted earlier by kerned−width), CJK-family advance = box height + spacing
|
|
759
|
-
let penV = 0;
|
|
760
|
-
for (let i = 0; i < line.graphemes.length; i++) {
|
|
761
|
-
const o = line.charStyles[i];
|
|
762
|
-
let color;
|
|
763
|
-
let strokeDecl = null;
|
|
764
|
-
if (pass === 'stroke') {
|
|
765
|
-
strokeDecl = resolveStrokeDecl(baseStroke, o);
|
|
766
|
-
if (!strokeDecl)
|
|
767
|
-
continue;
|
|
768
|
-
color = charFillColor(strokeDecl.color, strokeBase);
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
const override = o?.fill;
|
|
772
|
-
if (!override && !hasFill)
|
|
773
|
-
continue;
|
|
774
|
-
// Per-character fill: style-cached parse result, avoids repeated parse per glyph
|
|
775
|
-
color = override ? charFillColor(override, nodeColor) : nodeColor;
|
|
776
|
-
}
|
|
777
|
-
const hasFontOverride = o !== undefined && (o.fontSize !== undefined || o.fontFamily !== undefined || o.fontWeight !== undefined || o.fontStyle !== undefined);
|
|
778
|
-
const glyphStyle = hasFontOverride && o
|
|
779
|
-
? {
|
|
780
|
-
...style,
|
|
781
|
-
fontSize: o.fontSize ?? style.fontSize,
|
|
782
|
-
fontFamily: o.fontFamily ?? style.fontFamily,
|
|
783
|
-
fontWeight: o.fontWeight ?? style.fontWeight,
|
|
784
|
-
fontStyle: o.fontStyle ?? style.fontStyle
|
|
785
|
-
}
|
|
786
|
-
: style;
|
|
787
|
-
const jitter = charJitterY(textOffsetY, glyphStyle.fontSize, globalCharIndex + i);
|
|
788
|
-
const { rs, scale } = glyphRasterPlan(glyphStyle.fontSize, bucket);
|
|
789
|
-
const cell = this.glyphAtlas.get(glyphStyle, rs, line.graphemes[i], strokeDecl);
|
|
790
|
-
if (!cell)
|
|
791
|
-
continue;
|
|
792
|
-
const box = line.boxes[i];
|
|
793
|
-
const w = cell.wPx / scale;
|
|
794
|
-
const h = cell.hPx / scale;
|
|
795
|
-
let glyphMatrix;
|
|
796
|
-
if (vertical) {
|
|
797
|
-
// Vertical per-character posture (fabric _renderStr 2711-2743, internal coordinate system——object matrix still
|
|
798
|
-
// goes through the generic transform including angle, zero angle special-casing):
|
|
799
|
-
// latin/brackets drawn flat (baseline fillText same as horizontal), symbol/cjk via anchor translate + rotate(−π/2);
|
|
800
|
-
// the quad is equivalent to unrotated cell placement being moved along with the anchor R(−90°)——
|
|
801
|
-
// corner = anchor + R·(rel + local), glyph ink exactly coincides with fabric translate/rotate/fillText
|
|
802
|
-
// K-line:fabric 竖排对 charTop 加偏移后才算旋转锚点——锚点/平画 y + jitter 等价
|
|
803
|
-
const g = line.graphemes[i];
|
|
804
|
-
const klass = verticalCharClass(g);
|
|
805
|
-
const fontSize = glyphStyle.fontSize;
|
|
806
|
-
const advance = verticalRenderAdvance(g, box, verticalCharSpacing);
|
|
807
|
-
if (klass === 'latin' || klass === 'bracket') {
|
|
808
|
-
const drawX = lineLeft + penV + (klass === 'latin' ? box.kernedWidth - box.width : 0);
|
|
809
|
-
const tlx = drawX + (cell.inkLeftPx - cell.padPx) / scale;
|
|
810
|
-
const tly = baselineY + jitter - (cell.ascentPx + cell.padPx) / scale;
|
|
811
|
-
glyphMatrix = multiply(nodeMatrix, [1, 0, 0, 1, tlx + w / 2, tly + h / 2]);
|
|
812
|
-
}
|
|
813
|
-
else {
|
|
814
|
-
const anchorX = lineLeft + penV + verticalAnchorShiftX(fontSize);
|
|
815
|
-
const anchorY = baselineY + jitter + verticalAnchorShiftY(klass, box, fontSize);
|
|
816
|
-
const relX = (cell.inkLeftPx - cell.padPx) / scale + w / 2;
|
|
817
|
-
const relY = h / 2 - (cell.ascentPx + cell.padPx) / scale;
|
|
818
|
-
glyphMatrix = multiply(nodeMatrix, multiply([1, 0, 0, 1, anchorX, anchorY], multiply([0, -1, 1, 0, 0, 0], [1, 0, 0, 1, relX, relY])));
|
|
819
|
-
}
|
|
820
|
-
penV += advance;
|
|
821
|
-
}
|
|
822
|
-
else {
|
|
823
|
-
const penX = lineLeft + box.left;
|
|
824
|
-
const tlx = penX + (cell.inkLeftPx - cell.padPx) / scale;
|
|
825
|
-
const tly = baselineY + jitter - (cell.ascentPx + cell.padPx) / scale;
|
|
826
|
-
glyphMatrix = multiply(nodeMatrix, [1, 0, 0, 1, tlx + w / 2, tly + h / 2]);
|
|
827
|
-
}
|
|
828
|
-
this.batch.pushQuad(glyphMatrix, w, h, color, this.glyphAtlas.textureOf(cell), [cell.u0, cell.v0, cell.u1, cell.v1]);
|
|
829
|
-
}
|
|
830
|
-
globalCharIndex += line.graphemes.length;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* 列表前缀 GL 绘制(renderGlyphPass 行首前缀块的 companion):图集 cell
|
|
835
|
-
* 定位与横排字形同构(ink 左/上对齐 + pad),penX 按布局产出的逐字素 advance
|
|
836
|
-
* 推进(前缀内 kerning 近似——canvas 烘焙族走整串出笔保留,fabric 原样)。
|
|
837
|
-
*/
|
|
838
|
-
pushPrefixGlyphs(node, prefix, lineLeft, baselineY, strokeDecl, color, bucket) {
|
|
839
|
-
const graphemes = graphemeSplit(prefix.text);
|
|
840
|
-
let penX = lineLeft;
|
|
841
|
-
for (let j = 0; j < graphemes.length; j++) {
|
|
842
|
-
const { rs, scale } = glyphRasterPlan(prefix.style.fontSize, bucket);
|
|
843
|
-
const cell = this.glyphAtlas.get(prefix.style, rs, graphemes[j], strokeDecl);
|
|
844
|
-
if (cell) {
|
|
845
|
-
const w = cell.wPx / scale;
|
|
846
|
-
const h = cell.hPx / scale;
|
|
847
|
-
const tlx = penX + (cell.inkLeftPx - cell.padPx) / scale;
|
|
848
|
-
const tly = baselineY - (cell.ascentPx + cell.padPx) / scale;
|
|
849
|
-
this.batch.pushQuad(multiply(node.matrix, [1, 0, 0, 1, tlx + w / 2, tly + h / 2]), w, h, color, this.glyphAtlas.textureOf(cell), [cell.u0, cell.v0, cell.u1, cell.v1]);
|
|
850
|
-
}
|
|
851
|
-
penX += prefix.advances[j] ?? 0;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|