Introduction
A Gerber image is built as an ordered stream of graphical objects: draws, arcs, flashes and regions. Each has dark or clear polarity and is laid over what came before. Dark adds material to the image, clear erases it. Draws, arcs and flashes are made with apertures.
Defining apertures
AD creates an aperture from a template and adds it to the aperture dictionary: %ADDntemplate[,p{Xp}]*%. Aperture numbers run from 10 to 2147483647, with optional leading zeros after D. D00 to D09 are reserved. A number cannot be assigned twice, and the aperture must be defined before it is used. The aperture attributes in the dictionary at that moment are attached to it.
| Template | Parameters | Shape |
|---|---|---|
C | diameter[Xhole] | Circle. Diameter 0 or more. A zero circle makes no image but can carry attributes. No other aperture may have zero size. |
R | xXy[Xhole] | Rectangle. Both sizes greater than 0. |
O | xXy[Xhole] | Obround: a rectangle whose shorter sides are rounded into half circles. |
P | diameterXvertices[Xrotation[Xhole]] | Regular polygon. Outer diameter greater than 0, 3 to 12 vertices. At rotation 0 one vertex is on the positive X axis. |
A hole is a centred circle with a diameter greater than 0 that fits strictly inside the shape. It is transparent: a flash does not clear what is under it. Examples: %ADD10C,0.1*%, %ADD11R,0.6X0.3X0.1*%, %ADD12P,1.0X6X30*%.
Dnn* makes a defined aperture current.
Macro apertures
%AMname*…% defines a template from primitives and variables. The name must be new and not that of a standard template. The macro must come before the first AD that uses it, and may be used by many. Attributes are attached to apertures, not to templates. Sizes are in the file unit. Line breaks may separate the words. The result is placed with the macro origin at the flash point.
| Code | Primitive | Parameters in order |
|---|---|---|
| 0 | Comment | A space, then text. |
| 1 | Circle | Exposure, diameter (0 or more), centre X, centre Y, optional rotation. |
| 20 | Vector line | Exposure, width (0 or more), start X, start Y, end X, end Y, rotation. The ends are square. |
| 21 | Centre line (rectangle) | Exposure, width, height (0 or more), centre X, centre Y, rotation. |
| 4 | Outline | Exposure, number of further points n (3 or more), start X, start Y, n X,Y pairs, rotation. The last point equals the start. At most 5000 vertices. The outline must obey the contour rules below, and its coordinates are not modal. |
| 5 | Regular polygon | Exposure, vertices (3 to 12), centre X, centre Y, diameter (0 or more), rotation. At rotation 0 the first vertex is on the positive X axis. |
| 7 | Thermal | Centre X, centre Y, outer diameter, inner diameter, gap width, rotation. Outer is larger than inner, inner is 0 or more, and the gap is less than the outer diameter divided by √2. The four gaps lie on the X and Y axes. If gap × √2 is at least the inner diameter, the inner circle disappears. Exposure is always on. |
Primitives 2, 6 and 22 are deprecated.
Exposure is 1 (on) or 0 (off). Off erases earlier primitives of the same macro only, leaving a transparent hole. The finished shape is one positive object. Rotation is in degrees counterclockwise, and is always about the macro origin, not the centre of the primitive.
Expressions and variables
A parameter may be an expression of unsigned decimals, variables $n (n a positive integer), brackets and the operators + and - (unary or binary), x (multiply, lower case) and /, with the usual precedence. $1, $2 and so on take the parameters given by AD. A word $n=expression* defines a further variable. Undefined variables are 0. Redefining a variable makes the file invalid.
%AMDonut*
1,1,$1,$2,$3*
$4=$1x0.5*
1,0,$4,$2,$3*%
%ADD20Donut,1.0X0X0*%
Operations
| Code | Syntax | Outside a region | Inside a region |
|---|---|---|---|
| D01 plot | [Xx][Yy][IiJj]D01* | Creates a draw or arc object, the current aperture stroked along the path. | Adds a segment to the contour. No aperture is used. |
| D02 move | [Xx][Yy]D02* | Moves the current point. | Closes the contour and starts another. |
| D03 flash | [Xx][Yy]D03* | Places the aperture origin at the point: the geometric centre of a standard aperture, or the macro origin. | Not allowed. |
A plot of zero length looks like a flash but is a draw object. Pads must be flashed.
Lines and arcs
G01 selects straight segments, G02 clockwise arcs and G03 counterclockwise arcs. G75 must be given before the first arc, otherwise the file is invalid. An arc D01 requires both I and J, the offsets from the start point to the centre. There is no default, so a zero offset is written I0 or J0. When the end point equals the start point the arc is a full circle.
The start and end radii need not be exactly equal. Any continuous curve from start to end that moves monotonically in angle and stays in the ring between the two radii is a valid reading. The centre must not lie on or near the line through start and end, except between them. Writers should replace arcs shorter than about 2 µm by straight segments, and split arcs that are nearly full circles.
Regions
G36* starts a region and G37* ends it. Between them only D01, D02, G01, G02 and G03 take part. Each contour starts after a D02 and must be closed explicitly, its last point exactly equal to its first. Contours are filled one by one and the region is their union, so separate contours cannot cut holes. Holes are made with cut-ins, or by laying clear objects over the region. Attribute commands are not allowed inside a region.
A contour is a chain of connected segments. It must be simple (its segments meet only at their joints, with no zero-length draws or full circles among several segments), or simple with cut-ins:
- A cut-in is a pair of fully coincident straight segments, horizontal or vertical.
- All cut-ins of one contour run in the same direction.
- A cut-in touches the contour only at its two ends.
Any other self-touching or crossing is forbidden, including partly overlapping segments, coincident diagonals or arcs, tangent arcs, a vertex lying on a segment, points where more than two segments end, and full circles (unless the circle is the whole contour or sits at the end of a cut-in). The direction of a contour does not matter. An invalid contour has no defined meaning.
Transformations
These commands set graphics state. Each holds until changed, replaces its earlier value rather than adding to it, and acts on the aperture about its own origin without altering the dictionary.
| Command | Values | Effect |
|---|---|---|
| LP | D, C | Dark or clear polarity of following objects. |
| LM | N, X, Y, XY | No mirroring, invert the signs of X, of Y, or of both. |
| LR | Decimal | Rotation in degrees counterclockwise. |
| LS | Decimal greater than 0 | Scale factor. |
Mirroring is applied before rotation. Polarity applies to regions too; mirroring, rotation and scaling do not. LM, LR and LS were added in revision 2016.12.
Block apertures
%ABDnn*% … %AB*% collects the objects made between the two commands into aperture nn, without an AD. Blocks may be nested, but hold no step and repeat. Inner blocks stay available for the rest of the file. The block origin is the point (0, 0) of the file. After the closing command the current point is undefined; the rest of the graphics state remains.
A block is an ordered list of objects, each with its own polarity. Flashing it applies mirroring, rotation and scaling to the whole block. Under dark polarity the objects are added as they are. Under clear polarity every polarity is toggled, through all levels of nesting. A flash updates the current point and otherwise leaves the graphics state unchanged.
Step and repeat
%SRXnxYnyIdxJdy*% opens a block and %SR*% closes it. The objects of the block are repeated nx by ny times at steps dx and dy. It is the objects that are copied, not the commands, so all copies are identical. The block is repeated first along Y, then along X. Where a repeat count is 1, a step of 0 is recommended. Blocks may hold dark and clear objects, and clear ones also erase what lies beneath outside the block. A file may have several step and repeat statements, one after another. The current point is undefined after the block.
Links
Reference
- Ucamco downloads – the Gerber Layer Format Specification (revision 2026.05) and its grammar