bodoni / svg

Composer and parser for SVG
Other
304 stars 44 forks source link

Add more documentation with examples #67

Open Makogan opened 1 year ago

Makogan commented 1 year ago

It would be helpful to have a few more small examples. One thing in particular would be how to add multiple objects. Like a square and a circle, both with different stroke styles.

As it stands one might thing that the way to do this would be:

let front = square(start, size);
    let path = Path::new()
        .set("fill", "none")
        .set("stroke", "black")
        .set("stroke-width", 3)
        .set("d", front);

    let back = Data::new()
        .move_to((start.0 - size / 5, start.1 + size / 5))
        .line_by((0, size))
        .line_by((size, 0))
        .line_by((0, -size))
        .close();

    let other_path = Path::new()
        .set("fill", "none")
        .set("stroke", "black")
        .set("stroke-width", 3)
        .set("d", back);

    path.add(other_path)
But no svg renderer accepts that as a valid output, they render only one of the 2 boxess.
jdvfx commented 1 year ago

Have a look at this repo: https://github.com/Lakret/gir/blob/master/mazes/src/draw.rs They're using into_iter().fold() to add paths from a Vec of Path into the document.

IvanUkhov commented 1 year ago

Yes, indeed the documentation is sparse. The assumption here is that the user is familiar with the format and knows what combines with what and how. The example you gave breaks against the rules (at least, I have not see nesting paths in paths), which are not enforced by the crate.

In any case, the format will probably not be explained here; it does not feel to belong. One could show more examples, but they will not be exhaustive, and one would run into problems still if there is no prior knowledge of the format.