The abstract glbarcode::Barcode class is the base class for all glbarcode++ barcode types. This class provides the core interface for these implementations.
The first step in generating a barcode is accomplished by instantiating the appropriate concrete barcode class. These concrete classes are derived from the glbarcode::Barcode base class. glbarcode++ currently includes the following concrete barcode classes:
Class | Symbology | Type ID | Notes |
---|---|---|---|
glbarcode::BarcodeCode39 | Code39 | "code39" | |
glbarcode::BarcodeCode39Ext | Extended Code39 | "code39ext" | Code39 with extended encoding to support full ASCII data. |
glbarcode::BarcodeUpcA | UPC-A | "upc-a" | |
glbarcode::BarcodeEan13 | EAN-13 | "ean-13" | |
glbarcode::BarcodeOnecode | USPS ONECODE | "onecode" | |
glbarcode::BarcodePostnet | USPS POSTNET | "postnet" | Supports all valid USPS data lengths: 5, 8 and 11. |
glbarcode::BarcodePostnet5 | USPS POSTNET-5 | "postnet-5" | Only supports data length of 5 (ZIP only) |
glbarcode::BarcodePostnet9 | USPS POSTNET-9 | "postnet-9" | Only supports data length of 9 (ZIP+4) |
glbarcode::BarcodePostnet11 | USPS POSTNET-11 | "postnet-11" | Only supports data length of 11 (ZIP+4+DC) |
glbarcode::BarcodeCepnet | CEPNET | "cepnet" | Brazilian Post barcode. Based on USPS POSTNET. |
glbarcode::BarcodeDataMatrix | Data Matrix | "datamatrix" | Data Matrix IEC16022 ECC 200 |
glbarcode::BarcodeQrcode | QR Code | "qrcode" | Simple front-end to libqrencode. |
For example, to instantiate a Code39 barcode object:
Barcodes can also be instantiated using the glbarcode::Factory barcode factory.
A list (TypeIdList
) of supported barcode type IDs can be obtained with the getSupportedTypes()
method. A type ID is simply a standard string (std::string). For example:
Finally, a barcode is instantiated using the createBarcode()
method. For example, to instantiate a Code39 barcode object:
where "code39" is the corresponding type ID string from the table in Concrete Barcode Classes. Valid IDs can also be obtained using the getSupportedTypes()
method as described above.
The glbarcode::Barcode class currently supports the following options that may be applied to any barcode type:
Options are set using the appropriate set accessor methods. These set accessors are designed to allow chaining of multiple accessors as in the following example code:
Options can also be queried using the appropriate get accessors, as in the following example code:
Individual concrete barcode classes may also implement options specific to its barcode type or symbology.
A barcode is "built" using the glbarcode::Barcode::build() method:
where
data
is a string
containing the raw barcode data to be encodedw
is the requested width of the barcode in points (1 point = 1/72 inch). This parameter is only a suggestion – the actual width of the resulting barcode may differ due to requirements for minimum symbol sizes for the specific symbology standard. Setting w=0 will allow the barcode's height to be autosized based on a nominal symbol size.h
is the requested height of the barcode in points (1 point = 1/72 inch). This parameter is only a suggestion – the actual height of the resulting barcode may differ due to requirements for minimum symbol sizes for the specific symbology standard. Setting w=0 will allow the barcode's height to be autosized based on a nominal symbol size.Barcodes are rendered using the glbarcode::Barcode::render() method:
where
renderer
is a glbarcode::Renderer.glbarcode++ currently provides the following renderers:
Class | Description |
---|---|
glbarcode::RendererDebug | A renderer that simply prints drawing information to stdout . |
glbarcode::RendererSvg | Scalable Vector Graphics (SVG) renderer. Can render to a given filename or to stdout . |
glbarcode::RendererEps | Encapsolated Postscript (EPS) renderer. Can render to a given filename or to stdout . |
For example, the following will render barcode
to an SVG file named "example.svg":
The following simple program will create a Code39 barcode object encoding the data "EXAMPLE-123" and rendering it to an SVG file named "Example.svg":
This example will produce the following SVG file: