🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #2334

Re: Barcodes

#2334
From: J. Deters
Date: Fri, 08 Jun 1990 18:18
301 lines
8071 bytes
> Article <1990Jun4.222656.2821@jarvis.csri.toronto.edu> From: thomson@beaches.toronto.edu (Brian Thomson)

>Since the topic of barcodes has come up, and we have seen a (programmed)
>definition of code39, does anyone have a definition of UPC code they
>could post?
>					Curiously yours,
>		    Brian Thomson,	    CSRI Univ. of Toronto
>		    utcsri!uthub!thomson, thomson@hub.toronto.edu

Here's a UPC definition I grabbed off the net a few years back.  I've
rewritten the upc shell script to include the HRI code underneath and
beside the bars (just like on a milk carton!)  Wow.

Many thanks to the original poster of this font.  We used it to
produce our code books for our Estee Lauder cosmetics counter.

-j
-----8<-----Cut Here-----8<-----Cut Here-----8<-----Cut Here-----
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	README
#	upc.pro
#	upc
# This archive created: Fri Jun  8 13:08:43 1990
# By:	J. Deters (Terrapin Transit Authority)
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'
Enclosed is a UN!X shell script, upc, that builds and prints a
UPC code on a page.  Also enclosed is the file upc.pro, a
PostScript definition of the UPC font.

To print a UPC code with the script:

  $ upc 0 12345 67890 | to your favorite printer.

WARNING:  I had some trouble with this font on our 300 dpi
Dijit 1/PS printers and a Barcode Industries scanner.

The line thickness of any stripe may be off by one pixel row
due to rounding differences.  What happened in our case was:
We printed a UPC book with bar codes in two columns.  The codes
in the first column scanned fine, but the second column had
problems unless we turned the scanner upside down!  It turned
out that the proportional width of the first bar in the code
to the other bars was significant to this scanner's recognition
software.  Since the first guard bar didn't exactly match the
second guard bar, it was not recognized.  A quick modification
to the scale at which we printed the barcode fixed the problem,
but since each printer is different, your mileage may vary.
SHAR_EOF
fi
if test -f 'upc.pro'
then
	echo shar: "will not over-write existing file 'upc.pro'"
else
cat << \SHAR_EOF > 'upc.pro'
%%
%%  Universal Product Code font
%%  Copyright (C) 1986 by Pipeline Associates, Inc.
%%  Permission is granted to use and distribute as long as this copyright
%%  notice remains intact and it is distributed free of charge.
%%
/UPCFontDict 8 dict def
/workdict 25 dict def
%% load up drawing procedures
workdict begin
	/mymove {transform round exch round exch itransform moveto} bind def
	/gray 0 def
	/d1 {
		1.3 setlinewidth
		1 0 mymove 1 100 lineto stroke
		2 0 translate
	} bind def
	/d2 {
		3.3 setlinewidth
		2 0 mymove 2 100 lineto stroke
		4 0 translate
	} bind def
	/d3 {
		5.3 setlinewidth
		3 0 mymove 3 100 lineto stroke
		6 0 translate
	} bind def
	/d4 {
		7.3 setlinewidth
		4 0 mymove 4 100 lineto stroke
		8 0 translate
	} bind def
	/cline1 {
		1 gray sub setgray
		d1
	} bind def
	/cline2 {
		1 gray sub setgray
		d2
	} bind def
	/cline3 {
		1 gray sub setgray
		d3
	} bind def
	/cline4 {
		1 gray sub setgray
		d4
	} bind def
	/line1 {
		gray setgray
		d1
	} bind def
	/line2 {
		gray setgray
		d2
	} bind def
	/line3 {
		gray setgray
		d3
	} bind def
	/line4 {
		gray setgray
		d4
	} bind def
end
/switch {
	workdict begin /gray 1 gray sub def end
	} def

UPCFontDict begin
/FontType 3 def
/FontMatrix [.01 0 0 .015 0 0] def
/FontBBox [0 0 10 100] def
/Encoding 128 array def
/Widths 128 array def

%% fill the Encoding array with the procs to run for each character
0 1 127 {Encoding exch /.notdef put} for
Encoding (0) 0 get /zero put
Encoding (1) 0 get /one put
Encoding (2) 0 get /two put
Encoding (3) 0 get /three put
Encoding (4) 0 get /four put
Encoding (5) 0 get /five put
Encoding (6) 0 get /six put
Encoding (7) 0 get /seven put
Encoding (8) 0 get /eight put
Encoding (9) 0 get /nine put
Encoding ( ) 0 get /space put
Encoding (|) 0 get /bar put

Widths (0) 0 get 14 put
Widths (1) 0 get 14 put
Widths (2) 0 get 14 put
Widths (3) 0 get 14 put
Widths (4) 0 get 14 put
Widths (5) 0 get 14 put
Widths (6) 0 get 14 put
Widths (7) 0 get 14 put
Widths (8) 0 get 14 put
Widths (9) 0 get 14 put
Widths ( ) 0 get 2 put
Widths (|) 0 get 2 put

%% define the procs
/CharProcs 20 dict def
CharProcs /.notdef {} put
CharProcs /zero {
	cline3 line2 cline1 line1
} put
CharProcs /one {
	cline2 line2 cline2 line1
} put
CharProcs /two {
	cline2 line1 cline2 line2
} put
CharProcs /three {
	cline1 line4 cline1 line1
} put
CharProcs /four {
	cline1 line1 cline3 line2
} put
CharProcs /five {
	cline1 line2 cline3 line1
} put
CharProcs /six {
	cline1 line1 cline1 line4
} put
CharProcs /seven {
	cline1 line3 cline1 line2
} put
CharProcs /eight {
	cline1 line2 cline1 line3
} put
CharProcs /nine {
	cline3 line1 cline1 line2
} put
CharProcs /space {
} put
CharProcs /bar {
	line1
} put
%% BuildChar is called by PS whenever a character is to be imaged out
%% of UPC
/BuildChar {
 workdict begin
  /char exch def
  /fontdict exch def
  /charname fontdict /Encoding get char get def
  /charproc fontdict /CharProcs get charname get def
  /charwidth fontdict /Widths get char get def
  charwidth 0 setcharwidth
  gsave
	charproc
  grestore
 end
} bind def
end
%% register font in postscript font machinery
/UPC UPCFontDict definefont pop
SHAR_EOF
fi
if test -f 'upc'
then
	echo shar: "will not over-write existing file 'upc'"
else
cat << \SHAR_EOF > 'upc'
#!/bin/sh
# upc -- print upc code with PostScript
# usage:  upc prod code-5 code-5
# prod is the product type (zero for store items)
# code-5 is a five digit code (needs two of these)

# Copyright (C) 1986 by Pipeline Associates, Inc.
# Permission is granted to use and distribute as long as this copyright
# notice remains intact and it is distributed free of charge.

UPCFONT=./upc.pro
X=1	# x coordinate of lower right corner (in inches)
Y=1	# x coordinate of lower right corner (in inches)

# calculate checksum
SUM=`echo "$2
$3
$2
$3" | sed "
	1s/\(.\)\(.\)\(.\)\(.\)\(.\)/a=$1 + \2 + \4/
	2s/\(.\)\(.\)\(.\)\(.\)\(.\)/b=\1 + \3 + \5/
	3s/\(.\)\(.\)\(.\)\(.\)\(.\)/c=\1 + \3 + \5/
	4s/\(.\)\(.\)\(.\)\(.\)\(.\)/s=(a+b)*3+c+\2+\4;(10-(s%10))%10/" | bc`

cat $UPCFONT
echo "gsave
$X 72 mul $Y 72 mul translate
/UPC findfont 50 scalefont setfont
/startbars (| |) def
0 0 moveto
startbars show
($1$2 | | ) show
switch
($3$SUM) show
switch
startbars show
0 setlinecap
12 setlinewidth
/sx1 (| |$1) stringwidth pop def
/sl2 ($2) stringwidth pop def
/sx2 (| |$1$2 | | ) stringwidth pop def
/sl3 ($3) stringwidth pop def
1 setgray
sx1 0 moveto
sl2 0 rlineto
stroke
sx2 0 moveto
sl3 0 rlineto
stroke
0 setgray
/Helvetica findfont 12 scalefont setfont
-15 30 moveto
($1) show
sx1 -4 moveto
($2) show
sx2 -4 moveto
($3) show
100 30 moveto
($SUM) show
grestore
showpage"
SHAR_EOF
chmod +x 'upc'
fi
exit 0
#	End of shell archive
-- 
J. Deters                                      +---------+
INTERNET:  jad@dayton.DHDSC.MN.ORG             | S H * T |
UUCP:  ...!bungia!dayton!jad                   +---------+
ICBM:  44^58'36"N by 93^16'12"W       "Vanna, I'd like to buy a vowel."
Technical Details
Message-ID: <7380@dayton.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!rutgers!dayton!jad
References: <1990Jun4.222656.2821@jarvis.csri.toronto.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!rutgers!dayton!jad
From: jad@dayton.UUCP (J. Deters)
Newsgroups: comp.lang.postscript
Subject: Re: Barcodes
Keywords: upc barcode font postscript
Message-ID: <7380@dayton.UUCP>
Date: 8 Jun 90 18:18:19 GMT
References: <1990Jun4.222656.2821@jarvis.csri.toronto.edu>
Reply-To: jad@dayton.UUCP (J. Deters)
Organization: Dayton-Hudson Dept. Stores Co.
Lines: 301