lib_gerber_edit
A Rust library for manipulating RS-274X (Extended Gerber) and Excellon drill files,
built on top of gerber-parser.
All lengths in the public API are in millimetres.
[]
= "0.2"
Features
- Load a full PCB stackup from a folder or individual file readers
- Translate layers or a whole board by any offset
- Scale layers by independent X/Y factors (includes unit conversion)
- Merge two boards or layers of the same type
- Step-and-repeat — tile a pattern across a grid
- Bounding-box queries — with correct tool-width and arc accounting
- Vector text — render ASCII strings into a Gerber silkscreen layer with configurable size, line thickness, and horizontal/vertical alignment
- Error messages include the file name and line number of the failing layer
Quick start
Panelise a board (2 × 1 grid)
use Board;
use ;
use Path;
let mut board = from_folder.unwrap;
let size = board.get_size;
let mut copy = board.clone;
copy.transform; // 2 mm gap
board.merge;
board.write_to_folder.unwrap;
Render text onto a silkscreen layer
use Board;
use ;
use ;
use ;
use Path;
// Build a reusable format: 3 mm tall, centred on the origin.
let fmt = new
.h_align
.v_align;
// Produce two layers from the same format object.
let rev_layer = fmt.build;
let mut board = from_folder.unwrap;
board.add_layer;
board.write_to_folder.unwrap;
API overview
Core traits
| Trait | Key method | Description |
|---|---|---|
LayerCorners |
get_corners() -> (Pos, Pos) |
Axis-aligned bounding box (ink boundary, tool width included) |
LayerCorners |
get_size() -> Size |
Width/height derived from get_corners |
LayerTransform |
transform(&Pos) |
Translate all coordinates |
LayerScale |
scale(x, y) |
Multiply X and Y coordinates independently |
LayerMerge |
merge(&Self) |
Append another layer/board; aperture IDs are remapped |
LayerStepAndRepeat |
step_and_repeat(nx, ny, offset) |
Grid replication |
All traits are implemented for Board, GerberLayerData, ExcellonLayerData, and LayerData.
Board
from_folder // load all recognised layers from a directory
new // load from in-memory readers
board.add_layer // merge if type exists, insert otherwise
board.get_layer // look up a layer by type
board.write_to_folder // write all layers back to disk
GerberLayerData
empty // blank layer ready for commands
from_type // parse with explicit type
from_commands // infer type from FileAttribute
layer.write_to // serialise to RS-274X
AsciiText
new // character height in mm
.ratio // line thickness as fraction of size (default 1.0)
.h_align // Left (default) | Center | Right
.v_align // Bottom (default) | Middle | Top
.build
The origin (0, 0) of the returned layer corresponds to the chosen alignment anchor.
Supported layer types
| Extension | LayerType |
|---|---|
.gtl |
Top |
.gbl |
Bottom |
.glN |
Inner(N) |
.gts / .gbs |
MaskTop / MaskBottom |
.gto / .gbo |
SilkScreenTop / SilkScreenBottom |
.gtp / .gbp |
PasteTop / PasteBottom |
.gm1 |
Dimensions |
.gm2 |
Milling |
.gvc |
VCut |
.drd / .drl |
Drill (Excellon) |
.gbr |
UndefinedGerber (type read from FileAttribute) |
Notes
- Tested primarily with output from KiCad and Autodesk Eagle.
- Arc bounding boxes follow RS-274X §5.3 (multi-quadrant G75). Single-quadrant G74 arcs may have imprecise bounding boxes.
- The library is functional but still evolving — contributions welcome.
Sample boards
| Path | Source |
|---|---|
test/mobo |
opulo-inc/lumenpnp — CERN-OHL-W v2 |