Path: utzoo!attcan!uunet!husc6!uwvax!oddjob!mimsy!aplcen!jhunix!bph_cwjb From: bph_cwjb@jhunix.HCF.JHU.EDU (William J. Bogstad) Newsgroups: comp.lang.postscript Subject: Re: print barcode Message-ID: <6440@jhunix.HCF.JHU.EDU> Date: 13 May 88 22:53:28 GMT References: <123@rubmez.UUCP> Reply-To: bph_cwjb@jhunix.UUCP (William J. Bogstad) Organization: Johns Hopkins Univ. Computing Ctr. Lines: 262 In article <123@rubmez.UUCP> frei@rubmez.UUCP (Matthias Frei ) writes: >Hy anybody, > >Did anybody write a PostScript-Procedure generating barcodes ? >What standards are there, and how to deal with them ? > >If you have any experiences in that subject, please mail to me. This was short enough and of perhaps general enough interest that I am posting it. I obtained it off of the net early last year. Bill Bogstad # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by bill on Mon Apr 6 18:23:24 EST 1987 # Contents: ORIGIN upc upc.pro echo x - ORIGIN sed 's/^@//' > "ORIGIN" <<'@//E*O*F ORIGIN//' @From: patwood@unirot.UUCP (Patrick Wood) Newsgroups: net.sources,comp.text Subject: upc fonts (long -- contains font listing) Keywords: upc barcode postscript font Date: 28 Mar 87 05:27:32 GMT Organization: Public Access Unix, Piscataway, NJ I hope this doesn't get screwed up and posted twice... The following shar is a PostScript UPC font and a shell program for generating UPC labels. Since I don't yet have a barcode reader, I'm interested in knowing whether these fellows work. The bar codes look correct to the naked eye, but we all know that means nothing to a bar code reader. If anyone out there can, let me know if this all works. If not, please send me your modifications or post to the net. Pat Wood {ihnp4,harpo,seismo}!bellcore!phw5!phw @//E*O*F ORIGIN// chmod u=rw,g=r,o=r ORIGIN echo x - upc sed 's/^@//' > "upc" <<'@//E*O*F 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 "$X 72 mul $Y 72 mul translate /UPC findfont 50 scalefont setfont 0 0 moveto (| |$1$2 | | ) show switch ($3$sum) show switch (| |) show showpage" @//E*O*F upc// chmod u=rwx,g=rx,o=rx upc echo x - upc.pro sed 's/^@//' > "upc.pro" <<'@//E*O*F 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 /gray 0 def /d1 { 1.3 setlinewidth 1 0 moveto 1 100 lineto stroke 2 0 translate } bind def /d2 { 3.3 setlinewidth 2 0 moveto 2 100 lineto stroke 4 0 translate } bind def /d3 { 5.3 setlinewidth 3 0 moveto 3 100 lineto stroke 6 0 translate } bind def /d4 { 7.3 setlinewidth 4 0 moveto 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 @//E*O*F upc.pro// chmod u=rw,g=r,o=r upc.pro echo Inspecting for damage in transit... temp=/tmp/shar$$; dtemp=/tmp/.shar$$ trap "rm -f $temp $dtemp; exit" 0 1 2 3 15 cat > $temp <<\!!! 18 121 757 ORIGIN 33 150 922 upc 159 587 3078 upc.pro 210 858 4757 total !!! wc ORIGIN upc upc.pro | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp if [ -s $dtemp ] then echo "Ouch [diff of wc output]:" ; cat $dtemp else echo "No problems found." fi exit 0 -- Bill Bogstad bogstad@cs.jhu.edu Work: (301)338-8019 bill@green.bph.jhu.edu