[Barcode] Some questions about barcode-0.95

Franz Zahaurek fzk@gams.at
31 Oct 2000 00:41:14 +0100


Hello,

Alessandro Rubini <rubini@gnu.org> writes:

Please excuse the lenghty replay, I try to be as short as possible.

> Hi.
> 
> > I have the following suggestions to make it even more usefull:
> > 
> > *) The generated PS-code uses absolut values for positioning. Why not
> > use normalized values and scale in x/y-direction?
> 
> Sorry, I didn't understand.

The question was not clear, sorry. I show by example what I ment:

A statement like:
barcode -u mm -e 39 -b '*1234-56789*' -g 50x20 >50x20.ps

gives lines like:

...
% 013113131111311313111311311113111331111313133111111111331113113111131313113311111113331111111131131313113113111113311311113113131111331113111131131311

 0.44 setlinewidth  10.29  12.95 moveto 0 53.05 rlineto stroke
 0.44 setlinewidth  12.65  12.95 moveto 0 53.05 rlineto stroke
 1.62 setlinewidth  14.42  12.95 moveto 0 53.05 rlineto stroke
 1.62 setlinewidth  16.78  12.95 moveto 0 53.05 rlineto stroke
...
 1.62 setlinewidth 146.58  12.95 moveto 0 53.05 rlineto stroke
 1.62 setlinewidth 148.94  12.95 moveto 0 53.05 rlineto stroke
 0.44 setlinewidth 150.71  12.95 moveto 0 53.05 rlineto stroke


And a statement like:
barcode -u mm -e 39 -b '*1234-56789*' -g 100x20 >100x20.ps

produces lines like:

...
% 013113131111311313111311311113111331111313133111111111331113113111131313113311111113331111111131131313113113111113311311113113131111331113111131131311
 1.03 setlinewidth  10.59  15.92 moveto 0 50.08 rlineto stroke
 1.03 setlinewidth  15.33  15.92 moveto 0 50.08 rlineto stroke
 3.40 setlinewidth  18.88  15.92 moveto 0 50.08 rlineto stroke
 3.40 setlinewidth  23.62  15.92 moveto 0 50.08 rlineto stroke
...
 3.40 setlinewidth 284.12  15.92 moveto 0 50.08 rlineto stroke
 3.40 setlinewidth 288.86  15.92 moveto 0 50.08 rlineto stroke
 1.03 setlinewidth 292.41  15.92 moveto 0 50.08 rlineto stroke
...


There are subtile differences in calculating the absolute values used
but in general the second PS-code results 'only' in a graph with
double length of the first one - the comment-line is allways the same.

So I thought it should be possible to define the graph in a generic
way (normalized) and scale it in x/y-direction.




Taking a closer look at the generated code, I found that there are
only bars at defined width and distance. The space is simply what
remains between bars and has no defined width of its own.

By now I know too less about barcodes (in german it's also:
"Strich-Code" meaning code from/by lines) to be more precise. Thank's
to your hint I have found the following code39-specification at:
http://209.249.179.251/pub/russadam/39code.html which says:

======= cite ===========
...
The "wide" element is a multiple of the "narrow" element and this
multiple must remain the same throughout the symbol. This multiple can
range between 2.0 and 3.0 if the narrow element is greater than 20
mils. If the narrow element is less than 20 mils, the multiple can
only range between 2.0 and 2.2.
...
========================

But if I calculate the ratio of wide to narrow linewidths I find:
first case: 1.62/0.44 = 3.68  --->   that's greater than 3.0
second case: 3.40/1.03 = 3.30 --->   that's greater than 3.0

Nevertheless it could be correctly scanned by a commmercial system :-)




Here are my theoretical suggestions for PS-code based on the
bar/space comment-line:

*) bars should not be drawn using setlinewith, but by drawing
rectangles of defined width (wide or narrow) and hight of 1
*) spaces should be drawn like bars.
*) both should be drawn following the comment-line-string

I am shure it's horrible prototype PS-code, please look at the sense
:-)

===================== PS-code ========================
%!
/leftstartofbar {10.5} def              % left margin is absolute
/barground {110.0} def                  % same with bottomline
/barhight {80.0 scaley mul} def         % 
/grau {0.9 setgray} def                 % color of the space
/schwarz {0.1 setgray} def              % color of the bar

% bar takes one value from the stack: theWidth of the bar
% it sets the drawing-color and fills a rectangle
% then moves the new origin to the right of the bar
/bar {
  /w exch def
  schwarz
  0 0 moveto
  0 barhight rlineto
  w 0 rlineto
  0 barhight neg rlineto
  closepath
  fill
  w 0 translate
} def

% space takes one value from the stack: theWidth of the space
% same as bar, only another color
/space {
  /w exch def
  grau
  0 0 moveto
  0 barhight rlineto
  w 0 rlineto
  0 barhight neg rlineto
  closepath
  fill
  w 0 translate
} def

%
% next two values can be changed as appropriate
%
/scalex {1.5} def          % scaling-factors
/scaley {0.5} def

leftstartofbar barground translate
0 0 moveto

1 neg             % set the bar/space toggle to -1 (space)

% use the comment as driving string (without the leading zero)
(13113131111311313111311311113111331111313133111111111331113113111131313113311111113331111111131131313113113111113311311113113131111331113111131131311)
  {exch           % exchange the toggle and the value from the  string
   neg            % negate the toggle
   dup            % duplicate the toggle
   1 eq           % compare the toggle with 1 (bar)
     {exch                   % if equal exchange it with the value
      48 sub scalex mul      % subtract 48 (ASCII-Value of 0) from the value
                             % and scale the result in x-direction
      bar}                   % draw the bar
     {exch                   % same with the spaces
      48 sub scalex mul
      space}
     ifelse
  } forall        % do it for all numbers in the string

stroke

showpage
===========================================================================





> > *) Positioning of text should also be configurable to be above the
> > bars with definable size.
> 
> This is not something I would do. If you want to write your own text,
> you can always do that by writing your postscript and telling the
> barcode library not to write any test.
[...]

Of course, that's the simplest way.

> 
> Any comment is welcome

Please don't take my comment to serious :-) It's just what comes to my
mind dealing the first time with barcodes and being a great fan of
GNU-software (and Linux) for years.

- Franz
-- 
Franz Zahaurek                        fzk@gams.at
Gymnasiumstr. 26/7                    http://www.fzk.at
1180 Wien