Comments (4)
Looks like this happens in Firefox (117.0.1) but not Safari (latest), so maybe it's a bug on the Firefox side.
Here's the hack I used to have sharp edges in Firefox (and still Safari), if anyone finds themself in the same boat,
src/tools.js
845,846c845,851
< // @TODO: shouldn't that be ~~(stroke_size / 2)?
< ctx.strokeRect(x + stroke_size / 2, y + stroke_size / 2, w - stroke_size, h - stroke_size);
---
> ctx.save();
> ctx.fillStyle = ctx.strokeStyle;
> ctx.fillRect(x, y, stroke_size, h);
> ctx.fillRect(x+w-stroke_size, y, stroke_size, h);
> ctx.fillRect(x, y, w, stroke_size);
> ctx.fillRect(x, y+h-stroke_size, w, stroke_size);
> ctx.restore();
And here's a shot of the box tool in Firefox at each line width (with View -> Zoom -> Large Size selected), to see what I mean,
from jspaint.
This is a bug due to some unknown changes in Firefox. I would pinpoint the changes with git bisect
but Firefox apparently takes 30GB of disk space to compile from source code.
Your fix looks good, and I would accept a PR with your changes. Or I could commit it and give you credit in the commit message.
Alternatives considered:
- Could use
draw_polygon
since a rectangle is a polygon, but getting the stroke lined up by its outside rather than its center would require offsetting it, anddraw_polygon
currently requires WebGL. I would rather reduce the need for WebGL, rather than expand it, since WebGL can crash. - The following works in Firefox 119.0, but not in Chrome, and I wouldn't be surprised if it broke in the future:
It would probably be slightly faster, but they say premature optimization is the root of all evil.
const offset = Math.round(stroke_size / 2) + (stroke_size % 2 === 0 ? 0.5 : 0); ctx.strokeRect(x + offset, y + offset, w - stroke_size, h - stroke_size);
from jspaint.
Hi, thank you for your consideration and reply. I'll put together a PR shortly.
from jspaint.
My first PR, hope I've done it correctly. Have a good day
from jspaint.
Related Issues (20)
- "Width" field is not focused and selected when opening Image -> Attributes... HOT 3
- How to open multiple windows in electron macOS? HOT 2
- why does electron app make requests to internet when started? HOT 4
- Bucket tool went weird today HOT 5
- i cant draw after making 1 brushstroke or anything on the canvas HOT 3
- Pixel data offset field from the BMP header is ignored
- The Recover Document (Woah!) pop-up still occurs despite the following HOT 2
- every stroke i make does not save on the canvas and keeps deleting the previous one HOT 31
- [feature] comic creator
- Shortcut keys?
- Pasted screenshots show up twice as big (HiDPI Retina screenshot) HOT 1
- Error when changing eraser size with keyboard
- Internal copy not working on macOS Safari
- Error trying to paste a screenshot on Windows 11
- Errors trying to paste/open an SVG file
- Shift+Insert, Ctrl+Insert, and Ctrl+Delete shortcuts throw errors HOT 1
- .bmp file saves incorrectly
- [feature] Windows 3.1 style tools HOT 1
- Canvases for palette colors and tool options become blank
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jspaint.