Serenity: LibWeb/LibGfx: Path filling behaves incorrectly

Created on 9 May 2020  路  12Comments  路  Source: SerenityOS/serenity

Just filing an issue for the sake of having one - I haven't actually investigated what's causing this. Might or might not be easy to fix.

canvas-path-quadratic-curve.html:

image

Most helpful comment

I guess I'll hack something up :shrug:

All 12 comments

I believe that's because we don't implicitly close paths when trying to fill them.
don't quote me on that though.

It's actually kind of odd that firefox and chrome do this; maybe stroke() is supposed to close the path?

adding ctx.closePath() after stroke() makes it looks correct...
shot-2020-05-10_01-06-18

Some CRC2D ops indeed do implicit path closing!
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fill

Open subpaths must be implicitly closed when being filled

ouch.
we don't really have such a concept.
that's a weird thing to do...as expected from _the web_, nothing is ever straightforward.

Let's just do a naive solution for now? Make a copy of the path and call close() on it. Doesn't have to be perfect, just has to work at first :)

That would attempt to close the last segment, which is already closed.

unless I'm just remembering how close() works wrong

edit:
what's even going on in Path::close()? it looks like we're trying to close the first "open" path and then immediately exiting?

Path::close() is same semantics as CanvasRenderingContext2D.closePath:

Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.

What if we had multiple "open subpaths"?

fill() suggests that we have to close _all_ of them, but closePath() seems to suggest that we only close the last one?

Yeah, just calling close won't work, it'll try to connect the beginning of the bezier curve to the start point of the other shape:
shot-2020-05-10_01-30-03

Ahh I see! Yeah I misread the spec, we should indeed implicitly close all open subpaths.

I guess I'll hack something up :shrug:

Thanks guys, lovely watching you two figuring this out! :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BenWiederhake picture BenWiederhake  路  6Comments

bgianfo picture bgianfo  路  6Comments

nibblebits picture nibblebits  路  4Comments

howar6hill picture howar6hill  路  3Comments

awesomekling picture awesomekling  路  6Comments