Quellcode durchsuchen

fix: 文字组件 超出高度 和矩阵调整错误 修复

bill vor 4 Monaten
Ursprung
Commit
a93e4e6d84

+ 2 - 1
src/core/components/text/index.ts

@@ -88,7 +88,7 @@ export const interactiveFixData: InteractiveFix<"text"> = ({ data, info }) => {
   return data;
 };
 
-export const getMinWidth = (data: TextData) =>  (data.fontSize || 12) * 2
+export const getMinWidth = (data: TextData) =>  Math.ceil((data.fontSize || 12) * 2)
 
 
 export const getWidth = (data: TextData, scaleX: number) => {
@@ -97,6 +97,7 @@ export const getWidth = (data: TextData, scaleX: number) => {
   if ("width" in data) {
     width = Math.max(data.width! * scaleX, minWidth);
   } else {
+    console.log(minWidth)
     width = Math.max(minWidth * scaleX, minWidth);
   }
   return width;

+ 9 - 14
src/core/components/text/text.vue

@@ -51,19 +51,16 @@ const { shape, tData, data, operateMenus, describes } = useComponentStatus<
   defaultStyle,
   transformType: "custom",
   customTransform(callback, shape, data) {
-    let initData: TextData;
     useCustomTransformer(shape, data, {
       openSnap: true,
       getRepShape($shape) {
         const repShape = cloneRepShape($shape).shape;
-        setShapeTransform(repShape, new Transform(data.value.mat));
-        repShape.width(data.value.width);
-        repShape.fontSize(data.value.fontSize);
-        initData = copy(data.value);
         return {
           shape: repShape,
           update(data) {
-            console.log("update");
+            data.width && repShape.width(data.width);
+            data.fontSize && repShape.fontSize(data.fontSize);
+            setShapeTransform(repShape, new Transform(data.mat));
           },
         };
       },
@@ -78,14 +75,10 @@ const { shape, tData, data, operateMenus, describes } = useComponentStatus<
         },
       },
       beforeHandler(data, mat) {
-        return matResponse({ mat, data: copy(initData) });
+        return matResponse({ data: copy(data), mat });
       },
       handler(data, mat) {
-        const a = matResponse({ mat, data: copy(initData) });
-        if (a.width) {
-          Object.assign(data, a);
-          return true;
-        }
+        return !!matResponse({ mat, data }).width;
       },
       callback,
     });
@@ -100,7 +93,7 @@ const { shape, tData, data, operateMenus, describes } = useComponentStatus<
     "fill",
     "stroke",
     "strokeWidth",
-    // "dash",
+    "dash",
     "opacity",
     "fontSize",
     "align",
@@ -117,7 +110,9 @@ watch(
     data.value.width = getWidth(data.value, 1);
     const $shape = shape.value?.getNode();
     $shape && $shape.fire("bound-change");
-  }
+    $shape?.draw();
+  },
+  { flush: "sync" }
 );
 
 const submitHandler = (val: string) => {

+ 1 - 1
src/core/hook/use-transformer.ts

@@ -522,7 +522,7 @@ export type CustomTransformerProps<
     data: T,
     mat: Transform,
     raw?: Transform
-  ) => Transform | void | true;
+  ) => Transform | void | boolean;
   callback?: (data: T, mat: Transform) => void;
   transformerConfig?: TransformerConfig;
 };

+ 2 - 2
src/core/viewer.ts

@@ -93,8 +93,8 @@ export class Viewer {
 
   scale(center: Pos, scale: number, initMat = this.viewMat) {
     const base = initMat.decompose().scaleX;
-    if (base * scale < 0.001 || base * scale > 1000) {
-      console.error("缩放范围0.001~1000 已超过范围无法缩放");
+    if (base * scale < 0.05 || base * scale > 50) {
+      console.error("缩放范围0.05~50 已超过范围无法缩放");
       return;
     }
     if (isNaN(center.x) || isNaN(center.y)) {