feat(image-annotate): 1.2.0 非破坏性裁剪(可撤销/不 flatten)+ 工具参数解耦与就地选项栏
This commit is contained in:
1 parent
a4e89f5f8b
commit
d8e4e0cb26
13 files changed
+1768
-1243
No files matched your search
@@ -105,6 +105,48 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
||||
bindCanvasEvents()
|
||||
}
|
||||
|
||||
/**
|
||||
* 只调整画布尺寸与交互层,不重建图层(裁剪 / 撤销裁剪共用)。
|
||||
*
|
||||
* 与 setupCanvas 的分工:setupCanvas 会清空 S.layers 并新建「原图 + 画笔」两层,
|
||||
* 那是「打开一张新图」的语义。裁剪只是在同一张图上换视窗,像素由调用方先搬好,
|
||||
* 这里只负责尺寸、交互层、矢量层与视图基准,图层结构原样保留。
|
||||
*
|
||||
* ⚠️ 这里会把每个图层 canvas 的像素缓冲清空(canvas.width 赋值即重置),
|
||||
* 调用方必须在调用前把像素复制出来,调用后写回。
|
||||
*/
|
||||
export function resizeWorkspace(w, h) {
|
||||
S.imgW = Math.max(1, Math.round(w))
|
||||
S.imgH = Math.max(1, Math.round(h))
|
||||
|
||||
S.textCanvas.width = S.imgW
|
||||
S.textCanvas.height = S.imgH
|
||||
S.strokeCanvas.width = S.imgW
|
||||
S.strokeCanvas.height = S.imgH
|
||||
S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18))
|
||||
for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) {
|
||||
if (!c || !cx) continue
|
||||
c.width = S.imgW + S.overlayPad * 2
|
||||
c.height = S.imgH + S.overlayPad * 2
|
||||
cx.setTransform(1, 0, 0, 1, S.overlayPad, S.overlayPad)
|
||||
}
|
||||
|
||||
purgeVectorCanvases()
|
||||
for (const layer of S.layers) {
|
||||
layer.canvas.width = S.imgW
|
||||
layer.canvas.height = S.imgH
|
||||
layer._bounds = undefined
|
||||
}
|
||||
|
||||
S.pickerComposite = null
|
||||
clearOverlay()
|
||||
computeFit()
|
||||
S.viewX = null
|
||||
applyView()
|
||||
renderObjects()
|
||||
renderLayerPanel()
|
||||
}
|
||||
|
||||
/** 计算「适应容器」的基准显示尺寸(不限制放大,小图也铺满) */
|
||||
function computeFit() {
|
||||
const availW = Math.max(50, S.canvasWrap.clientWidth - 48)
|
||||
|
||||
Reference in new issue
Block a user