TinyVG / specification

The specification for TinyVG. This is the central authority for the file system
https://tinyvg.tech/
MIT License
238 stars 6 forks source link

[Proposal] Add line caps #4

Open ikskuh opened 2 years ago

ikskuh commented 2 years ago

Someone asked me if line caps aren't in TinyVG. We maybe should add them, but they could be emulated with some path element as well.

neinseg commented 2 years ago

Even if user-configurable line caps / joins are not part of the standard, it would be very useful to have at least a defined default. AFAICT the spec currently does not say anything about how line caps and joins are supposed to be drawn, which makes it ambiguous. In particular it is unclear whether the default is a "butt" or "square" line cap.

ikskuh commented 2 years ago

The default right now is round, and this is definitly missing in the spec

neinseg commented 2 years ago

The example pictures for "draw lines" and "draw line strip" currently do not use round caps. The source SVG files do not have the line caps specified as part of the paths' style, so they default to "butt". In case line caps are configurable maybe it would be worth it using the same default as SVG just to avoid confusion?

ikskuh commented 2 years ago

Looking at the encoding of lines, this would require some restructuring of the encoding as we need at least one bit for round or square line endings. I don't think butt is a visually pleasing line ending, but i'm considering adding all three.

What are some cases of butt line endings?

For encoding, it would be possible to strip two bits off the line_width unit field, as it doesn't make much sense to have a line thickness of 1/4th of the image.

Accepting this for now, let's see how hard an implementation of this is.

neinseg commented 2 years ago

What are some cases of butt line endings?

Here's an example of something that you cannot easily represent without them. Left is with butt ending, right is how it would look with square ends.

butt line endings

You can easily map square ends to butt ends by extending the path tangentially by half the line width, but not the other way around. Without butt endings, any path with a thick stroke that has curvature near the ends has to be rendered into a filled outline instead.

ikskuh commented 2 years ago

Okay, so you say we should settle on butt or round? I'm okay with that!

neinseg commented 2 years ago

Yeah, that sounds good to me. Implementing a square to butt mapper in something like an SVG converter should be straightforward.