Apply to scale to lineWidth.

This will only work if scaling is proportional, i.e. X and Y axes are scaled the same.
This commit is contained in:
k1w1 2022-07-17 11:08:10 -07:00
parent 6e7449a639
commit 87d8a34ed6
4 changed files with 17 additions and 0 deletions

View File

@ -433,6 +433,9 @@ export default (function () {
//fill-opacity or stroke-opacity has already been set by stroke or fill.
continue;
}
} else if (keys[i] === 'lineWidth') {
var scale = this.__getTransformScale();
value = value * Math.max(scale.x, scale.y);
}
//otherwise only update attribute if right type, and not svg default
currentElement.setAttribute(attr, value);

View File

@ -10,6 +10,7 @@ import globalAlpha from './tests/globalalpha'
import gradient from './tests/gradient'
import linecap from './tests/linecap'
import linewidth from './tests/linewidth'
import scaledLine from './tests/scaledLine'
import rgba from './tests/rgba'
import rotate from './tests/rotate'
import saveandrestore from './tests/saveandrestore'
@ -32,6 +33,7 @@ const tests = [
gradient,
linecap,
linewidth,
scaledLine,
rgba,
rotate,
saveandrestore,

View File

@ -11,6 +11,7 @@ import globalAlpha from './tests/globalalpha'
import gradient from './tests/gradient'
import linecap from './tests/linecap'
import linewidth from './tests/linewidth'
import scaledLine from './tests/scaledLine'
import rgba from './tests/rgba'
import rotate from './tests/rotate'
import saveandrestore from './tests/saveandrestore'
@ -33,6 +34,7 @@ const tests = {
gradient,
linecap,
linewidth,
scaledLine,
rgba,
rotate,
saveandrestore,

10
test/tests/scaledLine.js Normal file
View File

@ -0,0 +1,10 @@
export default function scaledLine(ctx) {
ctx.scale(1.5, 1.5);
for (var i = 0; i < 10; i++){
ctx.lineWidth = 1+i;
ctx.beginPath();
ctx.moveTo(5+i*14,5);
ctx.lineTo(5+i*14,140);
ctx.stroke();
}
};