turnage / valora

painting by functions
https://paytonturnage.gitbook.io/valora/
MIT License
686 stars 30 forks source link

Rendering compound bezier curves with holes #52

Open t-veor opened 3 years ago

t-veor commented 3 years ago

I'm trying to render glyphs by loading the control points from a font and issuing the relevant bezier curve commands to Canvas, and of course this happens when I try to render an O: image

This is because the O glyph consists of two paths in opposite winding directions (I've coloured the start and end points of each path segment going from red to green so I could see the winding directions):

image

But of course with me trying to render two paths and fill them in, the outer path just completely fills in the inner one. Is there a way to specify winding direction or something that lets me mark a path as negative space? I couldn't figure out how to move the pen without creating a new path.

One way which I've found which helps is to not close paths early and treat the whole glyph as one path, because it looks like the rasteriser treats overlaps in the path as negative space:

image

But of course this breaks rendering glyphs which are actually made out of multiple overlapping paths:

image

Although I will admit this has the possibility of looking cool.

I can't see a way of rendering bitmaps either with the drawing API, so I can't get around the problem by just rendering to bitmap and drawing it.

turnage commented 3 years ago

Thank you for filing a detailed issue! The API does not enable users to express this.

Lyon may allow it, which is what the master branch uses. I don’t think adding a winding option to the path would be an invasive change, just API plumbing iirc.

If Lyon doesn’t allow it, I’ll get to it the branch with the custom rasterizer.

I’m not going to do this soon though. I’m happy to review any pull requests addressing this issue if someone wants to upstream a solution.

Vào CN, 4 thg 10, 2020 lúc 6:12 CH Tyler Zhang notifications@github.com đã viết:

I'm trying to render glyphs by loading the control points from a font and issuing the relevant bezier curve commands to Canvas, and of course this happens when I try to render an O: [image: image] https://user-images.githubusercontent.com/22255669/95027915-11e3cb80-0694-11eb-9343-536d79826456.png

This is because the O glyph consists of two paths in opposite winding directions (I've coloured the start and end points of each path segment going from red to green so I could see the winding directions):

[image: image] https://user-images.githubusercontent.com/22255669/95027827-9124cf80-0693-11eb-9aa4-0e7fcb127c97.png

But of course with me trying to render two paths and fill them in, the outer path just completely fills in the inner one. Is there a way to specify winding direction or something that lets me mark a path as negative space? I couldn't figure out how to move the pen without creating a new path.

One way which I've found which helps is to not close paths early and treat the whole glyph as one path, because it looks like the rasteriser treats overlaps in the path as negative space:

[image: image] https://user-images.githubusercontent.com/22255669/95028243-d0085480-0696-11eb-9ac8-ec5c5b901403.png

But of course this breaks rendering glyphs which are actually made out of multiple overlapping paths:

[image: image] https://user-images.githubusercontent.com/22255669/95028264-f201d700-0696-11eb-8350-3e7e7ae378ef.png

Although I will admit this has the possibility of looking cool.

I can't see a way of rendering bitmaps either with the drawing API, so I can't get around the problem by just rendering to bitmap and drawing it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/turnage/valora/issues/52, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWR64EZ2EUT4ICBYKY462DSJDXN3ANCNFSM4SD7G27A .