-
Notifications
You must be signed in to change notification settings - Fork 309
Narrow to Wide Module Ratios
There is a class of linear bar codes that can be rendered with a variable narrow-to-wide module ratio. These bar code symbologies are comprised of two types of elements - a narrow element (both bars and spaces) and a wide element (both bars and spaces) - the ratio of which can be changed to suit length and readability requirements. Two of the more common bar code types that use this scheme are Code 39 and Code 2 of 5.
The module ratio is often written as 1:X, where X typically ranges between 2 and 3. For example, a ratio of 1:2.5 means that the wide elements of the bar code are 2.5 times the width of the narrow elements.
In most bar code libraries, you specify the narrow-to-wide module ratio as the single value X. BWIPP works a little differently as it uses math magic to implement the module ratio. While the math makes the rendering code very flexible, it requires the user to have some internal knowledge of the library. Specifically, you must know the wide-width value that is hard-coded into BWIPP in order to understand the resulting module ratio.
For the most part, the wide-width value is always 3, meaning the default narrow-to-wide ratio is 1:3. But there are some exceptions:
- Interleaved 2 of 5 (encoder
interleaved2of5
) and its derivatives use a wide-width of 2 but override the BWIPP optionsbarratio
andspaceratio
so the resulting default ratio is 1:3. More on this below. - MSI Modified Plessey (encoder
msi
) uses a wide-width of 2. Its default ratio is 1:2.
The math used by the linear renderer is as follows:
X = w * r - r + 1
Where X
is the resulting module ratio, w
is the hard-coded wide-width and r
is the magic number you must know to get the desired 1:X ratio. Since it would be nice to think about ratios in the usual 1:X notation, let's refactor the equation:
r = (X - 1) / (w - 1)
Now we can calculate the mapping of the 1:X ratios to BWIPP's magic ratios:
Wide Width | 1:2.0 | 1:2.25 | 1:2.33 | 1:2.5 | 1:2.67 | 1:2.75 | 1:3.0 | 1:3.5 | 1:4.0 | 1:4.5 |
---|---|---|---|---|---|---|---|---|---|---|
2 | 1.00 | 1.25 | 1.33 | 1.50 | 1.67 | 1.75 | 2.00 | 2.50 | 3.00 | 3.50 |
3 | 0.50 | 0.63 | 0.67 | 0.75 | 0.83 | 0.88 | 1.00 | 1.25 | 1.50 | 1.75 |
For example, if you are using Code 39 (which has a wide-width of 3) and desire a 1:2.5 module ratio, you would specify 0.75
. BWIPP uses two separate options when changing the module ratio, barratio
which affects only the bar widths and spaceratio
which affects only the space widths. As a rule, you should
always provide the same value for both, otherwise the resulting bar code may be non-conformant.
barratio=0.75 spaceratio=0.75
The following is a summary of the bar code types that support a variable module ratio:
Symbology | Ratio Range (X value) |
Wide Width | Bar/Space Defaults* |
Default Ratio |
---|---|---|---|---|
Code 2 of 5 | 2 - 4.5 | 3 | 1 | 1:3 |
IATA 2 of 5 | ||||
Industrial 2 of 5 | ||||
COOP 2 of 5 | ||||
Datalogic 2 of 5 | ||||
Matrix 2 of 5 | ||||
Interleaved 2 of 5 | 2 - 3 | 2 | 2 | 1:3 |
ITF 14 | ||||
DP Identcode | ||||
DP Leitcode | ||||
Code 39 | 2 - 3 | 3 | 1 | 1:3 |
Code 39 Extended | ||||
Italian Pharmacode/Code 32 | ||||
HIBC Code 39 | ||||
Pharmazentralnummer (PZN) | ||||
Code 11 | 2.25 - 3.5 | 3 | 1 | 1:3 |
(Rationalized) Codabar | 2 - 3 | 3 | 1 | 1:3 |
Telepen | 2 - 3 | 3 | 1 | 1:3 |
Telepen Numeric | ||||
MSI Modified Plessey | 2 - 3 | 2 | 1 | 1:2 |
* The Bar/Space Defaults column shows the default values used for the barratio
and spaceratio
options.