Re-stroking paths creates unexpected fills
See original GitHub issueExpected Behaviour
In this code:
const ctx = canvas.getContext('2d');
ctx.beginPath() // Only needed in pureimage :/
// First sub-path
ctx.lineWidth = 26;
ctx.strokeStyle = 'rgba(255,165,0,0.5)'
ctx.moveTo(20, 20);
ctx.lineTo(160, 20);
ctx.stroke();
// Second sub-path
ctx.lineWidth = 14;
ctx.strokeStyle = 'rgba(0,255,0,0.5)'
ctx.moveTo(20, 80);
ctx.lineTo(220, 80);
ctx.stroke();
// Third sub-path
ctx.lineWidth = 4;
ctx.strokeStyle = 'rgba(255,192,203,0.5)'
ctx.moveTo(20, 140);
ctx.lineTo(280, 140);
ctx.stroke();
- Lines should be parallel
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/stroke#re-stroking_paths
Actual Behaviour
- lines are mostly parallel, with lots of diagonal fills
Steps To Reproduce
- Minimal: https://stackblitz.com/edit/koa-starter-yrc77r?file=index.js
- Workaround https://stackblitz.com/edit/koa-starter-zvulkw?file=index.js
- Where I had to workaround this bug: https://stackblitz.com/edit/feathersjs-7kqlyt?file=server.js
Any Relevant Code Snippets
Full koa server for testing:
import Koa from 'koa'
import { make, encodePNGToStream } from 'pureimage'
import { createWriteStream } from 'fs'
import logger from 'koa-logger'
import Router from '@koa/router'
import serve from 'koa-static'
const filepath = '/tmp/output.png'
function stroker(canvas) {
const ctx = canvas.getContext('2d')
ctx.beginPath()
// First sub-path
ctx.lineWidth = 26
ctx.strokeStyle = 'rgba(255,165,0,0.5)'
ctx.moveTo(20, 20)
ctx.lineTo(160, 20)
ctx.stroke()
// Second sub-path
ctx.lineWidth = 14
ctx.strokeStyle = 'rgba(0,255,0,0.5)'
ctx.moveTo(20, 80)
ctx.lineTo(220, 80)
ctx.stroke()
// Third sub-path
ctx.lineWidth = 4
ctx.strokeStyle = 'rgba(255,192,203,0.5)'
ctx.moveTo(20, 140)
ctx.lineTo(280, 140)
ctx.stroke()
}
const webCanvas = (ctx) => {
ctx.body = `
<h3>Expected Behavior:</h3>
<canvas id="canvas"></canvas>
<h3>Actual Behavior:</h3>
<img src="output.png" />
<script>
${stroker.toString()}
stroker(document.getElementById('canvas'))
</script>
`
}
const app = new Koa()
// middlewares
app.use(logger())
const router = Router()
router.get('/', webCanvas)
app.use(serve('/tmp'))
app.use(router.routes())
// Run canvas code on server
try {
const canvas = make(300, 150)
stroker(canvas)
await encodePNGToStream(canvas, createWriteStream(filepath))
console.log('done writing to ', filepath)
app.listen(3030)
} catch (err) {
// When a request is aborted - err is an AbortError
console.error(err)
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to fix the following unexpected clipping path? - TeX
I want to shade as follows. enter image description here. However, my code below produces an unexpected result as follows. enter image ...
Read more >Unexpected behaviour of JavaFX GraphicsContext.translate
When I stroke or fill a path after I have called the translate method ... Stroking text however, seems to paint the text...
Read more >femtovg/README.md at master · femtovg/femtovg · GitHub
Bézier paths filling and stroking; Solid color and image pattern fills and strokes; Gradients - box, linear and radial; Stroke width and miterlimit...
Read more >Why Are Open Paths an Issue With Stock Sites? (And How to ...
Open shapes that are unfilled are okay. That is, any path that has a stroke color but no fill color can remain open....
Read more >cairo_t: Cairo: A Vector Graphics Library
To draw with cairo, you create a cairo_t, set the target surface, and drawing options ... As an example, here is how one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just pushed back a fix. Can you see if the latest on MAIN fixes it? If so I’ll push out a release.
I’ve pushed the changes back and released a patch update on NPM. I’m going to mark this bug fixed. The remaining issues you see I think are due to color blending bugs (perhaps linear vs non-linear?).