use `line` svg element for straight lines

This commit is contained in:
abakkk 2020-06-07 20:08:42 +02:00
parent 5b7d1eedf4
commit 2c632c3d3a
1 changed files with 12 additions and 2 deletions

14
draw.js
View File

@ -1003,7 +1003,14 @@ const DrawingElement = new Lang.Class({
let color = this.eraser ? bgColor : this.color; let color = this.eraser ? bgColor : this.color;
let isStraightLine = this.shape == Shapes.LINE && (points.length < 3 || points[2] == points[1] || points[2] == points[0]); let isStraightLine = this.shape == Shapes.LINE && (points.length < 3 || points[2] == points[1] || points[2] == points[0]);
let fill = this.fill && !isStraightLine; let fill = this.fill && !isStraightLine;
let attributes = `fill="${fill ? color : 'transparent'}" ` + let attributes;
if (isStraightLine)
attributes = `stroke="${color}" ` +
`stroke-width="${this.line.lineWidth}" ` +
`stroke-linecap="${LineCapNames[this.line.lineCap].toLowerCase()}"`;
else
attributes = `fill="${fill ? color : 'transparent'}" ` +
`stroke="${color}" ` + `stroke="${color}" ` +
`${fill ? '' : 'fill-opacity="0"'} ` + `${fill ? '' : 'fill-opacity="0"'} ` +
`stroke-width="${this.line.lineWidth}" ` + `stroke-width="${this.line.lineWidth}" ` +
@ -1018,7 +1025,10 @@ const DrawingElement = new Lang.Class({
row += ` C ${points[0][0]} ${points[0][1]}, ${points[1][0]} ${points[1][1]}, ${points[2][0]} ${points[2][1]}`; row += ` C ${points[0][0]} ${points[0][1]}, ${points[1][0]} ${points[1][1]}, ${points[2][0]} ${points[2][1]}`;
row += `${fill ? 'z' : ''}"/>`; row += `${fill ? 'z' : ''}"/>`;
} else if (this.shape == Shapes.NONE || this.shape == Shapes.LINE) { } else if (this.shape == Shapes.LINE) {
row += `<line ${attributes} x1="${points[0][0]}" y1="${points[0][1]}" x2="${points[1][0]}" y2="${points[1][1]}"/>`;
} else if (this.shape == Shapes.NONE) {
row += `<path ${attributes} d="M${points[0][0]} ${points[0][1]}`; row += `<path ${attributes} d="M${points[0][0]} ${points[0][1]}`;
for (let i = 1; i < points.length; i++) for (let i = 1; i < points.length; i++)
row += ` L ${points[i][0]} ${points[i][1]}`; row += ` L ${points[i][0]} ${points[i][1]}`;