High-performance C++ Gerber file parsing and rendering library with separation architecture design between parsing and rendering
- Separation of parsing and rendering: Core parser is completely decoupled from rendering engine for easy extension and customization
- Multiple rendering engine support: Provides QPainter and QGraphicsScene rendering backends
- High performance: Optimized parsing algorithms and memory management
- Cross-platform: Based on Qt framework, supports Windows, Linux, macOS
- Python bindings: Complete Python interface through pybind11
If this project has been helpful to you, please consider supporting our development work. Your support will help us continuously improve the project:
Click the "Donate" button above or support in other ways:
- ⭐ Star this project - Let more people see it
- 🐛 Submit Issues - Report problems or suggest features
- 📖 Improve documentation - Help enhance user guides
- 🔄 Share with other developers - Spread the open source spirit
src/
├── parser/ # Gerber file parser
│ ├── gerber_parser/ # Parser core implementation
│ ├── engine/ # Parser engine interface
│ └── parser/ # Various Gerber code parsers
├── engines/ # Rendering engines
│ ├── qpainter_engine.cpp/h # QPainter rendering engine
│ ├── qgraphics_scene_engine.cpp/h # QGraphicsScene rendering engine
│ └── transformation.cpp/h # Coordinate transformation tools
└── pygerber-parser/ # Python bindings
- Supports complete Gerber file format (RS-274X)
- Parses various aperture types: circular, rectangular, polygonal, elliptical, macro-defined
- Supports G codes, D codes, M codes, and other Gerber commands
- Provides bounding box calculation and coordinate transformation
- Error handling and logging
- QPainter engine: Lightweight, suitable for image export and simple display
- QGraphicsScene engine: Feature-rich, supports interactive viewing and editing
- Extensible rendering interface, easy to add new rendering backends
- CMake 3.20+
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2019+)
- Qt 6.0+
- Python 3.6+ (optional, for Python bindings)
# Clone the project
git clone https://github.com/hsiang-lee/gerber-parser.git
cd gerber-parser
# Initialize submodules
git submodule update --init --recursive
# Create build directory
mkdir build && cd build
# Configure the project
cmake .. -DCMAKE_BUILD_TYPE=Release
# Compile
make -j$(nproc)The project provides several example programs:
# Convert Gerber file to PNG image
./example/gerber2image/gerber2image --gerber_file="path/to/gerber/file" --um_pixel=5# Launch interactive Gerber file viewer
./example/gerber_viewer/gerber_viewer# Viewer using QGraphicsScene
./example/gerber_viewer_qgraphics/gerber_viewer_qgraphics#include "gerber_parser/gerber_parser.h"
#include "engines/qpainter_engine.h"
// Parse Gerber file
auto parser = std::make_shared<GerberParser>("path/to/gerber/file");
auto gerber = parser->GetGerber();
// Get bounding box information
const auto& bbox = gerber->GetBBox();
std::cout << "Width: " << bbox.Width() << " Height: " << bbox.Height() << std::endl;
// Render using QPainter
QPixmap image(800, 600);
auto engine = std::make_unique<QPainterEngine>(&image, bbox, 0.05);
engine->RenderGerber(gerber);
image.save("output.png");import pygerber_parser
import numpy as np
from PIL import Image
# Method 1: Using functional API
image_data = pygerber_parser.gerber2image("path/to/gerber/file", 800, 600)
# Convert to PIL image
arr = np.array(image_data, dtype=np.uint8).reshape((600, 800, 4))
img = Image.fromarray(arr, 'RGBA')
img.save("output.png")
# Method 2: Using object-oriented API
parser = pygerber_parser.GerberParser("path/to/gerber/file")
if parser.is_valid():
print(f"Size: {parser.get_width()} x {parser.get_height()}")
image_data = parser.render_to_image(800, 600)
# Process image data...For detailed Python usage guide, please refer to PYTHON_USAGE.md
- Inherit from the
RenderEnginebase class - Implement the
RenderGerbermethod - Add new engine files in the
engines/directory - Update the CMakeLists.txt file
- Add new parsers in the
src/parser/gerber_parser/directory - Implement the corresponding parsing logic
- Update the parser factory class
The project includes a complete test suite:
# Enable test building
cmake .. -DBUILD_TESTS=ON
# Run tests
make testTest data is located in the tests/test_data/gerber/ directory.
We welcome all forms of contributions! Please refer to the following steps:
- Fork this project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Create a Pull Request
- Follow the .clang-format configuration in the project
- Use meaningful variable and function names
- Add appropriate comments and documentation
- Ensure all tests pass
This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to the following open source projects for their support:
- Qt - Cross-platform application framework
- pybind11 - Python binding generator
- Google Test - C++ testing framework
- gflags - Command line argument parsing
- Project homepage: https://github.com/hsiang-lee/gerber-parser.git
- Issues: https://github.com/hsiang-lee/gerber-parser/issues
- Email: leehsiang@hotmail.com
Gerber Parser - Making PCB file processing easier!


