1j01 / jspaint

🎨 Classic MS Paint, REVIVED + ✨Extras
https://jspaint.app/about
MIT License
7.16k stars 562 forks source link

Blended/Anti-Aliased edges on rectangle tool #326

Closed milksteakjellybeans closed 7 months ago

milksteakjellybeans commented 9 months ago

I don't recall for sure if this is how the original mspaint tool worked, but in jspaint I'm seeing that the rectangle tool has a blended / anti-aliased edge. I seem to recall the rectangle tool making a sharp edge. I tried out the online emulator as per the contributing doc and see no blending in that version, it's got a sharp edge there. The polygon tool, ellipse and rounded rec tool don't have the same blending in jspaint that the rectangle tool has.

Would this be considered a bug?

I went ahead and "fixed" this locally

milksteakjellybeans commented 9 months ago

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,

example

1j01 commented 7 months ago

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:

milksteakjellybeans commented 7 months ago

Hi, thank you for your consideration and reply. I'll put together a PR shortly.

milksteakjellybeans commented 7 months ago

My first PR, hope I've done it correctly. Have a good day