Quellcode durchsuchen

'图片及文本修改'

zhangyu vor 5 Jahren
Ursprung
Commit
d0a832feb2
2 geänderte Dateien mit 18 neuen und 13 gelöschten Zeilen
  1. 5 4
      saga-web-graph/src/items/SImageItem.ts
  2. 13 9
      saga-web-graph/src/items/STextItem.ts

+ 5 - 4
saga-web-graph/src/items/SImageItem.ts

@@ -54,6 +54,7 @@ export class SImageItem extends SObjectItem {
      */
     constructor(parent: SGraphItem | null, url?: string) {
         super(parent);
+        this.isTransform = false;
         if (url) this.url = url;
     } // Constructor
 
@@ -127,15 +128,15 @@ export class SImageItem extends SObjectItem {
             // @ts-ignore
             painter.drawImage(this.img, -width / 2, -height / 2, width, height);
             if (this.selected) {
-              painter.pen.lineWidth = painter.toPx(4);
-              painter.pen.lineDash = [painter.toPx(12), painter.toPx(28)];
+              painter.pen.lineWidth = 4;
+              painter.pen.lineDash = [12, 28];
               painter.pen.color = new SColor("#c0ccda");
               painter.brush.color = SColor.Transparent;
               painter.drawRect(this.boundingRect());
             }
         } else {
-            painter.pen.lineWidth = painter.toPx(1);
-            painter.pen.lineDash = [painter.toPx(3), painter.toPx(7)];
+            painter.pen.lineWidth = 1;
+            painter.pen.lineDash = [3, 7];
             painter.pen.color = new SColor("#c0ccda");
             painter.brush.color = SColor.Transparent;
             painter.drawRect(this.boundingRect());

+ 13 - 9
saga-web-graph/src/items/STextItem.ts

@@ -102,6 +102,7 @@ export class STextItem extends SObjectItem {
         this._text = str;
         this._font = new SFont("sans-serif", 12);
         this.height = 12;
+        this.isTransform = false;
     } // Constructor
 
     /**
@@ -137,10 +138,10 @@ export class STextItem extends SObjectItem {
         }
         if (this.borderStyle == SLineStyle.Dashed) {
             painter.pen.lineDash = [
-                painter.toPx(this.lineWidth * 3),
-                painter.toPx(this.lineWidth * 7)
+                this.lineWidth * 3,
+                this.lineWidth * 7
             ];
-            painter.pen.lineWidth = painter.toPx(this.lineWidth);
+            painter.pen.lineWidth = this.lineWidth;
             painter.brush.color = this.backgroundColor;
             painter.pen.color = this.strokeColor;
             painter.drawRect(this.boundingRect());
@@ -152,8 +153,8 @@ export class STextItem extends SObjectItem {
         this._textArr.forEach((text: string, index: number) => {
             painter.drawText(
                 text,
-                2,
-                index * (this.font.size + 2) + 2,
+                (this.font.size / 4),
+                index * (this.font.size * 1.25) + (this.font.size / 4),
                 this.maxWidth
             );
         });
@@ -165,19 +166,22 @@ export class STextItem extends SObjectItem {
      */
     protected drawFormatText(): void {
         if (this._painter instanceof SPainter) {
+            this._painter.save();
+            this._painter.font = this.font;
             let textMaxWidth = 0;
-            let textHeight: number = this.font.size;
+            let fontSize: number = this.font.size;
             this._textArr.forEach((text: string, index: number) => {
                 let textWidth: number = this._painter
-                    ? this._painter.textWidth(text) + 4
-                    : 4;
+                    ? this._painter.textWidth(text) + (fontSize / 2)
+                    : (fontSize / 2);
                 if (textWidth > textMaxWidth) {
                     textMaxWidth = textWidth;
                 }
             });
             // 在绘制文本后计算文本的宽高
             this.width = textMaxWidth;
-            this.height = (textHeight + 2) * this._textArr.length;
+            this.height = (fontSize * 1.25) * this._textArr.length + (fontSize / 8);
+            this._painter.restore();
         }
     } // Function drawFormatText()