[comp.fonts] Here is a PostScript font for Code 39 barcode

day@grand.UUCP (Dave Yost) (11/07/88)

Here is a Code39 barcode font.  Code39 is a widely-used,
standard, extremely reliable and very dense (bits of
information per unit of length) form of barcode.  It
is also known as "3 of 9 code".

This is not a real, fully-fleshed-out font, but it
works.  If someone would like to take it and finish it,
great.

The following PostScript file contains both the font and
some demo code.  Send it to your printer and you'll see
what it does.

Let's see more fonts posted to this group!

 --dave yost

%!
%%Creator: Dave Yost, Grand Software, Inc.
% 213-650-1089 {uunet,attmail}!grand!dyost or dyost@grand.COM
% Permission granted to all to copy, enhance, and use.

%%Title: Download font: Code39
%%CreationDate: November 5, 1988
%%Pages: 0

%  Code 39 barcode font
%  A code39 barcode strip must begin and end with asterisk (*WHATEVER*)
%  The characters printable by this font are:
%     ( $%*+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
%  There is no distinction between upper and lower case;
%  that is, the font will show (A) and (a) as the same barcode.
%  The graphic representations of Code39 characters are independent
%  of each other, so if you want to see how many characters there are,
%  you can separate them with whitespace.
%
%  Todo:
%     The font should automatically round its size to an integral
%     number of device pixels, at least at small sizes
%
%  Thanks to Pat Wood for his UPC barcode font,
%  which showed how to do a barcode font.
%
%  An excellent book on bar code is "Reading Between the Lines"
%  published by North American Technology, Inc.  +1 603-924-7136
%  ISBN 0-911261-00-1
%
%%EndComments

% FontDirectory /flow known{(flow in place--not loaded\n)print flush stop}
% {0 serverdict begin exitserver}ifelse
% - or -
% 0 serverdict begin exitserver

/Code39FontDict 8 dict def
/workdict 19 dict def
% load up drawing procedures
workdict begin
    /slimwidth 6 def
    /widewidth 14 def  % optimal wide/slim ratio is 2.25
    /nslim 6 def    % number of slim elements
    /nwide 3 def    % number of wide elements
    /unit nslim slimwidth mul nwide widewidth mul add def
    /width nslim 1 add slimwidth mul nwide widewidth mul add def
    /T true def
    /F false def
    /gray 0 def
    /c39 {
	dup 0 get { b1 } { b0 } ifelse
	dup 5 get { s1 } { s0 } ifelse
	dup 1 get { b1 } { b0 } ifelse
	dup 6 get { s1 } { s0 } ifelse
	dup 2 get { b1 } { b0 } ifelse
	dup 7 get { s1 } { s0 } ifelse
	dup 3 get { b1 } { b0 } ifelse
	dup 8 get { s1 } { s0 } ifelse
	dup 4 get { b1 } { b0 } ifelse
	pop
    } bind def
    /b0 {
	0 setgray
	slimwidth dup dup setlinewidth
	    .5 mul dup 0 moveto
		unit lineto
	    stroke
	    0 translate
    } bind def
    /b1 {
	0 setgray
	widewidth dup dup setlinewidth
	    .5 mul dup 0 moveto
		unit lineto
	    stroke
	    0 translate
    } bind def
    /s0 {
	slimwidth 0 translate
    } bind def
    /s1 {
	widewidth 0 translate
    } bind def

    Code39FontDict begin
	/FontType 3 def
	/FontMatrix [1 unit div 0 0 1 unit div 0 0] def
	/FontBBox [0 0 width width] 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
	0 1 127 {Widths exch width put} for

	Encoding (0) 0 get /C0 put
	Encoding (1) 0 get /C1 put
	Encoding (2) 0 get /C2 put
	Encoding (3) 0 get /C3 put
	Encoding (4) 0 get /C4 put
	Encoding (5) 0 get /C5 put
	Encoding (6) 0 get /C6 put
	Encoding (7) 0 get /C7 put
	Encoding (8) 0 get /C8 put
	Encoding (9) 0 get /C9 put
	Encoding (A) 0 get /Ca put
	Encoding (a) 0 get /Ca put
	Encoding (B) 0 get /Cb put
	Encoding (b) 0 get /Cb put
	Encoding (C) 0 get /Cc put
	Encoding (c) 0 get /Cc put
	Encoding (D) 0 get /Cd put
	Encoding (d) 0 get /Cd put
	Encoding (E) 0 get /Ce put
	Encoding (e) 0 get /Ce put
	Encoding (F) 0 get /Cf put
	Encoding (f) 0 get /Cf put
	Encoding (G) 0 get /Cg put
	Encoding (g) 0 get /Cg put
	Encoding (H) 0 get /Ch put
	Encoding (h) 0 get /Ch put
	Encoding (I) 0 get /Ci put
	Encoding (i) 0 get /Ci put
	Encoding (J) 0 get /Cj put
	Encoding (j) 0 get /Cj put
	Encoding (K) 0 get /Ck put
	Encoding (k) 0 get /Ck put
	Encoding (L) 0 get /Cl put
	Encoding (l) 0 get /Cl put
	Encoding (M) 0 get /Cm put
	Encoding (m) 0 get /Cm put
	Encoding (N) 0 get /Cn put
	Encoding (n) 0 get /Cn put
	Encoding (O) 0 get /Co put
	Encoding (o) 0 get /Co put
	Encoding (P) 0 get /Cp put
	Encoding (p) 0 get /Cp put
	Encoding (Q) 0 get /Cq put
	Encoding (q) 0 get /Cq put
	Encoding (R) 0 get /Cr put
	Encoding (r) 0 get /Cr put
	Encoding (S) 0 get /Cs put
	Encoding (s) 0 get /Cs put
	Encoding (T) 0 get /Ct put
	Encoding (t) 0 get /Ct put
	Encoding (U) 0 get /Cu put
	Encoding (u) 0 get /Cu put
	Encoding (V) 0 get /Cv put
	Encoding (v) 0 get /Cv put
	Encoding (W) 0 get /Cw put
	Encoding (w) 0 get /Cw put
	Encoding (X) 0 get /Cx put
	Encoding (x) 0 get /Cx put
	Encoding (Y) 0 get /Cy put
	Encoding (y) 0 get /Cy put
	Encoding (Z) 0 get /Cz put
	Encoding (z) 0 get /Cz put
	Encoding (-) 0 get /Cminus	put
	Encoding (.) 0 get /Cperiod	put
	Encoding ( ) 0 get /Cspace	put
	Encoding ($) 0 get /Cdollar	put
	Encoding (/) 0 get /Cslash	put
	Encoding (+) 0 get /Cplus	put
	Encoding (%) 0 get /Cpercent	put
	Encoding (*) 0 get /Cstar	put

	% define the procs
	/CharProcs 45 dict def
	CharProcs /.notdef {} put
	CharProcs /C0	{ [ F F T T F F T F F ] c39 } put
	CharProcs /C1	{ [ T F F F T F T F F ] c39 } put
	CharProcs /C2	{ [ F T F F T F T F F ] c39 } put
	CharProcs /C3	{ [ T T F F F F T F F ] c39 } put
	CharProcs /C4	{ [ F F T F T F T F F ] c39 } put
	CharProcs /C5	{ [ T F T F F F T F F ] c39 } put
	CharProcs /C6	{ [ F T T F F F T F F ] c39 } put
	CharProcs /C7	{ [ F F F T T F T F F ] c39 } put
	CharProcs /C8	{ [ T F F T F F T F F ] c39 } put
	CharProcs /C9	{ [ F T F T F F T F F ] c39 } put
	CharProcs /Ca	{ [ T F F F T F F T F ] c39 } put
	CharProcs /Cb	{ [ F T F F T F F T F ] c39 } put
	CharProcs /Cc	{ [ T T F F F F F T F ] c39 } put
	CharProcs /Cd	{ [ F F T F T F F T F ] c39 } put
	CharProcs /Ce	{ [ T F T F F F F T F ] c39 } put
	CharProcs /Cf	{ [ F T T F F F F T F ] c39 } put
	CharProcs /Cg	{ [ F F F T T F F T F ] c39 } put
	CharProcs /Ch	{ [ T F F T F F F T F ] c39 } put
	CharProcs /Ci	{ [ F T F T F F F T F ] c39 } put
	CharProcs /Cj	{ [ F F T T F F F T F ] c39 } put
	CharProcs /Ck	{ [ T F F F T F F F T ] c39 } put
	CharProcs /Cl	{ [ F T F F T F F F T ] c39 } put
	CharProcs /Cm	{ [ T T F F F F F F T ] c39 } put
	CharProcs /Cn	{ [ F F T F T F F F T ] c39 } put
	CharProcs /Co	{ [ T F T F F F F F T ] c39 } put
	CharProcs /Cp	{ [ F T T F F F F F T ] c39 } put
	CharProcs /Cq	{ [ F F F T T F F F T ] c39 } put
	CharProcs /Cr	{ [ T F F T F F F F T ] c39 } put
	CharProcs /Cs	{ [ F T F T F F F F T ] c39 } put
	CharProcs /Ct	{ [ F F T T F F F F T ] c39 } put
	CharProcs /Cu	{ [ T F F F T T F F F ] c39 } put
	CharProcs /Cv	{ [ F T F F T T F F F ] c39 } put
	CharProcs /Cw	{ [ T T F F F T F F F ] c39 } put
	CharProcs /Cx	{ [ F F T F T T F F F ] c39 } put
	CharProcs /Cy	{ [ T F T F F T F F F ] c39 } put
	CharProcs /Cz	{ [ F T T F F T F F F ] c39 } put
	CharProcs /Cminus	{ [ F F F T T T F F F ] c39 } put
	CharProcs /Cperiod	{ [ T F F T F T F F F ] c39 } put
	CharProcs /Cspace	{ [ F T F T F T F F F ] c39 } put
	CharProcs /Cdollar	{ [ F F F F F T T T F ] c39 } put
	CharProcs /Cslash	{ [ F F F F F T T F T ] c39 } put
	CharProcs /Cplus	{ [ F F F F F T F T T ] c39 } put
	CharProcs /Cpercent	{ [ F F F F F F T T T ] c39 } put
	CharProcs /Cstar	{ [ F F T T F T F F F ] c39 } put

	% BuildChar is called by PS
	% whenever a character is to be imaged out of Code39
	/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 % workdict
	} bind def
    end % Code39FontDict
end % workdict

% register font in postscript font machinery
/Code39 Code39FontDict definefont pop
/Code39minsize
    workdict begin
	unit
	% pixels per point:
	gsave initmatrix 1 0 dtransform pop grestore
	div
    end
def

/DoDemo true def
DoDemo {
    /inch { 72 mul } def

    /Times-Roman findfont 48 scalefont setfont
    1 inch 10 inch moveto
    (Code 39 Barcode) show

    % show the smallest printable size
    % show setting the height separately from the width
    /Height 48 def
    /Code39 findfont [ Code39minsize 0 0 Height 0 0 ] makefont setfont
    1 inch 9 inch moveto
    (*ABCDE*) show

    % show the size that would normally correspond to the height above
    /Height 48 def
    /Code39 findfont [ Height 0 0 Height 0 0 ] makefont setfont
    1 inch 8 inch moveto
    (*ABCDE*) show

    % show what each character looks like
    /Code39 findfont 24 scalefont setfont
    /C { show 12 0 rmoveto } def
    1 inch 7 inch moveto
    (*)C (A)C (B)C (C)C (D)C (E)C (*)C

    showpage
} if