Skip to content

Commit 95129be

Browse files
perf: 优化辅助线绘制 (#386)
1 parent a07eceb commit 95129be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/core/plugin/AlignGuidLinePlugin.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,8 @@ class AlignGuidLinePlugin {
7171
function drawLine(x1: number, y1: number, x2: number, y2: number) {
7272
if (viewportTransform == null) return;
7373

74-
ctx.save();
75-
ctx.lineWidth = This.defautOption.width;
76-
ctx.strokeStyle = This.defautOption.color;
77-
ctx.beginPath();
7874
ctx.moveTo(x1 * zoom + viewportTransform[4], y1 * zoom + viewportTransform[5]);
7975
ctx.lineTo(x2 * zoom + viewportTransform[4], y2 * zoom + viewportTransform[5]);
80-
ctx.stroke();
81-
ctx.restore();
8276
}
8377

8478
function isInRange(value1: number, value2: number) {
@@ -294,12 +288,18 @@ class AlignGuidLinePlugin {
294288
});
295289

296290
canvas.on('after:render', () => {
291+
ctx.save();
292+
ctx.beginPath();
293+
ctx.lineWidth = This.defautOption.width;
294+
ctx.strokeStyle = This.defautOption.color;
297295
for (let i = verticalLines.length; i--; ) {
298296
drawVerticalLine(verticalLines[i]);
299297
}
300298
for (let j = horizontalLines.length; j--; ) {
301299
drawHorizontalLine(horizontalLines[j]);
302300
}
301+
ctx.stroke();
302+
ctx.restore();
303303

304304
// noinspection NestedAssignmentJS
305305
verticalLines.length = 0;

0 commit comments

Comments
 (0)