Merge branch 'master' into display
Conflicts: client-barcode/freitagskasse.py
This commit is contained in:
commit
ed8659964c
|
@ -0,0 +1,409 @@
|
||||||
|
%!PS-Adobe-2.0 EPSF-2.0
|
||||||
|
%%Creator: Terry Burton
|
||||||
|
%%BoundingBox: 50 40 168 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 <544f20474f20414c4c> <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 177 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 <544f20474f204e4f4e45> <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 177 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 <544f20474f204f4e4c59> <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 177 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 <544f20474f2050524556> <696e636c7564657465787420696e636c756465636865636b> /code93 /uk.co.terryburton.bwipp findresource exec
|
||||||
|
grestore
|
||||||
|
|
||||||
|
showpage
|
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 157 KiB |
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import freitagslib.network as net
|
import freitagslib.network as net
|
||||||
from freitagslib.commands import BuyCommand, DepositCommand, ToGoCommand
|
from freitagslib.commands import BuyCommand, DepositCommand
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
@ -19,7 +19,7 @@ import time
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
|
||||||
COLOR_WARN = Fore.YELLOW
|
COLOR_HINT = Fore.YELLOW + Style.BRIGHT
|
||||||
COLOR_ERROR = Fore.RED
|
COLOR_ERROR = Fore.RED
|
||||||
COLOR_DEPOSIT = Fore.GREEN + Style.BRIGHT
|
COLOR_DEPOSIT = Fore.GREEN + Style.BRIGHT
|
||||||
COLOR_TO_GO = Fore.MAGENTA + Style.BRIGHT
|
COLOR_TO_GO = Fore.MAGENTA + Style.BRIGHT
|
||||||
|
@ -40,8 +40,13 @@ def print_display(s):
|
||||||
#display_fifo = open('/tmp/display', 'w')
|
#display_fifo = open('/tmp/display', 'w')
|
||||||
fd = os.open( "/tmp/display", os.O_WRONLY)
|
fd = os.open( "/tmp/display", os.O_WRONLY)
|
||||||
display_fifo = os.fdopen(fd,"w")
|
display_fifo = os.fdopen(fd,"w")
|
||||||
|
except OSError:
|
||||||
|
display_fifo = None
|
||||||
|
pass
|
||||||
|
return
|
||||||
except IOError:
|
except IOError:
|
||||||
display_fifo = None
|
display_fifo = None
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
display_fifo.write(s)
|
display_fifo.write(s)
|
||||||
display_fifo.flush()
|
display_fifo.flush()
|
||||||
|
@ -90,11 +95,16 @@ def warn_balance():
|
||||||
print_display('\e\x0cKontostand im Minus,bitte Geld aufladen.')
|
print_display('\e\x0cKontostand im Minus,bitte Geld aufladen.')
|
||||||
|
|
||||||
|
|
||||||
def error_page(message):
|
def error_page(error_message, hint_message=None):
|
||||||
clear()
|
clear()
|
||||||
print(COLOR_ERROR + message + COLOR_RESET)
|
print(COLOR_ERROR + error_message + COLOR_RESET)
|
||||||
print()
|
print()
|
||||||
delay('Weiter', 3)
|
delay_seconds = 3
|
||||||
|
if hint_message is not None:
|
||||||
|
print(COLOR_HINT + hint_message + COLOR_RESET)
|
||||||
|
print()
|
||||||
|
delay_seconds += 3
|
||||||
|
delay('Weiter', delay_seconds)
|
||||||
|
|
||||||
|
|
||||||
class Status:
|
class Status:
|
||||||
|
@ -115,22 +125,14 @@ class Status:
|
||||||
def color(amount):
|
def color(amount):
|
||||||
return COLOR_WITHDRAW if amount < 0 else COLOR_DEPOSIT
|
return COLOR_WITHDRAW if amount < 0 else COLOR_DEPOSIT
|
||||||
|
|
||||||
def color_command(command):
|
|
||||||
diff = command.difference()
|
|
||||||
if diff >= 0:
|
|
||||||
return COLOR_DEPOSIT
|
|
||||||
return COLOR_TO_GO if isinstance(command, ToGoCommand) else COLOR_WITHDRAW
|
|
||||||
|
|
||||||
def show_total(balance, plus=' '):
|
def show_total(balance, plus=' '):
|
||||||
print('%3s %-40s %s%c %6.2f Euro%s' \
|
print('%3s %-40s %s%c %6.2f Euro%s' \
|
||||||
% ('', '', color(balance), sign(balance, plus),
|
% ('', '', color(balance), sign(balance, plus),
|
||||||
abs(balance), COLOR_RESET))
|
abs(balance), COLOR_RESET))
|
||||||
|
|
||||||
def show_item(position, command):
|
def show_item(position, diff, label, color):
|
||||||
diff = command.difference()
|
|
||||||
label = command.label()
|
|
||||||
print('%2d) %-40s %s%c %6.2f Euro%s' \
|
print('%2d) %-40s %s%c %6.2f Euro%s' \
|
||||||
% (position, label, color_command(command), sign(diff),
|
% (position, label, color, sign(diff),
|
||||||
abs(diff), COLOR_RESET))
|
abs(diff), COLOR_RESET))
|
||||||
|
|
||||||
def show_bar():
|
def show_bar():
|
||||||
|
@ -145,8 +147,18 @@ class Status:
|
||||||
|
|
||||||
print('Geplante Änderungen:')
|
print('Geplante Änderungen:')
|
||||||
show_total(initial_balance)
|
show_total(initial_balance)
|
||||||
for i, (command, balance_backup) in enumerate(self.transfers):
|
i = 1
|
||||||
show_item(i + 1, command)
|
for command, dummy in self.transfers:
|
||||||
|
if isinstance(command, BuyCommand):
|
||||||
|
if (command.includes_commodity()):
|
||||||
|
show_item(i, -command.commodity_value(), command.commodity_label(), COLOR_WITHDRAW)
|
||||||
|
i += 1
|
||||||
|
if (command.includes_deposit()):
|
||||||
|
show_item(i, -command.deposit_value(), command.deposit_label(), COLOR_TO_GO)
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
show_item(i, command.difference(), command.label(), COLOR_DEPOSIT)
|
||||||
|
i += 1
|
||||||
show_bar()
|
show_bar()
|
||||||
if len(self.transfers) > 1:
|
if len(self.transfers) > 1:
|
||||||
show_total(self.balance - initial_balance, plus='+')
|
show_total(self.balance - initial_balance, plus='+')
|
||||||
|
@ -236,109 +248,78 @@ class Status:
|
||||||
|
|
||||||
if scope == TO_GO_ALL:
|
if scope == TO_GO_ALL:
|
||||||
"""
|
"""
|
||||||
Adds a ToGoCommands for each BuyCommands with deposit > 0 lacking a pair
|
Makes all BuyCommands with deposit > 0 include deposit
|
||||||
|
...and updates future balance accordingly.
|
||||||
"""
|
"""
|
||||||
after = list()
|
|
||||||
dummy, initial_balance = self.transfers[0]
|
dummy, initial_balance = self.transfers[0]
|
||||||
balance_before = initial_balance
|
balance_before = initial_balance
|
||||||
|
|
||||||
def body(prev, command, balance_before):
|
for command, dummy in self.transfers:
|
||||||
if isinstance(prev, BuyCommand) \
|
if isinstance(command, BuyCommand) \
|
||||||
and prev.deposit() > 0 \
|
and not command.includes_deposit() \
|
||||||
and (not isinstance(command, ToGoCommand) \
|
and command.deposit_value() > 0:
|
||||||
or (isinstance(command, ToGoCommand) \
|
command.include_deposit(True)
|
||||||
and prev.item() != command.item())):
|
|
||||||
to_go = ToGoCommand(prev.item())
|
|
||||||
prev.set_to_go(True)
|
|
||||||
after.append((to_go, balance_before))
|
|
||||||
balance_before += to_go.difference()
|
|
||||||
if command is not None:
|
|
||||||
after.append((command, balance_before))
|
|
||||||
balance_before += command.difference()
|
balance_before += command.difference()
|
||||||
return balance_before
|
|
||||||
|
|
||||||
prev = None
|
|
||||||
for command, dummy in list(self.transfers):
|
|
||||||
balance_before = body(prev, command, balance_before)
|
|
||||||
prev = command
|
|
||||||
balance_before = body(prev, None, balance_before)
|
|
||||||
|
|
||||||
self.balance = balance_before
|
self.balance = balance_before
|
||||||
self.transfers = after
|
|
||||||
elif scope == TO_GO_NONE:
|
elif scope == TO_GO_NONE:
|
||||||
"""
|
"""
|
||||||
Deletes all ToGoCommands
|
Makes all BuyCommands that include commodity
|
||||||
|
not include deposit any more
|
||||||
|
...and updates future balance accordingly.
|
||||||
"""
|
"""
|
||||||
after = list()
|
|
||||||
first_command, initial_balance = self.transfers[0]
|
first_command, initial_balance = self.transfers[0]
|
||||||
balance_before = initial_balance
|
balance_before = initial_balance
|
||||||
|
|
||||||
for command, dummy in list(self.transfers):
|
for command, dummy in self.transfers:
|
||||||
if isinstance(command, BuyCommand) \
|
if isinstance(command, BuyCommand) \
|
||||||
and command.is_to_go():
|
and command.includes_commodity():
|
||||||
command.set_to_go(False)
|
command.include_deposit(False)
|
||||||
elif isinstance(command, ToGoCommand):
|
|
||||||
continue
|
|
||||||
after.append((command, balance_before))
|
|
||||||
balance_before += command.difference()
|
balance_before += command.difference()
|
||||||
|
|
||||||
self.balance = balance_before
|
self.balance = balance_before
|
||||||
self.transfers = after
|
|
||||||
elif scope == TO_GO_PREV:
|
elif scope == TO_GO_PREV:
|
||||||
"""
|
"""
|
||||||
Adds a ToGoCommand after previous BuyCommand
|
Makes the last BuyCommand include deposit
|
||||||
|
...and updates future balance accordingly.
|
||||||
"""
|
"""
|
||||||
prev, balance_backup = self.transfers[-1]
|
prev, balance_backup = self.transfers[-1]
|
||||||
if not isinstance(prev, BuyCommand):
|
if not isinstance(prev, BuyCommand):
|
||||||
error_page(_PRODUCT_FIRST)
|
error_page(_PRODUCT_FIRST)
|
||||||
return
|
return
|
||||||
to_go = ToGoCommand(prev.item())
|
if prev.includes_deposit():
|
||||||
prev.set_to_go(True)
|
error_page('FEHLER: Pfand für Produkt "%s" bereits aktiviert' % prev.item_name())
|
||||||
self.transfers.append((to_go, self.balance))
|
return
|
||||||
self.balance += to_go.difference()
|
if prev.deposit_value() <= 0:
|
||||||
|
error_page('FEHLER: Produkt "%s" hat kein Pfand' % prev.item_name())
|
||||||
|
return
|
||||||
|
before = prev.difference()
|
||||||
|
prev.include_deposit(True)
|
||||||
|
after = prev.difference()
|
||||||
|
self.balance += (after - before)
|
||||||
elif scope == TO_GO_ONLY:
|
elif scope == TO_GO_ONLY:
|
||||||
"""
|
"""
|
||||||
Replace all BuyCommands with deposit > 0 by
|
Makes all BuyCommand that include commodity
|
||||||
a ToGoCommand. Resolve ToGoCommand duplicates.
|
be deposit only
|
||||||
|
...and updates future balance accordingly.
|
||||||
"""
|
"""
|
||||||
after = list()
|
dummy, initial_balance = self.transfers[0]
|
||||||
first_command, initial_balance = self.transfers[0]
|
|
||||||
balance_before = initial_balance
|
balance_before = initial_balance
|
||||||
|
|
||||||
for command, dummy in list(self.transfers):
|
for command, dummy in self.transfers:
|
||||||
if isinstance(command, ToGoCommand) \
|
if isinstance(command, BuyCommand) \
|
||||||
and prev_item is not None \
|
and command.deposit_value() > 0 \
|
||||||
and command.item() == prev_item:
|
and command.includes_commodity():
|
||||||
"""
|
command.include_commodity(False)
|
||||||
Skip this very duplicate
|
command.include_deposit(True)
|
||||||
"""
|
|
||||||
prev_item = None
|
|
||||||
continue
|
|
||||||
elif isinstance(command, BuyCommand) \
|
|
||||||
and command.deposit() > 0:
|
|
||||||
"""
|
|
||||||
Replace by ToGoCommand
|
|
||||||
"""
|
|
||||||
item = command.item()
|
|
||||||
command = ToGoCommand(item)
|
|
||||||
prev_item = item
|
|
||||||
else:
|
|
||||||
prev_item = None
|
|
||||||
after.append((command, balance_before))
|
|
||||||
balance_before += command.difference()
|
balance_before += command.difference()
|
||||||
|
|
||||||
self.balance = balance_before
|
self.balance = balance_before
|
||||||
self.transfers = after
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
assert(self.logged_in())
|
assert(self.logged_in())
|
||||||
if self.transfers:
|
if self.transfers:
|
||||||
(last_command, balance_backup) = self.transfers[-1]
|
dummy, balance_backup = self.transfers[-1]
|
||||||
if isinstance(last_command, ToGoCommand) \
|
|
||||||
and self.transfers:
|
|
||||||
second_last_command = self.transfers[-2]
|
|
||||||
if isinstance(second_last_command, BuyCommand):
|
|
||||||
second_last_command.set_to_go(False)
|
|
||||||
self.transfers.pop()
|
self.transfers.pop()
|
||||||
self.balance = balance_backup
|
self.balance = balance_backup
|
||||||
else:
|
else:
|
||||||
|
@ -378,7 +359,10 @@ def handle(line, status):
|
||||||
except urllib2.HTTPError as e:
|
except urllib2.HTTPError as e:
|
||||||
if e.code == 404: # URL not found == user unknown
|
if e.code == 404: # URL not found == user unknown
|
||||||
print_display('\e\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7])
|
print_display('\e\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7])
|
||||||
error_page('FEHLER: Benutzer "%s" nicht bekannt' % line)
|
error_page('FEHLER: Benutzer "%s" nicht bekannt' % line,
|
||||||
|
hint_message='Ist in der WebApp unter "Einstellungen" ' \
|
||||||
|
'für Ihren Account Plugin "BarcodePlugin" ' \
|
||||||
|
'als erlaubt markiert?')
|
||||||
else:
|
else:
|
||||||
print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
||||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||||
|
|
|
@ -5,18 +5,16 @@
|
||||||
# Licensed under GPL v3 or later
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import freitagslib.network as net
|
import freitagslib.network as net
|
||||||
from freitagslib.network import ITEM_ONLY, DEPOSIT_ONLY
|
from freitagslib.network import ITEM_ONLY, DEPOSIT_ONLY, ITEM_AND_DEPOSIT
|
||||||
|
|
||||||
|
|
||||||
class Command(object):
|
class DepositCommand(object):
|
||||||
def difference(self):
|
|
||||||
return self._difference
|
|
||||||
|
|
||||||
|
|
||||||
class DepositCommand(Command):
|
|
||||||
def __init__(self, amount):
|
def __init__(self, amount):
|
||||||
self._difference = amount
|
self._difference = amount
|
||||||
|
|
||||||
|
def difference(self):
|
||||||
|
self._difference
|
||||||
|
|
||||||
def run(self, user_name):
|
def run(self, user_name):
|
||||||
net.deposit(self._difference, net.DEPOSIT_CASH, user_name)
|
net.deposit(self._difference, net.DEPOSIT_CASH, user_name)
|
||||||
|
|
||||||
|
@ -24,43 +22,61 @@ class DepositCommand(Command):
|
||||||
return '%.2f Euro einzahlen' % self._difference
|
return '%.2f Euro einzahlen' % self._difference
|
||||||
|
|
||||||
|
|
||||||
class _ItemBasedCommand(Command):
|
class BuyCommand(object):
|
||||||
def __init__(self, item):
|
def __init__(self, item):
|
||||||
self._item = item
|
self._item = item
|
||||||
|
self._commodity = True
|
||||||
|
self._deposit = False
|
||||||
|
|
||||||
def item(self):
|
def _what_to_buy(self):
|
||||||
return self._item
|
if self._deposit and self._commodity:
|
||||||
|
return ITEM_AND_DEPOSIT
|
||||||
|
elif self._deposit:
|
||||||
|
return DEPOSIT_ONLY
|
||||||
|
elif self._commodity:
|
||||||
|
return ITEM_ONLY
|
||||||
|
else:
|
||||||
|
raise ValueError("BuyCommand in illegal state")
|
||||||
|
|
||||||
|
def difference(self):
|
||||||
class BuyCommand(_ItemBasedCommand):
|
if self._deposit and self._commodity:
|
||||||
def __init__(self, item):
|
return -(self._item.price + self._item.deposit)
|
||||||
super(BuyCommand, self).__init__(item)
|
elif self._deposit:
|
||||||
self._difference = -item.price
|
return -(self._item.deposit)
|
||||||
self._to_go = False ## TODO session state, instead?
|
elif self._commodity:
|
||||||
|
return -(self._item.price)
|
||||||
|
else:
|
||||||
|
raise ValueError("BuyCommand in illegal state")
|
||||||
|
|
||||||
def run(self, user_name):
|
def run(self, user_name):
|
||||||
net.buy_item(self._item.id, what_about_it=ITEM_ONLY, user_name=user_name)
|
net.buy_item(self._item.id, what_about_it=self._what_to_buy(), user_name=user_name)
|
||||||
|
|
||||||
def label(self):
|
def item_name(self):
|
||||||
return self._item.name
|
return self._item.name
|
||||||
|
|
||||||
def is_to_go(self):
|
def commodity_label(self):
|
||||||
return self._to_go
|
if self._deposit:
|
||||||
|
return self._item.name
|
||||||
|
else:
|
||||||
|
return "%s (exkl. Pfand)" % self._item.name
|
||||||
|
|
||||||
def set_to_go(self, to_go):
|
def deposit_label(self):
|
||||||
self._to_go = to_go
|
|
||||||
|
|
||||||
def deposit(self):
|
|
||||||
return self._item.deposit
|
|
||||||
|
|
||||||
|
|
||||||
class ToGoCommand(_ItemBasedCommand):
|
|
||||||
def __init__(self, item):
|
|
||||||
super(ToGoCommand, self).__init__(item)
|
|
||||||
self._difference = -item.deposit
|
|
||||||
|
|
||||||
def run(self, user_name):
|
|
||||||
net.buy_item(self._item.id, what_about_it=DEPOSIT_ONLY, user_name=user_name)
|
|
||||||
|
|
||||||
def label(self):
|
|
||||||
return '%s Pfand' % self._item.name
|
return '%s Pfand' % self._item.name
|
||||||
|
|
||||||
|
def includes_commodity(self):
|
||||||
|
return self._commodity
|
||||||
|
|
||||||
|
def includes_deposit(self):
|
||||||
|
return self._deposit
|
||||||
|
|
||||||
|
def include_commodity(self, commodity):
|
||||||
|
self._commodity = commodity
|
||||||
|
|
||||||
|
def include_deposit(self, deposit):
|
||||||
|
self._deposit = deposit
|
||||||
|
|
||||||
|
def commodity_value(self):
|
||||||
|
return self._item.price
|
||||||
|
|
||||||
|
def deposit_value(self):
|
||||||
|
return self._item.deposit
|
||||||
|
|
|
@ -26,34 +26,41 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<table width="800px" class="details">
|
<table class="details">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Buchung</th>
|
<th>Buchung</th>
|
||||||
<th>Einkauf</th>
|
<th style="text-align:left">Einkauf</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Buchung</th>
|
<th>Buchung</th>
|
||||||
<th>Einkauf</th>
|
<th style="text-align:left">Einkauf</th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for order in history.object_list %}
|
{% for order in history.object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td width="150px">
|
||||||
{{ order.dateTime|date:"Y-m-d H:i" }}
|
{{ order.dateTime|date:"Y-m-d H:i" }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td style="text-align:left">
|
||||||
<ul>
|
<table>
|
||||||
|
<tr>
|
||||||
{% for item in order.purchase_set.all %}
|
{% for item in order.purchase_set.all %}
|
||||||
<li>
|
<td width="80px">
|
||||||
<strong>{{ item.buyable.name }}{% if item.isDeposit %} Pfand{% endif %}</strong>
|
{% if not item.isDeposit %}
|
||||||
|
<img src="{{ MEDIA_URL }}{{ item.buyable.image }}" width=64 height=64>
|
||||||
|
{% else %}
|
||||||
|
<b>{{ item.buyable.name }} Pfand</b>
|
||||||
|
{% endif %}
|
||||||
|
<br/>
|
||||||
zu {{ item.price|floatformat:2 }} €
|
zu {{ item.price|floatformat:2 }} €
|
||||||
</li>
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</tr>
|
||||||
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -1,36 +1,238 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
{% if allMost %}
|
<div style="width:1200px">
|
||||||
Am beliebtesten ist: <br /> <br />
|
{% if allMostDrinks or allMostSnacks %}
|
||||||
{% for buyable in allMost %}
|
<table width="100%" class="showitem" style="border-width:0px">
|
||||||
<a href="/store/show/{{ buyable.buyable__id }}">{{ buyable.buyable__name }}</a> ( {{ buyable.num_buys }} mal) <br />
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h1>Die beliebtesten Artikel</h1>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h1>Deine Lieblingsartikel</h1>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h1>Zuletzt hattest du:</h1>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="-moz-transform: rotate(270deg); -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); -o-transform: rotate(270deg); transform: rotate(270deg)">
|
||||||
|
<h1 style="vertical-align:top">Getränke</h1>
|
||||||
|
</td>
|
||||||
|
<td style="vertical-align:top">
|
||||||
|
{% if allMostDrinks %}
|
||||||
|
<table width=100%>
|
||||||
|
{% for buyable in allMostDrinks %}
|
||||||
|
<tr>
|
||||||
|
<td width="80px">
|
||||||
|
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>{{ buyable.buyable__name }}</b><br/>({{ buyable.num_buys }} mal)
|
||||||
|
</td>
|
||||||
|
<td width="150px">
|
||||||
|
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
|
||||||
|
{% if buyable.buyable__deposit > 0 %}
|
||||||
|
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
|
||||||
|
{% else %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<br />
|
</table>
|
||||||
|
{% else %}
|
||||||
|
Noch keine gekauft.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td style="vertical-align:top">
|
||||||
|
{% if usersMostDrinks %}
|
||||||
|
<table width=100%>
|
||||||
|
{% for buyable in usersMostDrinks %}
|
||||||
|
<tr>
|
||||||
|
<td width="80px">
|
||||||
|
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>{{ buyable.buyable__name }}</b><br/> ({{ buyable.num_buys }} mal)
|
||||||
|
</td>
|
||||||
|
<td width="150px">
|
||||||
|
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
|
||||||
|
{% if buyable.buyable__deposit > 0 %}
|
||||||
|
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
|
||||||
|
{% else %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
Noch keine gekauft.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td style="vertical-align:top">
|
||||||
|
{% if usersLastDrinks %}
|
||||||
|
<table width=100%>
|
||||||
|
{% for buyable in usersLastDrinks %}
|
||||||
|
<tr>
|
||||||
|
<td width="80px">
|
||||||
|
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>{{ buyable.buyable__name }}</b>
|
||||||
|
</td>
|
||||||
|
<td width="150px">
|
||||||
|
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
|
||||||
|
{% if buyable.buyable__deposit > 0 %}
|
||||||
|
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
|
||||||
|
{% else %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
Noch keine gekauft.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th style="-moz-transform: rotate(270deg); -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); -o-transform: rotate(270deg); transform: rotate(270deg)">
|
||||||
|
<h1>Snacks</h1>
|
||||||
|
</th>
|
||||||
|
<td style="vertical-align:top">
|
||||||
|
{% if allMostSnacks %}
|
||||||
|
<table width=100%>
|
||||||
|
{% for buyable in allMostSnacks %}
|
||||||
|
<tr>
|
||||||
|
<td width="80px">
|
||||||
|
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>{{ buyable.buyable__name }}</b><br/> ({{ buyable.num_buys }} mal)
|
||||||
|
</td>
|
||||||
|
<td width="150px">
|
||||||
|
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
|
||||||
|
{% if buyable.buyable__deposit > 0 %}
|
||||||
|
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
|
||||||
|
{% else %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
Noch keine gekauft.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td style="vertical-align:top">
|
||||||
|
{% if usersMostSnacks %}
|
||||||
|
<table width=100%>
|
||||||
|
{% for buyable in usersMostSnacks %}
|
||||||
|
<tr>
|
||||||
|
<td width="80px">
|
||||||
|
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>{{ buyable.buyable__name }}</b><br/> ({{ buyable.num_buys }} mal)
|
||||||
|
</td>
|
||||||
|
<td width="150px">
|
||||||
|
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
|
||||||
|
{% if buyable.buyable__deposit > 0 %}
|
||||||
|
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
|
||||||
|
{% else %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
Noch keine gekauft.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td style="vertical-align:top">
|
||||||
|
{% if usersLastSnacks %}
|
||||||
|
<table width=100%>
|
||||||
|
{% for buyable in usersLastSnacks %}
|
||||||
|
<tr>
|
||||||
|
<td width="80px">
|
||||||
|
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>{{ buyable.buyable__name }}</b>
|
||||||
|
</td>
|
||||||
|
<td width="150px">
|
||||||
|
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
|
||||||
|
{% if buyable.buyable__deposit > 0 %}
|
||||||
|
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
|
||||||
|
{% else %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
Noch keine gekauft.
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ error }}
|
{{ error }}
|
||||||
Noch niemand hat was gekauft?
|
Es hat scheinbar noch niemand etwas gekauft. <a href="/store/">Sei der Erste!</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr>
|
</div>
|
||||||
{% if usersMost %}
|
|
||||||
Am oeftesten hattest du: <br /> <br />
|
{% comment %}
|
||||||
{% for buyable in usersMost %}
|
<div style="width:800px">
|
||||||
<a href="/store/show/{{ buyable.buyable__id }}">{{ buyable.buyable__name }}</a> ( {{ buyable.num_buys }} mal) <br />
|
{% if usersMostSnacks or usersMostDrinks %}
|
||||||
{% endfor %}
|
<h1>Deine Lieblingsartikel</h1>
|
||||||
<br />
|
<table class="showitem" width="100%" style="border-width:0px">
|
||||||
|
<tr>
|
||||||
|
<th width="50%">
|
||||||
|
Getränke
|
||||||
|
</th>
|
||||||
|
<th width="50%">
|
||||||
|
Snacks
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ error }}
|
{{ error }}
|
||||||
Nix gekauft?
|
Wie es aussieht, hast du noch nichts gekauft. <a href="/store/">Das kannst du ändern!</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr>
|
</div>
|
||||||
{% if usersLast %}
|
<div style="width:800px">
|
||||||
Als letztes hattest du: <br /> <br />
|
{% if usersLastSnacks or usersLastDrinks %}
|
||||||
{% for buyable in usersLast %}
|
<h1>Du hattest als letztes:</h1>
|
||||||
<a href="/store/show/{{ buyable.buyable__id }}">{{ buyable.buyable__name }}</a> <br />
|
<table class="showitem" width="100%" style="border-width:0px">
|
||||||
{% endfor %}
|
<tr>
|
||||||
<br />
|
<th width="50%">
|
||||||
|
Getränke
|
||||||
|
</th>
|
||||||
|
<th width="50%">
|
||||||
|
Snacks
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ error }}
|
{{ error }}
|
||||||
Noch nix gekauft?
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endcomment %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf8 -*-
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
@ -5,18 +6,46 @@ from django.db.models import Count
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from main.models import Plugin, PluginPermission
|
from main.models import Plugin, PluginPermission
|
||||||
|
|
||||||
|
from buyable.models import Purchase, Buyable, BuyableType
|
||||||
from buyable.models import Purchase, Buyable
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def startpage(request):
|
def startpage(request):
|
||||||
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
|
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
|
||||||
sie ueber mehrere Tabellen joined,filtered und wieder reduced.
|
sie ueber mehrere Tabellen joined,filtered und wieder reduced.
|
||||||
'''
|
'''
|
||||||
allMost = Purchase.objects.filter(isDeposit=False).values('buyable__name', 'buyable__id').annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
drinks = BuyableType.objects.get(name="Getränk").buyable_set.all()
|
||||||
usersMost = Purchase.objects.filter(isDeposit=False).values('buyable__name','buyable__id').filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
snacks = BuyableType.objects.get(name="Snack").buyable_set.all()
|
||||||
usersLast = Purchase.objects.filter(isDeposit=False).values('buyable__name','buyable__id').filter(order__user=request.user.id).order_by('-order__dateTime')
|
|
||||||
return render_to_response("main/startpage.html", {'allMost' : allMost,'usersMost': usersMost, 'usersLast' : usersLast[:12]}, RequestContext(request))
|
allMost = Purchase.objects.filter(isDeposit=False).values('buyable__name', 'buyable__id','buyable__image','buyable__price','buyable__deposit')
|
||||||
|
|
||||||
|
allMostDrinks = allMost.filter(buyable__in=drinks).annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
||||||
|
allMostSnacks = allMost.filter(buyable__in=snacks).annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
||||||
|
|
||||||
|
usersMostDrinks = allMost.filter(buyable__in=drinks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
||||||
|
usersMostSnacks = allMost.filter(buyable__in=snacks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
||||||
|
|
||||||
|
# usersLastDrinks = allMost.filter(buyable__in=drinks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-order__dateTime')
|
||||||
|
# usersLastSnacks = allMost.filter(buyable__in=snacks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-order__dateTime')
|
||||||
|
|
||||||
|
usersLastDrinks = allMost.filter(buyable__in=drinks).filter(order__user=request.user.id).order_by('-order__dateTime')
|
||||||
|
usersLastSnacks = allMost.filter(buyable__in=snacks).filter(order__user=request.user.id).order_by('-order__dateTime')
|
||||||
|
|
||||||
|
#if someone knows a better way to do this, just replace this code
|
||||||
|
#purpose: filter usersLast so that it only contains unique items
|
||||||
|
usersLastDrinks_unique = []
|
||||||
|
for x in usersLastDrinks:
|
||||||
|
if not x in usersLastDrinks_unique:
|
||||||
|
usersLastDrinks_unique.append(x)
|
||||||
|
#usersLastDrinks = map(lambda x:{ "buyable__name" : x }, usersLastDrinks_unique)
|
||||||
|
usersLastDrinks = usersLastDrinks_unique
|
||||||
|
|
||||||
|
usersLastSnacks_unique = []
|
||||||
|
for x in usersLastSnacks:
|
||||||
|
if not x in usersLastSnacks_unique:
|
||||||
|
usersLastSnacks_unique.append(x)
|
||||||
|
usersLastSnacks = usersLastSnacks_unique
|
||||||
|
|
||||||
|
return render_to_response("main/startpage.html", {'allMostDrinks' : allMostDrinks[:5], 'allMostSnacks' : allMostSnacks[:5], 'usersMostDrinks': usersMostDrinks[:5], 'usersMostSnacks': usersMostSnacks[:5], 'usersLastDrinks' : usersLastDrinks[:10], 'usersLastSnacks' : usersLastSnacks[:10]}, RequestContext(request))
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
""" The "no registration available" page... """
|
""" The "no registration available" page... """
|
||||||
|
|
|
@ -26,20 +26,55 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="width:800px;margin-top:25px"><h1>Vergangene Transaktionen:</h1>
|
<div style="width:800px;margin-top:25px"><h1>Vergangene Transaktionen:</h1>
|
||||||
|
<table class="showitem" style="border-width:0px">
|
||||||
|
{% comment %}
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Datum
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Uhrzeit
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Betrag
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Typ
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Status
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
{% for transaction in history %}
|
{% for transaction in history %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
{% if forloop.first and transacted %}
|
{% if forloop.first and transacted %}
|
||||||
<b>
|
<b>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
[ {{ transaction.dateTime }} ] {{ transaction.amount|floatformat:2 }} € durch {{ transaction.transactionType }}
|
[ {{ transaction.dateTime|date:"j. M Y" }},
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ transaction.dateTime|date:"H:i" }} Uhr ]
|
||||||
|
<td>
|
||||||
|
<b>{{ transaction.amount|floatformat:2 }}€</b>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
durch {{ transaction.transactionType }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
{% if not transaction.transactionType.needsCheck or transaction.checked %}
|
{% if not transaction.transactionType.needsCheck or transaction.checked %}
|
||||||
eingegangen
|
eingegangen
|
||||||
{% else %}
|
{% else %}
|
||||||
<b> aber noch nicht bestätigt </b>
|
<b> aber noch nicht bestätigt </b>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</td>
|
||||||
{% if forloop.first and transacted %}
|
{% if forloop.first and transacted %}
|
||||||
</b>
|
</b>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br />
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue