|
@@ -9,6 +9,8 @@ import { elementService } from "../Service/ElementService.js";
|
|
|
import UIEvents from "@/graphic/enum/UIEvents.js";
|
|
|
import VectorCategory from "@/graphic/enum/VectorCategory.js";
|
|
|
import Settings from "@/graphic/Settings.js";
|
|
|
+import { Canvg } from 'canvg'
|
|
|
+import SVGIcons from "../CanvasStyle/ImageLabels/SVGIcons";
|
|
|
|
|
|
const imgCache = {};
|
|
|
const help = {
|
|
@@ -727,20 +729,36 @@ export default class Draw {
|
|
|
}
|
|
|
|
|
|
drawSVG(vector) {
|
|
|
- let points = [];
|
|
|
- for (let i = 0; i < vector.points.length; ++i) {
|
|
|
- const point = coordinate.getScreenXY(vector.points[i]);
|
|
|
- points.push(point);
|
|
|
- }
|
|
|
+ const points = vector.points.map(coordinate.getScreenXY.bind(coordinate))
|
|
|
+ const svgWidth= 64
|
|
|
+ const svgHidth= 64
|
|
|
+ const width = mathUtil.getDistance(points[0], points[1])
|
|
|
+ const height = mathUtil.getDistance(points[0], points[3])
|
|
|
+ const dires = [points[0], {...points[0], x: 10000}, points[1]]
|
|
|
+ let angle = mathUtil.Angle(...dires) * (Math.PI / 180)
|
|
|
+ angle = mathUtil.isClockwise(dires) ? angle : -angle;
|
|
|
+
|
|
|
this.context.save();
|
|
|
- this.context.beginPath();
|
|
|
- this.context.moveTo(points[0].x, points[0].y);
|
|
|
- this.context.lineTo(points[1].x, points[1].y);
|
|
|
- this.context.lineTo(points[2].x, points[2].y);
|
|
|
- this.context.lineTo(points[3].x, points[3].y);
|
|
|
- this.context.closePath();
|
|
|
- this.context.stroke();
|
|
|
- this.context.restore();
|
|
|
+ this.context.translate(points[0].x, points[0].y)
|
|
|
+ this.context.rotate(angle)
|
|
|
+ this.context.scale(width / svgWidth, height / svgHidth)
|
|
|
+ const [style] = help.setVectorStyle(this.context, vector)
|
|
|
+ this.context.lineWidth = style.lineWidth / (width / svgWidth)
|
|
|
+ SVGIcons.keche_plane.draw(this.context)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (import.meta.env.DEV) {
|
|
|
+ this.context.restore();
|
|
|
+ this.context.beginPath();
|
|
|
+ this.context.moveTo(points[0].x, points[0].y);
|
|
|
+ this.context.lineTo(points[1].x, points[1].y);
|
|
|
+ this.context.lineTo(points[2].x, points[2].y);
|
|
|
+ this.context.lineTo(points[3].x, points[3].y);
|
|
|
+ this.context.closePath();
|
|
|
+ this.context.stroke();
|
|
|
+ this.context.restore();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
drawLineText(vector, style) {
|