Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(render): context native line width (#1381)

Univer36aa42990ac5
diff --git a/packages/engine-render/src/context.ts b/packages/engine-render/src/context.ts
index f63e93dfd6..3c105a5996 100644
--- a/packages/engine-render/src/context.ts
+++ b/packages/engine-render/src/context.ts
@@ -127,6 +127,10 @@ export class UniverRenderingContext2D implements CanvasRenderingContext2D {
this._context.lineWidth = val / Math.max(scaleX, scaleY);
}
+ setLineWidthNative(val: number) {
+ this._context.lineWidth = val;
+ }
+
// miterLimit: number;
get miterLimit() {
return this._context.miterLimit;
diff --git a/packages/engine-render/src/shape/shape.ts b/packages/engine-render/src/shape/shape.ts
index dbf535ce40..eb9ec220ef 100644
--- a/packages/engine-render/src/shape/shape.ts
+++ b/packages/engine-render/src/shape/shape.ts
@@ -307,7 +307,7 @@ export abstract class Shape<T> extends BaseObject {
private static _setStrokeStyles(ctx: UniverRenderingContext, props: IShapeProps) {
const { strokeWidth, strokeLineCap, strokeDashOffset, strokeLineJoin, strokeMiterLimit, stroke } = props;
- ctx.lineWidth = strokeWidth!;
+ ctx.setLineWidthNative(strokeWidth!);
ctx.lineCap = strokeLineCap!;
ctx.lineDashOffset = strokeDashOffset!;
ctx.lineJoin = strokeLineJoin!;
diff --git a/packages/sheets-ui/src/services/selection/selection-shape.ts b/packages/sheets-ui/src/services/selection/selection-shape.ts
index 514543d892..16d58ceffb 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape.ts
@@ -478,7 +478,7 @@ export class SelectionShape {
this.dashRect.hide();
this._stopAntLineAnimation();
} else {
- const dashRectWidth = style.strokeWidth * 4;
+ const dashRectWidth = style.strokeWidth * 2 / scale;
this.dashRect.transformByState({
height: endY - startY,
width: endX - startX,
@@ -1086,7 +1086,7 @@ export class SelectionShape {
private _startAntLineAnimation() {
const scale = this._getScale();
- this._antLineOffset += 0.5 / scale;
+ this._antLineOffset += 0.6 / scale;
if (this._antLineOffset > 16 / scale) {
this._antLineOffset = 0;
}