Skip to content

Commit c216f41

Browse files
Add SVG export for cells and libraries (#192)
## Summary - Add `cell_to_svg` and `library_to_svg` public functions to the `gdsr` crate - Render polygons, paths, boxes, text, and nodes as SVG elements with layer-based coloring (same 16-color palette as viewer) - Flatten cell references recursively so nested hierarchies render correctly - Auto-size viewport to bounding box with 5% margin - Flip Y axis (GDS Y-up → SVG Y-down) via SVG transform group - Escape text content for XML safety Closes #134 ## Test plan - 11 new snapshot tests covering each element type, reference flattening, multi-layer colors, XML escaping, empty cells, and Y-flip transform - Full test suite passes (691 tests) - All pre-commit checks pass --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 06194c0 commit c216f41

File tree

4 files changed

+542
-1
lines changed

4 files changed

+542
-1
lines changed

crates/gdsr/examples/sample.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use gdsr::{
22
Cell, DataType, Grid, HorizontalPresentation, Layer, Library, Path, PathType, Point, Polygon,
3-
Reference, Text, Unit, VerticalPresentation,
3+
Reference, Text, Unit, VerticalPresentation, cell_to_svg,
44
};
55

66
fn main() -> Result<(), gdsr::GdsError> {
@@ -155,5 +155,12 @@ fn main() -> Result<(), gdsr::GdsError> {
155155

156156
library.write_file("sample.gds", 1e-6, 1e-9)?;
157157

158+
let svg = cell_to_svg(
159+
library.get_cell("top").expect("top cell exists"),
160+
&library,
161+
1e-9,
162+
);
163+
std::fs::write("sample.svg", &svg).expect("failed to write SVG");
164+
158165
Ok(())
159166
}

crates/gdsr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ pub use traits::{Dimensions, Movable, ToGds, Transformable};
2727
pub use transformation::{Reflection, Rotation, Scale, Transformation, Translation};
2828
pub use types::{AngleInRadians, DataType, Layer, LayerMapping};
2929
pub use units::{DEFAULT_FLOAT_UNITS, DEFAULT_INTEGER_UNITS, FloatUnit, IntegerUnit, Unit};
30+
pub use utils::svg::cell_to_svg;

crates/gdsr/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod gds_format;
22
pub mod io;
3+
pub mod svg;

0 commit comments

Comments
 (0)