All barcode implementations are derived from the abstract glbarcode::Barcode class. The glbarcode::Barcode1dBase subclass of glbarcode::Barcode provides a common framework for the implementation of 1D barcodes. Therefore, creating new 1D barcode types (or symbologies) would be typically accomplished by implementing a subclass of this glbarcode::Barcode1dBase class rather than directly implementing the glbarcode::Barcode class.
A 1D barcode subclass must implement the following virtual methods (or callbacks):
glbarcode::Barcode1dBase::encode() – The encode method is used to encode data such that it can later be vectorized. The encoded data is usually a list of characters that represent an atomic barcode element. For example, the following is the character encoding used by the Code39 implementation:
| Character | Meaning |
|---|---|
| N | A narrow bar. |
| W | A wide bar. |
| n | A narrow space (gap between bars) |
| w | A wide space (gap between bars) |
| i | Inter-symbol gap |
Other encoding examples can be found in the existing barcode implementations.
A barcode subclass may also need to implement the following virtual methods:
The following figure illustrates the data flow between these methods, which are called by glbarcode::Barcode1dBase::build():
To be able to register a barcode type with the barcode factory, it must implement a static create method that returns a pointer to a newly allocated barcode:
This is used to register the barcode using glbarcode::Factory::registerType:
As a complete example, the following is the glbarcode++ implementation of a custom barcode type called "mybarcode".
MyBarcode.hpp:
MyBarcode.cpp:
Now to put it into action.
main.c:
This example will produce the following SVG file: