Skip to content

feat: add optional Inkscape-layer SVG export#279

Merged
spe-ciellt merged 2 commits intogerbv:developfrom
5shekel:feature/svg-export-layers
Feb 27, 2026
Merged

feat: add optional Inkscape-layer SVG export#279
spe-ciellt merged 2 commits intogerbv:developfrom
5shekel:feature/svg-export-layers

Conversation

@5shekel
Copy link
Copy Markdown
Contributor

@5shekel 5shekel commented Feb 24, 2026

note: this is generated code, prompt as follows

add option in svg export to output all gerber layers as svg layers, in inkscape style.

given the quality of this project, and lack of deep understanding from my side i cannot say this is valid PR.
it does work on my tests and is a feature i was craving for ages.
might be of interest to others.

image

Add a new SVG export option that preserves visible Gerber layers as Inkscape layers so exported artwork remains editable by layer. Wire the option into both CLI and GUI export flows and document usage in help/man text.

@5shekel 5shekel marked this pull request as draft February 24, 2026 10:29
@spe-ciellt
Copy link
Copy Markdown
Contributor

Hello @5shekel

Thank you for you pull request. Seems like a useful thing.

Tested the branch — builds clean, no regressions (89/100 pass, same 11 failures as develop baseline). That is because Cairo versioning thing, but it builds and is accepted by the regression tests in the pipeline. The feature works correctly; layered SVG output is well-formed and opens with proper Inkscape layers.

A few things worth addressing:

1. Nested <svg> inside layer groups
The output wraps each layer in a child <svg> inside the <g>, which is non-standard for Inkscape layers. Standard practice is to put drawing primitives directly in the <g>. It works in Inkscape but may behave oddly in other SVG editors. Not a blocker for a first version.

2. Partial output on error
If exportimage_render_svg_layers_from_project() fails mid-loop, it still writes the partial SVG to disk. Should either skip writing or g_unlink() the output file on error.

3. Silent background skip
exportimage_append_svg_background() silently skips pure white and pure black — worth a comment explaining why, since it'll surprise anyone who deliberately set a white background.

Final note
When you fix this, could you merge all commits into one and then force-push it to this branch? (git push --force-with-lease)

@spe-ciellt spe-ciellt self-assigned this Feb 24, 2026
@spe-ciellt spe-ciellt self-requested a review February 24, 2026 17:43
@spe-ciellt spe-ciellt added the enhancement New feature or request label Feb 24, 2026
@spe-ciellt spe-ciellt marked this pull request as ready for review February 24, 2026 17:44
static void
exportimage_append_svg_background (GString *svgOut, gerbv_project_t *gerbvProject) {
GdkColor *bg = &gerbvProject->background;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please elaborate on why this colors are changed. And also please use {} even if it is an one-liner on the if, for, while, etc.

if (svgText == NULL)
return NULL;

svgOpen = strstr (svgText, "<svg");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on wrapping inner block <svg>...</svg>.

Copy link
Copy Markdown
Contributor

@spe-ciellt spe-ciellt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do a review. This is really the first time using the github interface, so please bear with me. Else I just let the comment I wrote speak for itself.

Add SVG export options for CLI and GUI to emit visible Gerber files as Inkscape layer groups, and align the output structure for broader SVG editor compatibility. Prevent partial layered SVG files on export failures and document legacy white/black background handling behavior.
@5shekel 5shekel force-pushed the feature/svg-export-layers branch from f5ee365 to 8da9640 Compare February 24, 2026 19:09
@spe-ciellt
Copy link
Copy Markdown
Contributor

Re-checked after the two follow-up commits (8da9640, aa22e7d). All three issues from the earlier review have been addressed:

1. Nested <svg> inside layer groups — Fixed
exportimage_extract_svg_inner_content() now extracts only what's between the Cairo <svg> opening tag and </svg>, so each Inkscape layer <g> contains drawing primitives directly. No more nested <svg>.

2. Partial output file on error — Fixed
The function builds the entire SVG in a GString in memory and only writes to disk at the end, guarded by !hadError. A failed layer mid-loop leaves no partial file on disk.

3. Undocumented background skip — Fixed
The comment in exportimage_append_svg_background() now explains that white/black are intentionally skipped to stay consistent with the non-layered SVG export path.

One minor item still open: exportimage_extract_svg_inner_content() uses strstr/strchr/g_strrstr to slice up Cairo's SVG output. A short comment noting that this relies on Cairo's stable output format would help future maintainers. Not a blocker.

Tested the updated branch against example/hellboard/ (3 layers):

  • Builds clean
  • Output is valid XML; each <g inkscape:groupmode="layer"> contains <path> elements directly — no nested `
  • Layer z-order matches gerbv's normal rendering order (last_loaded → 0)
  • Cairo does not emit <defs>/clip-path for Gerber content, so the string-extraction approach loses nothing in practice (though worth a comment if that ever changes)
  • Pixel-for-pixel identical to the flat SVG export (ImageMagick compare -metric AE = 0)

Otherwise looks good — backward-compatible, feature works correctly.

@spe-ciellt spe-ciellt merged commit bda8447 into gerbv:develop Feb 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants