From 87d8a34ed666bd7c4cbca27025d01e91b9dce216 Mon Sep 17 00:00:00 2001 From: k1w1 Date: Sun, 17 Jul 2022 11:08:10 -0700 Subject: [PATCH] Apply to scale to lineWidth. This will only work if scaling is proportional, i.e. X and Y axes are scaled the same. --- context.js | 3 +++ test/index.js | 2 ++ test/rendering.test.js | 2 ++ test/tests/scaledLine.js | 10 ++++++++++ 4 files changed, 17 insertions(+) create mode 100644 test/tests/scaledLine.js diff --git a/context.js b/context.js index 50e067b..873455b 100644 --- a/context.js +++ b/context.js @@ -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); diff --git a/test/index.js b/test/index.js index 1e9ace3..7fa08c5 100644 --- a/test/index.js +++ b/test/index.js @@ -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, diff --git a/test/rendering.test.js b/test/rendering.test.js index 4f01cfa..4e35894 100644 --- a/test/rendering.test.js +++ b/test/rendering.test.js @@ -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, diff --git a/test/tests/scaledLine.js b/test/tests/scaledLine.js new file mode 100644 index 0000000..0a910b4 --- /dev/null +++ b/test/tests/scaledLine.js @@ -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(); + } +}; \ No newline at end of file