Add current demo code of Freitagskasse Barcode Client and related HOWTO paper

master
Sebastian Pipping 13 years ago
parent 6003472f33
commit 7922d3254c

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 42 141 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <434f4d4d4954> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 195 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f53495420302e3031> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 195 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f53495420302e3035> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 195 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f53495420302e3130> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 195 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f53495420302e3530> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 195 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f53495420312e3030> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 195 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f53495420352e3030> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 204 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f5349542031302e3030> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 40 204 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <4445504f5349542035302e3030> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

@ -0,0 +1,409 @@
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: Terry Burton
%%BoundingBox: 50 42 123 122
%%EndComments
%%EndProlog
currentglobal
true setglobal
/Generic /Category findresource
dup length 1 add dict copy
dup /InstanceType /packedarraytype put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /f () def
txt {
{} forall
2 copy s ne exch f ne or {
2 copy /s exch def /f exch def
exch findfont exch scalefont setfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont findfont textsize scalefont setfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
(211113) (211212) (211311) (221112) (221211)
(231111) (112113) (112212) (112311) (122112)
(132111) (111123) (111222) (111321) (121122)
(131121) (212112) (212211) (211122) (211221)
(221121) (222111) (112122) (112221) (122121)
(123111) (121131) (311112) (311211) (321111)
(112131) (113121) (211131) (121221) (312111)
(311121) (122211) (111141) (1111411)
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/barlen barcode length def
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
1 string dup 0 4 -1 roll put /char exch def
barchars char search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
} ifelse
/enc encs indx get def % Get the indxth encoding
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
end
} bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
gsave
50 50 translate
0 0 moveto <554e444f> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
grestore
showpage

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 165 KiB

@ -0,0 +1,180 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL v3 or later
from __future__ import print_function
import sys
import decimal
import os
import time
def clear():
os.system('clear')
CODES = {
'UNDO':('undo',),
'COMMIT':('commit',),
'DEPOSIT 0.01':('deposit', decimal.Decimal('0.01')),
'DEPOSIT 0.05':('deposit', decimal.Decimal('0.05')),
'DEPOSIT 0.10':('deposit', decimal.Decimal('0.10')),
'DEPOSIT 0.50':('deposit', decimal.Decimal('0.50')),
'DEPOSIT 1.00':('deposit', decimal.Decimal('1.00')),
'DEPOSIT 5.00':('deposit', decimal.Decimal('5.00')),
'DEPOSIT 10.00':('deposit', decimal.Decimal('10.00')),
'DEPOSIT 50.00':('deposit', decimal.Decimal('50.00')),
'731453722620':('buy', 'CD Eagle Eye-Cherry - Desireless', decimal.Decimal('8.00')),
# http://www.gearfuse.com/wp-content/uploads/2008/07/mate.png
'4029764001807':('buy', 'Club Mate 0.5l', decimal.Decimal('0.60')),
'4013595054149':('buy', 'Vita Cola 1.0l', decimal.Decimal('0.79')),
}
def delay(what, seconds):
for i in xrange(seconds, 0, -1):
if i < seconds:
sys.stdout.write('\r')
sys.stdout.write('%s in %d Sekunden... ' % (what, i))
sys.stdout.flush()
time.sleep(1)
def warn_balance():
print('Kontostrand im Minus, NICHT cool!')
def error_page(message):
clear()
print(message)
print()
delay('Weiter', 3)
class Status:
def __init__(self):
self._reset()
def _reset(self):
self.login_code = None
self.login_name = None
self.balance = None
self.transfers = None
def dump(self):
if self.logged_in():
print('Eingeloggt als: %s' % (self.login_name))
print()
if self.transfers:
print('Geplante Änderungen:')
initial_balance = self.transfers[0][2]
print(('%3s %-40s %c %6.2f Euro') % ('', '', ' ' if initial_balance > 0 else '-', abs(initial_balance)))
for i, (label, difference, balance_backup) in enumerate(self.transfers):
print(('%2d) %-40s %c %6.2f Euro') % (i + 1, label, '+' if difference > 0 else '-', abs(difference)))
print(('%3s %-40s %8s') % ('', '', '============='))
print(('%3s %-40s %c %6.2f Euro') % ('', '', ' ' if self.balance > 0 else '-', abs(self.balance)))
if self.balance < 0:
warn_balance()
print()
print('Committen nicht vergessen!')
else:
print('Kontostand beträgt: %.2f Euro' % (self.balance))
if self.balance < 0:
print()
warn_balance()
else:
print('Bitte einloggen.')
print()
print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.')
print()
def logged_in(self):
return self.login_code is not None
def login(self, code):
assert(not self.logged_in())
self.login_code = code
self.login_name = 'Sebastian Pipping' ############
self.balance = decimal.Decimal('0.20') ######################
self.transfers = list()
def commit(self):
assert(self.logged_in())
# TODO save balance
self.transfers = None
# Show final balance for some time
clear()
self.dump()
delay('Logout', 3)
# Logout
self._reset()
def _do_money(self, label, difference):
log_entry = (label, difference, self.balance)
self.transfers.append(log_entry)
self.balance = self.balance + difference
def buy(self, title, price):
assert(self.logged_in())
self._do_money(title, -price)
def deposit(self, amount):
assert(self.logged_in())
self._do_money('%.2f Euro einzahlen' % amount, amount)
def undo(self):
assert(self.logged_in())
if self.transfers:
(label, difference, balance_backup) = self.transfers[-1]
self.transfers.pop()
self.balance = balance_backup
else:
error_page('FEHLER: Nichts da, was ich rückgängig machen könnte.')
def print_prompt():
sys.stdout.write(">>> ")
def handle(line, status):
if line == 'exit':
clear()
sys.exit(0)
if status.logged_in():
if line in CODES:
call = CODES[line]
method = call[0]
params = call[1:]
getattr(status, method)(*params)
else:
error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line)
else:
status.login(line)
def main():
status = Status()
while True:
clear()
status.dump()
print_prompt()
l = sys.stdin.readline()
if not l:
break
line = l.rstrip()
handle(line, status)
if __name__ == '__main__':
main()
Loading…
Cancel
Save