linebender / linebender/resvg

(`usvg`) Option to preserve primitive shapes (rect, ellipse, polygon)

Open
#974 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.1k
Forks
348
Avg merge
1d 14h
Merged PRs (30d)
3

Description

Hi. First of all, I want to thank for such dedicated works.

I am using usvg as drop in replacement of svgo and svgson (in js ecosystem) for the usecase of..
1. optimizging part (✅)
2. resolved values (✅)
3. mapping them into my own struct (❌)

As usvg currently only have (by design) `Group`, `Path`, `Image`, `Text`
And the primitive shapes being all converted to Path, which is a solid, simple and clean choice. BUT for my case, I actually need to preserve such ``, ``, `` as non-path-resolved primitive node.

Wondering if this might be a consideration.
And the effort needed to have such as opt-in feature (willing to contribute)

## Suggestions

**A. Extend `Node::Path`**
make `Node::Path` have extra auxilary properties, passed down from original shapes

```rs
#[derive(Clone, Debug)]
pub struct Path {
pub(crate) id: String,
pub(crate) visible: bool,
pub(crate) fill: Option,
pub(crate) stroke: Option,
pub(crate) paint_order: PaintOrder,
pub(crate) rendering_mode: ShapeRendering,
pub(crate) data: Arc,
...
pub(crate) original_element_tag: SVGElementType
pub(crate) original_element_attributes: HashMap
}
```

**B. Introduce `Node::Rect` and so on**
Introduce `Node::Rect` as standard Node

```rs
#[derive(Clone, Debug)]
pub struct Rectangle {
pub(crate) id: String,
pub(crate) visible: bool,
pub(crate) fill: Option,
pub(crate) stroke: Option,
pub(crate) paint_order: PaintOrder,
pub(crate) rendering_mode: ShapeRendering,
...
}
```

**C. callback for collecting data while traversal**
Callback system or plugin-like system, where I can collect data if certain element is converted to path, I can store that, use the style output from `Node::Path` while knowing the original attributes, rx, etc..

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with usvg's Node model, especially Node::Path and the conversion of primitive shapes into paths. Compare suggestions A, B, and C, then define an agreed opt-in design whose completion criteria specify how rect, ellipse, and polygon data are preserved while existing path behavior remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.