Git Product home page Git Product logo

Comments (4)

milksteakjellybeans avatar milksteakjellybeans commented on May 24, 2024

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

from jspaint.

1j01 avatar 1j01 commented on May 24, 2024

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, and draw_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:
    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);
    It would probably be slightly faster, but they say premature optimization is the root of all evil.

from jspaint.

milksteakjellybeans avatar milksteakjellybeans commented on May 24, 2024

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

from jspaint.

milksteakjellybeans avatar milksteakjellybeans commented on May 24, 2024

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

from jspaint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.