🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #2329

Re: Printing Barcodes (3of9 font included)

#2329
From: J. Deters
Date: Thu, 07 Jun 1990 19:26
370 lines
14254 bytes
> Article <1004@io.tegra.COM> From: phillips@tegra.COM (Steve Phillips)
>In article <9208@teda.UUCP> bob@teda.UUCP (Bob Armstrong) writes:
>>  Can someone direct me to a font or program for printing code 39 (3 of 9)
>>barcodes ?  Postscript output is best, but I would take anything (maybe
>>Epson ?).
>>Thanks,
>>Bob Armstrong
>>bob@teda.uucp {sun,decwrl,pyramid}!teda!bob
>I believe that Adobe makes two PostScript fonts for barcodes, one for UPC and
>one for Code 39.  You might want to check with your local Adobe font vendor.
>
>Steve Phillips                                         Tegra-Varityper, Inc.
>tegra!phillips@uunet.com                               Billerica, MA

Or, your local net.denizens may have written their own fonts.  You just
never know... :-)

Anyway, I wrote the following a few years back.  We're now basing an
entire inventory on it, so it darn well better work!  But, see the
disclaimer included anyway...
-----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
#	3of9
# This archive created: Thu Jun  7 13:52:14 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'
This is a PostScript prolog that will generate a 3 of 9 barcode font.
I wrote it a few years ago after seeing something similar posted
for UPC codes by Pipeline Associates.  (This is completely different
code, however.)  It allows full ASCII text (lower case is translated
into upper case -- there are no lower case 3 of 9 codes.

Also enclosed is a small shell script that will wrap your text up
in asterisks, append the prolog, and print the barcode on the page.
If you want to truly conform to MIL-STD-1189A (4 SEPTEMBER 1984),
Military Standard Department of Defense Bar Code Symbology (SDS), you'll
have to code for it appropriately (my sample doesn't fit all their
wonderful dimensions).

  Character density:  9.4 CPI to 3.0 CPI
  Minimum nominal unit size (thin bar):  .0075 inch
  Maximum nominal unit size (thin bar):  .0400 inch
  Nominal wide to narrow ratio:  2.2:1 to 3.0:1 for codes whose
                                 unit size is less than .015 inch
                                 2.0:1 to 3.0:1 for codes whose
                                 unit size is equal to or more than
                                 .015 inch
  Minimum bar height:  .25 inch
  Density range    Minimum height    Maximum height
  1.7<=CPI<3.0     .75               1.25
  3.0<=CPI<6.5     .375              .875
  6.5<=CPI<9.4     .25               .5
  Intercharacter gap:  The minimum gap is the same as the minimum
  dimension of a narrow element.  The maximum gap shall be no more
  than three times the width of a narrow element.
  Margins (quiet zones):  The minimum left and right margins shall
  be 10 times the width of one narrow element or .25 inch (whichever
  is greater).
  Human-readable interpretation (HRI):  The HRI shall represent only
  the encoded characters, and start and stop asterisks shall be
  suppressed.  It is not intended to be machine readable.  The HRI
  is to be printed in an easily readable font, and are to be a
  minimum of .094 inch in height.  The HRI shall be printed above
  or preferably below the bar code.
  Spacing between bar code and HRI:  Minimum of .1 inch, max of .25 inch.
  Spacing between edge of label and HRI:  Minimum .0625 inch
  Spacing between SDS messages (vertical):  Min .375 inch, max .75 inch.
  Spacing between SDS messages (horiz.):  Min .5 inch
  Maximum number of encoded characters:  30 data, 32 including start and
  stop characters, and other control characters that may be used.

There is a bunch of other stuff in this MIL-SPEC pertaining to opacity,
reflectivity, tolerances, and spots and voids that probably won't
affect anyone using a 300dpi printer with black ink.

DISCLAIMER:  I am not responsible.  Just ask my boss.  This code is
provided AS IS, and I make no warranties about its fitness for a
particular purpose.  If you use this code and it doesn't work for you,
tough.  I can't be held responsible for any damages for your using this
code.  How's that for a nasty thing to have to say?
SHAR_EOF
fi
if test -f '3of9'
then
	echo shar: "will not over-write existing file '3of9'"
else
cat << \SHAR_EOF > '3of9'
%
%  3 of 9 font.  Copyright (C) 1989, John Deters.  All rights reserved.
%  Permission is hereby granted to freely use this software in any
%  application, commercial or otherwise, as long as this notice is preserved,
%  and as long as this portion of the software remains freely redistributable.
%
/3of9FontDict 55 dict def
/workdict 55 dict def 
% load up drawing procedures
workdict begin
	/sp1 {
		1 setgray
		2 setlinewidth
		1 0 moveto 1 75 lineto stroke
		2 0 translate
	} bind def
	/sp2 {
		1 setgray
		5 setlinewidth
		2.5 0 moveto 2.5 75 lineto stroke
		5 0 translate
	} bind def
	/mk1 {
		0 setgray
		2 setlinewidth
		1 0 moveto 1 75 lineto stroke
		2 0 translate
	} bind def
	/mk2 {
		0 setgray
		5 setlinewidth
		2.5 0 moveto 2.5 75 lineto stroke
		5 0 translate
	} bind def
end

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

% Put the proc names of each character in the array 'Encoding'
0 1 127 {Encoding exch /.notdef put} for
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) 0 get /zero put
Encoding (A) 0 get /leta put
Encoding (B) 0 get /letb put
Encoding (C) 0 get /letc put
Encoding (D) 0 get /letd put
Encoding (E) 0 get /lete put
Encoding (F) 0 get /letf put
Encoding (G) 0 get /letg put
Encoding (H) 0 get /leth put
Encoding (I) 0 get /leti put
Encoding (J) 0 get /letj put
Encoding (K) 0 get /letk put
Encoding (L) 0 get /letl put
Encoding (M) 0 get /letm put
Encoding (N) 0 get /letn put
Encoding (O) 0 get /leto put
Encoding (P) 0 get /letp put
Encoding (Q) 0 get /letq put
Encoding (R) 0 get /letr put
Encoding (S) 0 get /lets put
Encoding (T) 0 get /lett put
Encoding (U) 0 get /letu put
Encoding (V) 0 get /letv put
Encoding (W) 0 get /letw put
Encoding (X) 0 get /letx put
Encoding (Y) 0 get /lety put
Encoding (Z) 0 get /letz put
Encoding (a) 0 get /leta put
Encoding (b) 0 get /letb put
Encoding (c) 0 get /letc put
Encoding (d) 0 get /letd put
Encoding (e) 0 get /lete put
Encoding (f) 0 get /letf put
Encoding (g) 0 get /letg put
Encoding (h) 0 get /leth put
Encoding (i) 0 get /leti put
Encoding (j) 0 get /letj put
Encoding (k) 0 get /letk put
Encoding (l) 0 get /letl put
Encoding (m) 0 get /letm put
Encoding (n) 0 get /letn put
Encoding (o) 0 get /leto put
Encoding (p) 0 get /letp put
Encoding (q) 0 get /letq put
Encoding (r) 0 get /letr put
Encoding (s) 0 get /lets put
Encoding (t) 0 get /lett put
Encoding (u) 0 get /letu put
Encoding (v) 0 get /letv put
Encoding (w) 0 get /letw put
Encoding (x) 0 get /letx put
Encoding (y) 0 get /lety put
Encoding (z) 0 get /letz put
Encoding (-) 0 get /dash put
Encoding (.) 0 get /period put
Encoding ( ) 0 get /space put
Encoding (*) 0 get /star put
Encoding ($) 0 get /dollar put
Encoding (/) 0 get /slash put
Encoding (+) 0 get /plus put
Encoding (%) 0 get /percent put
Encoding (|) 0 get /bar put

Widths (1) 0 get 29 put
Widths (2) 0 get 29 put
Widths (3) 0 get 29 put
Widths (4) 0 get 29 put
Widths (5) 0 get 29 put
Widths (6) 0 get 29 put
Widths (7) 0 get 29 put
Widths (8) 0 get 29 put
Widths (9) 0 get 29 put
Widths (0) 0 get 29 put
Widths (A) 0 get 29 put
Widths (B) 0 get 29 put
Widths (C) 0 get 29 put
Widths (D) 0 get 29 put
Widths (E) 0 get 29 put
Widths (F) 0 get 29 put
Widths (G) 0 get 29 put
Widths (H) 0 get 29 put
Widths (I) 0 get 29 put
Widths (J) 0 get 29 put
Widths (K) 0 get 29 put
Widths (L) 0 get 29 put
Widths (M) 0 get 29 put
Widths (N) 0 get 29 put
Widths (O) 0 get 29 put
Widths (P) 0 get 29 put
Widths (Q) 0 get 29 put
Widths (R) 0 get 29 put
Widths (S) 0 get 29 put
Widths (T) 0 get 29 put
Widths (U) 0 get 29 put
Widths (V) 0 get 29 put
Widths (W) 0 get 29 put
Widths (X) 0 get 29 put
Widths (Y) 0 get 29 put
Widths (Z) 0 get 29 put
Widths (a) 0 get 29 put
Widths (b) 0 get 29 put
Widths (c) 0 get 29 put
Widths (d) 0 get 29 put
Widths (e) 0 get 29 put
Widths (f) 0 get 29 put
Widths (g) 0 get 29 put
Widths (h) 0 get 29 put
Widths (i) 0 get 29 put
Widths (j) 0 get 29 put
Widths (k) 0 get 29 put
Widths (l) 0 get 29 put
Widths (m) 0 get 29 put
Widths (n) 0 get 29 put
Widths (o) 0 get 29 put
Widths (p) 0 get 29 put
Widths (q) 0 get 29 put
Widths (r) 0 get 29 put
Widths (s) 0 get 29 put
Widths (t) 0 get 29 put
Widths (u) 0 get 29 put
Widths (v) 0 get 29 put
Widths (w) 0 get 29 put
Widths (x) 0 get 29 put
Widths (y) 0 get 29 put
Widths (z) 0 get 29 put
Widths (-) 0 get 29 put
Widths (.) 0 get 29 put
Widths ( ) 0 get 29 put
Widths (*) 0 get 29 put
Widths ($) 0 get 29 put
Widths (/) 0 get 29 put
Widths (+) 0 get 29 put
Widths (%) 0 get 29 put
Widths (|) 0 get 4 put

% define each letter in bar code
/CharProcs 55 dict def
CharProcs /.notdef	{} put
CharProcs /one		{ mk2 sp1 mk1 sp2 mk1 sp1 mk1 sp1 mk2 sp1 } put
CharProcs /two		{ mk1 sp1 mk2 sp2 mk1 sp1 mk1 sp1 mk2 sp1 } put
CharProcs /three	{ mk2 sp1 mk2 sp2 mk1 sp1 mk1 sp1 mk1 sp1 } put
CharProcs /four		{ mk1 sp1 mk1 sp2 mk2 sp1 mk1 sp1 mk2 sp1 } put
CharProcs /five		{ mk2 sp1 mk1 sp2 mk2 sp1 mk1 sp1 mk1 sp1 } put
CharProcs /six		{ mk1 sp1 mk2 sp2 mk2 sp1 mk1 sp1 mk1 sp1 } put
CharProcs /seven	{ mk1 sp1 mk1 sp2 mk1 sp1 mk2 sp1 mk2 sp1 } put
CharProcs /eight	{ mk2 sp1 mk1 sp2 mk1 sp1 mk2 sp1 mk1 sp1 } put
CharProcs /nine		{ mk1 sp1 mk2 sp2 mk1 sp1 mk2 sp1 mk1 sp1 } put
CharProcs /zero		{ mk1 sp1 mk1 sp2 mk2 sp1 mk2 sp1 mk1 sp1 } put
CharProcs /leta		{ mk2 sp1 mk1 sp1 mk1 sp2 mk1 sp1 mk2 sp1 } put
CharProcs /letb		{ mk1 sp1 mk2 sp1 mk1 sp2 mk1 sp1 mk2 sp1 } put
CharProcs /letc		{ mk2 sp1 mk2 sp1 mk1 sp2 mk1 sp1 mk1 sp1 } put
CharProcs /letd		{ mk1 sp1 mk1 sp1 mk2 sp2 mk1 sp1 mk2 sp1 } put
CharProcs /lete		{ mk2 sp1 mk1 sp1 mk2 sp2 mk1 sp1 mk1 sp1 } put
CharProcs /letf		{ mk1 sp1 mk2 sp1 mk2 sp2 mk1 sp1 mk1 sp1 } put
CharProcs /letg		{ mk1 sp1 mk1 sp1 mk1 sp2 mk2 sp1 mk2 sp1 } put
CharProcs /leth		{ mk2 sp1 mk1 sp1 mk1 sp2 mk2 sp1 mk1 sp1 } put
CharProcs /leti		{ mk1 sp1 mk2 sp1 mk1 sp2 mk2 sp1 mk1 sp1 } put
CharProcs /letj		{ mk1 sp1 mk1 sp1 mk2 sp2 mk2 sp1 mk1 sp1 } put
CharProcs /letk		{ mk2 sp1 mk1 sp1 mk1 sp1 mk1 sp2 mk2 sp1 } put
CharProcs /letl		{ mk1 sp1 mk2 sp1 mk1 sp1 mk1 sp2 mk2 sp1 } put
CharProcs /letm		{ mk2 sp1 mk2 sp1 mk1 sp1 mk1 sp2 mk1 sp1 } put
CharProcs /letn		{ mk1 sp1 mk1 sp1 mk2 sp1 mk1 sp2 mk2 sp1 } put
CharProcs /leto		{ mk2 sp1 mk1 sp1 mk2 sp1 mk1 sp2 mk1 sp1 } put
CharProcs /letp		{ mk1 sp1 mk2 sp1 mk2 sp1 mk1 sp2 mk1 sp1 } put
CharProcs /letq		{ mk1 sp1 mk1 sp1 mk1 sp1 mk2 sp2 mk2 sp1 } put
CharProcs /letr		{ mk2 sp1 mk1 sp1 mk1 sp1 mk2 sp2 mk1 sp1 } put
CharProcs /lets		{ mk1 sp1 mk2 sp1 mk1 sp1 mk2 sp2 mk1 sp1 } put
CharProcs /lett		{ mk1 sp1 mk1 sp1 mk2 sp1 mk2 sp2 mk1 sp1 } put
CharProcs /letu		{ mk2 sp2 mk1 sp1 mk1 sp1 mk1 sp1 mk2 sp1 } put
CharProcs /letv		{ mk1 sp2 mk2 sp1 mk1 sp1 mk1 sp1 mk2 sp1 } put
CharProcs /letw		{ mk2 sp2 mk2 sp1 mk1 sp1 mk1 sp1 mk1 sp1 } put
CharProcs /letx		{ mk1 sp2 mk1 sp1 mk2 sp1 mk1 sp1 mk2 sp1 } put
CharProcs /lety		{ mk2 sp2 mk1 sp1 mk2 sp1 mk1 sp1 mk1 sp1 } put
CharProcs /letz		{ mk1 sp2 mk2 sp1 mk2 sp1 mk1 sp1 mk1 sp1 } put
CharProcs /dash		{ mk1 sp2 mk1 sp1 mk1 sp1 mk2 sp1 mk2 sp1 } put
CharProcs /period	{ mk2 sp2 mk1 sp1 mk1 sp1 mk2 sp1 mk1 sp1 } put
CharProcs /space	{ mk1 sp2 mk2 sp1 mk1 sp1 mk2 sp1 mk1 sp1 } put
CharProcs /star		{ mk1 sp2 mk1 sp1 mk2 sp1 mk2 sp1 mk1 sp1 } put
CharProcs /dollar	{ mk1 sp2 mk1 sp2 mk1 sp2 mk1 sp1 mk1 sp1 } put
CharProcs /slash	{ mk1 sp2 mk1 sp2 mk1 sp1 mk1 sp2 mk1 sp1 } put
CharProcs /plus		{ mk1 sp2 mk1 sp1 mk1 sp2 mk1 sp2 mk1 sp1 } put
CharProcs /percent	{ mk1 sp1 mk1 sp2 mk1 sp2 mk1 sp2 mk1 sp1 } put
CharProcs /bar		{ mk1 sp1 } put
% PostScript will call BuildChar for each character printed in 3of9.
/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
/3of9 3of9FontDict definefont pop
%
% 3of9 is now loaded in the printer and can be used like any other font.
% Don't forget that you must include the stars at both ends of the text.
% Also, you must print out the human readable text beneath the bar code,
% if you wish to conform to MIL-STD-1189A (suppress the asterisks).
%
/3of9 findfont 30 scalefont setfont
72 72 translate
0 0 moveto
(*1234567890180100*) show
showpage
SHAR_EOF
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: <7376@dayton.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!mit-eddie!rutgers!dayton!jad
References: <9208@teda.UUCP> <1004@io.tegra.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!mit-eddie!rutgers!dayton!jad
From: jad@dayton.UUCP (J. Deters)
Newsgroups: comp.lang.postscript
Subject: Re: Printing Barcodes (3of9 font included)
Summary: 3of9 font
Keywords: barcode code39 3 of 9
Message-ID: <7376@dayton.UUCP>
Date: 7 Jun 90 19:26:54 GMT
References: <9208@teda.UUCP> <1004@io.tegra.COM>
Reply-To: jad@dayton.DHDSC.MN.ORG (J. Deters)
Organization: Terrapin Transit Authority
Lines: 370