Gerber and NC drill file to SVG converter
Gerber and NC drill file to SVG converter for Node and the browser.
$ npm install --save gerber-to-svg
var gerberToSvg =var converter =
See the API documentation for full details.
$ npm install -g gerber-to-svg
$ gerber2svg [options] -- gerber_files
|switch||type||what it does|
||string||specify an output directory|
||boolean||do not print warnings and messages|
||int||indent output with this length tabs (2 if unspecified)|
||color||give the layer this color (defaults to "currentColor")|
||boolean||append .svg rather than replacing the existing extension|
||array||override coordinate decimal places format with '[INT,DEC]'|
||string||override zero suppression with 'L' or 'T'|
||string||set backup units to 'mm' or 'in'|
||boolean||set backup absolute/incremental notation with 'A' or 'I'|
||boolean||rearrange trace paths by to occur in physical order|
||boolean/number||optimize paths and fill gaps smaller than 0.00011 (or specified number) in layer units|
||boolean||display version information|
||boolean||display this help text|
$ gerber2svg gerber.gbr- convert gerber.gbr and output to stdout
$ gerber2svg -o out gerber.gbr- convert and output to out/gerber.svg
$ gerber2svg -o out -a gerber.gbr- output to out/gerber.gbr.svg
Since Gerber is just a vector image format, this library takes in a Gerber file and spits it out in a different format, namely SVG. This converter uses RS-274X and strives to be true to the latest format specification.
Everywhere that is "dark" or "exposed" in the Gerber (think a copper trace or a line on the silkscreen) will be "currentColor" in the SVG. You can set this with the "color" CSS property or the "color" attribute in the SVG node itself.
Everywhere that is "clear" (anywhere that was never drawn on or was drawn on but cleared later) will be transparent. This is accomplished though judicious use of SVG masks and groups.
The bounding box is carefully calculated as the file is being converted, so the
height of the resulting SVG should be nearly (if not exactly) the real world size of the Gerber image. The SVG's
viewBox is in 1000x Gerber units, so its
min-y values can be used to align SVGs generated from different board layers.
Excellon / NC drill files do not have a completely clearly defined spec, so drill file parsing is lenient in its attempt to generate an image. It should auto-detect when a drill file has been entered. You may need to override parsing settings (see API.md) to get drill files to render properly if they do not adhere to certain assumptions. The library must make these assumptions because Excellon does not define commands for certain formatting decisions.
Clone and then
$ npm install. Please accompany all PRs with applicable tests (unit and/or visual). Please test your code in browsers, as Travis CI cannot run browser tests for PRs.
$ npm test- run the tests, calculate coverage, and lint
$ npm run test:watch- run the tests on code changes (does not lint nor cover)
$ npm run lint- lint the code (will be run as a pre-commit script)
$ npm run test:browser- run the unit tests in a local browser
$ npm run test:sauce- run the units tests in several browsers using Open Sauce (Sauce Labs account and local .zuulrc required)
The visual test suite made up of sample Gerber files and expected (looks-like) results. Expected SVGs are output from gerbv or hand-coded if the gerbv render is incorrect. Sample files live in test-visual/gerber and expected results live in test-visual/expected.
To run the visual tests, run
$ npm run test:visual and point your browser to localhost:4242. Refreshing the page will re-render the files.