summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/dvips/pst-barcode
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-08-12 23:59:52 +0000
committerKarl Berry <karl@freefriends.org>2009-08-12 23:59:52 +0000
commitdc5141dcc0afae34b80bc9538a865a84dc4f7e20 (patch)
tree4ee283e8534e03c345b2c4b70eb28347ee1fb9d1 /Master/texmf-dist/dvips/pst-barcode
parent27a19abcb11fade54f7d0e9000f04ab4dff216c5 (diff)
pst-barcode update (12aug09)
git-svn-id: svn://tug.org/texlive/trunk@14633 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/dvips/pst-barcode')
-rw-r--r--Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro5269
1 files changed, 3729 insertions, 1540 deletions
diff --git a/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro b/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro
index 67d1e4950ff..4e7442342b0 100644
--- a/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro
+++ b/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro
@@ -3,10 +3,10 @@
%%DocumentPaperSizes: a4
%%EndComments
-% Barcode Writer in Pure PostScript - Version 2008-07-10
+% Barcode Writer in Pure PostScript - Version 2009-08-12
% http://www.terryburton.co.uk/barcodewriter/
%
-% Copyright (c) 2008 Terry Burton - tez@terryburton.co.uk
+% Copyright (c) 2004-2009 Terry Burton
%
% Permission is hereby granted, free of charge, to any
% person obtaining a copy of this software and associated
@@ -40,57 +40,643 @@
% --BEGIN TEMPLATE--
+% --BEGIN RENDERER renlinear--
+/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
+ /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 maxh gt {/maxh h def} if
+ } {
+ /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 {
+ {} forall
+ newpath setlinewidth moveto 0 exch rlineto stroke
+ } 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
+% --END RENDERER renlinear--
+
+% --BEGIN RENDERER renmatrix--
+/renmatrix {
+
+ 20 dict begin
+
+ /args exch def
+
+ % Default options
+ /width 1 def
+ /height 1 def
+ /color (unset) def
+ /backgroundcolor (unset) def
+
+ % Apply the renderer options and the user options
+ args {def} forall
+ opt {def} forall
+
+ /width width cvr def
+ /height height cvr def
+ /color color cvlit def
+ /backgroundcolor backgroundcolor cvlit def
+
+ % Extend bitmap horizontally to an 8-bit boundary
+ /pixx8 pixx 8 div ceiling cvi 8 mul def
+ /pixs8 [ pixx8 pixy mul {0} repeat ] def
+ 0 1 pixy 1 sub {
+ /i exch def
+ pixs8 pixx8 i mul pixs pixx i mul pixx getinterval putinterval
+ } for
+ /pixs pixs8 def
+
+ % Convert bitmap into 8-bit sample string
+ /imgstr pixs length 8 idiv string def
+ 0 1 pixs length 1 sub {
+ /i exch def
+ imgstr i 8 idiv 2 copy get 2 7 i 8 mod sub exp cvi pixs i get mul add put
+ } for
+
+ % 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
+
+ % Draw the image
+ gsave
+ currentpoint translate
+ 72 width mul 72 height mul scale
+ .0001 .0001 moveto .9999 .0001 lineto .9999 .9999 lineto .0001 .9999 lineto closepath
+ backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
+ color (unset) ne { color setanycolor } if
+ pixx pixy true [ pixx 0 0 pixy neg 0 pixy ] {imgstr} imagemask
+ grestore
+
+ end
+
+} bind def
+% --END RENDERER renmatrix--
+
+% --BEGIN RENDERER renmaximatrix--
+/renmaximatrix {
+
+ 20 dict begin
+
+ /args exch def % We are given some arguments
+
+ % Apply the renderer options and the user options
+ args {def} forall
+ opt {def} forall
+
+ gsave
+
+ currentpoint translate
+
+ 2.4945 dup scale % from 1pt to 1.88mm
+ 0.5 0.5774 translate
+
+ pixs {
+ dup
+ /x exch 30 mod def
+ /y exch 30 idiv def
+ y 2 mod 0 eq {x} {x 0.5 add} ifelse
+ 32 y sub 0.8661 mul
+ moveto
+ 0 0.5774 rmoveto
+ -0.5 -0.2887 rlineto
+ 0 -0.5774 rlineto
+ 0.5 -0.2887 rlineto
+ 0.5 0.2887 rlineto
+ 0 0.5774 rlineto
+ -0.5 0.2887 rlineto
+ closepath fill
+ } forall
+
+ % Plot the locator symbol
+ newpath 14 13.8576 0.5774 0 360 arc closepath
+ 14 13.8576 1.3359 360 0 arcn closepath fill
+ newpath 14 13.8576 2.1058 0 360 arc closepath
+ 14 13.8576 2.8644 360 0 arcn closepath fill
+ newpath 14 13.8576 3.6229 0 360 arc closepath
+ 14 13.8576 4.3814 360 0 arcn closepath fill
+
+ grestore
+
+ end
+
+} bind def
+% --END RENDERER renmaximatrix--
+
+% --BEGIN ENCODER ean5--
+% --DESC: EAN-5 (5 digit addon)
+% --EXAM: 90200
+% --EXOP: includetext guardwhitespace
+% --RNDR: renlinear
+/ean5 {
+
+ 20 dict begin
+
+ /options exch def % We are given an option string
+ /barcode exch def % We are given a barcode string
+
+ /dontdraw false def
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textxoffset 0 def
+ /textyoffset (unset) def
+ /height 0.7 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
+ /height height cvr def
+ /textxoffset textxoffset cvr def
+ textyoffset (unset) eq {
+ /textyoffset height 72 mul 1 add def
+ } {
+ /textyoffset textyoffset cvr def
+ } ifelse
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (112) (11)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ % Determine the mirror map based on mod 10 checksum
+ /mirrormaps
+ [ (11000) (10100) (10010) (10001) (01100)
+ (00110) (00011) (01010) (01001) (00101)
+ ] def
+ /checksum 0 def
+ 0 1 4 {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 eq {
+ /checksum barchar 3 mul checksum add def
+ } {
+ /checksum barchar 9 mul checksum add def
+ } ifelse
+ } for
+ /checksum checksum 10 mod def
+ /mirrormap mirrormaps checksum get def
+
+ /sbs 31 string def
+ /txt 5 array def
+
+ 0 1 4 {
+ /i exch def
+
+ % Prefix with either a start character or separator character
+ i 0 eq {
+ sbs 0 encs 10 get putinterval
+ } {
+ sbs i 1 sub 6 mul 7 add encs 11 get putinterval
+ } ifelse
+
+ % Lookup the encoding for the barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
+ /enclen enc length def
+ /revenc enclen string def
+ 0 1 enclen 1 sub {
+ /j exch def
+ /char enc j get def
+ revenc enclen j sub 1 sub char put
+ } for
+ /enc revenc def
+ } if
+ sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
+ } for
+
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /sbs [sbs {48 sub} forall]
+ /bhs [16{height}repeat]
+ /bbs [16{0}repeat]
+ includetext {
+ /txt txt
+ } if
+ /opt options
+ /guardrightpos 10
+ /guardrightypos textyoffset 4 add
+ /bordertop 10
+ >>
+
+ dontdraw not //renlinear if
+
+ end
+
+} bind def
+% --END ENCODER ean5--
+
+% --BEGIN ENCODER ean2--
+% --DESC: EAN-2 (2 digit addon)
+% --EXAM: 05
+% --EXOP: includetext guardwhitespace
+% --RNDR: renlinear
+/ean2 {
+
+ 20 dict begin
+
+ /options exch def % We are given an options string
+ /barcode exch def % We are given a barcode string
+
+ /dontdraw false def
+ /includetext false def % Enable/disable text
+ /textfont /Helvetica def
+ /textsize 12 def
+ /textxoffset 0 def
+ /textyoffset (unset) def
+ /height 0.7 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
+ /height height cvr def
+ /textxoffset textxoffset cvr def
+ textyoffset (unset) eq {
+ /textyoffset height 72 mul 1 add def
+ } {
+ /textyoffset textyoffset cvr def
+ } ifelse
+
+ % Create an array containing the character mappings
+ /encs
+ [ (3211) (2221) (2122) (1411) (1132)
+ (1231) (1114) (1312) (1213) (3112)
+ (112) (11)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789) def
+
+ % Determine the mirror map based on mod 4 checksum
+ /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
+
+ /sbs 13 string def
+ /txt 2 array def
+
+ 0 1 1 {
+ /i exch def
+
+ % Prefix with either a start character or separator character
+ i 0 eq {
+ sbs 0 encs 10 get putinterval
+ } {
+ sbs i 1 sub 6 mul 7 add encs 11 get putinterval
+ } ifelse
+
+ % Lookup the encoding for the barcode character
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard seek and post
+ /enc encs indx get def % Get the indxth encoding
+ mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
+ /enclen enc length def
+ /revenc enclen string def
+ 0 1 enclen 1 sub {
+ /j exch def
+ /char enc j get def
+ revenc enclen j sub 1 sub char put
+ } for
+ /enc revenc def
+ } if
+ sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
+ txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
+ } for
+
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /sbs [sbs {48 sub} forall]
+ /bhs [12{height}repeat]
+ /bbs [12{0}repeat]
+ includetext {
+ /txt txt
+ } if
+ /opt options
+ /guardrightpos 10
+ /guardrightypos textyoffset 4 add
+ /bordertop 10
+ >>
+
+ dontdraw not //renlinear if
+
+ end
+
+} bind def
+% --END ENCODER ean2--
+
% --BEGIN ENCODER ean13--
+% --SUGGESTS ean5 ean2--
% --DESC: EAN-13
% --EXAM: 977147396801
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
/ean13 {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textyoffset -4 def
/height 1 def
-
- % Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ /addongap 12 def
+
+ % Parse the input options, either a string or a dict
+ 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
-
- /barlen barcode length def % Length of the code
+ /addongap addongap cvr def
- % Add checksum digit to barcode if length is even
- barlen 2 mod 0 eq {
- /pad barlen 1 add string def % Create pad one bigger than barcode
- /checksum 0 def
- 0 1 barlen 1 sub {
- /i exch def
- /barchar barcode i get 48 sub def
- i 2 mod 0 eq {
- /checksum barchar checksum add def
- } {
- /checksum barchar 3 mul checksum add def
- } ifelse
- } for
- /checksum 10 checksum 10 mod sub 10 mod def
- pad 0 barcode putinterval % Add barcode to the start of the pad
- pad barlen checksum 48 add put % Put ascii for checksum at end of pad
- /barcode pad def % barcode=pad
- /barlen barlen 1 add def % barlen++
- } if
+ % Split off the addon
+ barcode ( ) search {
+ /barcode exch def
+ pop
+ /addon exch def
+ } {
+ pop
+ /addon () def
+ } ifelse
+
+ % Add checksum digit
+ /pad 13 string def
+ /checksum 0 def
+ 0 1 11 {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 eq {
+ /checksum barchar checksum add def
+ } {
+ /checksum barchar 3 mul checksum add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad 12 checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def
% Create an array containing the character mappings
/encs
@@ -108,8 +694,8 @@
(011001) (011100) (010101) (010110) (011010)
] def
- /sbs barlen 1 sub 4 mul 11 add string def
- /txt barlen array def
+ /sbs 59 string def
+ /txt 13 array def
% Put the start character
sbs 0 encs 10 get putinterval
@@ -158,61 +744,122 @@
} for
% Put the end character
- sbs barlen 1 sub 4 mul 8 add encs 12 get putinterval
-
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
+ sbs 56 encs 12 get putinterval
+
+ /sbs [sbs {48 sub} forall] def
includetext {
- retval (bhs) [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] put
- retval (bbs) [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] put
- retval (txt) txt put
+ /bhs [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] def
+ /bbs [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] def
} {
- retval (bhs) [30{height}repeat] put
- retval (bbs) [30{0}repeat] put
+ /bhs [30{height}repeat] def
+ /bbs [30{0}repeat] def
+ /txt [] def
} ifelse
- retval (opt) useropts put
- retval (guardrightpos) 10 put
- retval (borderbottom) 5 put
- retval
-
+ /guardrightypos 0 def
+
+ % Append the addon
+ addon () ne {
+ /addopts <<
+ /dontdraw true
+ /includetext true
+ /height height 0.15 sub
+ /textxoffset 95 addongap add
+ >> def
+ addon length 2 eq {addon addopts //ean2 exec} if
+ addon length 5 eq {addon addopts //ean5 exec} if
+ /addcode exch def
+ /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
+ /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
+ /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
+ /txt [txt aload pop addcode (txt) get aload pop] def
+ /guardrightypos height 72 mul 6 sub def
+ } if
+
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs bhs
+ /bbs bbs
+ /txt txt
+ /opt options
+ /guardrightpos 10
+ /guardrightypos guardrightypos
+ /borderbottom 5
+ >>
+
+ dontdraw not //renlinear if
+
end
} bind def
-/ean13 load 0 1 dict put
% --END ENCODER ean13--
% --BEGIN ENCODER ean8--
+% --SUGGESTS ean5 ean2--
% --DESC: EAN-8
% --EXAM: 01335583
% --EXOP: includetext guardwhitespace height=0.5
% --RNDR: renlinear
/ean8 {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textyoffset -4 def
/height 1 def
-
- % Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ /addongap 12 def
+
+ % Parse the input options, either a string or a dict
+ 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
-
+ /addongap addongap cvr def
+
+ % Split off the addon
+ barcode ( ) search {
+ /barcode exch def
+ pop
+ /addon exch def
+ } {
+ pop
+ /addon () def
+ } ifelse
+
+ % Add checksum digit
+ /pad 8 string def
+ /checksum 0 def
+ 0 1 6 {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 ne {
+ /checksum barchar checksum add def
+ } {
+ /checksum barchar 3 mul checksum add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad 7 checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def
+
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
@@ -223,9 +870,8 @@
% Create a string of the available characters
/barchars (0123456789) def
- /barlen barcode length def % Length of the code
- /sbs barlen 4 mul 11 add string def
- /txt barlen array def
+ /sbs 43 string def
+ /txt 8 array def
% Put the start character
sbs 0 encs 10 get putinterval
@@ -260,83 +906,122 @@
} for
% Put the end character
- sbs barlen 4 mul 8 add encs 12 get putinterval
+ sbs 40 encs 12 get putinterval
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
+ /sbs [sbs {48 sub} forall] def
includetext {
- retval (bhs) [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] put
- retval (bbs) [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] put
- retval (txt) txt put
+ /bhs [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] def
+ /bbs [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] def
} {
- retval (bhs) [22{height}repeat] put
- retval (bbs) [22{0}repeat] put
+ /bhs [22{height}repeat] def
+ /bbs [22{0}repeat] def
+ /txt [] def
} ifelse
- retval (opt) useropts put
- retval (guardleftpos) 10 put
- retval (guardrightpos) 10 put
- retval (borderbottom) 5 put
- retval
+ /guardrightypos 0 def
+
+ % Append the addon
+ addon () ne {
+ /addopts <<
+ /dontdraw true
+ /includetext true
+ /height height 0.15 sub
+ /textxoffset 67 addongap add
+ >> def
+ addon length 2 eq {addon addopts //ean2 exec} if
+ addon length 5 eq {addon addopts //ean5 exec} if
+ /addcode exch def
+ /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
+ /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
+ /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
+ /txt [txt aload pop addcode (txt) get aload pop] def
+ /guardrightypos height 72 mul 6 sub def
+ } if
+
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs bhs
+ /bbs bbs
+ /txt txt
+ /opt options
+ /guardleftpos 10
+ /guardrightpos 10
+ /guardrightypos guardrightypos
+ /borderbottom 5
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/ean8 load 0 1 dict put
% --END ENCODER ean8--
% --BEGIN ENCODER upca--
+% --SUGGESTS ean5 ean2--
% --DESC: UPC-A
% --EXAM: 78858101497
% --EXOP: includetext
% --RNDR: renlinear
/upca {
- 0 begin
+ 20 dict begin
/options exch def
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textyoffset -4 def
- /height 1 def
-
+ /height 1 def
+ /addongap 12 def
+
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
-
- /barlen barcode length def % Length of the code
-
- % Add checksum digit to barcode if length is odd
- barlen 2 mod 0 ne {
- /pad barlen 1 add string def % Create pad one bigger than barcode
- /checksum 0 def
- 0 1 barlen 1 sub {
- /i exch def
- /barchar barcode i get 48 sub def
- i 2 mod 0 ne {
- /checksum checksum barchar add def
- } {
- /checksum checksum barchar 3 mul add def
- } ifelse
- } for
- /checksum 10 checksum 10 mod sub 10 mod def
- pad 0 barcode putinterval % Add barcode to the start of the pad
- pad barlen checksum 48 add put % Put ascii for checksum at end of pad
- /barcode pad def % barcode=pad
- /barlen barlen 1 add def % barlen++
- } if
+ /addongap addongap cvr def
+
+ % Split off the addon
+ barcode ( ) search {
+ /barcode exch def
+ pop
+ /addon exch def
+ } {
+ pop
+ /addon () def
+ } ifelse
+
+ % Add checksum digit to barcode
+ /pad 12 string def % Create pad one bigger than barcode
+ /checksum 0 def
+ 0 1 10 {
+ /i exch def
+ /barchar barcode i get 48 sub def
+ i 2 mod 0 ne {
+ /checksum checksum barchar add def
+ } {
+ /checksum checksum barchar 3 mul add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad 11 checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def
% Create an array containing the character mappings
/encs
@@ -348,8 +1033,8 @@
% Create a string of the available characters
/barchars (0123456789) def
- /sbs barlen 4 mul 11 add string def
- /txt barlen array def
+ /sbs 59 string def
+ /txt 12 array def
% Put the start character
sbs 0 encs 10 get putinterval
@@ -392,67 +1077,110 @@
} for
% Put the end character
- sbs barlen 4 mul 8 add encs 12 get putinterval
+ sbs 56 encs 12 get putinterval
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
+ /sbs [sbs {48 sub} forall] def
includetext {
- retval (bhs) [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 5{height}repeat] put
- retval (bbs) [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0 0] put
- retval (txt) txt put
+ /bhs [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 4{height}repeat] def
+ /bbs [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0] def
} {
- retval (bhs) [31{height}repeat] put
- retval (bbs) [31{0}repeat] put
+ /bhs [30{height}repeat] def
+ /bbs [30{0}repeat] def
+ /txt [] def
} ifelse
- retval (opt) useropts put
- retval (borderbottom) 5 put
- retval
+ /guardrightypos 0 def
+
+ % Append the addon
+ addon () ne {
+ /addopts <<
+ /dontdraw true
+ /includetext true
+ /height height 0.15 sub
+ /textxoffset 95 addongap add
+ >> def
+ addon length 2 eq {addon addopts //ean2 exec} if
+ addon length 5 eq {addon addopts //ean5 exec} if
+ /addcode exch def
+ /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
+ /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
+ /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
+ /txt [txt aload pop addcode (txt) get aload pop] def
+ /guardrightypos height 72 mul 6 sub def
+ } if
+
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs bhs
+ /bbs bbs
+ /txt txt
+ /opt options
+ /guardrightpos 10
+ /guardrightypos guardrightypos
+ /borderbottom 5
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/upca load 0 1 dict put
% --END ENCODER upca--
% --BEGIN ENCODER upce--
+% --SUGGESTS ean5 ean2--
% --DESC: UPC-E
% --EXAM: 0123456
% --EXOP: includetext height=0.4
% --RNDR: renlinear
/upce {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textyoffset -4 def
/height 1 def
-
+ /addongap 12 def
+
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
-
- /barlen barcode length def % Length of the code
+ /addongap addongap cvr def
+
+ % Split off the addon
+ barcode ( ) search {
+ /barcode exch def
+ pop
+ /addon exch def
+ } {
+ pop
+ /addon () def
+ } ifelse
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
(1231) (1114) (1312) (1213) (3112)
- (111) (1111111)
+ (111) (111111)
] def
% Create a string of the available characters
@@ -463,49 +1191,45 @@
(011001) (011100) (010101) (010110) (011010)
] def
- % Add checksum digit to barcode if length is odd
- barlen 2 mod 0 ne {
- % Derive the equivalent UPC-A for its checksum
- /upcacode (00000000000) 11 string copy def
- barcode 6 get 48 sub 2 le {
- upcacode 1 barcode 1 2 getinterval putinterval
- upcacode 3 barcode 6 1 getinterval putinterval
- upcacode 8 barcode 3 3 getinterval putinterval
- } if
- barcode 6 get 48 sub 3 eq {
- upcacode 1 barcode 1 3 getinterval putinterval
- upcacode 9 barcode 4 2 getinterval putinterval
- } if
- barcode 6 get 48 sub 4 eq {
- upcacode 1 barcode 1 4 getinterval putinterval
- upcacode 10 barcode 5 1 getinterval putinterval
- } if
- barcode 6 get 48 sub 5 ge {
- upcacode 1 barcode 1 5 getinterval putinterval
- upcacode 10 barcode 6 1 getinterval putinterval
- } if
- /checksum 0 def
- 0 1 10 {
- /i exch def
- /barchar upcacode i get 48 sub def
- i 2 mod 0 ne {
- /checksum checksum barchar add def
- } {
- /checksum checksum barchar 3 mul add def
- } ifelse
- } for
- /checksum 10 checksum 10 mod sub 10 mod def
- /pad barlen 1 add string def % Create pad one bigger than barcode
- pad 0 barcode putinterval % Add barcode to the start of the pad
- pad barlen checksum 48 add put % Put ascii for checksum at end of pad
- /barcode pad def % barcode=pad
- /barlen barlen 1 add def % barlen++
+ % Derive the equivalent UPC-A for its checksum
+ /upcacode (00000000000) 11 string copy def
+ barcode 6 get 48 sub 2 le {
+ upcacode 1 barcode 1 2 getinterval putinterval
+ upcacode 3 barcode 6 1 getinterval putinterval
+ upcacode 8 barcode 3 3 getinterval putinterval
} if
- /txt barlen array def
+ barcode 6 get 48 sub 3 eq {
+ upcacode 1 barcode 1 3 getinterval putinterval
+ upcacode 9 barcode 4 2 getinterval putinterval
+ } if
+ barcode 6 get 48 sub 4 eq {
+ upcacode 1 barcode 1 4 getinterval putinterval
+ upcacode 10 barcode 5 1 getinterval putinterval
+ } if
+ barcode 6 get 48 sub 5 ge {
+ upcacode 1 barcode 1 5 getinterval putinterval
+ upcacode 10 barcode 6 1 getinterval putinterval
+ } if
+ /checksum 0 def
+ 0 1 10 {
+ /i exch def
+ /barchar upcacode i get 48 sub def
+ i 2 mod 0 ne {
+ /checksum checksum barchar add def
+ } {
+ /checksum checksum barchar 3 mul add def
+ } ifelse
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ /pad 8 string def
+ pad 0 barcode putinterval % Add barcode to the start of the pad
+ pad 7 checksum 48 add put % Put ascii for checksum at end of pad
+ /barcode pad def
+ /txt 8 array def
txt 0 [barcode 0 1 getinterval -7 textyoffset textfont textsize 2 sub] put
% Determine the mirror map based on checksum
- /mirrormap mirrormaps barcode barlen 1 sub get 48 sub get def
+ /mirrormap mirrormaps checksum get def
% Invert the mirrormap if we are using a non-zero number system
barcode 0 get 48 eq {
@@ -521,7 +1245,7 @@
/mirrormap invt def
} if
- /sbs barlen 2 sub 4 mul 10 add string def
+ /sbs 33 string def
% Put the start character
sbs 0 encs 10 get putinterval
@@ -551,286 +1275,110 @@
txt 7 [barcode 7 1 getinterval 6 7 mul 11 add textyoffset textfont textsize 2 sub] put
% Put the end character
- sbs barlen 2 sub 4 mul 3 add encs 11 get putinterval
+ sbs 27 encs 11 get putinterval
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
+ /sbs [sbs {48 sub} forall] def
includetext {
- retval (bhs) [height height 12{height .075 sub}repeat height height height] put
- retval (bbs) [0 0 12{.075}repeat 0 0 0] put
- retval (txt) txt put
- } {
- retval (bhs) [17{height}repeat] put
- retval (bbs) [17{0}repeat] put
- } ifelse
- retval (opt) useropts put
- retval (borderbottom) 5 put
- retval
-
- end
-
-} bind def
-/upce load 0 1 dict put
-% --END ENCODER upce--
-
-% --BEGIN ENCODER ean5--
-% --DESC: EAN-5 (5 digit addon)
-% --EXAM: 90200
-% --EXOP: includetext guardwhitespace
-% --RNDR: renlinear
-/ean5 {
-
- 0 begin
-
- /options exch def % We are given an option string
- /useropts options def
- /barcode exch def % We are given a barcode string
-
- /includetext false def % Enable/disable text
- /textfont /Helvetica def
- /textsize 12 def
- /textyoffset (unset) def
- /height 0.7 def
-
- % Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
- /textfont textfont cvlit def
- /textsize textsize cvr def
- /height height cvr def
- textyoffset (unset) eq {
- /textyoffset height 72 mul 1 add def
+ /bhs [height height 12{height .075 sub}repeat height height height] def
+ /bbs [0 0 12{.075}repeat 0 0 0] def
} {
- /textyoffset textyoffset cvr def
+ /bhs [17{height}repeat] def
+ /bbs [17{0}repeat] def
+ /txt [] def
} ifelse
-
- /barlen barcode length def % Length of the code
-
- % Create an array containing the character mappings
- /encs
- [ (3211) (2221) (2122) (1411) (1132)
- (1231) (1114) (1312) (1213) (3112)
- (112) (11)
- ] def
-
- % Create a string of the available characters
- /barchars (0123456789) def
-
- % Determine the mirror map based on mod 10 checksum
- /mirrormaps
- [ (11000) (10100) (10010) (10001) (01100)
- (00110) (00011) (01010) (01001) (00101)
- ] def
- /checksum 0 def
- 0 1 4 {
- /i exch def
- /barchar barcode i get 48 sub def
- i 2 mod 0 eq {
- /checksum barchar 3 mul checksum add def
- } {
- /checksum barchar 9 mul checksum add def
- } ifelse
- } for
- /checksum checksum 10 mod def
- /mirrormap mirrormaps checksum get def
-
- /sbs 31 string def
- /txt 5 array def
-
- 0 1 4 {
- /i exch def
-
- % Prefix with either a start character or separator character
- i 0 eq {
- sbs 0 encs 10 get putinterval
- } {
- sbs i 1 sub 6 mul 7 add encs 11 get putinterval
- } ifelse
-
- % Lookup the encoding for the barcode character
- barcode i 1 getinterval barchars exch search
- pop % Discard true leaving pre
- length /indx exch def % indx is the length of pre
- pop pop % Discard seek and post
- /enc encs indx get def % Get the indxth encoding
- mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
- /enclen enc length def
- /revenc enclen string def
- 0 1 enclen 1 sub {
- /j exch def
- /char enc j get def
- revenc enclen j sub 1 sub char put
- } for
- /enc revenc def
- } if
- sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
- txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textyoffset textfont textsize] put
- } for
+ /guardrightypos 0 def
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [16{height}repeat] put
- retval (bbs) [16{0}repeat] put
- includetext {
- retval (txt) txt put
+ % Append the addon
+ addon () ne {
+ /addopts <<
+ /dontdraw true
+ /includetext true
+ /height height 0.15 sub
+ /textxoffset 51 addongap add
+ >> def
+ addon length 2 eq {addon addopts //ean2 exec} if
+ addon length 5 eq {addon addopts //ean5 exec} if
+ /addcode exch def
+ /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
+ /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
+ /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
+ /txt [txt aload pop addcode (txt) get aload pop] def
+ /guardrightypos height 72 mul 6 sub def
} if
- retval (opt) useropts put
- retval (guardrightpos) 10 put
- retval (guardrightypos) textyoffset 4 add put
- retval (bordertop) 10 put
- retval
-
- end
-
-} bind def
-/ean5 load 0 1 dict put
-% --END ENCODER ean5--
-
-% --BEGIN ENCODER ean2--
-% --DESC: EAN-2 (2 digit addon)
-% --EXAM: 05
-% --EXOP: includetext guardwhitespace
-% --RNDR: renlinear
-/ean2 {
-
- 0 begin
-
- /options exch def % We are given an options string
- /useropts options def
- /barcode exch def % We are given a barcode string
-
- /includetext false def % Enable/disable text
- /textfont /Helvetica def
- /textsize 12 def
- /textyoffset (unset) def
- /height 0.7 def
-
- % Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
- /textfont textfont cvlit def
- /textsize textsize cvr def
- /height height cvr def
- textyoffset (unset) eq {
- /textyoffset height 72 mul 1 add def
- } {
- /textyoffset textyoffset cvr def
- } ifelse
-
- /barlen barcode length def % Length of the code
-
- % Create an array containing the character mappings
- /encs
- [ (3211) (2221) (2122) (1411) (1132)
- (1231) (1114) (1312) (1213) (3112)
- (112) (11)
- ] def
-
- % Create a string of the available characters
- /barchars (0123456789) def
-
- % Determine the mirror map based on mod 4 checksum
- /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
-
- /sbs 13 string def
- /txt 2 array def
-
- 0 1 1 {
- /i exch def
-
- % Prefix with either a start character or separator character
- i 0 eq {
- sbs 0 encs 10 get putinterval
- } {
- sbs i 1 sub 6 mul 7 add encs 11 get putinterval
- } ifelse
-
- % Lookup the encoding for the barcode character
- barcode i 1 getinterval barchars exch search
- pop % Discard true leaving pre
- length /indx exch def % indx is the length of pre
- pop pop % Discard seek and post
- /enc encs indx get def % Get the indxth encoding
- mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
- /enclen enc length def
- /revenc enclen string def
- 0 1 enclen 1 sub {
- /j exch def
- /char enc j get def
- revenc enclen j sub 1 sub char put
- } for
- /enc revenc def
- } if
- sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
- txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textyoffset textfont textsize] put
- } for
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [12{height}repeat] put
- retval (bbs) [12{0}repeat] put
- includetext {
- retval (txt) txt put
- } if
- retval (opt) useropts put
- retval (guardrightpos) 10 put
- retval (guardrightypos) textyoffset 4 add put
- retval (bordertop) 10 put
- retval
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs bhs
+ /bbs bbs
+ /txt txt
+ /opt options
+ /guardrightpos 10
+ /guardrightypos guardrightypos
+ /borderbottom 5
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/ean2 load 0 1 dict put
-% --END ENCODER ean2--
+% --END ENCODER upce--
% --BEGIN ENCODER isbn--
% --REQUIRES ean13--
+% --SUGGESTS ean5 ean2--
% --DESC: ISBN
-% --EXAM: 978-1-56592-479
+% --EXAM: 978-1-56592-479 54495
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
/isbn {
- 0 begin
+ 20 dict begin
/options exch def % We are given an options string
- /useropts options def
/isbntxt exch def % We are given the isbn text with dashes
+ /dontdraw false def
/includetext false def % Enable/disable ISBN text
/isbnfont /Courier def
/isbnsize 9 def
/isbnpos (unset) def
/height 1 def
-
+ /addongap 12 def
+
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
/isbnfont isbnfont cvlit def
/isbnsize isbnsize cvr def
/height height cvr def
+ /addongap addongap cvr def
isbnpos (unset) eq {
/isbnpos height 72 mul 3 add def
} {
/isbnpos isbnpos cvr def
} ifelse
-
+
+ % Split off the addon
+ isbntxt ( ) search {
+ /isbntxt exch def
+ pop
+ /addon exch def
+ } {
+ pop
+ /addon () def
+ } ifelse
+
% Read the digits from isbntxt and calculate checksums
/isbn 13 string def
/checksum10 0 def
@@ -840,12 +1388,16 @@
/isbnchar isbntxt i get 48 sub def
isbnchar -3 ne { % Ignore dashes
isbn n isbnchar 48 add put
- /checksum10 checksum10 10 n sub isbnchar mul add def
- n 2 mod 0 eq {
- /checksum13 isbnchar checksum13 add def
- } {
- /checksum13 isbnchar 3 mul checksum13 add def
- } ifelse
+ n 9 lt {
+ /checksum10 checksum10 10 n sub isbnchar mul add def
+ } if
+ n 12 lt {
+ n 2 mod 0 eq {
+ /checksum13 isbnchar checksum13 add def
+ } {
+ /checksum13 isbnchar 3 mul checksum13 add def
+ } ifelse
+ } if
/n n 1 add def
} if
/i i 1 add def
@@ -865,17 +1417,14 @@
pad 0 (ISBN ) putinterval
pad 5 isbntxt putinterval % Add isbntxt to the pad
- % Add checksum digit if isbntxt length is 11 or 15
- isbntxt length 11 eq isbntxt length 12 eq or
- isbntxt length 15 eq or isbntxt length 16 eq or {
- pad pad length 2 sub 45 put % Put a dash
- checksum 10 eq {
- pad pad length 1 sub checksum 78 add put % Check digit for 10 is X
- } {
- pad pad length 1 sub checksum 48 add put % Put check digit
- } ifelse
- } if
- /isbntxt pad def % isbntxt=pad
+ % Add checksum digit
+ pad pad length 2 sub 45 put % Put a dash
+ checksum 10 eq {
+ pad pad length 1 sub checksum 78 add put % Check digit for 10 is X
+ } {
+ pad pad length 1 sub checksum 48 add put % Put check digit
+ } ifelse
+ /isbntxt pad def
% Convert ISBN digits to EAN-13
/barcode 12 string def
@@ -886,8 +1435,19 @@
barcode 0 isbn putinterval
} ifelse
- % Get the result of encoding with ean13
- /args barcode options ean13 def
+ % Append the addon
+ addon () ne {
+ 12 addon length add 1 add string
+ dup 0 barcode putinterval
+ dup 12 ( ) putinterval
+ dup 13 addon putinterval
+ /barcode exch def
+ } if
+
+ % Get the result of encoding with ean13
+ options (dontdraw) true put
+ options (addongap) addongap put
+ /args barcode options //ean13 exec def
% Add the ISBN text
includetext {
@@ -907,13 +1467,14 @@
} ifelse
} if
- args (opt) useropts put
+ args (opt) options put
args
+ dontdraw not //renlinear if
+
end
} bind def
-/isbn load 0 1 dict put
% --END ENCODER isbn--
% --BEGIN ENCODER code128--
@@ -923,12 +1484,12 @@
% --RNDR: renlinear
/code128 {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
@@ -936,11 +1497,16 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -1022,21 +1588,22 @@
/txt txt 0 j getinterval def
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/code128 load 0 1 dict put
% --END ENCODER code128--
% --BEGIN ENCODER code39--
@@ -1046,26 +1613,32 @@
% --RNDR: renlinear
/code39 {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def
/includecheckintext false def
+ /hidestars false def
/textfont /Courier def
/textsize 10 def
/textyoffset -7 def
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -1101,7 +1674,11 @@
% Put the start character
sbs 0 encs 43 get putinterval
- txt 0 [(*) 0 textyoffset textfont textsize] put
+ hidestars not {
+ txt 0 [(*) 0 textyoffset textfont textsize] put
+ } {
+ txt 0 [() 0 textyoffset textfont textsize] put
+ } ifelse
0 1 barlen 1 sub {
/i exch def
@@ -1126,28 +1703,37 @@
txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
} ifelse
sbs barlen 10 mul 20 add encs 43 get putinterval
- txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put
+ hidestars not {
+ txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put
+ } {
+ txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put
+ } ifelse
} {
sbs barlen 10 mul 10 add encs 43 get putinterval
- txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put
+ hidestars not {
+ txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put
+ } {
+ txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
+ } ifelse
} ifelse
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/code39 load 0 1 dict put
% --END ENCODER code39--
% --BEGIN ENCODER code93--
@@ -1157,12 +1743,12 @@
% --RNDR: renlinear
/code93 {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/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
@@ -1171,11 +1757,16 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -1252,21 +1843,22 @@
} ifelse
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/code93 load 0 1 dict put
% --END ENCODER code93--
% --BEGIN ENCODER interleaved2of5--
@@ -1276,12 +1868,12 @@
% --RNDR: renlinear
/interleaved2of5 {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/includecheckintext false def
@@ -1291,10 +1883,15 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
@@ -1386,78 +1983,139 @@
sbs barlen 5 mul 4 add encs 11 get putinterval
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/interleaved2of5 load 0 1 dict put
% --END ENCODER interleaved2of5--
% --BEGIN ENCODER rss14--
-% --DESC: Reduced Space Symbology 14 (RSS-14)
-% --EXAM: 24012345678905
-% --EXOP: height=0.3
-% --RNDR: renlinear
+% --DESC: GS1 DataBar Omnidirectional
+% --EXAM: (01)24012345678905
+% --EXOP:
+% --RNDR: renlinear renmatrix
/rss14 {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
- /height 1 def
+ /dontdraw false def
+ /height 33 72 div def
/linkage false def
+ /format (omni) def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
+
+ format (truncated) eq {/height 13 72 div def} if
+ /height height cvr def
+
+ % Strip the AI and optional check digit
+ barcode length dup 17 eq exch 18 eq or {
+ barcode 0 4 getinterval (\(01\)) eq {
+ /binval [
+ linkage {1} {0} ifelse
+ barcode 4 13 getinterval {48 sub} forall
+ ] def
+ } if
+ } if
+
+ % Calculate EAN checksum and add to end of barcode
+ /checksum 0 def
+ 0 1 12 {
+ /i exch def
+ /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ 18 string
+ dup 0 barcode 0 17 getinterval putinterval
+ dup 17 checksum 48 add put
+ /barcode exch def
+
% Create the human readable text
/txt barcode length array def
0 1 barcode length 1 sub {
/i exch def
txt i [barcode i 1 getinterval 0 0 () 0] put
} for
-
- /height height cvr def
+ /ncr { % n r
+ 2 copy sub 2 copy lt {exch} if % n r maxd mind
+ 1 1 5 3 roll % mind j=1 v=1 n maxd
+ 1 add -1 exch { % mind j v n -1 maxd+1
+ mul % mind j v*i
+ 1 index 3 index le {
+ 1 index idiv exch 1 add exch
+ } if
+ } for
+ { % mind j v
+ 1 index 3 index gt {exit} if
+ 1 index idiv exch 1 add exch
+ } loop
+ exch pop exch pop
+ } bind def
+
/getRSSwidths {
/oe exch def
+ /el exch def
/mw exch def
/nm exch def
/val exch def
- /j 0 def /i 0 def {
- /v () def
- mw 1 ne {/v i mw 4 string cvrs def} if
- 0 v {48 sub add} forall 4 add nm eq {
- /out [ 4 {1} repeat v {47 sub} forall ] v length 4 getinterval def
- /hasone false def out {1 eq {/hasone true def} if} forall
- oe not hasone or {
- j val eq {exit} if
- /j j 1 add def
+ /out el array def
+ /mask 0 def
+ 0 1 el 2 sub {
+ /bar exch def
+ /ew 1 def
+ /mask mask 1 bar bitshift or def {
+ /sval nm ew sub 1 sub el bar sub 2 sub ncr def
+ oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
+ /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
} if
- } if
- /i i 1 add def
- } loop
+ el bar sub 2 gt {
+ /lval 0 def
+ nm ew sub el sub bar add 2 add -1 mw 1 add {
+ nm exch sub ew sub 1 sub el bar sub 3 sub ncr
+ /lval exch lval add def
+ } for
+ /sval sval lval el bar sub 1 sub mul sub def
+ } {
+ nm ew sub mw gt {/sval sval 1 sub def} if
+ } ifelse
+ /val val sval sub def
+ val 0 lt {exit} if
+ /ew ew 1 add def
+ /mask mask 1 bar bitshift not and def
+ } loop
+ /val val sval add def
+ /nm nm ew sub def
+ out bar ew put
+ } for
+ out el 1 sub nm put
out
} bind def
-
- /binval [barcode {48 sub} forall] def
- /binval [linkage {1} {0} ifelse binval 0 13 getinterval {} forall] def
-
+
0 1 12 {
/i exch def
binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put
@@ -1547,14 +2205,14 @@
/i i 8 add def
} loop
- /d1wo d1 d1gs sub d1te idiv d1elo d1mwo false getRSSwidths def
- /d1we d1 d1gs sub d1te mod d1ele d1mwe true getRSSwidths def
- /d2wo d2 d2gs sub d2to mod d2elo d2mwo true getRSSwidths def
- /d2we d2 d2gs sub d2to idiv d2ele d2mwe false getRSSwidths def
- /d3wo d3 d3gs sub d3te idiv d3elo d3mwo false getRSSwidths def
- /d3we d3 d3gs sub d3te mod d3ele d3mwe true getRSSwidths def
- /d4wo d4 d4gs sub d4to mod d4elo d4mwo true getRSSwidths def
- /d4we d4 d4gs sub d4to idiv d4ele d4mwe false getRSSwidths def
+ /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 4 false getRSSwidths def
+ /d1we d1 d1gs sub d1te mod d1ele d1mwe 4 true getRSSwidths def
+ /d2wo d2 d2gs sub d2to mod d2elo d2mwo 4 true getRSSwidths def
+ /d2we d2 d2gs sub d2to idiv d2ele d2mwe 4 false getRSSwidths def
+ /d3wo d3 d3gs sub d3te idiv d3elo d3mwo 4 false getRSSwidths def
+ /d3we d3 d3gs sub d3te mod d3ele d3mwe 4 true getRSSwidths def
+ /d4wo d4 d4gs sub d4to mod d4elo d4mwo 4 true getRSSwidths def
+ /d4we d4 d4gs sub d4to idiv d4ele d4mwe 4 false getRSSwidths def
/d1w 8 array def
0 1 3 {
@@ -1620,49 +2278,187 @@
checkrt i checkrtrev 4 i sub get put
} for
- /sbs [
- 1 d1w {} forall checklt {} forall d2w {}
- forall d4w {} forall checkrt {} forall d3w {} forall 1 1
- ] def
-
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) sbs put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
- retval (txt) txt put
- retval (textxalign) (center) put
- retval (opt) useropts put
- retval
+ % Stacked format
+ format (omni) eq format (truncated) eq or { % linear
+ /sbs [
+ 1 d1w {} forall checklt {} forall d2w {} forall
+ d4w {} forall checkrt {} forall d3w {} forall 1 1
+ ] def
+
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs [sbs length 1 add 2 idiv {height} repeat]
+ /bbs [sbs length 1 add 2 idiv {0} repeat]
+ /txt txt
+ /textxalign (center)
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
+
+ } { % 2D - stacked or stackedomni
+
+ /top [ 1 1 d1w {} forall checklt {} forall d2w {} forall 1 1 0 ] def
+ /bot [ 1 1 d4w {} forall checkrt {} forall d3w {} forall 1 1 0 ] def
+ 0 2 24 {
+ /i exch def
+ top i get {0} repeat
+ top i 1 add get {1} repeat
+ } for
+ 50 array astore /top exch def
+ 0 2 24 {
+ /i exch def
+ bot i get {1} repeat
+ bot i 1 add get {0} repeat
+ } for
+ 50 array astore /bot exch def
+
+ % Stacked
+ format (stacked) eq {
+ /sep [ 50 {0} repeat ] def
+ 4 1 45 {
+ /i exch def
+ top i get bot i get eq {
+ sep i 1 top i get sub put
+ } {
+ sep i 1 sep i 1 sub get sub put
+ } ifelse
+ } for
+ /pixs [
+ 5 {top aload pop} repeat
+ sep aload pop
+ 7 {bot aload pop} repeat
+ ] def
+ /pixy pixs length 50 idiv def
+ } if
+
+ % Stacked omnidirectional
+ format (stackedomni) eq {
+ /sep1 [ top {1 exch sub} forall ] def
+ sep1 0 [ 0 0 0 0 ] putinterval
+ sep1 46 [ 0 0 0 0 ] putinterval
+ 18 1 30 {
+ /i exch def
+ top i get 0 eq {
+ top i 1 sub get 1 eq {
+ 1
+ } {
+ sep1 i 1 sub get 0 eq {1} {0} ifelse
+ } ifelse
+ } {
+ 0
+ } ifelse
+ sep1 exch i exch put
+ } for
+ /sep2 [ 0 0 0 0 21 { 0 1 } repeat 0 0 0 0 ] def
+ /sep3 [ bot {1 exch sub} forall ] def
+ sep3 0 [ 0 0 0 0 ] putinterval
+ sep3 46 [ 0 0 0 0 ] putinterval
+ 19 1 31 {
+ /i exch def
+ bot i get 0 eq {
+ bot i 1 sub get 1 eq {
+ 1
+ } {
+ sep3 i 1 sub get 0 eq {1} {0} ifelse
+ } ifelse
+ } {
+ 0
+ } ifelse
+ sep3 exch i exch put
+ } for
+ checksum 9 mod 3 eq { % Right shifted module for value 3 finder
+ sep3 19 [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval
+ } if
+ /pixs [
+ 33 {top aload pop} repeat
+ sep1 aload pop
+ sep2 aload pop
+ sep3 aload pop
+ 33 {bot aload pop} repeat
+ ] def
+ /pixy pixs length 50 idiv def
+ } if
+
+ % Return the arguments
+ <<
+ /ren (renmatrix)
+ /pixs pixs
+ /pixx 50
+ /pixy pixy
+ /height pixy 72 div
+ /width 50 72 div
+ /opt options
+ >>
+
+ dontdraw not //renmatrix if
+
+ } ifelse
+
end
} bind def
-/rss14 load 0 1 dict put
% --END ENCODER rss14--
% --BEGIN ENCODER rsslimited--
-% --DESC: Reduced Space Symbology Limited (RSS-Limited)
-% --EXAM: 00978186074271
+% --DESC: GS1 DataBar Limited
+% --EXAM: (01)15012345678907
% --EXOP: height=0.3
% --RNDR: renlinear
/rsslimited {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
- /height 1 def
-
+ /dontdraw false def
+ /height 10 72 div def
+ /linkage false def
+
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
+ /height height cvr def
+
+ % Strip the AI and optional check digit
+ barcode length dup 17 eq exch 18 eq or {
+ barcode 0 5 getinterval dup (\(01\)0) eq exch (\(01\)1) eq or {
+ /binval [
+ barcode 4 13 getinterval {48 sub} forall
+ ] def
+ linkage {
+ /linkval [ 2 0 1 5 1 3 3 5 3 1 0 9 6 ] def
+ 0 1 binval length 1 sub {
+ /i exch def
+ binval i binval i get linkval i get add put
+ } for
+ } if
+ } if
+ } if
+
+ % Calculate EAN checksum and add to end of barcode
+ /checksum 0 def
+ 0 1 12 {
+ /i exch def
+ /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
+ } for
+ /checksum 10 checksum 10 mod sub 10 mod def
+ 18 string
+ dup 0 barcode 0 17 getinterval putinterval
+ dup 17 checksum 48 add put
+ /barcode exch def
+
% Create the human readable text
/txt barcode length array def
0 1 barcode length 1 sub {
@@ -1670,33 +2466,61 @@
txt i [barcode i 1 getinterval 0 0 () 0] put
} for
- /height height cvr def
-
+ /ncr { % n r
+ 2 copy sub 2 copy lt {exch} if % n r maxd mind
+ 1 1 5 3 roll % mind j=1 v=1 n maxd
+ 1 add -1 exch { % mind j v n -1 maxd+1
+ mul % mind j v*i
+ 1 index 3 index le {
+ 1 index idiv exch 1 add exch
+ } if
+ } for
+ { % mind j v
+ 1 index 3 index gt {exit} if
+ 1 index idiv exch 1 add exch
+ } loop
+ exch pop exch pop
+ } bind def
+
/getRSSwidths {
/oe exch def
/el exch def
/mw exch def
/nm exch def
/val exch def
- /j 0 def /i 0 def {
- /v () def
- mw 1 ne {/v i mw el string cvrs def} if
- 0 v {48 sub add} forall el add nm eq {
- /out [ el {1} repeat v {47 sub} forall ] v length el getinterval def
- /hasone false def out {1 eq {/hasone true def} if} forall
- oe not hasone or {
- j val eq {exit} if
- /j j 1 add def
+ /out el array def
+ /mask 0 def
+ 0 1 el 2 sub {
+ /bar exch def
+ /ew 1 def
+ /mask mask 1 bar bitshift or def {
+ /sval nm ew sub 1 sub el bar sub 2 sub ncr def
+ oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
+ /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
} if
- } if
- /i i 1 add def
- } loop
+ el bar sub 2 gt {
+ /lval 0 def
+ nm ew sub el sub bar add 2 add -1 mw 1 add {
+ nm exch sub ew sub 1 sub el bar sub 3 sub ncr
+ /lval exch lval add def
+ } for
+ /sval sval lval el bar sub 1 sub mul sub def
+ } {
+ nm ew sub mw gt {/sval sval 1 sub def} if
+ } ifelse
+ /val val sval sub def
+ val 0 lt {exit} if
+ /ew ew 1 add def
+ /mask mask 1 bar bitshift not and def
+ } loop
+ /val val sval add def
+ /nm nm ew sub def
+ out bar ew put
+ } for
+ out el 1 sub nm put
out
} bind def
-
- /binval [barcode {48 sub} forall] def
- /binval [binval 0 13 getinterval {} forall] def
-
+
0 1 11 {
/i exch def
binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
@@ -1819,70 +2643,593 @@
] def
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) sbs put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
- retval (txt) txt put
- retval (textxalign) (center) put
- retval (opt) useropts put
- retval
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs [sbs length 1 add 2 idiv {height} repeat]
+ /bbs [sbs length 1 add 2 idiv {0} repeat]
+ /txt txt
+ /textxalign (center)
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/rsslimited load 0 1 dict put
% --END ENCODER rsslimited--
% --BEGIN ENCODER rssexpanded--
-% --DESC: Reduced Space Symbology Expanded (RSS-Expanded)
-% --EXAM: 000000010011001010100001000000010000
-% --EXOP: height=0.3
-% --RNDR: renlinear
+% --DESC: GS1 DataBar Expanded
+% --EXAM: (01)95012345678903(3103)000123
+% --EXOP: segments=4
+% --RNDR: renlinear renmatrix
/rssexpanded {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
- /height 1 def
-
+ /dontdraw false def
+ /height 34 72 div def
+ /segments 22 def
+ /linkage false def
+
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
+ 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
+
+ /height height cvr def
+ /segments segments cvi def
+
+ % Expand ordinals of the form ^NNN to ASCII
+ /expand {
+ /in exch def
+ /out in length string def
+ /j 0 def
+ in
+ { % loop
+ (^) search {
+ dup out exch j exch putinterval
+ length j add 1 add /j exch def
+ pop
+ dup 0 3 getinterval cvi out exch j 1 sub exch put
+ dup length 3 sub 3 exch getinterval
+ } {
+ dup out exch j exch putinterval
+ length j add /j exch def
+ out 0 j getinterval exit
+ } ifelse
+ } loop
+ } bind def
+
+ % Parse out AIs
+ /ais [] def
+ /aival 2 dict def
+ barcode dup length 1 sub 1 exch getinterval
+ { % loop
+ dup () eq {exit} if
+ (\)) search pop
+ exch pop
+ exch (\() search {
+ exch pop exch 3 1 roll
+ } {
+ () 3 1 roll
+ } ifelse
+ [ ais aload pop counttomark 2 add index ] /ais exch def
+ aival 3 1 roll expand put
} loop
+ pop
+
+ % Method selection
+ { % common exit
+
+ % (01)9...(3103)...
+ ais length 2 eq {
+ ais 0 get (01) eq ais 1 get (3103) eq and {
+ aival (01) get 0 1 getinterval (9) eq aival (3103) get cvi 32767 le and {
+ (0100) false exit
+ } if
+ } if
+ } if
+
+ % (01)9...(3202)...
+ ais length 2 eq {
+ ais 0 get (01) eq ais 1 get (3202) eq and {
+ aival (01) get 0 1 getinterval (9) eq aival (3202) get cvi 9999 le and {
+ (0101) false exit
+ } if
+ } if
+ } if
+
+ % (01)9...(3203)...
+ ais length 2 eq {
+ ais 0 get (01) eq ais 1 get (3203) eq and {
+ aival (01) get 0 1 getinterval (9) eq aival (3203) get cvi 22767 le and {
+ (0101) false exit
+ } if
+ } if
+ } if
+
+ % (01)9...(310x/320x)...[(11/13/15/17)...]
+ ais length dup 2 eq exch 3 eq or {
+ /ai310x false 3100 1 3109 {10 4 string cvrs ais 1 get eq or} for def
+ /ai320x false 3200 1 3209 {10 4 string cvrs ais 1 get eq or} for def
+ ais length 3 eq {
+ /aibad true [ (11) (13) (15) (17) ] {ais 2 get ne and} forall def
+ } {
+ /aibad false def
+ } ifelse
+ ais 0 get (01) eq ai310x ai320x or and aibad not and {
+ ais length 3 eq {
+ aival (01) get 0 1 getinterval (9) eq
+ aival ais 1 get get cvi 99999 le and
+ aival ais 2 get get cvi 999999 le and {
+ ai310x ais 2 get (11) eq and { (0111000) false exit } if
+ ai320x ais 2 get (11) eq and { (0111001) false exit } if
+ ai310x ais 2 get (13) eq and { (0111010) false exit } if
+ ai320x ais 2 get (13) eq and { (0111011) false exit } if
+ ai310x ais 2 get (15) eq and { (0111100) false exit } if
+ ai320x ais 2 get (15) eq and { (0111101) false exit } if
+ ai310x ais 2 get (17) eq and { (0111110) false exit } if
+ ai320x ais 2 get (17) eq and { (0111111) false exit } if
+ } if
+ } {
+ aival (01) get 0 1 getinterval (9) eq
+ aival ais 1 get get cvi 99999 le and {
+ ai310x { (0111000) false exit } if
+ ai320x { (0111001) false exit } if
+ } if
+ } ifelse
+ } if
+ } if
+
+ % (01)9...(392x)...
+ ais length 2 ge {
+ /ai392x false 3920 1 3923 {10 4 string cvrs ais 1 get eq or} for def
+ ais 0 get (01) eq ai392x and {
+ aival (01) get 0 1 getinterval (9) eq { (01100) true exit } if
+ } if
+ } if
+
+ % (01)9...(393x)...
+ ais length 2 ge {
+ /ai393x false 3930 1 3933 {10 4 string cvrs ais 1 get eq or} for def
+ ais 0 get (01) eq ai393x and {
+ aival (01) get 0 1 getinterval (9) eq { (01101) true exit } if
+ } if
+ } if
+
+ % (01)...
+ ais 0 get (01) eq { (1) true exit } if
+
+ % Freeform
+ (00) true exit
+
+ } loop
+ /gpfallow exch def
+ /method exch def
+
+ /conv12to40 {
+ (0000000000000000000000000000000000000000) 40 string copy
+ 2 copy 0 10 getinterval exch 0 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
+ 2 copy 10 10 getinterval exch 3 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
+ 2 copy 20 10 getinterval exch 6 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
+ 2 copy 30 10 getinterval exch 9 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
+ exch pop
+ } bind def
+
+ /conv13to44 {
+ (00000000000000000000000000000000000000000000) 44 string copy
+ 2 copy 0 4 getinterval exch 0 1 getinterval cvi 2 4 string cvrs dup length 4 exch sub exch putinterval
+ dup 3 -1 roll 1 12 getinterval conv12to40 4 exch putinterval
+ } bind def
+
+ /tobin {
+ string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for
+ dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
+ } bind def
+
+ method (00) eq {
+ /cdf [] def
+ /gpf [] def
+ } if
+
+ method (1) eq {
+ /cdf aival (01) get 0 13 getinterval conv13to44 def
+ /cdf [ cdf {48 sub} forall ] def
+ /gpf [] def
+ /ais ais 1 ais length 1 sub getinterval def
+ } if
+
+ method (0100) eq {
+ /cdf 55 string def
+ cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval
+ cdf 40 aival (3103) get cvi 15 tobin putinterval
+ /cdf [ cdf {48 sub} forall ] def
+ /gpf [] def
+ /ais [] def
+ } if
+
+ method (0101) eq {
+ /cdf 55 string def
+ cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval
+ ais 1 get (3202) eq {
+ aival (3202) get cvi 15 tobin
+ } {
+ aival (3203) get cvi 10000 add 15 tobin
+ } ifelse
+ cdf exch 40 exch putinterval
+ /cdf [ cdf {48 sub} forall ] def
+ /gpf [] def
+ /ais [] def
+ } if
+
+ method length 7 eq {
+ /cdf 76 string def
+ cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval
+ 6 string dup 0 ais 1 get 3 1 getinterval putinterval
+ dup aival ais 1 get get 1 5 getinterval 1 exch putinterval cvi 20 tobin
+ cdf exch 40 exch putinterval
+ ais length 3 eq {
+ aival ais 2 get get
+ dup 0 2 getinterval cvi 384 mul exch
+ dup 2 2 getinterval cvi 1 sub 32 mul exch
+ 4 2 getinterval cvi add add
+ } {
+ 38400
+ } ifelse
+ 16 tobin cdf exch 60 exch putinterval
+ /cdf [ cdf {48 sub} forall ] def
+ /gpf [] def
+ /ais [] def
+ } if
+
+ method (01100) eq {
+ /cdf 42 string def
+ cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval
+ cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval
+ /cdf [ cdf {48 sub} forall ] def
+ /gpf [ aival ais 1 get get {} forall ] def
+ /ais ais 2 ais length 2 sub getinterval def
+ } if
+
+ method (01101) eq {
+ /cdf 52 string def
+ cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval
+ cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval
+ cdf 42 aival ais 1 get get 0 3 getinterval cvi 10 tobin putinterval
+ /cdf [ cdf {48 sub} forall ] def
+ /gpf [ aival ais 1 get get dup length 3 sub 3 exch getinterval {} forall ] def
+ /ais ais 2 ais length 2 sub getinterval def
+ } if
+
+ % Variable length symbol field
+ gpfallow {
+ /vlf 2 array def
+ } {
+ /vlf [] def
+ } ifelse
+
+ % FNC1 terminated AIs
+ % TODO this list seems wrong
+ /aifnc1 100 dict def
+ [
+ 10
+ 21 22
+ 240 241 242
+ 250 251 253 254
+ 30 37
+ 3900 1 3909 {} for
+ 3910 1 3919 {} for
+ 3920 1 3929 {} for
+ 3930 1 3939 {} for
+ 400 401 402 403
+ 420 421 422 423 424 425 426
+ 7001 7002 7003
+ 7030 1 7039 {} for
+ 8001 8002 8003 8004 8005 8006 8007 8008
+ 8018 8020
+ 8100 8101 8102
+ 8110
+ 90 1 99 {} for
+ ] {
+ 10 4 string cvrs dup aifnc1 3 1 roll put
+ } forall
+
+ /fnc1 -1 def /lnumeric -2 def /lalpha -3 def /liso646 -4 def
+
+ /numeric <<
+ 0 1 119 {
+ dup (00) 2 string copy dup 3 -1 roll 11 2 string cvrs
+ dup length 2 exch sub exch putinterval
+ dup 0 get 65 eq {dup 0 94 put} if
+ dup 1 get 65 eq {dup 1 94 put} if
+ exch 8 add
+ (0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs
+ dup length 7 exch sub exch putinterval
+ } for
+ lalpha (0000)
+ >> def
+
+ /alpha <<
+ 48 1 57 {dup 43 sub 5 tobin} for
+ fnc1 (01111)
+ 65 1 90 {dup 33 sub 6 tobin} for
+ 42 (111010)
+ 44 1 47 {dup 15 add 6 tobin} for
+ lnumeric (000)
+ liso646 (00100)
+ >> def
+
+ /iso646 <<
+ 48 1 57 {dup 43 sub 5 tobin} for
+ fnc1 (01111)
+ 65 1 90 {dup 1 sub 7 tobin} for
+ 97 1 122 {dup 7 sub 7 tobin} for
+ 33 (11101000)
+ 34 (11101001)
+ 37 1 47 {dup 197 add 8 tobin} for
+ 58 1 63 {dup 187 add 8 tobin} for
+ 95 (11111011)
+ 32 (11111100)
+ lnumeric (000)
+ lalpha (00100)
+ >> def
+
+ % Append the remaining AI data
+ 0 1 ais length 1 sub {
+ /i exch def
+ /ai ais i get def
+ /val aival ai get def
+ gpf length ai length add val length add array
+ dup 0 gpf putinterval
+ dup gpf length ai [ exch {} forall ] putinterval
+ dup gpf length ai length add val [ exch {} forall ] putinterval
+ /gpf exch def
+ i ais length 1 sub ne aifnc1 ai known and { % Append FNC1
+ gpf length 1 add array
+ dup 0 gpf putinterval
+ dup gpf length fnc1 put
+ /gpf exch def
+ } if
+ } for
+
+ % Calculate the number of bits remaining to the next valid symbol size
+ /rembits {
+ dup
+ 12 div ceiling cvi 12 mul % Round up to multiple of 12
+ 48 2 copy lt {exch} if pop % At least 4 symbols
+ dup 12 idiv dup segments mod 1 eq { % At least 2 symbols on last row of stacked symbol
+ 1 add 12 mul exch pop
+ } {
+ pop
+ } ifelse
+ exch sub
+ } bind def
+
+ /encode {
+ dup /raw ne {exch get} {pop} ifelse
+ [ exch {48 sub} forall ]
+ dup length exch
+ gpfenc exch j exch putinterval
+ /j exch j add def
+ } bind def
+
+ % Pre-compute alpha and numeric runlengths and position of next ISO646-only characters
+ /numericruns [ gpf length {0} repeat 0 -1 ] def
+ /alpharuns [ gpf length {0} repeat 0 ] def
+ /nextiso646only [ gpf length {0} repeat 9999 ] def
+ gpf length 1 sub -1 0 {
+ /i exch def
+ gpf i get
+ (00) 2 string copy
+ dup 0 gpf i get dup fnc1 eq {pop 94} if put
+ i gpf length 1 sub lt {dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put} if
+ numeric exch known {
+ numericruns i numericruns i 2 add get 2 add put
+ } {
+ numericruns i 0 put
+ } ifelse
+ dup alpha exch known {
+ alpharuns i alpharuns i 1 add get 1 add put
+ } {
+ alpharuns i 0 put
+ } ifelse
+ dup iso646 exch known exch alpha exch known not and {
+ nextiso646only i 0 put
+ } {
+ nextiso646only i nextiso646only i 1 add get 1 add put
+ } ifelse
+ } for
+
+ % Encode the general purpose field
+ /gpfenc 252 array def
+ /i 0 def /j 0 def /mode (numeric) def
+ { % loop
+ i gpf length eq {exit} if
+ { % not a loop but common exit point
+
+ mode (numeric) eq {
+ i gpf length 2 sub lt {
+ 2 string
+ dup 0 gpf i get dup fnc1 eq {pop 94} if put
+ dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put
+ dup numeric exch known {
+ numeric encode
+ /i i 2 add def
+ exit
+ } if
+ pop
+ lalpha numeric encode
+ /mode (alpha) def
+ exit
+ } {
+ gpf i get dup 48 lt exch 57 gt or {
+ lalpha numeric encode
+ /mode (alpha) def
+ exit
+ } if
+ 12 1 add method length add vlf length add cdf length add j add rembits
+ dup 4 ge exch 6 le and { % C1 + 1 into 4 bits
+ (0000) 4 string copy dup gpf i get 47 sub 2 4 string cvrs
+ dup length 4 exch sub exch putinterval /raw encode
+ /i i 1 add def
+ exit
+ } { % C1.FNC1
+ 2 string dup 0 gpf i get put dup 1 94 put numeric encode
+ /i i 1 add def
+ exit
+ } ifelse
+ } ifelse
+ } if
+
+ mode (alpha) eq {
+ gpf i get fnc1 eq {
+ fnc1 alpha encode
+ /i i 1 add def
+ exit
+ } if
+ gpf i get dup iso646 exch known exch alpha exch known not and {
+ liso646 alpha encode
+ /mode (iso646) def
+ exit
+ } if
+ numericruns i get 6 ge {
+ lnumeric alpha encode
+ /mode (numeric) def
+ exit
+ } if
+ numericruns i get dup 4 ge exch i add gpf length eq and {
+ lnumeric alpha encode
+ /mode (numeric) def
+ exit
+ } if
+ gpf i get alpha encode
+ /i i 1 add def
+ exit
+ } if
+
+ mode (iso646) eq {
+ gpf i get fnc1 eq {
+ fnc1 iso646 encode
+ /i i 1 add def
+ exit
+ } if
+ numericruns i get 4 ge nextiso646only i get 10 ge and {
+ lnumeric iso646 encode
+ /mode (numeric) def
+ exit
+ } if
+ alpharuns i get 5 ge nextiso646only i get 10 ge and {
+ lalpha iso646 encode
+ /mode (alpha) def
+ exit
+ } if
+ gpf i get iso646 encode
+ /i i 1 add def
+ exit
+ } if
+
+ } loop
+ } loop
+ /gpf gpfenc 0 j getinterval def
+
+ % Complete the variable length field and create pad
+ 1 12 add method length add vlf length add cdf length add gpf length add
+ dup rembits dup array /pad exch def
+ vlf length 0 ne {
+ add 12 idiv
+ dup 2 mod vlf exch 0 exch put
+ 14 le {0} {1} ifelse vlf exch 1 exch put
+ } {
+ pop pop
+ } ifelse
+ pad length 0 gt {
+ 0 5 pad length 1 sub { % Fill with 00100
+ /i exch def
+ pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval
+ } for
+ mode (numeric) eq { % Prefix shift from numeric to ASCII
+ /pad [ 0 0 0 0 pad aload pop ] 0 pad length getinterval def
+ } if
+ } if
+
+ % Concatinate fields
+ /binval [
+ linkage {1} {0} ifelse
+ method {48 sub} forall
+ vlf aload pop
+ cdf aload pop
+ gpf aload pop
+ pad aload pop
+ ] def
+ /datalen binval length 12 idiv def
+
+ /ncr { % n r
+ 2 copy sub 2 copy lt {exch} if % n r maxd mind
+ 1 1 5 3 roll % mind j=1 v=1 n maxd
+ 1 add -1 exch { % mind j v n -1 maxd+1
+ mul % mind j v*i
+ 1 index 3 index le {
+ 1 index idiv exch 1 add exch
+ } if
+ } for
+ { % mind j v
+ 1 index 3 index gt {exit} if
+ 1 index idiv exch 1 add exch
+ } loop
+ exch pop exch pop
+ } bind def
- /height height cvr def
-
/getRSSwidths {
/oe exch def
+ /el exch def
/mw exch def
/nm exch def
/val exch def
- /j 0 def /i 0 def {
- /v () def
- mw 1 ne {/v i mw 4 string cvrs def} if
- 0 v {48 sub add} forall 4 add nm eq {
- /out [ 4 {1} repeat v {47 sub} forall ] v length 4 getinterval def
- /hasone false def out {1 eq {/hasone true def} if} forall
- /lessfive out 0 get 5 lt def
- oe not hasone lessfive and or {
- j val eq {exit} if
- /j j 1 add def
+ /out el array def
+ /mask 0 def
+ 0 1 el 2 sub {
+ /bar exch def
+ /ew 1 def
+ /mask mask 1 bar bitshift or def {
+ /sval nm ew sub 1 sub el bar sub 2 sub ncr def
+ oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
+ /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
} if
- } if
- /i i 1 add def
- } loop
+ el bar sub 2 gt {
+ /lval 0 def
+ nm ew sub el sub bar add 2 add -1 mw 1 add {
+ nm exch sub ew sub 1 sub el bar sub 3 sub ncr
+ /lval exch lval add def
+ } for
+ /sval sval lval el bar sub 1 sub mul sub def
+ } {
+ nm ew sub mw gt {/sval sval 1 sub def} if
+ } ifelse
+ /val val sval sub def
+ val 0 lt {exit} if
+ /ew ew 1 add def
+ /mask mask 1 bar bitshift not and def
+ } loop
+ /val val sval add def
+ /nm nm ew sub def
+ out bar ew put
+ } for
+ out el 1 sub nm put
out
} bind def
- /binval [barcode {48 sub} forall] def
- /datalen binval length 12 idiv def
-
/tab174 [
347 0 12 5 7 2 87 4
1387 348 10 7 5 4 52 20
@@ -1912,8 +3259,8 @@
/j j 8 add def
} loop
- /dwo d dgs sub dte idiv delo dmwo true getRSSwidths def
- /dwe d dgs sub dte mod dele dmwe false getRSSwidths def
+ /dwo d dgs sub dte idiv delo dmwo 4 true getRSSwidths def
+ /dwe d dgs sub dte mod dele dmwe 4 false getRSSwidths def
/dw 8 array def
x 2 mod 0 eq {
@@ -1934,40 +3281,74 @@
} for
- /widths [
- dxw {{} forall} forall
+ /finderwidths [
+ 1 8 4 1 1 1 1 4 8 1
+ 3 6 4 1 1 1 1 4 6 3
+ 3 4 6 1 1 1 1 6 4 3
+ 3 2 8 1 1 1 1 8 2 3
+ 2 6 5 1 1 1 1 5 6 2
+ 2 2 9 1 1 1 1 9 2 2
] def
+ /finderseq [
+ [0 1]
+ [0 3 2]
+ [0 5 2 7]
+ [0 9 2 7 4]
+ [0 9 2 7 6 11]
+ [0 9 2 7 8 11 10]
+ [0 1 2 3 4 5 6 7]
+ [0 1 2 3 4 5 6 9 8]
+ [0 1 2 3 4 5 6 9 10 11]
+ [0 1 2 3 4 7 6 9 8 11 10]
+ ] def
+
+ /seq finderseq datalen 2 sub 2 idiv get def
+ /fxw seq length array def
+ 0 1 seq length 1 sub {
+ /x exch def
+ fxw x finderwidths seq x get 5 mul 5 getinterval put
+ } for
+
/checkweights [
- 77 96 32 81 27 9 3 1
- 20 60 180 118 143 7 21 63
- 205 209 140 117 39 13 145 189
- 193 157 49 147 19 57 171 91
- 132 44 85 169 197 136 186 62
- 185 133 188 142 4 12 36 108
- 50 87 29 80 97 173 128 113
- 150 28 84 41 123 158 52 156
- 166 196 206 139 187 203 138 46
- 76 17 51 153 37 111 122 155
- 146 119 110 107 106 176 129 43
- 16 48 144 10 30 90 59 177
- 164 125 112 178 200 137 116 109
- 70 210 208 202 184 130 179 115
- 190 204 68 93 31 151 191 134
- 148 22 66 198 172 94 71 2
- 40 154 192 64 162 54 18 6
- 120 149 25 75 14 42 126 167
- 175 199 207 69 23 78 26 79
- 103 98 83 38 114 131 182 124
- 159 53 88 170 127 183 61 161
- 55 165 73 8 24 72 5 15
- 89 100 174 58 160 194 135 45
+ -1 -1 -1 -1 -1 -1 -1 -1 % A1L
+ 77 96 32 81 27 9 3 1 % A1R
+ 20 60 180 118 143 7 21 63 % A2L
+ 205 209 140 117 39 13 145 189 % A2R
+ 193 157 49 147 19 57 171 91 % B1L
+ 132 44 85 169 197 136 186 62 % B1R
+ 185 133 188 142 4 12 36 108 % B2L
+ 50 87 29 80 97 173 128 113 % B2R
+ 150 28 84 41 123 158 52 156 % C1L
+ 166 196 206 139 187 203 138 46 % C1R
+ 76 17 51 153 37 111 122 155 % C2L
+ 146 119 110 107 106 176 129 43 % C2R
+ 16 48 144 10 30 90 59 177 % D1L
+ 164 125 112 178 200 137 116 109 % D1R
+ 70 210 208 202 184 130 179 115 % D2L
+ 190 204 68 93 31 151 191 134 % D2R
+ 148 22 66 198 172 94 71 2 % E1L
+ 40 154 192 64 162 54 18 6 % E1R
+ 120 149 25 75 14 42 126 167 % E2L
+ 175 199 207 69 23 78 26 79 % E2R
+ 103 98 83 38 114 131 182 124 % F1L
+ 159 53 88 170 127 183 61 161 % F1R
+ 55 165 73 8 24 72 5 15 % F2L
+ 89 100 174 58 160 194 135 45 % F2R
] def
-
+
+ /checkweightseq [
+ seq {16 mul checkweights exch 16 getinterval aload pop} forall
+ ] dup length 8 sub 8 exch getinterval def
+
+ /widths [
+ dxw {{} forall} forall
+ ] def
+
/checksum 0 def
0 1 widths length 1 sub {
/i exch def
- /checksum checksum widths i get checkweights i get mul add def
+ /checksum checksum widths i get checkweightseq i get mul add def
} for
/checksum checksum 211 mod datalen 3 sub 211 mul add def
@@ -1983,69 +3364,169 @@
/i i 8 add def
} loop
- /cwo checksum cgs sub cte idiv celo cmwo true getRSSwidths def
- /cwe checksum cgs sub cte mod cele cmwe false getRSSwidths def
-
+ /cwo checksum cgs sub cte idiv celo cmwo 4 true getRSSwidths def
+ /cwe checksum cgs sub cte mod cele cmwe 4 false getRSSwidths def
+
/cw 8 array def
0 1 3 {
/i exch def
cw i 2 mul cwo i get put
cw i 2 mul 1 add cwe i get put
} for
-
- /finderwidths [
- 1 8 4 1 1 1 1 4 8 1
- 3 6 4 1 1 1 1 4 6 3
- 3 4 6 1 1 1 1 6 4 3
- 3 2 8 1 1 1 1 8 2 3
- 2 6 5 1 1 1 1 5 6 2
- 2 2 9 1 1 1 1 9 2 2
- ] def
-
- /finderseq [
- [0 1]
- [0 3 2]
- [0 5 2 7]
- [0 9 2 7 4]
- [0 9 2 7 6 11]
- [0 9 2 7 8 11 10]
- [0 1 2 3 4 5 6 7]
- [0 1 2 3 4 5 6 9 8]
- [0 1 2 3 4 5 6 9 10 11]
- [0 1 2 3 4 7 6 9 8 11 10]
- ] def
- /seq finderseq datalen 2 add 2 idiv 2 sub get def
- /fxw seq length array def
- 0 1 seq length 1 sub {
- /x exch def
- fxw x finderwidths seq x get 5 mul 5 getinterval put
- } for
-
- /sbs [
- 1
- cw {} forall
- 0 1 datalen 1 sub {
- /i exch def
- i 2 mod 0 eq {fxw i 2 idiv get {} forall} if
- dxw i get {} forall
+ 22 array dup dup
+ 0 cw put 1 dxw putinterval 0 datalen 1 add getinterval
+ /dxw exch def
+ /datalen dxw length def
+
+ % Encode row runlengths
+ /rows datalen segments div ceiling cvi array def
+ /numrows rows length def
+ 0 1 numrows 1 sub {
+ /r exch def
+ mark
+ segments 4 mod 0 ne r 2 mod 1 eq and {0} if
+ 1 1
+ 0 1 segments 1 sub {
+ /pos exch r segments mul add def
+ pos datalen lt {
+ dxw pos get {} forall
+ pos 2 mod 0 eq {fxw pos 2 idiv get {} forall} if
+ } if
} for
1 1
- ] def
-
- % Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) sbs put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
- retval (opt) useropts put
- retval
+ counttomark array astore rows exch r exch put pop
+ } for
+
+ numrows 1 eq { % Linear
+
+ % Remove leading space
+ /sbs rows 0 get dup length 1 sub 1 exch getinterval def
+
+ /sbs [
+ 1
+ 0 1 datalen 1 sub {
+ /i exch def
+ dxw i get {} forall
+ i 2 mod 0 eq {fxw i 2 idiv get {} forall} if
+ } for
+ 1 1
+ ] def
+
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs [sbs length 1 add 2 idiv {height} repeat]
+ /bbs [sbs length 1 add 2 idiv {0} repeat]
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
+
+ } { % 2D - stacked
+
+ /seps numrows array def
+ 0 1 numrows 1 sub {
+
+ /r exch def
+ /row rows r get def
+
+ % Sample runlengths into bitmap
+ mark
+ 0 2 row length 1 sub {
+ /i exch def
+ row i get {0} repeat
+ i row length 1 sub lt {row i 1 add get {1} repeat} if
+ } for
+ counttomark array astore /row exch def pop
+
+ % Derive the separator pattern
+ /sep [ row {1 exch sub} forall ] def
+ sep 0 [ 0 0 0 0 ] putinterval
+ sep row length 4 sub [ 0 0 0 0 ] putinterval
+ /finderpos [ % Finder pattern module positions
+ 19 98 row length 13 sub {} for
+ 68 98 row length 13 sub {} for
+ ] def
+ finderpos {
+ dup 14 add 1 exch {
+ /i exch def
+ row i get 0 eq {
+ row i 1 sub get 1 eq {
+ 1
+ } {
+ sep i 1 sub get 0 eq {1} {0} ifelse
+ } ifelse
+ } {
+ 0
+ } ifelse
+ sep exch i exch put
+ } for
+ } forall
+
+ % For even segment-pair symbols reverse alternate rows
+ segments 4 mod 0 eq r 2 mod 1 eq and {
+ rows r get length rows 0 get length ne % Except partial width last row
+ finderpos length 2 mod 1 eq and { % with odd finders
+ /row [ 0 row aload pop ] def
+ /sep [ 0 sep aload pop ] def
+ } {
+ row length 1 sub -1 0 {row exch get} for
+ row astore pop
+ sep length 1 sub -1 0 {sep exch get} for
+ sep astore pop
+ } ifelse
+ } if
+
+ rows r row put
+ seps r sep put
+
+ } for
+
+ % Extend last row and separator to fill width of symbol
+ /pixx rows 0 get length def
+ [ pixx {0} repeat ] dup 0 rows numrows 1 sub get putinterval
+ rows exch numrows 1 sub exch put
+ [ pixx {0} repeat ] dup 0 seps numrows 1 sub get putinterval
+ seps exch numrows 1 sub exch put
+
+ % Middle separator pattern
+ /sep [ pixx 2 idiv 1 add { 0 1 } repeat ] 0 pixx getinterval def
+ sep 0 [0 0 0 0] putinterval
+ sep pixx 4 sub [0 0 0 0] putinterval
+
+ % Compose the symbol
+ /pixs [
+ 0 1 numrows 1 sub {
+ /r exch def
+ r 0 ne {
+ seps r get aload pop
+ } if
+ 34 {rows r get aload pop} repeat
+ r numrows 1 sub ne {
+ seps r get aload pop
+ sep aload pop
+ } if
+ } for
+ ] def
+
+ <<
+ /ren (renmatrix)
+ /pixs pixs
+ /pixx pixx
+ /pixy pixs length pixx idiv
+ /height pixs length pixx idiv 72 div
+ /width pixx 72 div
+ /opt options
+ >>
+
+ dontdraw not //renmatrix if
+
+ } ifelse
end
} bind def
-/rssexpanded load 0 1 dict put
% --END ENCODER rssexpanded--
% --BEGIN ENCODER pharmacode--
@@ -2055,23 +3536,28 @@
% --RNDR: renlinear
/pharmacode {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/height 8 2.835 mul 72 div def
/nwidth 0.5 2.835 mul def
/wwidth 1.5 2.835 mul def
/swidth 1.0 2.835 mul def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
+
/height height cvr def
/nwidth nwidth cvr def
/wwidth wwidth cvr def
@@ -2103,20 +3589,21 @@
} for
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) sbs put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
- retval (txt) txt put
- retval (textxalign) (center) put
- retval (opt) useropts put
- retval
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs [sbs length 1 add 2 idiv {height} repeat]
+ /bbs [sbs length 1 add 2 idiv {0} repeat]
+ /txt txt
+ /textxalign (center)
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/pharmacode load 0 1 dict put
% --END ENCODER pharmacode--
% --BEGIN ENCODER code2of5--
@@ -2126,14 +3613,12 @@
% --RNDR: renlinear
/code2of5 {
- % Thanks to Michael Landers
-
- 0 begin % Confine variable to local scope
+ 20 dict begin % Confine variable to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includecheck false def
/includetext false def % Enable/disable text
/includecheckintext false def
@@ -2143,10 +3628,15 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
@@ -2210,21 +3700,22 @@
} ifelse
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/code2of5 load 0 1 dict put
% --END ENCODER code2of5--
% --BEGIN ENCODER code11--
@@ -2234,12 +3725,12 @@
% --RNDR: renlinear
/code11 {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includecheck false def
/includetext false def
/includecheckintext false def
@@ -2249,11 +3740,16 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -2285,7 +3781,7 @@
} ifelse
% Put the start character
- sbs 0 encs 10 get putinterval
+ sbs 0 encs 11 get putinterval
/checksum1 0 def /checksum2 0 def
@@ -2340,21 +3836,22 @@
} ifelse
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/code11 load 0 1 dict put
% --END ENCODER code11--
% --BEGIN ENCODER rationalizedCodabar--
@@ -2364,12 +3861,12 @@
% --RNDR: renlinear
/rationalizedCodabar {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/includecheckintext false def
@@ -2379,10 +3876,15 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
@@ -2459,21 +3961,22 @@
} ifelse
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/rationalizedCodabar load 0 1 dict put
% --END ENCODER rationalizedCodabar--
% --BEGIN ENCODER onecode--
@@ -2483,30 +3986,49 @@
% --RNDR: renlinear
/onecode {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
- /height 0.175 def
+ /dontdraw false def
+ /height 0.15 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
+
/height height cvr def
/barlen barcode length def
% Create the human readable text
- /txt barcode length array def
- 0 1 barcode length 1 sub {
+ /txtdict <<
+ 2 dup
+ 5 dup
+ barcode 5 1 getinterval (9) eq {14} {11} ifelse dup
+ 20 dup
+ 25 dup
+ 29 dup
+ >> def
+ /txt barlen 6 add array def
+ /spacecnt 0 def
+ 0 1 barlen 1 sub {
/i exch def
- txt i [barcode i 1 getinterval 0 0 () 0] put
+ txtdict i known {
+ txt i spacecnt add [( ) 0 0 () 0] put
+ /spacecnt spacecnt 1 add def
+ } if
+ txt i spacecnt add [barcode i 1 getinterval 0 0 () 0] put
} for
+ /txt txt 0 barcode length spacecnt add getinterval def
/normalize {
/base exch def
@@ -2770,20 +4292,25 @@
} if
} for
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (bbs) bbs put
- retval (bhs) bhs put
- retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
- retval (txt) txt put
- retval (textxalign) (center) put
- retval (opt) useropts put
- retval
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /bbs bbs
+ /bhs bhs
+ /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
+ /txt txt
+ /textxalign (left)
+ /textfont /Helvetica
+ /textyoffset 1
+ /textxoffset -0.3
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/onecode load 0 1 dict put
% --END ENCODER onecode--
% --BEGIN ENCODER postnet--
@@ -2793,12 +4320,12 @@
% --RNDR: renlinear
/postnet {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/includecheckintext false def
/textfont /Courier def
@@ -2807,11 +4334,16 @@
/height 0.125 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -2885,21 +4417,23 @@
} for
bhs barlen 5 mul 6 add heights putinterval
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (bhs) bhs put
- retval (bbs) [bhs length {0} repeat] put
- retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /bhs bhs
+ /bbs [bhs length {0} repeat]
+ /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
includetext {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/postnet load 0 1 dict put
% --END ENCODER postnet--
% --BEGIN ENCODER royalmail--
@@ -2909,12 +4443,12 @@
% --RNDR: renlinear
/royalmail {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/includecheckintext false def
/textfont /Courier def
@@ -2923,11 +4457,16 @@
/height 0.175 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -3006,21 +4545,23 @@
} if
} for
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (bbs) bbs put
- retval (bhs) bhs put
- retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /bbs bbs
+ /bhs bhs
+ /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
includetext {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/royalmail load 0 1 dict put
% --END ENCODER royalmail--
% --BEGIN ENCODER auspost--
@@ -3030,12 +4571,12 @@
% --RNDR: renlinear
/auspost {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10 def
@@ -3044,11 +4585,16 @@
/custinfoenc (character) def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -3200,21 +4746,23 @@
} if
} for
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (bbs) bbs put
- retval (bhs) bhs put
- retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /bbs bbs
+ /bhs bhs
+ /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
includetext {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/auspost load 0 1 dict put
% --END ENCODER auspost--
% --BEGIN ENCODER kix--
@@ -3224,12 +4772,12 @@
% --RNDR: renlinear
/kix {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/includecheckintext false def
/textfont /Courier def
@@ -3238,11 +4786,16 @@
/height 0.175 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -3300,23 +4853,186 @@
} if
} for
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (bbs) bbs put
- retval (bhs) bhs put
- retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /bbs bbs
+ /bhs bhs
+ /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
includetext {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/kix load 0 1 dict put
% --END ENCODER kix--
+% --BEGIN ENCODER japanpost--
+% --DESC: Japan Post 4 State Customer Code
+% --EXAM: 6540123789-A-K-Z
+% --EXOP: includetext includecheckintext
+% --RNDR: renlinear
+/japanpost {
+
+ 20 dict begin
+
+ /options exch def % We are given an option string
+ /barcode exch def % We are given a barcode string
+
+ /dontdraw false def
+ /includetext false def % Enable/disable text
+ /includecheckintext false def
+ /textfont /Courier def
+ /textsize 10 def
+ /textyoffset -7 def
+ /height 0.175 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
+
+ % Create an array containing the character mappings
+ % 0123456789- C1C2C3C4C5C6C7C8 ST EN
+ /encs
+ [ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030)
+ (120) (102) (210) (012) (201) (021) (003) (333)
+ (31) (13)
+ ] def
+
+ % Create a string of the available characters
+ /barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
+ /barlen barcode length def
+
+ /encstr 20 1 add 3 mul 4 add string def
+ /digits 20 array def
+ /txt barlen 1 add array def
+
+ % Put start character
+ encstr 0 encs 19 get putinterval
+
+ /checksum 0 def
+ /j 0 def /i 0 def
+ 0 1 barlen 1 sub {
+ /i exch def
+ barcode i 1 getinterval barchars exch search
+ pop % Discard true leaving pre
+ length /indx exch def % indx is the length of pre
+ pop pop % Discard match and post
+ indx 11 ge indx 37 lt and { % Insert escape
+ j 18 gt {exit} if % Should fit in 20 chars
+ % 11-20: C1 (11)
+ % 21-30: C2 (12)
+ % 31-36: C3 (13)
+ /digit indx 1 sub 10 idiv 10 add def
+ encstr j 3 mul 2 add encs digit get putinterval
+ /checksum checksum digit add def
+ digits j digit put
+ /j j 1 add def
+ } if
+ j 19 gt {exit} if % Should fit in 20 chars
+ /digit 0 def
+ indx 37 eq {
+ /digit 14 def % space (C14)
+ } if
+ indx 11 ge indx 37 lt and {
+ /digit indx 1 sub 10 mod def
+ } if
+ indx 11 lt {
+ /digit indx def
+ } if
+ encstr j 3 mul 2 add encs digit get putinterval % space
+ /checksum checksum digit add def
+ digits j digit put
+ txt i [barcode i 1 getinterval j 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
+ /j j 1 add def
+ } for
+
+ % Fill spaces (c14) at right end
+ j 1 20 1 sub {
+ /k exch def
+ encstr k 3 mul 2 add encs 14 get putinterval
+ /checksum checksum 14 add def
+ digits k 14 put
+ } for
+
+ % Put the checksum character
+ /checksum checksum 19 mod 19 exch sub def
+ encstr 2 20 3 mul add encs checksum get putinterval
+
+ % Put end character
+ encstr 2 21 3 mul add encs 20 get putinterval
+ /checkdigit ( ) def
+ includecheckintext {
+ /checkdigit barchars checksum 1 getinterval def
+ } if
+ txt i 1 add [ checkdigit 20 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
+
+ % Put end character
+ encstr 20 1 add 3 mul 2 add encs 20 get putinterval
+
+ /bbs 21 3 mul 4 add array def
+ /bhs bbs length array def
+ 0 1 bbs length 1 sub {
+ /i exch def
+ /enc encstr i 1 getinterval def
+ /bunit 0 def
+ /hunit 0 def
+ enc (0) eq {
+ /bunit 3 def
+ /hunit 2 def
+ } if
+ enc (1) eq {
+ /bunit 0 def
+ /hunit 5 def
+ } if
+ enc (2) eq {
+ /bunit 3 def
+ /hunit 5 def
+ } if
+ enc (3) eq {
+ /bunit 0 def
+ /hunit 8 def
+ } if
+ bbs i bunit height mul 8 div put
+ bhs i hunit height mul 8 div put
+ } for
+
+ % Return the arguments
+ <<
+ /ren (renlinear)
+ /bbs bbs
+ /bhs bhs
+ /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
+ includetext {
+ /txt txt
+ } if
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
+
+ end
+
+} bind def
+% --END ENCODER japanpost--
+
% --BEGIN ENCODER msi--
% --DESC: MSI Modified Plessey
% --EXAM: 0123456789
@@ -3324,12 +5040,12 @@
% --RNDR: renlinear
/msi {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/includecheckintext false def
@@ -3339,10 +5055,15 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
@@ -3369,7 +5090,6 @@
/txt barlen array def
} ifelse
-
% Put start character
sbs 0 encs 10 get putinterval
/checksum 0 def
@@ -3406,21 +5126,22 @@
} ifelse
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/msi load 0 1 dict put
% --END ENCODER msi--
% --BEGIN ENCODER plessey--
@@ -3430,12 +5151,12 @@
% --RNDR: renlinear
/plessey {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
+ /dontdraw false def
/includetext false def % Enable/disable text
/includecheckintext false def
/textfont /Courier def
@@ -3444,11 +5165,16 @@
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
@@ -3529,21 +5255,22 @@
sbs barlen 8 mul 24 add encs 17 get putinterval
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
+ <<
+ /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 {
- retval (txt) txt put
+ /txt txt
} if
- retval (opt) useropts put
- retval
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/plessey load 0 1 dict put
% --END ENCODER plessey--
% --BEGIN ENCODER raw--
@@ -3553,34 +5280,41 @@
% --RNDR: renlinear
/raw {
- 0 begin % Confine variables to local scope
+ 20 dict begin % Confine variables to local scope
/options exch def % We are given an option string
- /useropts options def
/sbs exch def % We are given a barcode string
+ /dontdraw false def
/height 1 def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
+
/height height cvr def
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) [sbs {48 sub} forall] put
- retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
- retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
- retval (opt) useropts put
- retval
+ <<
+ /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]
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/raw load 0 1 dict put
% --END ENCODER raw--
% --BEGIN ENCODER symbol--
@@ -3590,11 +5324,13 @@
% --RNDR: renlinear
/symbol {
- 0 begin % Confine variables to local scope
+ 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
+
barcode (fima) eq {
/sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def
/bhs [.625 .625 .625 .625 .625] def
@@ -3620,61 +5356,137 @@
} if
% Return the arguments
- /retval 8 dict def
- retval (ren) (renlinear) put
- retval (sbs) sbs put
- retval (bhs) bhs put
- retval (bbs) bbs put
- retval (opt) options put
- retval
+ <<
+ /ren (renlinear)
+ /sbs sbs
+ /bhs bhs
+ /bbs bbs
+ /opt options
+ >>
+
+ dontdraw not //renlinear if
end
} bind def
-/symbol load 0 1 dict put
% --END ENCODER symbol--
% --BEGIN ENCODER pdf417--
% --DESC: PDF417
-% --EXAM: ^453^178^121^239
-% --EXOP: columns=2 rows=10
+% --EXAM: This is PDF417
+% --EXOP: columns=2
% --RNDR: renmatrix
/pdf417 {
- 0 begin
+ 20 dict begin
/options exch def
- /useropts options def
/barcode exch def
+ /dontdraw false def
/compact false def
/eclevel -1 def
/columns 0 def
/rows 0 def
/rowmult 3 def
+ /raw false def
+ /parse false def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
/eclevel eclevel cvi def
/columns columns cvi def
/rows rows cvi def
/rowmult rowmult cvr def
- % Split the input barcode into an array of codewords
- /datcws barcode length array def
- /i 0 def /j 0 def
- { % loop
- i barcode length eq {exit} if
- /cw barcode i 1 add 3 getinterval cvi def
- datcws j cw put
- /i i 4 add def
- /j j 1 add def
- } loop
- /datcws datcws 0 j getinterval def
+ % Parse ordinals of the form ^NNN to ASCII
+ parse {
+ /msg barcode length string def
+ /j 0 def
+ barcode
+ { % loop
+ (^) search {
+ dup msg exch j exch putinterval
+ length j add 1 add /j exch def
+ pop
+ dup 0 3 getinterval cvi msg exch j 1 sub exch put
+ dup length 3 sub 3 exch getinterval
+ } {
+ dup msg exch j exch putinterval
+ length j add /j exch def
+ /barcode msg 0 j getinterval def
+ exit
+ } ifelse
+ } loop
+ } if
+
+ % Convert input into array of codewords
+ raw {
+ /datcws barcode length array def
+ /i 0 def /j 0 def
+ { % loop
+ i barcode length eq {exit} if
+ /cw barcode i 1 add 3 getinterval cvi def
+ datcws j cw put
+ /i i 4 add def
+ /j j 1 add def
+ } loop
+ /datcws datcws 0 j getinterval def
+ } { % Simple autoencoder from input to codewords using byte mode
+ /barlen barcode length def
+ barlen 6 mod 0 eq {
+ /datcws barlen 6 idiv 5 mul 1 add array def
+ datcws 0 924 put
+ } {
+ /datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def
+ datcws 0 901 put
+ } ifelse
+
+ % Rebase groups of 6 bytes splitting into 3 byte chunks
+ 0 1 barlen 6 idiv 1 sub {
+ /i exch def
+ /msbs [ barcode i 6 mul 3 getinterval {} forall ] def
+ /mscs [
+ msbs aload pop exch 256 mul add exch 65536 mul add
+ 3 {dup 900 mod exch 900 idiv} repeat
+ ] def
+ /lsbs [barcode i 6 mul 3 add 3 getinterval {} forall] def
+ /lscs [
+ lsbs aload pop exch 256 mul add exch 65536 mul add
+ 3 {dup 900 mod exch 900 idiv} repeat
+ ] def
+ /cws 5 array def
+ lscs 0 get mscs 0 get 316 mul add
+ cws 4 2 index 900 mod put
+ 900 idiv lscs 1 get add mscs 0 get 641 mul add mscs 1 get 316 mul add
+ cws 3 2 index 900 mod put
+ 900 idiv lscs 2 get add mscs 0 get 20 mul add mscs 1 get 641 mul add mscs 2 get 316 mul add
+ cws 2 2 index 900 mod put
+ 900 idiv lscs 3 get add mscs 1 get 20 mul add mscs 2 get 641 mul add
+ cws 1 2 index 900 mod put
+ 900 idiv mscs 2 get 20 mul add
+ cws 0 3 -1 roll 900 mod put
+ datcws i 5 mul 1 add cws putinterval
+ } for
+
+ % Add the remaining bytes to the end of the codewords
+ /rem barlen 6 mod def
+ rem 0 ne {
+ datcws datcws length rem sub
+ [ barcode barlen rem sub rem getinterval {} forall ]
+ putinterval
+ } if
+
+ } ifelse
% Determine the error correction level if unspecified
/m datcws length def
@@ -3714,23 +5526,16 @@
cws n [ k {0} repeat 0 ] putinterval
% Calculate the log and anti-log tables
- /rslog [ -928 928 {0} repeat ] def
- /rsalog [ 1 928 {0} repeat ] def
- 1 1 928 {
- /i exch def
- rsalog i rsalog i 1 sub get 3 mul put
- rsalog i get 928 ge { rsalog i rsalog i get 929 mod put } if
- rslog rsalog i get i put
- } for
+ /rsalog [ 1 928 {dup 3 mul 929 mod} repeat ] def
+ /rslog 929 array def
+ 1 1 928 {dup rsalog exch get exch rslog 3 1 roll put} for
% Function to calculate the product in the field
/rsprod {
- /y exch def
- /x exch def
- x y mul 0 ne {
- rsalog rslog x get rslog y get add 928 mod get
+ 2 copy 0 ne exch 0 ne and {
+ rslog exch get exch rslog exch get add 928 mod rsalog exch get
} {
- 0
+ pop pop 0
} ifelse
} bind def
@@ -3756,7 +5561,7 @@
cws n j add cws n j add 1 add get 929 t coeffs k j sub 1 sub get mul 929 mod sub add 929 mod put
} for
} for
- n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub put } for
+ n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub 929 mod put } for
% Trim the working space from the end of the codewords
/cws cws 0 cws length 1 sub getinterval def
@@ -4048,58 +5853,273 @@
} for
- /retval 7 dict def
- retval (ren) (renmatrix) put
- retval (pixs) pixs put
- retval (pixx) rwid put
- retval (pixy) r put
- retval (height) r 72 div rowmult mul put
- retval (width) rwid 72 div put
- retval (opt) useropts put
- retval
+ % Return the arguments
+ <<
+ /ren (renmatrix)
+ /pixs pixs
+ /pixx rwid
+ /pixy r
+ /height r 72 div rowmult mul
+ /width rwid 72 div
+ /opt options
+ >>
+
+ dontdraw not //renmatrix if
end
} bind def
-/pdf417 load 0 1 dict put
% --END ENCODER pdf417--
% --BEGIN ENCODER datamatrix--
% --DESC: Data Matrix
-% --EXAM: ^142^164^186
+% --EXAM: This is Data Matrix!
% --EXOP: rows=32 columns=32
% --RNDR: renmatrix
/datamatrix {
- 0 begin
+ 20 dict begin
/options exch def
- /useropts options def
/barcode exch def
+ /dontdraw false def
/columns 0 def
/rows 0 def
+ /encoding (byte) def
+ /raw false def
+ /parse false def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
/columns columns cvi def
/rows rows cvi def
- % Split the input barcode into an array of codewords
- /cws barcode length array def
- /i 0 def /j 0 def
- { % loop
- i barcode length eq {exit} if
- /cw barcode i 1 add 3 getinterval cvi def
- cws j cw put
- /i i 4 add def
- /j j 1 add def
- } loop
- /cws cws 0 j getinterval def
+ % Parse ordinals of the form ^NNN to ASCII
+ parse {
+ /msg barcode length string def
+ /j 0 def
+ barcode
+ { % loop
+ (^) search {
+ dup msg exch j exch putinterval
+ length j add 1 add /j exch def
+ pop
+ dup 0 3 getinterval cvi msg exch j 1 sub exch put
+ dup length 3 sub 3 exch getinterval
+ } {
+ dup msg exch j exch putinterval
+ length j add /j exch def
+ /barcode msg 0 j getinterval def
+ exit
+ } ifelse
+ } loop
+ } if
+
+ /barlen barcode length def
+
+ raw {/encoding (raw) def} if
+
+ encoding (raw) eq {
+ /cws barlen array def
+ /i 0 def /j 0 def
+ { % loop
+ i barlen eq {exit} if
+ /cw barcode i 1 add 3 getinterval cvi def
+ cws j cw put
+ /i i 4 add def
+ /j j 1 add def
+ } loop
+ /cws cws 0 j getinterval def
+ } if
+
+ encoding (byte) eq {
+ barlen 250 lt {
+ /cws [231 barlen barcode {} forall] def
+ } {
+ /cws [231 barlen 250 idiv 249 add barlen 250 mod barcode {} forall] def
+ } ifelse
+ 1 1 cws length 1 sub {
+ /i exch def
+ i 1 add 149 mul 255 mod 1 add cws i get add
+ dup 256 ge {256 sub} if
+ cws exch i exch put
+ } for
+ } if
+
+ encoding (ascii) eq {
+ /cws barlen 2 mul array def
+ /i 0 def /j 0 def
+ { % loop
+ i barlen eq {exit} if
+ /char barcode i get def
+ char 48 ge char 57 le and i barlen 1 sub lt and {
+ barcode i 1 add get dup 48 ge exch 57 le and { % Digit pair
+ cws j barcode i 2 getinterval cvi 130 add put
+ /i i 2 add def
+ /j j 1 add def
+ } { % Singular digit
+ cws j char 1 add put
+ /i i 1 add def
+ /j j 1 add def
+ } ifelse
+ } { char 127 le { % ASCII
+ cws j char 1 add put
+ /i i 1 add def
+ /j j 1 add def
+ } { % Extended ASCII
+ cws j 235 put
+ cws j 1 add char 127 sub put
+ /i i 1 add def
+ /j j 2 add def
+ } ifelse } ifelse
+ } loop
+ /cws cws 0 j getinterval def
+ } if
+
+ encoding (edifact) eq {
+ /cws 1558 array def
+ /i 0 def /j 1 def /k 0 def
+ cws 0 240 put
+ { % loop
+ i barlen gt {exit} if
+ /k 0 def /v 0 def
+ { % loop until triplet is full or beyond end of data
+ k 4 eq i barlen gt or {exit} if
+ /cval (unset) def
+ i barlen lt {
+ /char barcode i get def
+ char 32 ge char 94 le and {
+ /cval char 63 and def
+ } if
+ } { % Unlatch at end of data
+ /cval 31 def
+ } ifelse
+ /v v cval 3 k sub 6 mul bitshift or def
+ /k k 1 add def
+ /i i 1 add def
+ } loop
+ cws j [ v -16 bitshift v -8 bitshift 255 and v 255 and ] putinterval
+ /j j 3 add def
+ } loop
+ /cws cws 0 j getinterval def
+ } if
+
+ encoding (c40) eq encoding (text) eq or encoding (x12) eq or {
+
+ /s1 0 def /s2 1 def /s3 2 def /us 30 def
+
+ encoding (c40) eq {
+ /latch 230 def
+ /charmap [
+ 0 1 31 { [ exch s1 exch ] } for % 0-31
+ [ 3 ] % 32
+ 0 1 14 { [ exch s2 exch ] } for % 33-47
+ 4 1 13 { [ exch ] } for % 48-57
+ 15 1 21 { [ exch s2 exch ] } for % 58-64
+ 14 1 39 { [ exch ] } for % 65-90
+ 22 1 26 { [ exch s2 exch ] } for % 91-95
+ [ s3 0 ] % 96
+ 1 1 26 { [ exch s3 exch ] } for % 97-122
+ 27 1 31 { [ exch s3 exch ] } for % 123-127
+ 0 1 31 { [ s2 us 4 -1 roll s1 exch ] } for % 128-159
+ [ s2 us 3 ] % 160
+ 0 1 14 { [ s2 us 4 -1 roll s2 exch ] } for % 161-175
+ 4 1 13 { [ s2 us 4 -1 roll ] } for % 176-185
+ 15 1 21 { [ s2 us 4 -1 roll s2 exch ] } for % 186-192
+ 14 1 39 { [ s2 us 4 -1 roll ] } for % 193-218
+ 22 1 26 { [ s2 us 4 -1 roll s2 exch ] } for % 219-223
+ [ s2 us s3 0 ] % 224
+ 1 1 26 { [ s2 us 4 -1 roll s3 exch ] } for % 225-250
+ 27 1 31 { [ s2 us 4 -1 roll s3 exch ] } for % 251-255
+ ] def
+ } if
+
+ encoding (text) eq {
+ /latch 239 def
+ /charmap [
+ 0 1 31 { [ exch s1 exch ] } for % 0-31
+ [ 3 ] % 32
+ 0 1 14 { [ exch s2 exch ] } for % 33-47
+ 4 1 13 { [ exch ] } for % 48-57
+ 15 1 21 { [ exch s2 exch ] } for % 58-64
+ 1 1 26 { [ exch s3 exch ] } for % 65-90
+ 22 1 26 { [ exch s2 exch ] } for % 91-95
+ [ s3 0 ] % 96
+ 14 1 39 { [ exch ] } for % 97-122
+ 27 1 31 { [ exch s3 exch ] } for % 123-127
+ 0 1 31 { [ s2 us 4 -1 roll s1 exch ] } for % 128-159
+ [ s2 us 3 ] % 160
+ 0 1 14 { [ s2 us 4 -1 roll s2 exch ] } for % 161-175
+ 4 1 13 { [ s2 us 4 -1 roll ] } for % 176-185
+ 15 1 21 { [ s2 us 4 -1 roll s2 exch ] } for % 186-192
+ 1 1 26 { [ s2 us 4 -1 roll s3 exch ] } for % 193-218
+ 22 1 26 { [ s2 us 4 -1 roll s2 exch ] } for % 219-223
+ [ s2 us s3 0 ] % 224
+ 14 1 39 { [ s2 us 4 -1 roll ] } for % 225-250
+ 27 1 31 { [ s2 us 4 -1 roll s3 exch ] } for % 251-255
+ ] def
+ } if
+
+ encoding (x12) eq {
+ /latch 238 def
+ /charmap [
+ 13 { [ () ] } repeat % 0-12
+ [ 0 ] % 13
+ 18 { [ () ] } repeat % 14-31
+ [ 3 ] % 32
+ 9 { [ () ] } repeat % 33-41
+ [ 1 ] % 42
+ 5 { [ () ] } repeat % 43-47
+ 4 1 13 { [ exch ] } for % 48-57
+ 4 { [ () ] } repeat % 58-61
+ [ 2 ] % 62
+ 2 { [ () ] } repeat % 63-64
+ 14 1 39 { [ exch ] } for % 65-90
+ 165 { [ () ] } repeat % 91-255
+ ] def
+ } if
+
+ % Derive the encoded character stream
+ /encstr barlen 4 mul array def
+ /j 0 def
+ 0 1 barlen 1 sub {
+ barcode exch get charmap exch get
+ dup encstr exch j exch putinterval
+ length j add /j exch def
+ } for
+ /encstr encstr 0 j getinterval def
+ /enclen j def
+
+ % Compress triples into doubles
+ /cws 1558 array def
+ /i 0 def /j 1 def /k 0 def
+ cws 0 latch put
+ { % loop
+ i enclen ge {exit} if
+ /k 0 def /v 1 def
+ { % loop until triple is full or end of data
+ k 3 eq i enclen ge or {exit} if
+ /v v encstr i get 40 2 k sub exp cvi mul add def
+ /k k 1 add def
+ /i i 1 add def
+ } loop
+ cws j [ v -8 bitshift v 255 and ] putinterval
+ /j j 2 add def
+ } loop
+ cws j 254 put
+ /cws cws 0 j 1 add getinterval def
+
+ } if
% Basic metrics for the each symbol
% rows cols regh regv rscw rsbl
@@ -4195,23 +6215,16 @@
} for
% Calculate the log and anti-log tables
- /rslog [ -255 255 {0} repeat ] def
- /rsalog [ 1 255 {0} repeat ] def
- 1 1 255 {
- /i exch def
- rsalog i rsalog i 1 sub get 2 mul put
- rsalog i get 256 ge { rsalog i rsalog i get 301 xor put } if
- rslog rsalog i get i put
- } for
+ /rsalog [ 1 255 { dup 2 mul dup 256 ge {301 xor} if } repeat ] def
+ /rslog 256 array def
+ 1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
% Function to calculate the product in the field
/rsprod {
- /y exch def
- /x exch def
- x y mul 0 ne {
- rsalog rslog x get rslog y get add 255 mod get
+ 2 copy 0 ne exch 0 ne and {
+ rslog exch get exch rslog exch get add 255 mod rsalog exch get
} {
- 0
+ pop pop 0
} ifelse
} bind def
@@ -4238,17 +6251,17 @@
ecb length 1 sub -1 0 {
/j exch def
/p ecb length j sub 1 sub def
- t 0 eq {
- ecb p 0 put
- } {
- ecb p rsalog rslog t get rslog coeffs j get get add 255 mod get put
- } ifelse
+ ecb p t coeffs j get rsprod put
j 0 gt { ecb p ecb p 1 add get ecb p get xor put } if
} for
} for
- ecbs i ecb put
} for
+ % Strange fixup for 144x144 symbols
+ ncws 1558 eq {
+ /ecbs [ ecbs 8 2 getinterval {} forall ecbs 0 8 getinterval {} forall ] def
+ } if
+
% Extend codewords with the interleaved error correction codes
/cws [ cws {} forall rscw {0} repeat ] def
0 1 rscw 1 sub {
@@ -4256,108 +6269,115 @@
cws ncws i add ecbs i rsbl mod get i rsbl idiv get put
} for
- % Create the module placement matrix
+ % Place the codewords into the matrix
/module {
- /tmpc exch def
- /tmpr exch def
- tmpr 0 lt {
- /tmpr tmpr mrows add def
- /tmpc tmpc 4 mrows 4 add 8 mod sub add def
- } if
- tmpc 0 lt {
- /tmpc tmpc mcols add def
- /tmpr tmpr 4 mcols 4 add 8 mod sub add def
- } if
- mmat tmpr mcols mul tmpc add bit put
- /bit bit 1 add def
+ % cw row col shape
+ 4 -1 roll
+ (00000000) 8 string copy dup 3 -1 roll 2 8 string cvrs
+ dup length 8 exch sub exch putinterval
+ 7 -1 0 {1 index exch get 48 sub exch} for pop
+ 11 -3 roll
+ % 1 2 4 8 16 32 64 128 row col shape
+ { % Place each bit of the codeword in the shape, MSB first
+ exec
+ 1 index 0 lt {
+ exch mrows add exch
+ 4 mrows 4 add 8 mod sub add
+ } if
+ dup 0 lt {
+ mcols add exch
+ 4 mcols 4 add 8 mod sub add exch
+ } if
+ exch mcols mul add
+ mmat exch 5 -1 roll put
+ } forall
} bind def
+ % Placement patterns
+ /dmn [
+ { 2 copy 2 sub exch 2 sub exch } bind { 2 copy 1 sub exch 2 sub exch } bind
+ { 2 copy 2 sub exch 1 sub exch } bind { 2 copy 1 sub exch 1 sub exch } bind
+ { 2 copy exch 1 sub exch } bind { 2 copy 2 sub } bind
+ { 2 copy 1 sub } bind { 2 copy } bind
+ ] def
+
+ /dmc1 [
+ { mrows 1 sub 0 } bind { mrows 1 sub 1 } bind
+ { mrows 1 sub 2 } bind { 0 mcols 2 sub } bind
+ { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind
+ { 2 mcols 1 sub } bind { 3 mcols 1 sub } bind
+ ] def
+
+ /dmc2 [
+ { mrows 3 sub 0 } bind { mrows 2 sub 0 } bind
+ { mrows 1 sub 0 } bind { 0 mcols 4 sub } bind
+ { 0 mcols 3 sub } bind { 0 mcols 2 sub } bind
+ { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind
+ ] def
+
+ /dmc3 [
+ { mrows 3 sub 0 } bind { mrows 2 sub 0 } bind
+ { mrows 1 sub 0 } bind { 0 mcols 2 sub } bind
+ { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind
+ { 2 mcols 1 sub } bind { 3 mcols 1 sub } bind
+ ] def
+
+ /dmc4 [
+ { mrows 1 sub 0 } bind { mrows 1 sub mcols 1 sub } bind
+ { 0 mcols 3 sub } bind { 0 mcols 2 sub } bind
+ { 0 mcols 1 sub } bind { 1 mcols 3 sub } bind
+ { 1 mcols 2 sub } bind { 1 mcols 1 sub } bind
+ ] def
+
/mmat [ mrows mcols mul {-1} repeat ] def
- /bit 0 def /row 4 def /col 0 def
+ cws length 1 sub -1 0 {cws exch get} for % Reverse cws onto stack
+ 4 0 % Starting row and column
{ % loop
-
- row mrows eq col 0 eq and {
- [ [mrows 1 sub 0] [mrows 1 sub 1] [mrows 1 sub 2] [0 mcols 2 sub]
- [0 mcols 1 sub] [1 mcols 1 sub] [2 mcols 1 sub] [3 mcols 1 sub] ]
- {{} forall module} forall
+ 2 copy 0 eq exch mrows eq and {
+ dmc1 module
} if
- row mrows 2 sub eq col 0 eq and mcols 4 mod 0 ne and {
- [ [mrows 3 sub 0] [mrows 2 sub 0] [mrows 1 sub 0] [0 mcols 4 sub]
- [0 mcols 3 sub] [0 mcols 2 sub] [0 mcols 1 sub] [1 mcols 1 sub] ]
- {{} forall module} forall
+ 2 copy 0 eq exch mrows 2 sub eq and mcols 4 mod 0 ne and {
+ dmc2 module
} if
- row mrows 2 sub eq col 0 eq and mcols 8 mod 4 eq and {
- [ [mrows 3 sub 0] [mrows 2 sub 0] [mrows 1 sub 0] [0 mcols 2 sub]
- [0 mcols 1 sub] [1 mcols 1 sub] [2 mcols 1 sub] [3 mcols 1 sub] ]
- {{} forall module} forall
+ 2 copy 0 eq exch mrows 2 sub eq and mcols 8 mod 4 eq and {
+ dmc3 module
} if
- row mrows 4 add eq col 2 eq and mcols 8 mod 0 eq and {
- [ [mrows 1 sub 0] [mrows 1 sub mcols 1 sub] [0 mcols 3 sub] [0 mcols 2 sub]
- [0 mcols 1 sub] [1 mcols 3 sub] [1 mcols 2 sub] [1 mcols 1 sub] ]
- {{} forall module} forall
+ 2 copy 2 eq exch mrows 4 add eq and mcols 8 mod 0 eq and {
+ dmc4 module
} if
{ % loop for sweeping upwards
- row mrows lt col 0 ge and {
- mmat row mcols mul col add get -1 eq {
- [ [row 2 sub col 2 sub] [row 2 sub col 1 sub] [row 1 sub col 2 sub] [row 1 sub col 1 sub]
- [row 1 sub col] [row col 2 sub] [row col 1 sub] [row col] ]
- {{} forall module} forall
+ 2 copy 0 ge exch mrows lt and {
+ 2 copy exch mcols mul add mmat exch get -1 eq {
+ dmn module
} if
} if
- /row row 2 sub def
- /col col 2 add def
- row 0 ge col mcols lt and not {exit} if
+ 2 add exch 2 sub exch
+ 2 copy mcols lt exch 0 ge and not {exit} if
} loop
- /row row 1 add def
- /col col 3 add def
+ 3 add exch 1 add exch
{ % loop for sweeping downwards
- row 0 ge col mcols lt and {
- mmat row mcols mul col add get -1 eq {
- [ [row 2 sub col 2 sub] [row 2 sub col 1 sub] [row 1 sub col 2 sub] [row 1 sub col 1 sub]
- [row 1 sub col] [row col 2 sub] [row col 1 sub] [row col] ]
- {{} forall module} forall
+ 2 copy mcols lt exch 0 ge and {
+ 2 copy exch mcols mul add mmat exch get -1 eq {
+ dmn module
} if
} if
- /row row 2 add def
- /col col 2 sub def
- row mrows lt col 0 ge and not {exit} if
+ 2 sub exch 2 add exch
+ 2 copy 0 ge exch mrows lt and not {exit} if
} loop
- /row row 3 add def
- /col col 1 add def
+ 1 add exch 3 add exch
+
+ 2 copy mcols lt exch mrows lt or not {pop pop exit} if
- row mrows lt col mcols lt or not {exit} if
} loop
% Set checker pattern if required
mmat mrows mcols mul 1 sub get -1 eq {
- mmat mrows mcols 1 sub mul 2 sub [-1 -2] putinterval
- mmat mrows mcols mul 2 sub [-2 -1] putinterval
+ mmat mrows mcols 1 sub mul 2 sub [1 0] putinterval
+ mmat mrows mcols mul 2 sub [0 1] putinterval
} if
- % Invert the map to form the mapping matrix correcting the checker case
- /modmap mrows mcols mul 8 idiv 8 mul array def
- 0 1 mmat length 1 sub {
- /i exch def
- mmat i get 0 ge {
- modmap mmat i get i put
- } {
- mmat i mmat i get 2 add put
- } ifelse
- } for
-
- % Place the codewords in the matrix according to the mapping matrix
- 0 1 cws length 1 sub {
- /i exch def
- [ 8 {0} repeat cws i get 2 8 string cvrs {48 sub} forall ]
- dup length 8 sub 8 getinterval /bits exch def
- 0 1 7 {
- /j exch def
- mmat modmap i 8 mul j add get bits j get put
- } for
- } for
-
% Place the modules onto a pixel map between alignment patterns
/pixs rows cols mul array def
/cwpos 0 def
@@ -4378,56 +6398,149 @@
} if
} for
- /retval 7 dict def
- retval (ren) (renmatrix) put
- retval (pixs) pixs put
- retval (pixx) cols put
- retval (pixy) rows put
- retval (height) rows 72 div 1.5 mul put
- retval (width) cols 72 div 1.5 mul put
- retval (opt) useropts put
- retval
+ % Return the arguments
+ <<
+ /ren (renmatrix)
+ /pixs pixs
+ /pixx cols
+ /pixy rows
+ /height rows 72 div 1.5 mul
+ /width cols 72 div 1.5 mul
+ /opt options
+ >>
+
+ dontdraw not //renmatrix if
end
} bind def
-/datamatrix load 0 1 dict put
% --END ENCODER datamatrix--
% --BEGIN ENCODER qrcode--
% --DESC: QR Code
-% --EXAM: 000100000010000000001100010101100110000110000
-% --EXOP: version=1 eclevel=M
+% --EXAM: http://www.terryburton.co.uk/barcodewriter/
+% --EXOP: eclevel=M
% --RNDR: renmatrix
/qrcode {
- 0 begin
+ 20 dict begin
/options exch def
- /useropts options def
/barcode exch def
+ /dontdraw false def
/format (full) def % full or micro
/version (unset) def
- /eclevel (L) def % L, M, Q or H
+ /eclevel (unset) def % L, M, Q or H
+ /raw false def
+ /parse false def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
+
+ % Parse ordinals of the form ^NNN to ASCII
+ parse {
+ /msg barcode length string def
+ /j 0 def
+ barcode
+ { % loop
+ (^) search {
+ dup msg exch j exch putinterval
+ length j add 1 add /j exch def
+ pop
+ dup 0 3 getinterval cvi msg exch j 1 sub exch put
+ dup length 3 sub 3 exch getinterval
+ } {
+ dup msg exch j exch putinterval
+ length j add /j exch def
+ /barcode msg 0 j getinterval def
+ exit
+ } ifelse
+ } loop
+ } if
% Convert from input into message bitstream
- /msgbits barcode def
+ raw {
+ /msgbits barcode def
+ } { % Simple autoencoder from input to bitstream using byte mode only for full format symbols
+
+ /barlen barcode length def
+ eclevel (unset) eq {/eclevel (M) def} if
+
+ % Determine smallest symbol version to hold given amount of byte-encoded data
+ version (unset) eq {
+ /caps [
+ [
+ 17 32 53 78 106 134 154 192 230 271 % 1-L - 10-L
+ 321 367 425 458 520 586 644 718 792 858 % 11-L - 20-L
+ 929 1003 1091 1171 1273 1367 1465 1528 1628 1732 % 21-L - 30-L
+ 1840 1952 2068 2188 2303 2431 2563 2699 2809 2953 % 31-L - 40-L
+ ] [
+ 14 26 42 62 84 106 122 152 180 213 % 1-M - 10-M
+ 251 287 331 362 412 450 504 560 624 666 % 11-M - 20-M
+ 711 779 857 911 997 1059 1125 1190 1264 1370 % 21-M - 30-M
+ 1452 1538 1628 1722 1809 1911 1989 2099 2213 2331 % 31-M - 40-M
+ ] [
+ 11 20 32 46 60 74 86 108 130 151 % 1-Q - 10-Q
+ 177 203 241 258 292 322 364 394 442 482 % 11-Q - 20-Q
+ 509 565 611 661 715 751 805 868 908 982 % 21-Q - 30-Q
+ 1030 1112 1168 1228 1283 1351 1423 1499 1579 1663 % 31-Q - 40-Q
+ ] [
+ 7 14 24 34 44 58 64 84 98 119 % 1-H - 10-H
+ 137 155 177 194 220 250 280 310 338 382 % 11-H - 20-H
+ 403 439 461 511 535 593 625 658 698 742 % 21-H - 30-H
+ 790 842 898 958 983 1051 1093 1139 1219 1273 % 31-H - 40-H
+ ]
+ ] def
+ /caps caps (LMQH) eclevel search pop length exch pop exch pop get def
+ /i 1 def
+ {
+ barlen caps i 1 sub get le {exit} if
+ /i i 1 add def
+ } loop
+ /version i 10 2 string cvrs def
+ } if
+
+ % Set the control character data for the version
+ /mid (0100) def /term (0000) def /cclen 8 def
+ version 0 1 getinterval (M) ne { % Version 10 and above
+ version cvi 10 ge {/cclen 16 def} if
+ } if
+ /midlen mid length def
+ /termlen term length def
+
+ % Create the bitstream as byte_mode_id character_count data_bytes term
+ /msgbits midlen cclen add barlen 8 mul add termlen add string def
+ msgbits 0 mid putinterval
+ (0000000000000000) 0 cclen getinterval cclen string copy
+ dup barlen cvi 2 cclen string cvrs dup length cclen exch sub exch putinterval
+ /cc exch def
+ msgbits midlen cc putinterval
+ 0 1 barlen 1 sub {
+ /i exch def
+ (00000000) 8 string copy dup barcode i get cvi 2 8 string cvrs dup length 8 exch sub exch putinterval
+ msgbits midlen cclen add i 8 mul add 3 -1 roll putinterval
+ } for
+ msgbits midlen cclen add barlen 8 mul add term putinterval
+
+ } ifelse
% Lookup the most appropriate symbol specification
/metrics [
% format vers size align modules error codewords error correction blocks
% L M Q H L1 L2 M1 M2 Q1 Q2 H1 H2
- [ (micro) (M1) 11 98 99 36 [ 2 99 99 99 ] [ 1 0 99 99 99 99 99 99 ] ]
- [ (micro) (M2) 13 98 99 80 [ 5 6 99 99 ] [ 1 0 1 0 99 99 99 99 ] ]
- [ (micro) (M3) 15 98 99 132 [ 6 8 99 99 ] [ 1 0 1 0 99 99 99 99 ] ]
- [ (micro) (M4) 17 98 99 192 [ 8 10 14 99 ] [ 1 0 1 0 1 0 99 99 ] ]
+ [ (micro) (M1) 11 98 99 36 [ 2 99 99 99 ] [ 1 0 -1 -1 -1 -1 -1 -1 ] ]
+ [ (micro) (M2) 13 98 99 80 [ 5 6 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ]
+ [ (micro) (M3) 15 98 99 132 [ 6 8 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ]
+ [ (micro) (M4) 17 98 99 192 [ 8 10 14 99 ] [ 1 0 1 0 1 0 -1 -1 ] ]
[ (full) (1) 21 98 99 208 [ 7 10 13 17 ] [ 1 0 1 0 1 0 1 0 ] ]
[ (full) (2) 25 18 99 359 [ 10 16 22 28 ] [ 1 0 1 0 1 0 1 0 ] ]
[ (full) (3) 29 22 99 567 [ 15 26 36 44 ] [ 1 0 1 0 2 0 2 0 ] ]
@@ -4469,7 +6582,6 @@
[ (full) (39) 173 26 54 28256 [ 720 1316 1950 2310 ] [ 20 4 40 7 43 22 10 67 ] ]
[ (full) (40) 177 30 58 29648 [ 750 1372 2040 2430 ] [ 19 6 18 31 34 34 20 61 ] ]
] def
-
/eclval (LMQH) eclevel search pop length exch pop exch pop def
/i 0 def
{ % loop
@@ -4493,17 +6605,17 @@
/dmod dcws 8 mul lc4b {4} {0} ifelse sub def % Number of data modules
/ecb1 m 7 get eclval 2 mul get def % First error correction blocks
/ecb2 m 7 get eclval 2 mul 1 add get def % Second error correction blocks
- /dcpb dcws ecb1 ecb2 add idiv def % Base data codewords per block
- /ecpb ncws ecb1 ecb2 add idiv dcpb sub def % Error correction codewords per block
/okay true def
- version (unset) ne version vers ne and {/okay false def} if
- version (unset) eq format frmt ne and {/okay false def} if
- msgbits length dmod gt {/okay false def} if
+ version vers ne {/okay false def} if % The version must match that supplied
+ msgbits length dmod gt {/okay false def} if % Bitstream must fit into data modules
+ ecb1 -1 eq ecb2 -1 eq or {/okay false def} if % Error correction level must be valid
okay {exit} if
/i i 1 add def
} loop
/format frmt def
/version vers def
+ /dcpb dcws ecb1 ecb2 add idiv def % Base data codewords per block
+ /ecpb ncws ecb1 ecb2 add idiv dcpb sub def % Error correction codewords per block
% Expand the message bits by adding padding as necessary
/pad dmod string def
@@ -4532,23 +6644,16 @@
} for
% Calculate the log and anti-log tables
- /rslog [ -255 255 {0} repeat ] def
- /rsalog [ 1 255 {0} repeat ] def
- 1 1 255 {
- /i exch def
- rsalog i rsalog i 1 sub get 2 mul put
- rsalog i get 256 ge { rsalog i rsalog i get 285 xor put } if
- rslog rsalog i get i put
- } for
+ /rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] def
+ /rslog 256 array def
+ 1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
% Function to calculate the product in the field
/rsprod {
- /y exch def
- /x exch def
- x y mul 0 ne {
- rsalog rslog x get rslog y get add 255 mod get
+ 2 copy 0 ne exch 0 ne and {
+ rslog exch get exch rslog exch get add 255 mod rsalog exch get
} {
- 0
+ pop pop 0
} ifelse
} bind def
@@ -4820,14 +6925,89 @@
} if
} ifelse
} loop
+
+ % Evaluate runlength encoded rows or columns in full symbols
+ /evalfulln1n3 {
+ /scrle exch def
+ % Detect runs of 5 or more like modules
+ /scr1 0 scrle { dup 5 ge {add 2 sub dup} if pop } forall def
+ % Detect 1:1:3:1:1 ratio next to 4 modules of whitespace
+ /scr3 0 def
+ 3 2 scrle length 3 sub { % Scan odd (dark) runs within bounds
+ /j exch def
+ scrle j get 3 mod 0 eq { % Multiple of 3 black modules
+ /fact scrle j get 3 idiv def
+ scrle j 2 sub 5 getinterval {fact eq} forall and exch pop and and {
+ j 3 eq j 4 add scrle length ge or { % At either extent of run
+ /scr3 scr3 40 add def
+ } { % Bounded by dark modules
+ scrle j 3 sub get 4 ge scrle j 3 add get 4 ge or {
+ /scr3 scr3 40 add def
+ } if
+ } ifelse
+ } if
+ } if
+ } for
+ scr1 scr3
+ } bind def
% Evaluation algorithm for full symbols
/evalfull {
/sym exch def
- m 2 eq {1} {2} ifelse % In future we may evaluate the masks
+
+ /n1 0 def /n2 0 def /n3 0 def
+ /rle size array def
+ /lastpairs size array def
+ /thispairs size array def
+ /sizeadd1 size 1 add def
+ 0 1 size 1 sub {
+ /i exch def
+
+ % Runlength encode (light, dark, light, ...) and evaluate each column
+ mark 0 0
+ i size dup dup mul 1 sub {
+ sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse
+ } for
+ pop
+ rle 0 counttomark 2 sub getinterval astore
+ evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
+ pop
+
+ % Runlength encode (light, dark, light, ...) and evaluate each row
+ /symrow sym i size mul size getinterval def
+ mark 0 0
+ symrow {
+ exch 1 index eq {exch 1 add exch} {1 exch} ifelse
+ } forall
+ pop
+ rle 0 counttomark 2 sub getinterval astore
+ evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
+ pop
+
+ % Count and score same coloured blocks
+ /lastpairs thispairs /thispairs lastpairs def def
+ symrow 0 get 1 eq {0} {1} ifelse
+ symrow {exch 1 index add exch} forall
+ pop
+ thispairs astore pop
+ i 0 gt {
+ mark
+ lastpairs aload pop thispairs aload pop
+ n2 size { exch sizeadd1 index add 3 and 0 eq {3 add} if } repeat
+ /n2 exch def
+ cleartomark
+ } if
+
+ } for
+
+ % Score dark/light imbalance
+ /dark 0 sym {add} forall def
+ /n4 dark 100 mul size dup mul div 50 sub abs 5 div cvi 10 mul def
+
+ n1 n2 add n3 add n4 add
} bind def
-
- % Evaluation algoritm for micro symbols
+
+ % Evaluation algorithm for micro symbols
/evalmicro {
/sym exch def
/dkrhs 0 def /dkbot 0 def
@@ -4909,116 +7089,381 @@
} forall
} for
} if
-
- /retval 7 dict def
- retval (ren) (renmatrix) put
- retval (pixs) pixs put
- retval (pixx) size put
- retval (pixy) size put
- retval (height) size 2 mul 72 div put
- retval (width) size 2 mul 72 div put
- retval (opt) useropts put
- retval
+
+ % Return the arguments
+ <<
+ /ren (renmatrix)
+ /pixs pixs
+ /pixx size
+ /pixy size
+ /height size 2 mul 72 div
+ /width size 2 mul 72 div
+ /opt options
+ >>
+
+ dontdraw not //renmatrix if
end
} bind def
-/qrcode load 0 1 dict put
% --END ENCODER qrcode--
% --BEGIN ENCODER maxicode--
% --DESC: MaxiCode
-% --EXAM: ^059^042^041^059^040^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291^0471^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^030^062^004^063
-% --EXOP: mode=2
+% --EXAM: [\)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004
+% --EXOP: mode=2 parse
% --RNDR: renmaximatrix
/maxicode {
- 0 begin
+ 20 dict begin
/options exch def % We are given an option string
- /useropts options def
/barcode exch def % We are given a barcode string
- /mode 4 def
+ /dontdraw false def
+ /mode -1 def
/sam -1 def
+ /parse false def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
+ 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
/mode mode cvi def
/sam sam cvi def
- /txtvals (@ABCDEFGHIJKLMNOPQRSTUVWXYZ@@@@@ @@@@@@@@@@@@@@@0123456789@@@@@@) def
-
- % Parse a given message into codewords
- /maxiparse {
- /txt exch def
- /out txt length array def
- /i 0 def /j 0 def
- { % loop
- i txt length eq {exit} if
- txt i 1 getinterval (^) eq {
- % Codeword is given by the next three characters
- /cw txt i 1 add 3 getinterval cvi def
- /i i 4 add def
+ % Parse ordinals of the form ^NNN to ASCII
+ parse {
+ /msg barcode length string def
+ /j 0 def
+ barcode
+ { % loop
+ (^) search {
+ dup msg exch j exch putinterval
+ length j add 1 add /j exch def
+ pop
+ dup 0 3 getinterval cvi msg exch j 1 sub exch put
+ dup length 3 sub 3 exch getinterval
} {
- % Codeword is the characters position in txtvals
- txtvals txt i 1 getinterval search
- pop length /cw exch def pop pop
- /i i 1 add def
- } ifelse
- out j cw put
- /j j 1 add def
+ dup msg exch j exch putinterval
+ length j add /j exch def
+ /barcode msg 0 j getinterval def
+ exit
+ } ifelse
} loop
- out 0 j getinterval
- } bind def
-
- % Calcalate the structured append mode insert
- /sami () def
- sam -1 ne {
- /sami (^033^000) 8 string copy def
- sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add 10 2 string cvrs
- dup length 8 exch sub sami exch 3 -1 roll putinterval
} if
+
+ /msg barcode def
+ /msglen msg length def
- % Message handling for modes 2 and 3
+ % Special message handling for modes 2 and 3
mode 2 eq mode 3 eq or {
- /msg barcode def
-
% Normalise messages that begin with a field identifier [)>RS01GSyy
- msg (^059^042^041^059^040^03001^029) search {
- pop
- dup length 2 add string /fid exch def
- fid 0 3 -1 roll putinterval
- dup fid fid length 2 sub 3 -1 roll 0 2 getinterval putinterval
- dup length 2 sub 2 exch getinterval /msg exch def
+ msg 0 7 getinterval <5b293e1e30311d> eq {
+ /fid msg 0 9 getinterval def
+ /msg msg 9 msglen 9 sub getinterval def
} {
- pop
/fid () def
} ifelse
- % Read the postcode, country code and service code fields
- msg (^029) search pop /pc exch def
- pop (^029) search pop /cc exch def
- pop (^029) search pop /sc exch def
+ % Read the postcode, country code and service code fields seperated by GS
+ msg <1d> search pop /pcode exch def
+ pop <1d> search pop /ccode exch def
+ pop <1d> search pop /scode exch def
pop /msg exch def
+ % Prepend the field identifier
+ msg length fid length add string dup
+ 0 fid putinterval dup
+ fid length msg putinterval
+ /msg exch def
+ /msglen msg length def
+
+ } if
+
+ % Special function characters
+ /eci -1 def /pad -2 def /ns -3 def
+ /la -4 def /lb -5 def
+ /sa -6 def /sb -7 def /sc -8 def /sd -9 def /se -10 def
+ /sa2 -11 def /sa3 -12 def
+ /lkc -13 def /lkd -14 def /lke -15 def
+ /pd2 -16 def /pd3 -17 def
+
+ % Character maps for each state
+ /charmaps [
+ % A B C D E
+ [ 13 (`) 192 224 0 ] % 0
+ [ (A) (a) 193 225 1 ] % 1
+ [ (B) (b) 194 226 2 ] % 2
+ [ (C) (c) 195 227 3 ] % 3
+ [ (D) (d) 196 228 4 ] % 4
+ [ (E) (e) 197 229 5 ] % 5
+ [ (F) (f) 198 230 6 ] % 6
+ [ (G) (g) 199 231 7 ] % 7
+ [ (H) (h) 200 232 8 ] % 8
+ [ (I) (i) 201 233 9 ] % 9
+ [ (J) (j) 202 234 10 ] % 10
+ [ (K) (k) 203 235 11 ] % 11
+ [ (L) (l) 204 236 12 ] % 12
+ [ (M) (m) 205 237 13 ] % 13
+ [ (N) (n) 206 238 14 ] % 14
+ [ (O) (o) 207 239 15 ] % 15
+ [ (P) (p) 208 240 16 ] % 16
+ [ (Q) (q) 209 241 17 ] % 17
+ [ (R) (r) 210 242 18 ] % 18
+ [ (S) (s) 211 243 19 ] % 19
+ [ (T) (t) 212 244 20 ] % 20
+ [ (U) (u) 213 245 21 ] % 21
+ [ (V) (v) 214 246 22 ] % 22
+ [ (W) (w) 215 247 23 ] % 23
+ [ (X) (x) 216 248 24 ] % 24
+ [ (Y) (y) 217 249 25 ] % 25
+ [ (Z) (z) 218 250 26 ] % 26
+ [ eci eci eci eci eci ] % 27
+ [ 28 28 28 28 pad ] % 28
+ [ 29 29 29 29 pad ] % 29
+ [ 30 30 30 30 27 ] % 30
+ [ ns ns ns ns ns ] % 31
+ [ ( ) ({) 219 251 28 ] % 32
+ [ pad pad 220 252 29 ] % 33
+ [ (") (}) 221 253 30 ] % 34
+ [ (#) (~) 222 254 31 ] % 35
+ [ ($) 127 223 255 159 ] % 36
+ [ (%) (;) 170 161 160 ] % 37
+ [ (&) (<) 172 168 162 ] % 38
+ [ (') (=) 177 171 163 ] % 39
+ [ 40 (>) 178 175 164 ] % 40
+ [ 41 (?) 179 176 165 ] % 41
+ [ (*) ([) 181 180 166 ] % 42
+ [ (+) 92 185 183 167 ] % 43
+ [ (,) (]) 186 184 169 ] % 44
+ [ (-) (^) 188 187 173 ] % 45
+ [ (.) (_) 189 191 174 ] % 46
+ [ (/) ( ) 190 138 182 ] % 47
+ [ (0) (,) 128 139 149 ] % 48
+ [ (1) (.) 129 140 150 ] % 49
+ [ (2) (/) 130 141 151 ] % 50
+ [ (3) (:) 131 142 152 ] % 51
+ [ (4) (@) 132 143 153 ] % 52
+ [ (5) (!) 133 144 154 ] % 53
+ [ (6) (|) 134 145 155 ] % 54
+ [ (7) pd2 135 146 156 ] % 55
+ [ (8) sa2 136 147 157 ] % 56
+ [ (9) sa3 137 148 158 ] % 57
+ [ (:) pd3 la la la ] % 58
+ [ sb sa ( ) ( ) ( ) ] % 59
+ [ sc sc lkc sc sc ] % 60
+ [ sd sd sd lkd sd ] % 61
+ [ se se se se lke ] % 62
+ [ lb la lb lb lb ] % 63
+ ] def
+
+ % Invert charmaps to give character to value maps for each state
+ /charvals [ 64 dict 64 dict 64 dict 64 dict 64 dict ] def
+ 0 1 charmaps length 1 sub {
+ /i exch def
+ /encs charmaps i get def
+ 0 1 4 {
+ /j exch def
+ encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
+ charvals j get exch i put
+ } for
+ } for
+ /seta charvals 0 get def
+ /setb charvals 1 get def
+ /setc charvals 2 get def
+ /setd charvals 3 get def
+ /sete charvals 4 get def
+
+ % Compute numeric runlengths
+ /nseq [ msglen 1 add {0} repeat ] def
+ msglen 1 sub -1 0 {
+ /i exch def
+ msg i get dup 48 ge exch 57 le and {
+ nseq i nseq i 1 add get 1 add put
+ } {
+ nseq i 0 put
+ } ifelse
+ } for
+ /nseq nseq 0 msglen getinterval def
+
+ % Encode the message from ASCII to codewords
+ /prefixinset {
+ 0 {
+ 2 copy exch length ge {exit} if
+ 2 copy get 3 index exch known {1 add} {exit} ifelse
+ } loop
+ exch pop exch pop
+ } bind def
+
+ /enc {
+ exch get out exch j exch put
+ /j j 1 add def
+ } bind def
+
+ /out 144 array def
+ /i 0 def /j 0 def /cset (seta) def
+ { % loop
+ % Exit when no characters remain latching back to A if necessary
+ i msglen eq {
+ cset (seta) ne cset (setb) ne and {
+ la cset load enc
+ /cset (seta) def
+ } if
+ exit
+ } if
+ { % not a loop but common exit point
+
+ % If 9 numerals available then use NS
+ nseq i get 9 ge {
+ msg i 9 getinterval cvi 4 { dup 63 and exch -6 bitshift } repeat cset load ns get
+ 0 2 10 {index} for 6 array astore 7 1 roll 6 {pop} repeat
+ out exch j exch putinterval
+ /i i 9 add def
+ /j j 6 add def
+ exit
+ } if
+
+ % Read next three characters
+ /char1 msg i get def
+ /char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def
+ /char3 i 2 add msglen lt {msg i 2 add get} {-99} ifelse def
+
+ % If current mode is sufficient then directly encode
+ cset load char1 known {
+ char1 cset load enc
+ /i i 1 add def
+ exit
+ } if
+
+ % For switching from A to B
+ cset (seta) eq setb char1 known and {
+ setb char2 known {
+ lb seta enc
+ /cset (setb) def
+ } {
+ sb seta enc
+ char1 setb enc
+ /i i 1 add def
+ } ifelse
+ exit
+ } if
+
+ % For switching from B to A encode according to length of prefix
+ cset (setb) eq seta char1 known and {
+ /p seta msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def
+ p 1 eq {
+ sa setb enc
+ char1 seta enc
+ /i i 1 add def
+ } if
+ p 2 eq {
+ sa2 setb enc
+ char1 seta enc
+ char2 seta enc
+ /i i 2 add def
+ } if
+ p 3 eq {
+ sa3 setb enc
+ char1 seta enc
+ char2 seta enc
+ char3 seta enc
+ /i i 3 add def
+ } if
+ p 4 ge {
+ la setb enc
+ /cset (seta) def
+ } if
+ exit
+ } if
+
+ % If character is in A or B then directly latch
+ seta char1 known {
+ la cset load enc
+ /cset (seta) def
+ exit
+ } if
+ setb char1 known {
+ lb cset load enc
+ /cset (setb) def
+ exit
+ } if
+
+ % Determine which one of sets C, D or E the character is in
+ setc char1 known {/setx (setc) def /sx sc def /lkx lkc def} if
+ setd char1 known {/setx (setd) def /sx sd def /lkx lkd def} if
+ sete char1 known {/setx (sete) def /sx se def /lkx lke def} if
+
+ % Encode according to the length of the prefix
+ /p setx load msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def
+ p 1 eq {
+ sx cset load enc
+ char1 setx load enc
+ /i i 1 add def
+ } if
+ p 2 eq {
+ sx cset load enc
+ char1 setx load enc
+ sx cset load enc
+ char2 setx load enc
+ /i i 2 add def
+ } if
+ p 3 eq {
+ sx cset load enc
+ char1 setx load enc
+ sx cset load enc
+ char2 setx load enc
+ sx cset load enc
+ char3 setx load enc
+ /i i 3 add def
+ } if
+ p 4 ge {
+ sx cset load enc
+ lkx setx load enc
+ /cset setx def
+ } if
+
+ exit
+ } loop % out
+ } loop
+ /encmsg out 0 j getinterval def
+ /padval cset load pad get def
+
+ % Prefix the encoded message with the structured append insert
+ /sami [] def
+ sam -1 ne {
+ /sami 2 array def
+ sami 0 seta pad get put
+ sami 1 sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add put
+ } if
+ /encmsg [ sami aload pop encmsg aload pop ] def
+
+ % Derive the primary and secondary codewords for modes 2 and 3
+ mode 2 eq mode 3 eq or {
+
% Calculate the fixed-width binary values for the mode, postcode, country code and service
/mdb (0000) 4 string copy dup mode cvi 2 4 string cvrs dup length 4 exch sub exch putinterval def
- /ccb (0000000000) 10 string copy dup cc cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
- /scb (0000000000) 10 string copy dup sc cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
+ /ccb (0000000000) 10 string copy dup ccode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
+ /scb (0000000000) 10 string copy dup scode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
/pcb (000000000000000000000000000000000000) 36 string copy def
mode 2 eq {
% For numeric postcode, first six bits represent length and remaining 30 bits the value
- pcb pc length 2 6 string cvrs dup length 6 exch sub exch putinterval
- pcb pc cvi 2 30 string cvrs dup length 36 exch sub exch putinterval
+ pcb pcode length 2 6 string cvrs dup length 6 exch sub exch putinterval
+ pcb pcode cvi 2 30 string cvrs dup length 36 exch sub exch putinterval
} { % mode=3
% For alphanumeric postcode, trim or pad with spaces to 6 chars and encode to binary
- /pccw ( ) 6 string copy dup 0 pc length 6 gt {pc 0 6 getinterval} {pc} ifelse putinterval maxiparse def
+ /pccw [
+ ( ) 6 string copy dup 0 pcode length 6 gt {pcode 0 6 getinterval} {pcode} ifelse putinterval
+ {seta exch get} forall
+ ] def
0 1 5 {
/i exch def
pcb pccw i get 2 6 string cvrs dup length 6 i mul 6 add exch sub exch putinterval
@@ -5050,24 +7495,24 @@
pri ps pri ps get ep add put
} for
- % Encode the secondary parts, including any SAM insert and field identifier
- /sec [ 84 {33} repeat ] def
- sec 0 [ sami maxiparse {} forall fid maxiparse {} forall msg maxiparse {} forall ] putinterval
+ % Pad the encoded message into the secondary component
+ /sec [ 84 {padval} repeat ] def
+ sec 0 encmsg putinterval
} if
- % Message handling for modes 4, 5 and 6
- mode 4 eq mode 5 eq or mode 6 eq or {
+ % Derive the primary and secondary codewords for modes 4, 5 and 6
+ mode 4 eq mode 5 eq or mode 6 eq or mode -1 eq or {
- % Prefix the message with the structured append insert
- /msg sami length barcode length add string def
- msg 0 sami putinterval
- msg sami length barcode putinterval
+ % If mode isn't specified then use EEC if message fits, otherwise SEC
+ mode -1 eq {
+ /mode encmsg length 77 le {5} {4} ifelse def
+ } if
% First symbol is the mode and the remainder are the padded message
- /cws [ mode 5 eq {78} {94} ifelse {33} repeat ] def
+ /cws [ mode 5 eq {78} {94} ifelse {padval} repeat ] def
cws 0 mode put
- cws 1 msg maxiparse putinterval
+ cws 1 encmsg putinterval
% Fit the message into the primary and secondary components
/pri cws 0 10 getinterval def
@@ -5223,51 +7668,107 @@
} for
/pixs [ pixs 0 j getinterval {} forall 28 29 280 281 311 457 488 500 530 670 700 677 707 ] def
- /retval 3 dict def
- retval (ren) (renmaximatrix) put
- retval (pixs) pixs put
- retval (opt) useropts put
- retval
+ % Return the arguments
+ <<
+ /ren (renmaximatrix)
+ /pixs pixs
+ /opt options
+ >>
+
+ dontdraw not //renmaximatrix if
end
} bind def
-/maxicode load 0 1 dict put
% --END ENCODER maxicode--
% --BEGIN ENCODER azteccode--
% --DESC: Aztec Code
-% --EXAM: 00100111001000000101001101111000010100111100101000000110
-% --EXOP: format=compact
+% --EXAM: This is Aztec Code
+% --EXOP: format=full
% --RNDR: renmatrix
/azteccode {
- 0 begin
+ 20 dict begin
/options exch def
- /useropts options def
/barcode exch def
+ /dontdraw false def
/format (unset) def % full, compact or rune
/readerinit false def
/layers -1 def
/eclevel 23 def
/ecaddchars 3 def
+ /raw false def
+ /parse false def
% Parse the input options
- options {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
+ 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
+
/layers layers cvi def
/eclevel eclevel cvr def
/ecaddchars ecaddchars cvi def
-
+
+ % Parse ordinals of the form ^NNN to ASCII
+ parse {
+ /msg barcode length string def
+ /j 0 def
+ barcode
+ { % loop
+ (^) search {
+ dup msg exch j exch putinterval
+ length j add 1 add /j exch def
+ pop
+ dup 0 3 getinterval cvi msg exch j 1 sub exch put
+ dup length 3 sub 3 exch getinterval
+ } {
+ dup msg exch j exch putinterval
+ length j add /j exch def
+ /barcode msg 0 j getinterval def
+ exit
+ } ifelse
+ } loop
+ } if
+
% Convert from input into message bitstream
/msgbits () def
- format (rune) ne {/msgbits barcode def} if
-
+ format (rune) ne raw and {/msgbits barcode def} if
+ format (rune) ne raw not and { % Simple autoencoder from input to bitstream using byte mode only
+
+ % Determine the character count
+ /barlen barcode length def
+ barlen 31 le {
+ (00000) 5 string copy dup barlen 2 5 string cvrs
+ dup length 5 exch sub exch putinterval
+ /cc exch def
+ } {
+ (0000000000000000) 16 string copy dup barlen 31 sub 2 16 string cvrs
+ dup length 16 exch sub exch putinterval
+ /cc exch def
+ } ifelse
+ /cclen cc length def
+
+ % Create the bitstream as byte_mode_id character_count data_bytes
+ /msgbits 5 cclen add barlen 8 mul add string def
+ msgbits 0 (11111) putinterval
+ msgbits 5 cc putinterval
+ 0 1 barlen 1 sub {
+ /i exch def
+ (00000000) 8 string copy dup barcode i get cvi 2 8 string cvrs dup length 8 exch sub exch putinterval
+ msgbits 5 cclen add i 8 mul add 3 -1 roll putinterval
+ } for
+
+ } if
+
% Lookup the most appropriate symbol specification
/metrics [
[ (rune) 0 0 0 6 ] % Special metric for rune symbols
@@ -5350,23 +7851,16 @@
/rscws exch def
% Calculate the log and anti-log tables
- /rslog [ 1 rsgf sub rsgf 1 sub {0} repeat ] def
- /rsalog [ 1 rsgf 1 sub {0} repeat ] def
- 1 1 rsgf 1 sub {
- /i exch def
- rsalog i rsalog i 1 sub get 2 mul put
- rsalog i get rsgf ge { rsalog i rsalog i get rspm xor put } if
- rslog rsalog i get i put
- } for
+ /rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
+ /rslog rsgf array def
+ 1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for
% Function to calculate the product in the field
/rsprod {
- /y exch def
- /x exch def
- x y mul 0 ne {
- rsalog rslog x get rslog y get add rsgf 1 sub mod get
+ 2 copy 0 ne exch 0 ne and {
+ rslog exch get exch rslog exch get add rsgf 1 sub mod rsalog exch get
} {
- 0
+ pop pop 0
} ifelse
} bind def
@@ -5578,326 +8072,21 @@
pixs modemap i get {} forall cmv modebits i get 48 sub put
} for
- /retval 7 dict def
- retval (ren) (renmatrix) put
- retval (pixs) pixs put
- retval (pixx) size put
- retval (pixy) size put
- retval (height) size 2 mul 72 div put
- retval (width) size 2 mul 72 div put
- retval (opt) useropts put
- retval
-
- end
-
-} bind def
-/azteccode load 0 1 dict put
-% --END ENCODER azteccode--
-
-% --BEGIN RENDERER renlinear--
-/renlinear {
-
- 0 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
- /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
- args {exch cvlit exch def} forall
-
- % Parse the user options
- opt {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
- /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
- /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
- /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 maxh gt {/maxh h def} if
- } {
- /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
- barcolor (unset) ne { barcolor setanycolor } if
- bars {
- {} forall
- newpath setlinewidth moveto 0 exch rlineto stroke
- } 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 {
- /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
- /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
- /textxpos textxoffset x tstr stringwidth pop sub 2 div add def
- textxalign (left) eq { /textxpos textxoffset def } if
- textxalign (right) eq { /textxpos x textxoffset sub tstr stringwidth pop sub def } if
- textxalign (offleft) eq { /textxpos tstr stringwidth pop textxoffset add neg def } if
- textxalign (offright) eq { /textxpos x textxoffset add def } if
- /textypos textyoffset textsize add 3 sub neg def
- textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
- textyalign (center) eq { /textypos textyoffset maxh textsize 4 sub sub 2 div add def } if
- textxpos textypos moveto tstr show
- } 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 load 0 1 dict put
-% --END RENDERER renlinear--
-
-% --BEGIN RENDERER renmatrix--
-/renmatrix {
-
- 0 begin
-
- /args exch def
-
- % Default options
- /width 1 def
- /height 1 def
-
- % Apply the renderer options
- args {exch cvlit exch def} forall
-
- % Parse the user options
- opt {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
- /width width cvr def
- /height height cvr def
-
- % Convert the bits into a string
- /imgstr pixs length string def
- 0 1 pixs length 1 sub {
- dup imgstr 3 1 roll pixs exch get 1 exch sub 255 mul put
- } for
-
- % Draw the image
- gsave
- currentpoint translate
- 72 width mul 72 height mul scale
- pixx pixy 8 [ pixx 0 0 pixy neg 0 pixy ] {imgstr} image
- grestore
-
- end
-
-} bind def
-/renmatrix load 0 1 dict put
-% --END RENDERER renmatrix--
-
-% --BEGIN RENDERER renmaximatrix--
-/renmaximatrix {
-
- 0 begin
-
- /args exch def % We are given some arguments
-
- % Apply the renderer options
- args {exch cvlit exch def} forall
-
- % Parse the user options
- opt {
- token false eq {exit} if dup length string cvs (=) search
- true eq {cvlit exch pop exch def} {cvlit true def} ifelse
- } loop
-
- gsave
-
- currentpoint translate
-
- 2.4945 dup scale % from 1pt to 1.88mm
- 0.5 0.5774 translate
-
- pixs {
- dup
- /x exch 30 mod def
- /y exch 30 idiv def
- y 2 mod 0 eq {x} {x 0.5 add} ifelse
- 32 y sub 0.8661 mul
- moveto
- 0 0.5774 rmoveto
- -0.5 -0.2887 rlineto
- 0 -0.5774 rlineto
- 0.5 -0.2887 rlineto
- 0.5 0.2887 rlineto
- 0 0.5774 rlineto
- -0.5 0.2887 rlineto
- closepath fill
- } forall
-
- % Plot the locator symbol
- newpath 14 13.8576 0.5774 0 360 arc closepath
- 14 13.8576 1.3359 360 0 arcn closepath fill
- newpath 14 13.8576 2.1058 0 360 arc closepath
- 14 13.8576 2.8644 360 0 arcn closepath fill
- newpath 14 13.8576 3.6229 0 360 arc closepath
- 14 13.8576 4.3814 360 0 arcn closepath fill
+ <<
+ /ren (renmatrix)
+ /pixs pixs
+ /pixx size
+ /pixy size
+ /height size 2 mul 72 div
+ /width size 2 mul 72 div
+ /opt options
+ >>
- grestore
+ dontdraw not //renmatrix if
end
} bind def
-/renmaximatrix load 0 1 dict put
-% --END RENDERER renmaximatrix--
-
-% --BEGIN DISPATCHER--
-/barcode {
- 0 begin
- dup (ren) get cvx exec
- end
-} bind def
-/barcode load 0 1 dict put
-% --END DISPATCHER--
+% --END ENCODER azteccode--
% --END TEMPLATE--