Dear All,

I am experimenting with the \D'.....' drawing command to produce barcodes in an attempt to create a generic solution which avoids the installation of a special barcode font.

The first experiment follows here. The logic is as follows. The macro .barcode is called with two arguments: (1) the sequence to be expressed as barcode and (2) the current position of the iterator. .barcode then picks the nth number and passes it to .printbar; .printbar in turn calls .Rbarcode and .Lbarcode with its appropriate pattern of whitespace and bars. Inside .barcode, currently the line "<\\*[mychain]>" is for diagnostic purposes only; it shows the current single digit of the barcode <n> which, at a later stage, should appear below its barcode.

So far, the logic to translate all digits of a given barcode number into black and white patterns works, but that's more or less all I could achieve so far.

My problems with this first attempt are twofold:

1. How do I control the size of the basic unit used by \D'P ... ' and \h'..' in order to get a nice display?

2. How do I make the barcodes to follow each other horizontally instead of each being displayed in a new line? I tried \c in various places but to no avail. Strangely enough, within .Rbarcode and .Lbarcode the sequence of \D and \h appears horizontally as desired.

Thank you all for pointing out the obvious flaws in my approach.

Best regards,

Oliver.


.\" vim:syntax=groff
.LP
.nr @hgt 2
.de Lbarcode
\h'\\$1p'
\D'P 0 -\n[@hgt] \\$2p 0 0 \n[@hgt]'
\h'\\$3p'
\D'P 0 -\n[@hgt] \\$4p 0 0 \n[@hgt]'
..
.de Rbarcode
\D'P 0 -\n[@hgt] \\$1p 0 0 \n[@hgt]'
\h'\\$2p'
\D'P 0 -\n[@hgt] \\$3p 0 0 \n[@hgt]'
\h'\\$4p'
..
.\" See section "Encoding" 
inhttps://en.wikipedia.org/wiki/Universal_Product_Code for a UPC-A barcode.
.de printbar
.nr X \\$1
.nr LR \\$2
.ie (\\n[LR] > 4) \{\
.if ( \\n[X] = 0 ) .Rbarcode 3 2 1 1
.if ( \\n[X] = 1 ) .Rbarcode 2 2 2 1
.if ( \\n[X] = 2 ) .Rbarcode 2 1 2 2
.if ( \\n[X] = 3 ) .Rbarcode 1 4 1 1
.if ( \\n[X] = 4 ) .Rbarcode 1 1 3 2
.if ( \\n[X] = 5 ) .Rbarcode 1 2 3 1
.if ( \\n[X] = 6 ) .Rbarcode 1 1 1 4
.if ( \\n[X] = 7 ) .Rbarcode 1 3 1 2
.if ( \\n[X] = 8 ) .Rbarcode 1 2 1 3
.if ( \\n[X] = 9 ) .Rbarcode 3 1 1 2
\}
.el \{\
.if ( \\n[X] = 0 ) .Lbarcode 3 2 1 1
.if ( \\n[X] = 1 ) .Lbarcode 2 2 2 1
.if ( \\n[X] = 2 ) .Lbarcode 2 1 2 2
.if ( \\n[X] = 3 ) .Lbarcode 1 4 1 1
.if ( \\n[X] = 4 ) .Lbarcode 1 1 3 2
.if ( \\n[X] = 5 ) .Lbarcode 1 2 3 1
.if ( \\n[X] = 6 ) .Lbarcode 1 1 1 4
.if ( \\n[X] = 7 ) .Lbarcode 1 3 1 2
.if ( \\n[X] = 8 ) .Lbarcode 1 2 1 3
.if ( \\n[X] = 9 ) .Lbarcode 3 1 1 2
\}
..
.de barcode
.ds mychain \\$1
.nr mypos \\$2
.substring mychain \\n[mypos] \\n[mypos]
<\\*[mychain]>
.printbar \\*[mychain] \\n[mypos]
..
My attempt:
.length @count 9876543210
.nr mynum 0 1
.while (\n[mynum] < \n[@count]) \{
.       barcode 9876543210 \n[mynum]
        \n+[mynum]\}




--
Dr. Oliver Corff
mailto:[email protected]

Reply via email to