home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / beeld / teken / scribus-1.3.3.9-win32-install.exe / share / plugins / barcode.ps next >
Text File  |  2007-04-17  |  115KB  |  3,583 lines

  1. %!PS-Adobe-2.0
  2. %%Creator: Terry Burton
  3. %%DocumentPaperSizes: a4
  4. %%EndComments
  5. %%EndProlog
  6.  
  7. % Barcode Writer in Pure PostScript - Version 2007-02-25
  8. % http://www.terryburton.co.uk/barcodewriter/
  9. %
  10. % Copyright (c) 2006 Terry Burton - tez@terryburton.co.uk
  11. %
  12. % Permission is hereby granted, free of charge, to any
  13. % person obtaining a copy of this software and associated
  14. % documentation files (the "Software"), to deal in the
  15. % Software without restriction, including without
  16. % limitation the rights to use, copy, modify, merge,
  17. % publish, distribute, sublicense, and/or sell copies of
  18. % the Software, and to permit persons to whom the Software
  19. % is furnished to do so, subject to the following
  20. % conditions:
  21. %
  22. % The above copyright notice and this permission notice
  23. % shall be included in all copies or substantial portions
  24. % of the Software.
  25. %
  26. % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  27. % KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  28. % THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  29. % PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  30. % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  31. % DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  32. % CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  33. % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  34. % IN THE SOFTWARE.
  35.  
  36. % Uncomment this next line to allow these procedure definitions to 
  37. % remain resident within a printer's PostScript virtual machine 
  38. % so that the barcode generation capability persists between jobs.
  39.  
  40. % serverdict begin 0 exitserver 
  41.  
  42. % --BEGIN TEMPLATE--
  43.  
  44. % --BEGIN ENCODER ean13--
  45. % --DESC: EAN-13
  46. % --EXAM: 977147396801
  47. /ean13 {
  48.  
  49.     0 begin
  50.  
  51.     /options exch def                  % We are given an option string
  52.     /useropts options def
  53.     /barcode exch def                  % We are given a barcode string
  54.  
  55.     /includetext false def             % Enable/disable text
  56.     /textfont /Helvetica def
  57.     /textsize 12 def
  58.     /textpos -4 def
  59.     /height 1 def
  60.     
  61.     % Parse the input options
  62.     options {
  63.         token false eq {exit} if dup length string cvs (=) search
  64.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  65.     } loop
  66.     
  67.     /textfont textfont cvlit def
  68.     /textsize textsize cvr def
  69.     /textpos textpos cvr def
  70.     /height height cvr def
  71.     
  72.     /barlen barcode length def         % Length of the code
  73.  
  74.     % Add checksum digit to barcode if length is even
  75.     barlen 2 mod 0 eq {
  76.         /pad barlen 1 add string def   % Create pad one bigger than barcode
  77.         /checksum 0 def
  78.         0 1 barlen 1 sub {
  79.             /i exch def
  80.             /barchar barcode i get 48 sub def
  81.             i 2 mod 0 eq {
  82.                 /checksum barchar checksum add def
  83.             } {
  84.                 /checksum barchar 3 mul checksum add def
  85.             } ifelse
  86.         } for
  87.         /checksum 10 checksum 10 mod sub 10 mod def
  88.         pad 0 barcode putinterval       % Add barcode to the start of the pad
  89.         pad barlen checksum 48 add put  % Put ascii for checksum at end of pad
  90.         /barcode pad def                % barcode=pad
  91.         /barlen barlen 1 add def        % barlen++
  92.     } if
  93.  
  94.     % Create an array containing the character mappings
  95.     /encs
  96.     [ (3211) (2221) (2122) (1411) (1132)
  97.       (1231) (1114) (1312) (1213) (3112)
  98.       (111) (11111) (111)
  99.     ] def
  100.  
  101.     % Create a string of the available characters
  102.     /barchars (0123456789) def
  103.  
  104.     % Digits to mirror on left side
  105.     /mirrormaps
  106.     [ (000000) (001011) (001101) (001110) (010011)
  107.       (011001) (011100) (010101) (010110) (011010)
  108.     ] def
  109.  
  110.     /sbs barlen 1 sub 4 mul 11 add string def
  111.     /txt barlen array def
  112.   
  113.     % Put the start character
  114.     sbs 0 encs 10 get putinterval
  115.  
  116.     % First digit - determine mirrormap by this and show before guard bars
  117.     /mirrormap mirrormaps barcode 0 get 48 sub get def
  118.     txt 0 [barcode 0 1 getinterval -10 textpos textfont textsize] put
  119.  
  120.     % Left side - performs mirroring
  121.     1 1 6 {
  122.         % Lookup the encoding for the each barcode character
  123.         /i exch def
  124.         barcode i 1 getinterval barchars exch search
  125.         pop                            % Discard true leaving pre
  126.         length /indx exch def          % indx is the length of pre
  127.         pop pop                        % Discard seek and post
  128.         /enc encs indx get def         % Get the indxth encoding
  129.         mirrormap i 1 sub get 49 eq {   % Reverse enc if 1 in this position in mirrormap
  130.             /enclen enc length def
  131.             /revenc enclen string def
  132.             0 1 enclen 1 sub {
  133.                 /j exch def
  134.                 /char enc j get def
  135.                 revenc enclen j sub 1 sub char put
  136.             } for
  137.             /enc revenc def
  138.         } if
  139.         sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
  140.         txt i [barcode i 1 getinterval i 1 sub 7 mul 4 add textpos textfont textsize] put
  141.     } for
  142.  
  143.     % Put the middle character
  144.     sbs 7 1 sub 4 mul 3 add encs 11 get putinterval
  145.  
  146.     % Right side
  147.     7 1 12 {
  148.         % Lookup the encoding for the each barcode character
  149.         /i exch def
  150.         barcode i 1 getinterval barchars exch search
  151.         pop                            % Discard true leaving pre
  152.         length /indx exch def          % indx is the length of pre
  153.         pop pop                        % Discard seek and post
  154.         /enc encs indx get def         % Get the indxth encoding
  155.         sbs i 1 sub 4 mul 8 add enc putinterval  % Put encoded digit into sbs
  156.         txt i [barcode i 1 getinterval i 1 sub 7 mul 8 add textpos textfont textsize] put
  157.     } for
  158.  
  159.     % Put the end character
  160.     sbs barlen 1 sub 4 mul 8 add encs 12 get putinterval
  161.     
  162.     % Return the arguments
  163.     /retval 4 dict def
  164.     retval (sbs) [sbs {48 sub} forall] put
  165.     includetext {
  166.         retval (bhs) [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] put
  167.         retval (bbs) [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] put
  168.         retval (txt) txt put
  169.     } {
  170.         retval (bhs) [30{height}repeat] put        
  171.         retval (bbs) [30{0}repeat] put
  172.     } ifelse
  173.     retval (opt) useropts put
  174.     retval (guardrightpos) 10 put
  175.     retval (borderbottom) 5 put
  176.     retval
  177.     
  178.     end
  179.  
  180. } bind def
  181. /ean13 load 0 1 dict put
  182. % --END ENCODER ean13--
  183.  
  184. % --BEGIN ENCODER ean8--
  185. % --DESC: EAN-8
  186. % --EXAM: 01335583
  187. /ean8 {
  188.  
  189.     0 begin
  190.  
  191.     /options exch def                  % We are given an option string
  192.     /useropts options def
  193.     /barcode exch def                  % We are given a barcode string
  194.  
  195.     /includetext false def              % Enable/disable text
  196.     /textfont /Helvetica def
  197.     /textsize 12 def
  198.     /textpos -4 def
  199.     /height 1 def
  200.     
  201.     % Parse the input options
  202.     options {
  203.         token false eq {exit} if dup length string cvs (=) search
  204.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  205.     } loop
  206.     
  207.     /textfont textfont cvlit def
  208.     /textsize textsize cvr def
  209.     /textpos textpos cvr def
  210.     /height height cvr def
  211.     
  212.     % Create an array containing the character mappings
  213.     /encs
  214.     [ (3211) (2221) (2122) (1411) (1132)
  215.       (1231) (1114) (1312) (1213) (3112)
  216.       (111) (11111) (111)
  217.     ] def
  218.  
  219.     % Create a string of the available characters
  220.     /barchars (0123456789) def
  221.  
  222.     /barlen barcode length def           % Length of the code
  223.     /sbs barlen 4 mul 11 add string def
  224.     /txt barlen array def
  225.     
  226.     % Put the start character
  227.     sbs 0 encs 10 get putinterval
  228.  
  229.     % Left side
  230.     0 1 3 {
  231.         % Lookup the encoding for the each barcode character
  232.         /i exch def
  233.         barcode i 1 getinterval barchars exch search
  234.         pop                                % Discard true leaving pre
  235.         length /indx exch def              % indx is the length of pre
  236.         pop pop                            % Discard seek and post
  237.         /enc encs indx get def             % Get the indxth encoding
  238.         sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
  239.         txt i [barcode i 1 getinterval i 7 mul 4 add textpos textfont textsize] put
  240.     } for
  241.  
  242.     % Put the middle character
  243.     sbs 4 4 mul 3 add encs 11 get putinterval
  244.  
  245.     % Right side
  246.     4 1 7 {
  247.         % Lookup the encoding for the each barcode character
  248.         /i exch def
  249.         barcode i 1 getinterval barchars exch search
  250.         pop                                % Discard true leaving pre
  251.         length /indx exch def              % indx is the length of pre
  252.         pop pop                            % Discard seek and post
  253.         /enc encs indx get def             % Get the indxth encoding
  254.         sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
  255.         txt i [barcode i 1 getinterval i 7 mul 8 add textpos textfont textsize] put
  256.     } for
  257.  
  258.     % Put the end character
  259.     sbs barlen 4 mul 8 add encs 12 get putinterval
  260.  
  261.     % Return the arguments
  262.     /retval 4 dict def
  263.     retval (sbs) [sbs {48 sub} forall] put
  264.     includetext {
  265.         retval (bhs) [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] put
  266.         retval (bbs) [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] put
  267.         retval (txt) txt put
  268.     } {
  269.         retval (bhs) [22{height}repeat] put        
  270.         retval (bbs) [22{0}repeat] put
  271.     } ifelse
  272.     retval (opt) useropts put
  273.     retval (guardleftpos) 10 put
  274.     retval (guardrightpos) 10 put
  275.     retval (borderbottom) 5 put
  276.     retval
  277.  
  278.     end
  279.  
  280. } bind def
  281. /ean8 load 0 1 dict put
  282. % --END ENCODER ean8--
  283.  
  284. % --BEGIN ENCODER upca--
  285. % --DESC: UPC-A
  286. % --EXAM: 78858101497
  287. /upca {
  288.  
  289.     0 begin
  290.  
  291.     /options exch def
  292.     /useropts options def
  293.     /barcode exch def             % We are given a barcode string
  294.  
  295.     /includetext false def         % Enable/disable text
  296.     /textfont /Helvetica def
  297.     /textsize 12 def
  298.     /textpos -4 def
  299.     /height 1 def
  300.     
  301.     % Parse the input options
  302.     options {
  303.         token false eq {exit} if dup length string cvs (=) search
  304.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  305.     } loop
  306.     
  307.     /textfont textfont cvlit def
  308.     /textsize textsize cvr def
  309.     /textpos textpos cvr def
  310.     /height height cvr def
  311.     
  312.     /barlen barcode length def         % Length of the code
  313.  
  314.     % Add checksum digit to barcode if length is odd
  315.     barlen 2 mod 0 ne {
  316.         /pad barlen 1 add string def   % Create pad one bigger than barcode
  317.         /checksum 0 def
  318.         0 1 barlen 1 sub {
  319.            /i exch def
  320.            /barchar barcode i get 48 sub def
  321.            i 2 mod 0 ne {
  322.                /checksum checksum barchar add def
  323.            } {
  324.                /checksum checksum barchar 3 mul add def
  325.            } ifelse
  326.         } for
  327.         /checksum 10 checksum 10 mod sub 10 mod def
  328.         pad 0 barcode putinterval       % Add barcode to the start of the pad
  329.         pad barlen checksum 48 add put  % Put ascii for checksum at end of pad
  330.         /barcode pad def                % barcode=pad
  331.         /barlen barlen 1 add def        % barlen++
  332.     } if
  333.  
  334.     % Create an array containing the character mappings
  335.     /encs
  336.     [ (3211) (2221) (2122) (1411) (1132)
  337.       (1231) (1114) (1312) (1213) (3112)
  338.       (111) (11111) (111)
  339.     ] def
  340.  
  341.     % Create a string of the available characters
  342.     /barchars (0123456789) def
  343.  
  344.     /sbs barlen 4 mul 11 add string def
  345.     /txt barlen array def
  346.  
  347.     % Put the start character
  348.     sbs 0 encs 10 get putinterval
  349.  
  350.     % Left side
  351.     0 1 5 {
  352.         % Lookup the encoding for the each barcode character
  353.         /i exch def
  354.         barcode i 1 getinterval barchars exch search
  355.         pop                                % Discard true leaving pre
  356.         length /indx exch def              % indx is the length of pre
  357.         pop pop                            % Discard seek and post
  358.         /enc encs indx get def             % Get the indxth encoding
  359.         sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
  360.         i 0 eq {      % First digit is before the guard bars
  361.             txt 0 [barcode 0 1 getinterval -7 textpos textfont textsize 2 sub] put
  362.         } {
  363.             txt i [barcode i 1 getinterval i 7 mul 4 add textpos textfont textsize] put
  364.         } ifelse
  365.     } for
  366.  
  367.     % Put the middle character
  368.     sbs 6 4 mul 3 add encs 11 get putinterval
  369.  
  370.     % Right side
  371.     6 1 11 {
  372.         % Lookup the encoding for the each barcode character
  373.         /i exch def
  374.         barcode i 1 getinterval barchars exch search
  375.         pop                                % Discard true leaving pre
  376.         length /indx exch def              % indx is the length of pre
  377.         pop pop                            % Discard seek and post
  378.         /enc encs indx get def             % Get the indxth encoding
  379.         sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
  380.         i 11 eq {       % Last digit is after guard bars
  381.             txt 11 [barcode 11 1 getinterval 96 textpos textfont textsize 2 sub] put
  382.         } {
  383.             txt i [barcode i 1 getinterval i 7 mul 8 add textpos textfont textsize] put
  384.         } ifelse
  385.     } for
  386.  
  387.     % Put the end character
  388.     sbs barlen 4 mul 8 add encs 12 get putinterval
  389.  
  390.     % Return the arguments
  391.     /retval 4 dict def
  392.     retval (sbs) [sbs {48 sub} forall] put
  393.     includetext {
  394.         retval (bhs) [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 5{height}repeat] put      
  395.         retval (bbs) [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0 0] put
  396.         retval (txt) txt put
  397.     } {
  398.         retval (bhs) [31{height}repeat] put
  399.         retval (bbs) [31{0}repeat] put
  400.     } ifelse
  401.     retval (opt) useropts put
  402.     retval (borderbottom) 5 put
  403.     retval
  404.  
  405.     end
  406.  
  407. } bind def
  408. /upca load 0 1 dict put
  409. % --END ENCODER upca--
  410.  
  411. % --BEGIN ENCODER upce--
  412. % --DESC: UPC-E
  413. % --EXAM: 0123456
  414. /upce {
  415.  
  416.     0 begin
  417.  
  418.     /options exch def                   % We are given an option string
  419.     /useropts options def
  420.     /barcode exch def                   % We are given a barcode string
  421.  
  422.     /includetext false def               % Enable/disable text
  423.     /textfont /Helvetica def
  424.     /textsize 12 def
  425.     /textpos -4 def
  426.     /height 1 def
  427.     
  428.     % Parse the input options
  429.     options {
  430.         token false eq {exit} if dup length string cvs (=) search
  431.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  432.     } loop
  433.     
  434.     /textfont textfont cvlit def
  435.     /textsize textsize cvr def
  436.     /textpos textpos cvr def
  437.     /height height cvr def
  438.     
  439.     /barlen barcode length def          % Length of the code
  440.  
  441.     % Create an array containing the character mappings
  442.     /encs
  443.     [ (3211) (2221) (2122) (1411) (1132)
  444.       (1231) (1114) (1312) (1213) (3112)
  445.       (111) (1111111)
  446.     ] def
  447.  
  448.     % Create a string of the available characters
  449.     /barchars (0123456789) def
  450.  
  451.     /mirrormaps
  452.     [ (000111) (001011) (001101) (001110) (010011)
  453.       (011001) (011100) (010101) (010110) (011010)
  454.     ] def
  455.  
  456.     % Add checksum digit to barcode if length is odd
  457.     barlen 2 mod 0 ne {
  458.         % Derive the equivalent UPC-A for its checksum
  459.         /upcacode (00000000000) def
  460.         barcode 6 get 48 sub 2 le {
  461.             upcacode 1 barcode 1 2 getinterval putinterval
  462.             upcacode 3 barcode 6 1 getinterval putinterval
  463.             upcacode 8 barcode 3 3 getinterval putinterval
  464.         } if
  465.         barcode 6 get 48 sub 3 eq {
  466.             upcacode 1 barcode 1 3 getinterval putinterval
  467.             upcacode 9 barcode 4 2 getinterval putinterval
  468.         } if
  469.         barcode 6 get 48 sub 4 eq {
  470.             upcacode 1 barcode 1 4 getinterval putinterval
  471.             upcacode 10 barcode 5 1 getinterval putinterval
  472.         } if
  473.         barcode 6 get 48 sub 5 ge {
  474.             upcacode 1 barcode 1 5 getinterval putinterval
  475.             upcacode 10 barcode 6 1 getinterval putinterval
  476.         } if
  477.         /checksum 0 def
  478.         0 1 10 {
  479.            /i exch def
  480.            /barchar upcacode i get 48 sub def
  481.            i 2 mod 0 ne {
  482.                /checksum checksum barchar add def
  483.            } {
  484.                /checksum checksum barchar 3 mul add def
  485.            } ifelse
  486.         } for
  487.         /checksum 10 checksum 10 mod sub 10 mod def
  488.         /pad barlen 1 add string def    % Create pad one bigger than barcode
  489.         pad 0 barcode putinterval       % Add barcode to the start of the pad
  490.         pad barlen checksum 48 add put  % Put ascii for checksum at end of pad
  491.         /barcode pad def                % barcode=pad
  492.         /barlen barlen 1 add def        % barlen++
  493.     } if
  494.     /txt barlen array def
  495.     txt 0 [barcode 0 1 getinterval -7 textpos textfont textsize 2 sub] put
  496.  
  497.     % Determine the mirror map based on checksum
  498.     /mirrormap mirrormaps barcode barlen 1 sub get 48 sub get def
  499.  
  500.     % Invert the mirrormap if we are using a non-zero number system
  501.     barcode 0 get 48 eq {
  502.         /invt mirrormap length string def
  503.         0 1 mirrormap length 1 sub {
  504.             /i exch def
  505.             mirrormap i get 48 eq {
  506.                 invt i 49 put
  507.             } {
  508.                 invt i 48 put
  509.             } ifelse
  510.         } for
  511.         /mirrormap invt def
  512.     } if
  513.  
  514.     /sbs barlen 2 sub 4 mul 10 add string def
  515.  
  516.     % Put the start character
  517.     sbs 0 encs 10 get putinterval
  518.  
  519.     1 1 6 {
  520.         /i exch def
  521.         % Lookup the encoding for the each barcode character
  522.         barcode i 1 getinterval barchars exch search
  523.         pop                            % Discard true leaving pre
  524.         length /indx exch def          % indx is the length of pre
  525.         pop pop                        % Discard seek and post
  526.         /enc encs indx get def         % Get the indxth encoding
  527.         mirrormap i 1 sub get 49 eq {  % Reverse enc if 1 in this position in mirrormap        
  528.             /enclen enc length def
  529.             /revenc enclen string def
  530.             0 1 enclen 1 sub {
  531.                 /j exch def
  532.                 /char enc j get def
  533.                 revenc enclen j sub 1 sub char put
  534.             } for
  535.             /enc revenc def
  536.         } if
  537.         sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
  538.         txt i [barcode i 1 getinterval i 1 sub 7 mul 4 add textpos textfont textsize] put
  539.     } for
  540.  
  541.     txt 7 [barcode 7 1 getinterval 6 7 mul 11 add textpos textfont textsize 2 sub] put
  542.  
  543.     % Put the end character
  544.     sbs barlen 2 sub 4 mul 3 add encs 11 get putinterval
  545.  
  546.     % Return the arguments
  547.     /retval 4 dict def
  548.     retval (sbs) [sbs {48 sub} forall] put
  549.     includetext {
  550.         retval (bhs) [height height 12{height .075 sub}repeat height height height] put      
  551.         retval (bbs) [0 0 12{.075}repeat 0 0 0] put    
  552.         retval (txt) txt put
  553.     } {
  554.         retval (bhs) [17{height}repeat] put      
  555.         retval (bbs) [17{0}repeat] put    
  556.     } ifelse
  557.     retval (opt) useropts put
  558.     retval (borderbottom) 5 put
  559.     retval
  560.  
  561.     end
  562.  
  563. } bind def
  564. /upce load 0 1 dict put
  565. % --END ENCODER upce--
  566.  
  567. % --BEGIN ENCODER ean5--
  568. % --DESC: EAN-5 (5 digit addon)
  569. % --EXAM: 0123456
  570. /ean5 {
  571.  
  572.     0 begin
  573.  
  574.     /options exch def                   % We are given an option string
  575.     /useropts options def
  576.     /barcode exch def                   % We are given a barcode string
  577.  
  578.     /includetext false def              % Enable/disable text
  579.     /textfont /Helvetica def
  580.     /textsize 12 def
  581.     /textpos (unset) def
  582.     /height 0.7 def    
  583.     
  584.     % Parse the input options
  585.     options {
  586.         token false eq {exit} if dup length string cvs (=) search
  587.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  588.     } loop
  589.     
  590.     /textfont textfont cvlit def
  591.     /textsize textsize cvr def
  592.     /height height cvr def
  593.     textpos (unset) eq {
  594.         /textpos height 72 mul 1 add def
  595.     } {
  596.         /textpos textpos cvr def
  597.     } ifelse
  598.     
  599.     /barlen barcode length def          % Length of the code
  600.  
  601.     % Create an array containing the character mappings
  602.     /encs
  603.     [ (3211) (2221) (2122) (1411) (1132)
  604.       (1231) (1114) (1312) (1213) (3112)
  605.       (112) (11)
  606.     ] def
  607.  
  608.     % Create a string of the available characters
  609.     /barchars (0123456789) def
  610.  
  611.     % Determine the mirror map based on mod 10 checksum
  612.     /mirrormaps
  613.     [ (11000) (10100) (10010) (10001) (01100)
  614.       (00110) (00011) (01010) (01001) (00101)
  615.     ] def
  616.     /checksum 0 def
  617.     0 1 4 {
  618.         /i exch def
  619.         /barchar barcode i get 48 sub def
  620.         i 2 mod 0 eq {
  621.             /checksum barchar 3 mul checksum add def
  622.         } {
  623.             /checksum barchar 9 mul checksum add def
  624.         } ifelse
  625.     } for
  626.     /checksum checksum 10 mod def
  627.     /mirrormap mirrormaps checksum get def
  628.  
  629.     /sbs 31 string def
  630.     /txt 5 array def
  631.    
  632.     0 1 4 {
  633.         /i exch def
  634.  
  635.         % Prefix with either a start character or separator character
  636.         i 0 eq {
  637.             sbs 0 encs 10 get putinterval
  638.         } {
  639.             sbs i 1 sub 6 mul 7 add encs 11 get putinterval
  640.         } ifelse
  641.  
  642.         % Lookup the encoding for the barcode character
  643.         barcode i 1 getinterval barchars exch search
  644.         pop                     % Discard true leaving pre
  645.         length /indx exch def   % indx is the length of pre
  646.         pop pop                 % Discard seek and post
  647.         /enc encs indx get def  % Get the indxth encoding
  648.         mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
  649.             /enclen enc length def
  650.             /revenc enclen string def
  651.             0 1 enclen 1 sub {
  652.                 /j exch def
  653.                 /char enc j get def
  654.                 revenc enclen j sub 1 sub char put
  655.             } for
  656.             /enc revenc def
  657.         } if
  658.         sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
  659.         txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textpos textfont textsize] put
  660.     } for
  661.  
  662.     % Return the arguments
  663.     /retval 4 dict def
  664.     retval (sbs) [sbs {48 sub} forall] put
  665.     retval (bhs) [16{height}repeat] put
  666.     retval (bbs) [16{0}repeat] put
  667.     includetext {
  668.         retval (txt) txt put
  669.     } if
  670.     retval (opt) useropts put
  671.     retval (guardrightpos) 10 put
  672.     retval (guardrightypos) textpos 4 add put
  673.     retval (bordertop) 10 put
  674.     retval
  675.  
  676.     end
  677.  
  678. } bind def
  679. /ean5 load 0 1 dict put
  680. % --END ENCODER ean5--
  681.  
  682. % --BEGIN ENCODER ean2--
  683. % --DESC: EAN-2 (2 digit addon)
  684. % --EXAM: 05
  685. /ean2 {
  686.  
  687.     0 begin
  688.  
  689.     /options exch def                   % We are given an options string
  690.     /useropts options def
  691.     /barcode exch def                   % We are given a barcode string
  692.  
  693.     /includetext false def               % Enable/disable text
  694.     /textfont /Helvetica def
  695.     /textsize 12 def
  696.     /textpos (unset) def
  697.     /height 0.7 def
  698.     
  699.     % Parse the input options
  700.     options {
  701.         token false eq {exit} if dup length string cvs (=) search
  702.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  703.     } loop
  704.     
  705.     /textfont textfont cvlit def
  706.     /textsize textsize cvr def
  707.     /height height cvr def
  708.     textpos (unset) eq {
  709.         /textpos height 72 mul 1 add def
  710.     } {
  711.         /textpos textpos cvr def
  712.     } ifelse
  713.     
  714.     /barlen barcode length def          % Length of the code
  715.  
  716.     % Create an array containing the character mappings
  717.     /encs
  718.     [ (3211) (2221) (2122) (1411) (1132)
  719.       (1231) (1114) (1312) (1213) (3112)
  720.       (112) (11)
  721.     ] def
  722.  
  723.     % Create a string of the available characters
  724.     /barchars (0123456789) def
  725.  
  726.     % Determine the mirror map based on mod 4 checksum
  727.     /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
  728.  
  729.     /sbs 13 string def
  730.     /txt 2 array def
  731.     
  732.     0 1 1 {
  733.         /i exch def
  734.  
  735.         % Prefix with either a start character or separator character
  736.         i 0 eq {
  737.             sbs 0 encs 10 get putinterval
  738.         } {
  739.             sbs i 1 sub 6 mul 7 add encs 11 get putinterval
  740.         } ifelse
  741.  
  742.         % Lookup the encoding for the barcode character
  743.         barcode i 1 getinterval barchars exch search
  744.         pop                     % Discard true leaving pre
  745.         length /indx exch def   % indx is the length of pre
  746.         pop pop                 % Discard seek and post
  747.         /enc encs indx get def  % Get the indxth encoding
  748.         mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap    
  749.             /enclen enc length def
  750.             /revenc enclen string def
  751.             0 1 enclen 1 sub {
  752.                 /j exch def
  753.                 /char enc j get def
  754.                 revenc enclen j sub 1 sub char put
  755.             } for
  756.             /enc revenc def
  757.         } if
  758.         sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
  759.         txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textpos textfont textsize] put
  760.     } for
  761.  
  762.     % Return the arguments
  763.     /retval 4 dict def
  764.     retval (sbs) [sbs {48 sub} forall] put
  765.     retval (bhs) [12{height}repeat] put
  766.     retval (bbs) [12{0}repeat] put
  767.     includetext {
  768.         retval (txt) txt put
  769.     } if
  770.     retval (opt) useropts put
  771.     retval (guardrightpos) 10 put
  772.     retval (guardrightypos) textpos 4 add put
  773.     retval (bordertop) 10 put
  774.     retval
  775.  
  776.     end
  777.  
  778. } bind def
  779. /ean2 load 0 1 dict put
  780. % --END ENCODER ean2--
  781.  
  782. % --BEGIN ENCODER isbn--
  783. % --REQUIRES ean13--
  784. % --DESC: ISBN
  785. % --EXAM: 1-86074-271
  786. /isbn {
  787.  
  788.     0 begin
  789.  
  790.     /options exch def      % We are given an options string
  791.     /useropts options def
  792.     /isbntxt exch def      % We are given the isbn text with dashes
  793.  
  794.     /includetext false def  % Enable/disable ISBN text
  795.     /isbnfont /Courier def
  796.     /isbnsize 9 def
  797.     /isbnpos (unset) def
  798.     /height 1 def
  799.     
  800.     % Parse the input options
  801.     options {
  802.         token false eq {exit} if dup length string cvs (=) search
  803.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  804.     } loop
  805.     
  806.     /isbnfont isbnfont cvlit def
  807.     /isbnsize isbnsize cvr def
  808.     /height height cvr def
  809.     isbnpos (unset) eq {
  810.         /isbnpos height 72 mul 3 add def
  811.     } {
  812.         /isbnpos isbnpos cvr def
  813.     } ifelse
  814.     
  815.     % Read the digits from isbntxt and calculate checksums
  816.     /isbn 13 string def
  817.     /checksum10 0 def
  818.     /checksum13 0 def
  819.     /i 0 def /n 0 def
  820.     { % loop
  821.         /isbnchar isbntxt i get 48 sub def
  822.         isbnchar -3 ne {     % Ignore dashes
  823.             isbn n isbnchar 48 add put
  824.             /checksum10 checksum10 10 n sub isbnchar mul add def
  825.             n 2 mod 0 eq {
  826.                 /checksum13 isbnchar checksum13 add def
  827.             } {
  828.                 /checksum13 isbnchar 3 mul checksum13 add def
  829.             } ifelse
  830.             /n n 1 add def
  831.         } if
  832.         /i i 1 add def
  833.         i isbntxt length eq {exit} if
  834.     } loop
  835.  
  836.     % Add the ISBN header to the isbntxt
  837.     n 9 eq n 10 eq or {
  838.         /checksum 11 checksum10 11 mod sub 11 mod def
  839.         /isbn isbn 0 9 getinterval def
  840.         /pad 18 string def
  841.     } {
  842.         /checksum 10 checksum13 10 mod sub 10 mod def
  843.         /isbn isbn 0 12 getinterval def
  844.         /pad 22 string def
  845.     } ifelse
  846.     pad 0 (ISBN ) putinterval
  847.     pad 5 isbntxt putinterval  % Add isbntxt to the pad
  848.  
  849.     % Add checksum digit if isbntxt length is 11 or 15
  850.     isbntxt length 11 eq isbntxt length 15 eq or {
  851.         pad isbntxt length 5 add 45 put  % Put a dash
  852.         checksum 10 eq {
  853.             pad isbntxt length 6 add checksum 78 add put  % Check digit for 10 is X
  854.         } {
  855.             pad isbntxt length 6 add checksum 48 add put  % Put check digit
  856.         } ifelse
  857.     } if
  858.     /isbntxt pad def                    % isbntxt=pad
  859.  
  860.     % Convert ISBN digits to EAN-13
  861.     /barcode 12 string def
  862.     isbn length 9 eq {        
  863.         barcode 0 (978) putinterval
  864.         barcode 3 isbn putinterval
  865.     } {
  866.         barcode 0 isbn putinterval
  867.     } ifelse
  868.  
  869.     % Get the result of encoding with ean13    
  870.     /args barcode options ean13 def
  871.  
  872.     % Add the ISBN text
  873.     includetext {
  874.         isbn length 9 eq {
  875.             /isbnxpos -1 def
  876.         } {
  877.             /isbnxpos -12 def
  878.         } ifelse
  879.         args (txt) known {
  880.             /txt args (txt) get def
  881.             /newtxt txt length 1 add array def
  882.             newtxt 0 txt putinterval
  883.             newtxt newtxt length 1 sub [isbntxt isbnxpos isbnpos isbnfont isbnsize] put
  884.             args (txt) newtxt put
  885.         } {
  886.             args (txt) [ [isbntxt isbnxpos isbnpos isbnfont isbnsize] ] put
  887.         } ifelse
  888.     } if
  889.  
  890.     args (opt) useropts put
  891.     args
  892.  
  893.     end
  894.  
  895. } bind def
  896. /isbn load 0 1 dict put
  897. % --END ENCODER isbn--
  898.  
  899. % --BEGIN ENCODER code128--
  900. % --DESC: Code 128
  901. % --EXAM: ^104^102Count^0990123456789^101!
  902. /code128 {
  903.  
  904.     0 begin                  % Confine variables to local scope
  905.  
  906.     /options exch def        % We are given an option string
  907.     /useropts options def
  908.     /barcode exch def        % We are given a barcode string
  909.  
  910.     /includetext false def    % Enable/disable text
  911.     /textfont /Courier def
  912.     /textsize 10 def
  913.     /textpos -7 def
  914.     /height 1 def
  915.     
  916.     % Parse the input options
  917.     options {
  918.         token false eq {exit} if dup length string cvs (=) search
  919.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  920.     } loop
  921.     
  922.     /textfont textfont cvlit def
  923.     /textsize textsize cvr def
  924.     /textpos textpos cvr def
  925.     /height height cvr def
  926.     
  927.     % Create an array containing the character mappings
  928.     /encs
  929.     [ (212222) (222122) (222221) (121223) (121322) (131222) (122213)
  930.       (122312) (132212) (221213) (221312) (231212) (112232) (122132)
  931.       (122231) (113222) (123122) (123221) (223211) (221132) (221231)
  932.       (213212) (223112) (312131) (311222) (321122) (321221) (312212)
  933.       (322112) (322211) (212123) (212321) (232121) (111323) (131123)
  934.       (131321) (112313) (132113) (132311) (211313) (231113) (231311)
  935.       (112133) (112331) (132131) (113123) (113321) (133121) (313121)
  936.       (211331) (231131) (213113) (213311) (213131) (311123) (311321)
  937.       (331121) (312113) (312311) (332111) (314111) (221411) (431111)
  938.       (111224) (111422) (121124) (121421) (141122) (141221) (112214)
  939.       (112412) (122114) (122411) (142112) (142211) (241211) (221114)
  940.       (413111) (241112) (134111) (111242) (121142) (121241) (114212)
  941.       (124112) (124211) (411212) (421112) (421211) (212141) (214121)
  942.       (412121) (111143) (111341) (131141) (114113) (114311) (411113)
  943.       (411311) (113141) (114131) (311141) (411131) (211412) (211214)
  944.       (211232) (2331112)
  945.     ] def
  946.  
  947.     % Create a string of the available characters for alphabets A and B
  948.     /barchars ( !"#$%&'\(\)*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~) def
  949.     /barlen barcode length def    % Length of the code
  950.     /sbs barlen 6 mul string def  % sbs is 6 times length of barcode
  951.     /txt barlen array def
  952.  
  953.     /mode -1 def         % A=0, B=1, C=2
  954.     /checksum barcode 1 3 getinterval cvi def  % Initialise the checksum
  955.  
  956.     /i 0 def /j 0 def
  957.     { % loop
  958.         i barlen eq {exit} if
  959.         barcode i 1 getinterval (^) eq {
  960.             % indx is given by the next three characters
  961.             /indx barcode i 1 add 3 getinterval cvi def
  962.             txt j [( ) j 11 mul textpos textfont textsize] put
  963.             /i i 4 add def
  964.         } {
  965.             % indx depends on the mode
  966.             mode 2 eq {
  967.                 /indx barcode i 2 getinterval cvi def
  968.                 txt j [barcode i 2 getinterval j 11 mul textpos textfont textsize] put
  969.                 /i i 2 add def
  970.             } {
  971.                 barchars barcode i 1 getinterval search
  972.                 pop                    % Discard true leaving pre
  973.                 length /indx exch def  % indx is the length of pre
  974.                 pop pop                % Discard seek and post
  975.                 txt j [barchars indx 1 getinterval j 11 mul textpos textfont textsize] put
  976.                 /i i 1 add def
  977.             } ifelse
  978.         } ifelse
  979.         /enc encs indx get def         % Get the indxth encoding
  980.         sbs j 6 mul enc putinterval    % Put encoded digit into sbs
  981.  
  982.         % Update the mode
  983.         indx 101 eq indx 103 eq or {/mode 0 def} if
  984.         indx 100 eq indx 104 eq or {/mode 1 def} if
  985.         indx 99 eq indx 105 eq or {/mode 2 def} if
  986.  
  987.         /checksum indx j mul checksum add def  % checksum+=indx*j
  988.         /j j 1 add def
  989.     } loop
  990.  
  991.     % Put the checksum character
  992.     /checksum checksum 103 mod def
  993.     sbs j 6 mul encs checksum get putinterval
  994.  
  995.     % Put the end character
  996.     sbs j 6 mul 6 add encs 106 get putinterval
  997.  
  998.     % Shrink sbs and txt to fit exactly
  999.     /sbs sbs 0 j 6 mul 13 add getinterval def
  1000.     /txt txt 0 j getinterval def
  1001.  
  1002.     % Return the arguments
  1003.     /retval 1 dict def
  1004.     retval (sbs) [sbs {48 sub} forall] put
  1005.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1006.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  1007.     includetext {
  1008.         retval (txt) txt put
  1009.     } if
  1010.     retval (opt) useropts put
  1011.     retval
  1012.  
  1013.     end
  1014.  
  1015. } bind def
  1016. /code128 load 0 1 dict put
  1017. % --END ENCODER code128--
  1018.  
  1019. % --BEGIN ENCODER code39--
  1020. % --DESC: Code 39
  1021. % --EXAM: THIS IS CODE 39
  1022. /code39 {
  1023.  
  1024.     0 begin                 % Confine variables to local scope
  1025.  
  1026.     /options exch def       % We are given an option string
  1027.     /useropts options def
  1028.     /barcode exch def       % We are given a barcode string
  1029.  
  1030.     /includecheck false def  % Enable/disable checkdigit
  1031.     /includetext false def
  1032.     /includecheckintext false def
  1033.     /textfont /Courier def
  1034.     /textsize 10 def
  1035.     /textpos -7 def
  1036.     /height 1 def
  1037.     
  1038.     % Parse the input options
  1039.     options {
  1040.         token false eq {exit} if dup length string cvs (=) search
  1041.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1042.     } loop
  1043.     
  1044.     /textfont textfont cvlit def
  1045.     /textsize textsize cvr def
  1046.     /textpos textpos cvr def
  1047.     /height height cvr def
  1048.     
  1049.     % Create an array containing the character mappings
  1050.     /encs
  1051.     [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131)
  1052.       (3113311111) (1133311111) (1113113131) (3113113111) (1133113111)
  1053.       (3111131131) (1131131131) (3131131111) (1111331131) (3111331111)
  1054.       (1131331111) (1111133131) (3111133111) (1131133111) (1111333111)
  1055.       (3111111331) (1131111331) (3131111311) (1111311331) (3111311311)
  1056.       (1131311311) (1111113331) (3111113311) (1131113311) (1111313311)
  1057.       (3311111131) (1331111131) (3331111111) (1311311131) (3311311111)
  1058.       (1331311111) (1311113131) (3311113111) (1331113111) (1313131111)
  1059.       (1313111311) (1311131311) (1113131311) (1311313111)
  1060.     ] def
  1061.  
  1062.     % Create a string of the available characters
  1063.     /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*) def
  1064.  
  1065.     /barlen barcode length def  % Length of the code
  1066.  
  1067.     includecheck {
  1068.         /sbs barlen 10 mul 30 add string def
  1069.         /txt barlen 3 add array def
  1070.     } {
  1071.         /sbs barlen 10 mul 20 add string def
  1072.         /txt barlen 2 add array def
  1073.     } ifelse
  1074.  
  1075.     /checksum 0 def
  1076.  
  1077.     % Put the start character
  1078.     sbs 0 encs 43 get putinterval
  1079.     txt 0 [(*) 0 textpos textfont textsize] put
  1080.  
  1081.     0 1 barlen 1 sub {
  1082.         /i exch def
  1083.         % Lookup the encoding for the each barcode character
  1084.         barcode i 1 getinterval barchars exch search
  1085.         pop                                  % Discard true leaving pre
  1086.         length /indx exch def                % indx is the length of pre
  1087.         pop pop                              % Discard seek and post
  1088.         /enc encs indx get def               % Get the indxth encoding
  1089.         sbs i 10 mul 10 add enc putinterval  % Put encoded digit into sbs
  1090.         txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textpos textfont textsize] put
  1091.         /checksum checksum indx add def
  1092.     } for
  1093.  
  1094.     % Put the checksum and end characters
  1095.     includecheck {
  1096.         /checksum checksum 43 mod def
  1097.         sbs barlen 10 mul 10 add encs checksum get putinterval
  1098.         includecheckintext {
  1099.             txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textpos textfont textsize] put
  1100.         } {
  1101.             txt barlen 1 add [() barlen 1 add 16 mul textpos textfont textsize] put
  1102.         } ifelse
  1103.         sbs barlen 10 mul 20 add encs 43 get putinterval
  1104.         txt barlen 2 add [(*) barlen 2 add 16 mul textpos textfont textsize] put
  1105.     } {
  1106.         sbs barlen 10 mul 10 add encs 43 get putinterval
  1107.         txt barlen 1 add [(*) barlen 1 add 16 mul textpos textfont textsize] put
  1108.     } ifelse
  1109.     
  1110.     % Return the arguments
  1111.     /retval 2 dict def
  1112.     retval (sbs) [sbs {48 sub} forall] put
  1113.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1114.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  1115.     includetext {
  1116.         retval (txt) txt put
  1117.     } if
  1118.     retval (opt) useropts put
  1119.     retval
  1120.  
  1121.     end
  1122.  
  1123. } bind def
  1124. /code39 load 0 1 dict put
  1125. % --END ENCODER code39--
  1126.  
  1127. % --BEGIN ENCODER code93--
  1128. % --DESC: Code 93
  1129. % --EXAM: THIS IS CODE 93
  1130. /code93 {
  1131.  
  1132.     0 begin                 % Confine variables to local scope
  1133.  
  1134.     /options exch def       % We are given an option string
  1135.     /useropts options def
  1136.     /barcode exch def       % We are given a barcode string
  1137.  
  1138.     /includecheck false def  % Enable/disable checkdigit
  1139.     /includetext false def   % Enable/disable text
  1140.     /textfont /Courier def
  1141.     /textsize 10 def
  1142.     /textpos -7 def
  1143.     /height 1 def
  1144.     
  1145.     % Parse the input options
  1146.     options {
  1147.         token false eq {exit} if dup length string cvs (=) search
  1148.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1149.     } loop
  1150.     
  1151.     /textfont textfont cvlit def
  1152.     /textsize textsize cvr def
  1153.     /textpos textpos cvr def
  1154.     /height height cvr def
  1155.     
  1156.     /encs
  1157.     [ (131112) (111213) (111312) (111411) (121113)
  1158.       (121212) (121311) (111114) (131211) (141111)
  1159.       (211113) (211212) (211311) (221112) (221211)
  1160.       (231111) (112113) (112212) (112311) (122112)
  1161.       (132111) (111123) (111222) (111321) (121122)
  1162.       (131121) (212112) (212211) (211122) (211221)
  1163.       (221121) (222111) (112122) (112221) (122121)
  1164.       (123111) (121131) (311112) (311211) (321111)
  1165.       (112131) (113121) (211131) (121221) (312111)
  1166.       (311121) (122211) (111141) (1111411)
  1167.     ] def
  1168.  
  1169.     % Create a string of the available characters
  1170.     /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
  1171.  
  1172.     /barlen barcode length def  % Length of the code    
  1173.     barcode {
  1174.         (^) search false eq {pop exit} if
  1175.         pop pop /barlen barlen 3 sub def
  1176.     } loop
  1177.  
  1178.     includecheck {
  1179.         /sbs barlen 6 mul 25 add string def
  1180.     } {
  1181.         /sbs barlen 6 mul 13 add string def
  1182.     } ifelse
  1183.     /txt barlen array def
  1184.     
  1185.     % Put the start character
  1186.     sbs 0 encs 47 get putinterval
  1187.     
  1188.     /checksum1 0 def /checksum2 0 def
  1189.  
  1190.     /i 0 def /j 0 def
  1191.     { % loop
  1192.         j barlen eq {exit} if
  1193.         barcode i 1 getinterval (^) eq {
  1194.             % indx is given by the next three characters
  1195.             /indx barcode i 1 add 3 getinterval cvi def
  1196.             txt j [( ) j 9 mul 9 add textpos textfont textsize] put
  1197.             /i i 4 add def
  1198.         } {
  1199.             barchars barcode i 1 getinterval search
  1200.             pop                         % Discard true leaving pre
  1201.             length /indx exch def       % indx is the length of pre
  1202.             pop pop                     % Discard seek and post
  1203.             txt j [barchars indx 1 getinterval j 9 mul 9 add textpos textfont textsize] put
  1204.             /i i 1 add def
  1205.         } ifelse
  1206.         /enc encs indx get def             % Get the indxth encoding
  1207.         sbs j 6 mul 6 add enc putinterval  % Put encoded digit into sbs
  1208.         /checksum1 checksum1 barlen j sub 1 sub 20 mod 1 add indx mul add def
  1209.         /checksum2 checksum2 barlen j sub 15 mod 1 add indx mul add def
  1210.         /j j 1 add def
  1211.     } loop
  1212.     
  1213.     includecheck {
  1214.         % Put the first checksum character
  1215.         /checksum1 checksum1 47 mod def
  1216.         /checksum2 checksum2 checksum1 add 47 mod def
  1217.         sbs j 6 mul 6 add encs checksum1 get putinterval
  1218.         sbs j 6 mul 12 add encs checksum2 get putinterval
  1219.         % Put the end character
  1220.         sbs j 6 mul 18 add encs 48 get putinterval
  1221.     } {
  1222.         % Put the end character
  1223.         sbs j 6 mul 6 add encs 48 get putinterval      
  1224.     } ifelse
  1225.  
  1226.     % Return the arguments
  1227.     /retval 1 dict def
  1228.     retval (sbs) [sbs {48 sub} forall] put
  1229.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1230.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  1231.     includetext {
  1232.         retval (txt) txt put
  1233.     } if
  1234.     retval (opt) useropts put
  1235.     retval
  1236.  
  1237.     end
  1238.  
  1239. } bind def
  1240. /code93 load 0 1 dict put
  1241. % --END ENCODER code93--
  1242.  
  1243. % --BEGIN ENCODER interleaved2of5--
  1244. % --DESC: Interleaved 2 of 5 (ITF)
  1245. % --EXAM: 24012345678905
  1246. /interleaved2of5 {
  1247.  
  1248.     0 begin         % Confine variables to local scope
  1249.  
  1250.     /options exch def               % We are given an option string
  1251.     /useropts options def
  1252.     /barcode exch def               % We are given a barcode string
  1253.  
  1254.     /includecheck false def         % Enable/disable checkdigit
  1255.     /includetext false def          % Enable/disable text
  1256.     /includecheckintext false def
  1257.     /textfont /Courier def
  1258.     /textsize 10 def
  1259.     /textpos -7 def
  1260.     /height 1 def
  1261.     
  1262.     % Parse the input options
  1263.     options {
  1264.         token false eq {exit} if dup length string cvs (=) search
  1265.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1266.     } loop
  1267.     
  1268.     /textfont textfont cvlit def
  1269.     /textsize textsize cvr def
  1270.     /textpos textpos cvr def
  1271.     /height height cvr def
  1272.     
  1273.     /barlen barcode length def      % Length of the code
  1274.  
  1275.     % Prefix 0 to barcode if length is even and including checkdigit
  1276.     % or length is odd and not including checkdigit
  1277.     barlen 2 mod 0 eq includecheck and          % even & includecheck
  1278.     barlen 2 mod 0 ne includecheck not and or { % odd  & !includecheck
  1279.         /pad barlen 1 add string def  % Create pad one bigger than barcode
  1280.         pad 0 48 put                  % Put ascii 0 at start of pad
  1281.         pad 1 barcode putinterval     % Add barcode to the end of pad
  1282.         /barcode pad def              % barcode=pad
  1283.         /barlen barlen 1 add def      % barlen++
  1284.     } if
  1285.  
  1286.     % Add checksum to end of barcode
  1287.     includecheck {
  1288.         /checksum 0 def
  1289.         0 1 barlen 1 sub {
  1290.             /i exch def
  1291.             i 2 mod 0 eq {
  1292.                 /checksum checksum barcode i get 48 sub 3 mul add def
  1293.             } {
  1294.                 /checksum checksum barcode i get 48 sub add def
  1295.             } ifelse
  1296.         } for
  1297.         /checksum 10 checksum 10 mod sub 10 mod def
  1298.         /pad barlen 1 add string def    % Create pad one bigger than barcode
  1299.         pad 0 barcode putinterval       % Add barcode to the start of pad
  1300.         pad barlen checksum 48 add put  % Add checksum to end of pad
  1301.         /barcode pad def                % barcode=pad
  1302.         /barlen barlen 1 add def        % barlen++
  1303.     } if
  1304.  
  1305.     % Create an array containing the character mappings
  1306.     /encs
  1307.     [ (11331) (31113) (13113) (33111) (11313)
  1308.       (31311) (13311) (11133) (31131) (13131)
  1309.       (1111)  (3111)
  1310.     ] def
  1311.  
  1312.     % Create a string of the available characters
  1313.     /barchars (0123456789) def
  1314.     /sbs barlen 5 mul 8 add string def
  1315.     /txt barlen array def
  1316.  
  1317.     % Put the start character
  1318.     sbs 0 encs 10 get putinterval
  1319.  
  1320.     0 2 barlen 1 sub {
  1321.     /i exch def
  1322.         % Lookup the encodings for two consecutive barcode characters
  1323.         barcode i 1 getinterval barchars exch search
  1324.         pop                           % Discard true leaving pre
  1325.         length /indx exch def         % indx is the length of pre
  1326.         pop pop                       % Discard seek and post
  1327.         /enca encs indx get def       % Get the indxth encoding
  1328.  
  1329.         barcode i 1 add 1 getinterval barchars exch search
  1330.         pop                           % Discard true leaving pre
  1331.         length /indx exch def         % indx is the length of pre
  1332.         pop pop                       % Discard seek and post
  1333.         /encb encs indx get def       % Get the indxth encoding
  1334.  
  1335.         % Interleave the two character encodings
  1336.         /intl enca length 2 mul string def
  1337.         0 1 enca length 1 sub {
  1338.             /j exch def
  1339.             /achar enca j get def
  1340.             /bchar encb j get def
  1341.             intl j 2 mul achar put
  1342.             intl j 2 mul 1 add bchar put
  1343.         } for
  1344.  
  1345.         sbs i 5 mul 4 add intl putinterval   % Put encoded digit into sbs
  1346.         txt i [barcode i 1 getinterval i 9 mul 4 add textpos textfont textsize] put
  1347.         includecheck includecheckintext not and barlen 2 sub i eq and {
  1348.             txt i 1 add [( ) i 1 add 9 mul 4 add textpos textfont textsize] put
  1349.         } {
  1350.             txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textpos textfont textsize] put
  1351.         } ifelse
  1352.     } for
  1353.  
  1354.     % Put the end character
  1355.     sbs barlen 5 mul 4 add encs 11 get putinterval
  1356.  
  1357.     % Return the arguments
  1358.     /retval 1 dict def
  1359.     retval (sbs) [sbs {48 sub} forall] put
  1360.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1361.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  1362.     includetext {
  1363.         retval (txt) txt put
  1364.     } if
  1365.     retval (opt) useropts put
  1366.     retval
  1367.  
  1368.     end
  1369.  
  1370. } bind def
  1371. /interleaved2of5 load 0 1 dict put
  1372. % --END ENCODER interleaved2of5--
  1373.  
  1374. % --BEGIN ENCODER rss14--
  1375. % --DESC: Reduced Space Symbology 14 (RSS-14)
  1376. % --EXAM: 24012345678905
  1377. /rss14 {
  1378.  
  1379.     0 begin            % Confine variables to local scope
  1380.  
  1381.     /options exch def  % We are given an option string
  1382.     /useropts options def
  1383.     /barcode exch def  % We are given a barcode string
  1384.  
  1385.     /height 1 def
  1386.     /linkage false def
  1387.     
  1388.     % Parse the input options
  1389.     options {
  1390.         token false eq {exit} if dup length string cvs (=) search
  1391.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1392.     } loop
  1393.     
  1394.     /height height cvr def
  1395.  
  1396.     /getRSSwidths {     
  1397.         /mw exch def
  1398.         /nm exch def
  1399.         /val exch def
  1400.         /j 0 def /i 0 def {
  1401.             /v () def
  1402.             mw 1 ne {/v i mw 4 string cvrs def} if          
  1403.             0 v {48 sub add} forall 4 add nm eq {               
  1404.                 j val eq {exit} if
  1405.                 /j j 1 add def
  1406.             } if
  1407.             /i i 1 add def
  1408.         } loop
  1409.         [4 {1} repeat v {47 sub} forall] v length 4 getinterval
  1410.     } bind def
  1411.  
  1412.     /binval [barcode {48 sub} forall] def
  1413.     /binval [linkage {1} {0} ifelse binval 0 13 getinterval {} forall] def
  1414.     
  1415.     0 1 12 {
  1416.         /i exch def
  1417.         binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put
  1418.         binval i binval i get 4537077 idiv put
  1419.     } for
  1420.     /right binval 13 get 4537077 mod def
  1421.     binval 13 2 copy get 4537077 idiv put
  1422.  
  1423.     /left 0 def
  1424.     /i true def
  1425.     0 1 13 {
  1426.         /j exch def
  1427.         binval j get
  1428.         dup 0 eq i and {
  1429.             pop
  1430.         } {
  1431.             /i false def
  1432.             /left left 3 -1 roll 10 13 j sub exp cvi mul add def
  1433.         } ifelse
  1434.     } for
  1435.     
  1436.     /d1 left 1597 idiv def
  1437.     /d2 left 1597 mod def
  1438.     /d3 right 1597 idiv def
  1439.     /d4 right 1597 mod def
  1440.  
  1441.     /tab164 [
  1442.         160   0     12 4   8 1  161   1
  1443.         960   161   10 6   6 3  80   10
  1444.         2014  961   8  8   4 5  31   34
  1445.         2714  2015  6  10  3 6  10   70
  1446.         2840  2715  4  12  1 8  1    126
  1447.     ] def
  1448.  
  1449.     /tab154 [
  1450.         335   0     5  10  2 7  4   84
  1451.         1035  336   7  8   4 5  20  35
  1452.         1515  1036  9  6   6 3  48  10
  1453.         1596  1516  11 4   8 1  81  1
  1454.     ] def
  1455.  
  1456.     /i 0 def {
  1457.         d1 tab164 i get le {
  1458.             tab164 i 1 add 7 getinterval {} forall
  1459.             /d1te exch def /d1to exch def
  1460.             /d1mwe exch def /d1mwo exch def
  1461.             /d1ele exch def /d1elo exch def
  1462.             /d1gs exch def
  1463.             exit
  1464.         } if
  1465.         /i i 8 add def
  1466.     } loop
  1467.  
  1468.     /i 0 def {
  1469.         d2 tab154 i get le {
  1470.             tab154 i 1 add 7 getinterval {} forall
  1471.             /d2te exch def /d2to exch def
  1472.             /d2mwe exch def /d2mwo exch def
  1473.             /d2ele exch def /d2elo exch def
  1474.             /d2gs exch def
  1475.             exit
  1476.         } if
  1477.         /i i 8 add def
  1478.     } loop
  1479.  
  1480.     /i 0 def {
  1481.         d3 tab164 i get le {
  1482.             tab164 i 1 add 7 getinterval {} forall
  1483.             /d3te exch def /d3to exch def
  1484.             /d3mwe exch def /d3mwo exch def
  1485.             /d3ele exch def /d3elo exch def
  1486.             /d3gs exch def
  1487.             exit
  1488.         } if
  1489.         /i i 8 add def
  1490.     } loop
  1491.  
  1492.     /i 0 def {
  1493.         d4 tab154 i get le {
  1494.             tab154 i 1 add 7 getinterval {} forall
  1495.             /d4te exch def /d4to exch def
  1496.             /d4mwe exch def /d4mwo exch def
  1497.             /d4ele exch def /d4elo exch def
  1498.             /d4gs exch def
  1499.             exit
  1500.         } if
  1501.         /i i 8 add def
  1502.     } loop
  1503.     
  1504.     /d1wo d1 d1gs sub d1te idiv d1elo d1mwo getRSSwidths def
  1505.     /d1we d1 d1gs sub d1te mod d1ele d1mwe getRSSwidths def
  1506.     /d2wo d2 d2gs sub d2to mod d2elo d2mwo getRSSwidths def
  1507.     /d2we d2 d2gs sub d2to idiv d2ele d2mwe getRSSwidths def
  1508.     /d3wo d3 d3gs sub d3te idiv d3elo d3mwo getRSSwidths def
  1509.     /d3we d3 d3gs sub d3te mod d3ele d3mwe getRSSwidths def
  1510.     /d4wo d4 d4gs sub d4to mod d4elo d4mwo getRSSwidths def
  1511.     /d4we d4 d4gs sub d4to idiv d4ele d4mwe getRSSwidths def
  1512.  
  1513.     /d1w 8 array def
  1514.     0 1 3 {
  1515.         /i exch def
  1516.         d1w i 2 mul d1wo i get put
  1517.         d1w i 2 mul 1 add d1we i get put
  1518.     } for
  1519.  
  1520.     /d2w 8 array def
  1521.     0 1 3 {
  1522.         /i exch def
  1523.         d2w 7 i 2 mul sub d2wo i get put
  1524.         d2w 6 i 2 mul sub d2we i get put
  1525.     } for
  1526.     
  1527.     /d3w 8 array def
  1528.     0 1 3 {
  1529.         /i exch def
  1530.         d3w 7 i 2 mul sub d3wo i get put
  1531.         d3w 6 i 2 mul sub d3we i get put
  1532.     } for
  1533.     
  1534.     /d4w 8 array def
  1535.     0 1 3 {
  1536.         /i exch def
  1537.         d4w i 2 mul d4wo i get put
  1538.         d4w i 2 mul 1 add d4we i get put
  1539.     } for
  1540.  
  1541.     /widths [
  1542.         d1w {} forall
  1543.         d2w {} forall
  1544.         d3w {} forall
  1545.         d4w {} forall
  1546.     ] def
  1547.     
  1548.     /checkweights [
  1549.         1   3   9   27  2   6   18  54
  1550.         58  72  24  8   29  36  12  4
  1551.         74  51  17  32  37  65  48  16
  1552.         64  34  23  69  49  68  46  59
  1553.     ] def
  1554.  
  1555.     /checkwidths [
  1556.         3 8 2 1 1   3 5 5 1 1   3 3 7 1 1
  1557.         3 1 9 1 1   2 7 4 1 1   2 5 6 1 1
  1558.         2 3 8 1 1   1 5 7 1 1   1 3 9 1 1
  1559.     ] def
  1560.     
  1561.     /checksum 0 def
  1562.     0 1 31 {
  1563.         /i exch def
  1564.         /checksum checksum widths i get checkweights i get mul add def 
  1565.     } for
  1566.     /checksum checksum 79 mod def    
  1567.     checksum 8 ge {/checksum checksum 1 add def} if
  1568.     checksum 72 ge {/checksum checksum 1 add def} if
  1569.     /checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def
  1570.     /checkrtrev checkwidths checksum 9 mod 5 mul 5 getinterval def
  1571.     /checkrt 5 array def
  1572.     0 1 4 {
  1573.         /i exch def
  1574.         checkrt i checkrtrev 4 i sub get put
  1575.     } for
  1576.  
  1577.     /sbs [
  1578.         1 d1w {} forall checklt {} forall d2w {}
  1579.         forall d4w {} forall checkrt {} forall d3w {} forall 1 1
  1580.     ] def
  1581.     
  1582.     % Return the arguments
  1583.     /retval 1 dict def
  1584.     retval (sbs) sbs put
  1585.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1586.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put   
  1587.     retval (opt) useropts put
  1588.     retval
  1589.  
  1590.     end
  1591.  
  1592. } bind def
  1593. /rss14 load 0 1 dict put
  1594. % --END ENCODER rss14--
  1595.  
  1596. % --BEGIN ENCODER rsslimited--
  1597. % --DESC: Reduced Space Symbology Limited (RSS-Limited)
  1598. % --EXAM: 00978186074271
  1599. /rsslimited {
  1600.  
  1601.     0 begin            % Confine variables to local scope
  1602.  
  1603.     /options exch def  % We are given an option string
  1604.     /useropts options def
  1605.     /barcode exch def  % We are given a barcode string
  1606.  
  1607.     /height 1 def
  1608.     
  1609.     % Parse the input options
  1610.     options {
  1611.         token false eq {exit} if dup length string cvs (=) search
  1612.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1613.     } loop
  1614.     
  1615.     /height height cvr def
  1616.  
  1617.     /getRSSwidths {
  1618.         /el exch def
  1619.         /mw exch def
  1620.         /nm exch def
  1621.         /val exch def
  1622.         /j 0 def /i 0 def {
  1623.             /v () def
  1624.             mw 1 ne {/v i mw el string cvrs def} if          
  1625.             0 v {48 sub add} forall el add nm eq {               
  1626.                 j val eq {exit} if
  1627.                 /j j 1 add def
  1628.             } if
  1629.             /i i 1 add def
  1630.         } loop
  1631.         [el {1} repeat v {47 sub} forall] v length el getinterval
  1632.     } bind def
  1633.     
  1634.     /binval [barcode {48 sub} forall] def
  1635.     /binval [binval 0 13 getinterval {} forall] def
  1636.     
  1637.     0 1 11 {
  1638.         /i exch def
  1639.         binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
  1640.         binval i binval i get 2013571 idiv put
  1641.     } for
  1642.     /d2 binval 12 get 2013571 mod def
  1643.     binval 12 2 copy get 2013571 idiv put
  1644.  
  1645.     /d1 0 def
  1646.     /i true def
  1647.     0 1 12 {
  1648.         /j exch def
  1649.         binval j get
  1650.         dup 0 eq i and {
  1651.             pop
  1652.         } {
  1653.             /i false def
  1654.             /d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def
  1655.         } ifelse
  1656.     } for
  1657.     
  1658.     /tab267 [
  1659.         183063   0        17 9   6 3  6538   28
  1660.         820063   183064   13 13  5 4  875    728
  1661.         1000775  820064   9  17  3 6  28     6454
  1662.         1491020  1000776  15 11  5 4  2415   203
  1663.         1979844  1491021  11 15  4 5  203    2408
  1664.         1996938  1979845  19 7   8 1  17094  1
  1665.         2013570  1996939  7  19  1 8  1      16632
  1666.     ] def
  1667.  
  1668.     /i 0 def {
  1669.         d1 tab267 i get le {
  1670.             tab267 i 1 add 7 getinterval {} forall
  1671.             /d1te exch def /d1to exch def
  1672.             /d1mwe exch def /d1mwo exch def
  1673.             /d1ele exch def /d1elo exch def
  1674.             /d1gs exch def
  1675.             exit
  1676.         } if
  1677.         /i i 8 add def
  1678.     } loop
  1679.  
  1680.     /i 0 def {
  1681.         d2 tab267 i get le {
  1682.             tab267 i 1 add 7 getinterval {} forall
  1683.             /d2te exch def /d2to exch def
  1684.             /d2mwe exch def /d2mwo exch def
  1685.             /d2ele exch def /d2elo exch def
  1686.             /d2gs exch def
  1687.             exit
  1688.         } if
  1689.         /i i 8 add def
  1690.     } loop
  1691.     
  1692.     /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 getRSSwidths def    
  1693.     /d1we d1 d1gs sub d1te mod d1ele d1mwe 7 getRSSwidths def
  1694.     /d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 getRSSwidths def    
  1695.     /d2we d2 d2gs sub d2te mod d2ele d2mwe 7 getRSSwidths def
  1696.     
  1697.     /d1w 14 array def
  1698.     0 1 6 {
  1699.         /i exch def
  1700.         d1w i 2 mul d1wo i get put
  1701.         d1w i 2 mul 1 add d1we i get put
  1702.     } for
  1703.  
  1704.     /d2w 14 array def
  1705.     0 1 6 {
  1706.         /i exch def
  1707.         d2w i 2 mul d2wo i get put
  1708.         d2w i 2 mul 1 add d2we i get put
  1709.     } for
  1710.  
  1711.     /widths [
  1712.         d1w {} forall
  1713.         d2w {} forall
  1714.     ] def
  1715.     
  1716.     /checkweights [
  1717.         1  3  9  27 81 65 17 51 64 14 42 37 22 66
  1718.         20 60 2  6  18 54 73 41 34 13 39 28 84 74
  1719.     ] def
  1720.  
  1721.     /checkseq [
  1722.         0 1 43 {} for
  1723.         45 52 57
  1724.         63 1 66 {} for
  1725.         73 1 79 {} for
  1726.         82
  1727.         126 1 130 {} for
  1728.         132
  1729.         141 1 146 {} for
  1730.         210 1 217 {} for
  1731.         220
  1732.         316 1 323 {} for
  1733.         326 337
  1734.     ] def
  1735.     
  1736.     /checksum 0 def
  1737.     0 1 27 {
  1738.         /i exch def
  1739.         /checksum checksum widths i get checkweights i get mul add def
  1740.     } for
  1741.     /checksum checksum 89 mod def
  1742.     /seq checkseq checksum get def
  1743.     /swidths seq 21 idiv 8 3 6 getRSSwidths def
  1744.     /bwidths seq 21 mod 8 3 6 getRSSwidths def
  1745.  
  1746.     /checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def
  1747.     0 1 5 {
  1748.         /i exch def
  1749.         checkwidths i 2 mul swidths i get put
  1750.         checkwidths i 2 mul 1 add bwidths i get put
  1751.     } for
  1752.     
  1753.     /sbs [
  1754.         1 d1w {} forall checkwidths {} forall d2w {} forall 1 1
  1755.     ] def
  1756.     
  1757.     % Return the arguments
  1758.     /retval 1 dict def
  1759.     retval (sbs) sbs put
  1760.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1761.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put   
  1762.     retval (opt) useropts put
  1763.     retval
  1764.  
  1765.     end
  1766.  
  1767. } bind def
  1768. /rsslimited load 0 1 dict put
  1769. % --END ENCODER rsslimited--
  1770.  
  1771. % --BEGIN ENCODER rssexpanded--
  1772. % --DESC: Reduced Space Symbology Expanded (RSS-Expanded)
  1773. % --EXAM: 000000010011001010100001000000010000
  1774. /rssexpanded {
  1775.  
  1776.     0 begin            % Confine variables to local scope
  1777.  
  1778.     /options exch def  % We are given an option string
  1779.     /useropts options def
  1780.     /barcode exch def  % We are given a barcode string
  1781.  
  1782.     /height 1 def
  1783.     
  1784.     % Parse the input options
  1785.     options {
  1786.         token false eq {exit} if dup length string cvs (=) search
  1787.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1788.     } loop
  1789.     
  1790.     /height height cvr def
  1791.  
  1792.     /getRSSwidths {     
  1793.         /mw exch def
  1794.         /nm exch def
  1795.         /val exch def
  1796.         /j 0 def /i 0 def {
  1797.             /v () def
  1798.             mw 1 ne {/v i mw 4 string cvrs def} if          
  1799.             0 v {48 sub add} forall 4 add nm eq {               
  1800.                 j val eq {exit} if
  1801.                 /j j 1 add def
  1802.             } if
  1803.             /i i 1 add def
  1804.         } loop
  1805.         [4 {1} repeat v {47 sub} forall] v length 4 getinterval
  1806.     } bind def
  1807.  
  1808.     /binval [barcode {48 sub} forall] def
  1809.     /datalen binval length 12 idiv def
  1810.     
  1811.     /tab174 [
  1812.         347   0     12 5   7 2  87  4
  1813.         1387  348   10 7   5 4  52  20
  1814.         2947  1388  8  9   4 5  30  52
  1815.         3987  2948  6  11  3 6  10  104
  1816.         4191  3988  4  13  1 8  1   204
  1817.     ] def
  1818.  
  1819.     /dxw datalen array def
  1820.     
  1821.     0 1 datalen 1 sub {
  1822.  
  1823.         /x exch def
  1824.  
  1825.         /d binval x 12 mul 12 getinterval def
  1826.         /d 0 0 1 11 {/j exch def 2 11 j sub exp cvi d j get mul add} for def
  1827.  
  1828.         /j 0 def {
  1829.             d tab174 j get le {
  1830.                 tab174 j 1 add 7 getinterval {} forall
  1831.                 /dte exch def /dto exch def
  1832.                 /dmwe exch def /dmwo exch def
  1833.                 /dele exch def /delo exch def
  1834.                 /dgs exch def
  1835.                 exit
  1836.             } if
  1837.             /j j 8 add def
  1838.         } loop
  1839.  
  1840.         /dwo d dgs sub dte idiv delo dmwo getRSSwidths def
  1841.         /dwe d dgs sub dte mod dele dmwe getRSSwidths def
  1842.  
  1843.         /dw 8 array def        
  1844.         x 2 mod 0 eq {                    
  1845.             0 1 3 {
  1846.                 /j exch def
  1847.                 dw 7 j 2 mul sub dwo j get put
  1848.                 dw 6 j 2 mul sub dwe j get put
  1849.             } for
  1850.         } {           
  1851.             0 1 3 {
  1852.                 /j exch def
  1853.                 dw j 2 mul dwo j get put
  1854.                 dw j 2 mul 1 add dwe j get put
  1855.             } for
  1856.         } ifelse
  1857.  
  1858.         dxw x dw put
  1859.  
  1860.     } for
  1861.     
  1862.     /widths [
  1863.         dxw {{} forall} forall
  1864.     ] def
  1865.  
  1866.     /checkweights [
  1867.         77   96   32   81   27   9    3    1
  1868.         20   60   180  118  143  7    21   63
  1869.         205  209  140  117  39   13   145  189
  1870.         193  157  49   147  19   57   171  91
  1871.         132  44   85   169  197  136  186  62
  1872.         185  133  188  142  4    12   36   108
  1873.         50   87   29   80   97   173  128  113
  1874.         150  28   84   41   123  158  52   156
  1875.         166  196  206  139  187  203  138  46
  1876.         76   17   51   153  37   111  122  155
  1877.         146  119  110  107  106  176  129  43
  1878.         16   48   144  10   30   90   59   177
  1879.         164  125  112  178  200  137  116  109
  1880.         70   210  208  202  184  130  179  115
  1881.         190  204  68   93   31   151  191  134
  1882.         148  22   66   198  172  94   71   2
  1883.         40   154  192  64   162  54   18   6
  1884.         120  149  25   75   14   42   126  167
  1885.         175  199  207  69   23   78   26   79
  1886.         103  98   83   38   114  131  182  124
  1887.         159  53   88   170  127  183  61   161
  1888.         55   165  73   8    24   72   5    15
  1889.         89   100  174  58   160  194  135  45
  1890.     ] def
  1891.     
  1892.     /checksum 0 def
  1893.     0 1 widths length 1 sub {
  1894.         /i exch def
  1895.         /checksum checksum widths i get checkweights i get mul add def 
  1896.     } for
  1897.     /checksum checksum 211 mod datalen 3 sub 211 mul add def
  1898.  
  1899.     /i 0 def {
  1900.         checksum tab174 i get le {
  1901.             tab174 i 1 add 7 getinterval {} forall
  1902.             /cte exch def /cto exch def
  1903.             /cmwe exch def /cmwo exch def
  1904.             /cele exch def /celo exch def
  1905.             /cgs exch def
  1906.             exit
  1907.         } if
  1908.         /i i 8 add def
  1909.     } loop
  1910.  
  1911.     /cwo checksum cgs sub cte idiv celo cmwo getRSSwidths def
  1912.     /cwe checksum cgs sub cte mod cele cmwe getRSSwidths def
  1913.     
  1914.     /cw 8 array def        
  1915.     0 1 3 {
  1916.         /i exch def
  1917.         cw i 2 mul cwo i get put
  1918.         cw i 2 mul 1 add cwe i get put
  1919.     } for
  1920.     
  1921.     /finderwidths [
  1922.         1 8 4 1 1    1 1 4 8 1
  1923.         3 6 4 1 1    1 1 4 6 3
  1924.         3 4 6 1 1    1 1 6 4 3
  1925.         3 2 8 1 1    1 1 8 2 3
  1926.         2 6 5 1 1    1 1 5 6 2
  1927.         2 2 9 1 1    1 1 9 2 2
  1928.     ] def
  1929.  
  1930.     /finderseq [
  1931.         [0 1]
  1932.         [0 3 2]
  1933.         [0 5 2 7]
  1934.         [0 9 2 7 4]
  1935.         [0 9 2 7 6 11]
  1936.         [0 9 2 7 8 11 10]
  1937.         [0 1 2 3 4 5 6 7]
  1938.         [0 1 2 3 4 5 6 9 8]
  1939.         [0 1 2 3 4 5 6 9 10 11]
  1940.         [0 1 2 3 4 7 6 9 8 11 10]
  1941.     ] def
  1942.  
  1943.     /seq finderseq datalen 2 add 2 idiv 2 sub get def
  1944.     /fxw seq length array def
  1945.     0 1 seq length 1 sub {
  1946.         /x exch def
  1947.         fxw x finderwidths seq x get 5 mul 5 getinterval put
  1948.     } for
  1949.     
  1950.     /sbs [
  1951.         1
  1952.         cw {} forall
  1953.         0 1 datalen 1 sub {
  1954.             /i exch def
  1955.             i 2 mod 0 eq {fxw i 2 idiv get {} forall} if
  1956.             dxw i get {} forall
  1957.         } for
  1958.         1 1
  1959.     ] def
  1960.     
  1961.     % Return the arguments
  1962.     /retval 1 dict def
  1963.     retval (sbs) sbs put
  1964.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  1965.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put   
  1966.     retval (opt) useropts put
  1967.     retval
  1968.  
  1969.     end
  1970.  
  1971. } bind def
  1972. /rssexpanded load 0 1 dict put
  1973. % --END ENCODER rssexpanded--
  1974.  
  1975. % --BEGIN ENCODER code2of5--
  1976. % --DESC: Code 25
  1977. % --EXAM: 01234567
  1978. /code2of5 {
  1979.  
  1980.     % Thanks to Michael Landers
  1981.  
  1982.     0 begin                 % Confine variable to local scope
  1983.  
  1984.     /options exch def       % We are given an option string
  1985.     /useropts options def
  1986.     /barcode exch def       % We are given a barcode string
  1987.  
  1988.     /includecheck false def
  1989.     /includetext false def   % Enable/disable text
  1990.     /includecheckintext false def
  1991.     /textfont /Courier def
  1992.     /textsize 10 def
  1993.     /textpos -7 def
  1994.     /height 1 def
  1995.     
  1996.     % Parse the input options
  1997.     options {
  1998.         token false eq {exit} if dup length string cvs (=) search
  1999.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2000.     } loop
  2001.     
  2002.     /textfont textfont cvlit def
  2003.     /textsize textsize cvr def
  2004.     /textpos textpos cvr def
  2005.     /height height cvr def
  2006.     
  2007.     % Create an array containing the character mappings
  2008.     /encs
  2009.     [ (1111313111) (3111111131) (1131111131) (3131111111)
  2010.       (1111311131) (3111311111) (1131311111) (1111113131)
  2011.       (3111113111) (1131113111) (313111) (311131)
  2012.     ] def
  2013.  
  2014.     % Create a string of the available characters
  2015.     /barchars (0123456789) def
  2016.  
  2017.     /barlen barcode length def            % Length of the code
  2018.  
  2019.     includecheck {
  2020.         /sbs barlen 10 mul 22 add string def
  2021.         /txt barlen 1 add array def
  2022.     } {
  2023.         /sbs barlen 10 mul 12 add string def
  2024.         /txt barlen array def
  2025.     } ifelse
  2026.     
  2027.     % Put the start character
  2028.     sbs 0 encs 10 get putinterval
  2029.  
  2030.     /checksum 0 def
  2031.     
  2032.     0 1 barlen 1 sub {
  2033.         /i exch def
  2034.         % Lookup the encoding for the each barcode character
  2035.         barcode i 1 getinterval barchars exch search
  2036.         pop                                 % Discard true leaving pre
  2037.         length /indx exch def               % indx is the length of pre
  2038.         pop pop                             % Discard seek and post
  2039.         /enc encs indx get def              % Get the indxth encoding
  2040.         sbs i 10 mul 6 add enc putinterval  % Put encoded digit into sbs
  2041.         txt i [barcode i 1 getinterval i 14 mul 10 add textpos textfont textsize] put
  2042.         barlen i sub 2 mod 0 eq {
  2043.             /checksum checksum indx add def
  2044.         } {            
  2045.             /checksum checksum indx 3 mul add def
  2046.         } ifelse        
  2047.     } for
  2048.     
  2049.     % Put the checksum and end characters
  2050.     includecheck {
  2051.         /checksum 10 checksum 10 mod sub 10 mod def
  2052.         sbs barlen 10 mul 6 add encs checksum get putinterval
  2053.         sbs barlen 10 mul 16 add encs 11 get putinterval
  2054.         includecheckintext {
  2055.             txt barlen [barchars checksum 1 getinterval barlen 14 mul 10 add textpos textfont textsize] put
  2056.         } {            
  2057.             txt barlen [( ) barlen 14 mul 10 add textpos textfont textsize] put
  2058.         } ifelse
  2059.     } {
  2060.         sbs barlen 10 mul 6 add encs 11 get putinterval
  2061.     } ifelse
  2062.     
  2063.     % Return the arguments
  2064.     /retval 1 dict def
  2065.     retval (sbs) [sbs {48 sub} forall] put
  2066.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  2067.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  2068.     includetext {
  2069.         retval (txt) txt put
  2070.     } if
  2071.     retval (opt) useropts put
  2072.     retval
  2073.  
  2074.     end
  2075.  
  2076. } bind def
  2077. /code2of5 load 0 1 dict put
  2078. % --END ENCODER code2of5--
  2079.  
  2080. % --BEGIN ENCODER code11--
  2081. % --DESC: Code 11
  2082. % --EXAM: 0123456789
  2083. /code11 {
  2084.  
  2085.     0 begin            % Confine variables to local scope
  2086.  
  2087.     /options exch def  % We are given an option string
  2088.     /useropts options def
  2089.     /barcode exch def  % We are given a barcode string
  2090.  
  2091.     /includecheck false def
  2092.     /includetext false def
  2093.     /includecheckintext false def
  2094.     /textfont /Courier def
  2095.     /textsize 10 def
  2096.     /textpos -7 def
  2097.     /height 1 def
  2098.     
  2099.     % Parse the input options
  2100.     options {
  2101.         token false eq {exit} if dup length string cvs (=) search
  2102.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2103.     } loop
  2104.     
  2105.     /textfont textfont cvlit def
  2106.     /textsize textsize cvr def
  2107.     /textpos textpos cvr def
  2108.     /height height cvr def
  2109.     
  2110.     % Create an array containing the character mappings
  2111.     /encs
  2112.     [ (111131) (311131) (131131) (331111) (113131)
  2113.       (313111) (133111) (111331) (311311) (311111)
  2114.       (113111) (113311)
  2115.     ] def
  2116.  
  2117.     % Create a string of the available characters
  2118.     /barchars (0123456789-) def
  2119.  
  2120.     /barlen barcode length def        % Length of the code
  2121.  
  2122.     includecheck {
  2123.         barlen 10 ge {
  2124.             /sbs barlen 6 mul 24 add string def
  2125.             /txt barlen 2 add array def
  2126.         } {
  2127.             /sbs barlen 6 mul 18 add string def
  2128.             /txt barlen 1 add array def
  2129.         } ifelse
  2130.     } {
  2131.         /sbs barlen 6 mul 12 add string def
  2132.         /txt barlen array def
  2133.     } ifelse
  2134.  
  2135.     % Put the start character
  2136.     sbs 0 encs 10 get putinterval
  2137.  
  2138.     /checksum1 0 def /checksum2 0 def
  2139.     
  2140.     /xpos 8 def
  2141.     0 1 barlen 1 sub {
  2142.         /i exch def
  2143.         % Lookup the encoding for the each barcode character
  2144.         barcode i 1 getinterval barchars exch search
  2145.         pop                                % Discard true leaving pre
  2146.         length /indx exch def              % indx is the length of pre
  2147.         pop pop                            % Discard seek and post
  2148.         /enc encs indx get def             % Get the indxth encoding
  2149.         sbs i 6 mul 6 add enc putinterval  % Put encoded digit into sbs
  2150.         txt i [barcode i 1 getinterval xpos textpos textfont textsize] put
  2151.         0 1 5 {       % xpos+=width of the character
  2152.             /xpos exch enc exch get 48 sub xpos add def
  2153.         } for
  2154.         /checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def
  2155.         /checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def
  2156.     } for
  2157.    
  2158.     % Put the checksum and end characters
  2159.     includecheck {
  2160.         /checksum1 checksum1 11 mod def        
  2161.         barlen 10 ge {
  2162.             /checksum2 checksum2 checksum1 add 11 mod def
  2163.             sbs barlen 6 mul 6 add encs checksum1 get putinterval        
  2164.             sbs barlen 6 mul 12 add encs checksum2 get putinterval
  2165.             includecheckintext {
  2166.                 txt barlen [barchars checksum1 1 getinterval xpos textpos textfont textsize] put
  2167.                 /enc encs checksum1 get def   
  2168.                 0 1 5 {       % xpos+=width of the character
  2169.                     /xpos exch enc exch get 48 sub xpos add def
  2170.                 } for
  2171.                 txt barlen 1 add [barchars checksum2 1 getinterval xpos textpos textfont textsize] put
  2172.             } {
  2173.                 txt barlen [() xpos textpos textfont textsize] put
  2174.                 txt barlen 1 add [() xpos textpos textfont textsize] put
  2175.             } ifelse
  2176.             sbs barlen 6 mul 18 add encs 11 get putinterval
  2177.         } {
  2178.             sbs barlen 6 mul 6 add encs checksum1 get putinterval          
  2179.             includecheckintext {
  2180.                 txt barlen [barchars checksum1 1 getinterval xpos textpos textfont textsize] put
  2181.             } {
  2182.                 txt barlen [() xpos textpos textfont textsize] put
  2183.             } ifelse
  2184.             sbs barlen 6 mul 12 add encs 11 get putinterval
  2185.         } ifelse
  2186.     } {
  2187.         sbs barlen 6 mul 6 add encs 11 get putinterval
  2188.     } ifelse
  2189.  
  2190.     % Return the arguments
  2191.     /retval 1 dict def
  2192.     retval (sbs) [sbs {48 sub} forall] put
  2193.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  2194.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  2195.     includetext {
  2196.         retval (txt) txt put
  2197.     } if
  2198.     retval (opt) useropts put
  2199.     retval
  2200.  
  2201.     end
  2202.  
  2203. } bind def
  2204. /code11 load 0 1 dict put
  2205. % --END ENCODER code11--
  2206.  
  2207. % --BEGIN ENCODER rationalizedCodabar--
  2208. % --DESC: Rationalized Codabar
  2209. % --EXAM: A0123456789B
  2210. /rationalizedCodabar {
  2211.  
  2212.     0 begin                    % Confine variables to local scope
  2213.  
  2214.     /options exch def          % We are given an option string
  2215.     /useropts options def
  2216.     /barcode exch def          % We are given a barcode string
  2217.  
  2218.     /includecheck false def     % Enable/disable checkdigit
  2219.     /includetext false def      % Enable/disable text
  2220.     /includecheckintext false def
  2221.     /textfont /Courier def
  2222.     /textsize 10 def
  2223.     /textpos -7 def
  2224.     /height 1 def
  2225.     
  2226.     % Parse the input options
  2227.     options {
  2228.         token false eq {exit} if dup length string cvs (=) search
  2229.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2230.     } loop
  2231.     
  2232.     /textfont textfont cvlit def
  2233.     /textsize textsize cvr def
  2234.     /textpos textpos cvr def
  2235.     /height height cvr def
  2236.     
  2237.     % Create an array containing the character mappings
  2238.     /encs
  2239.     [ (11111331) (11113311) (11131131) (33111111) (11311311)
  2240.       (31111311) (13111131) (13113111) (13311111) (31131111)
  2241.       (11133111) (11331111) (31113131) (31311131) (31313111)
  2242.       (11313131) (11331311) (13131131) (11131331) (11133311)
  2243.     ] def
  2244.  
  2245.     % Create a string of the available characters
  2246.     /barchars (0123456789-$:/.+ABCD) def
  2247.  
  2248.     /barlen barcode length def    % Length of the code
  2249.  
  2250.     includecheck {
  2251.         /sbs barlen 8 mul 8 add string def
  2252.         /txt barlen 1 add array def
  2253.     } {
  2254.         /sbs barlen 8 mul string def
  2255.         /txt barlen array def
  2256.     } ifelse
  2257.  
  2258.     /checksum 0 def
  2259.     /xpos 0 def
  2260.     0 1 barlen 2 sub {
  2261.         /i exch def
  2262.         % Lookup the encoding for the each barcode character
  2263.         barcode i 1 getinterval barchars exch search
  2264.         pop                          % Discard true leaving pre
  2265.         length /indx exch def        % indx is the length of pre
  2266.         pop pop                      % Discard seek and post
  2267.         /enc encs indx get def       % Get the indxth encoding
  2268.         sbs i 8 mul enc putinterval  % Put encoded digit into sbs
  2269.         txt i [barcode i 1 getinterval xpos textpos textfont textsize] put
  2270.         0 1 7 {       % xpos+=width of the character
  2271.             /xpos exch enc exch get 48 sub xpos add def
  2272.         } for
  2273.         /checksum checksum indx add def
  2274.     } for
  2275.  
  2276.     % Find index of last character
  2277.     barcode barlen 1 sub 1 getinterval barchars exch search
  2278.     pop                          % Discard true leaving pre
  2279.     length /indx exch def        % indx is the length of pre
  2280.     pop pop                      % Discard seek and post
  2281.  
  2282.     includecheck {
  2283.         % Put the checksum character
  2284.         /checksum checksum indx add def
  2285.         /checksum 16 checksum 16 mod sub 16 mod def
  2286.         sbs barlen 8 mul 8 sub encs checksum get putinterval
  2287.         includecheckintext {
  2288.             txt barlen 1 sub [barchars checksum 1 getinterval xpos textpos textfont textsize] put
  2289.         } {
  2290.             txt barlen 1 sub [( ) xpos textpos textfont textsize] put
  2291.         } ifelse
  2292.         0 1 7 {       % xpos+=width of the character
  2293.             /xpos exch encs checksum get exch get 48 sub xpos add def
  2294.         } for
  2295.         % Put the end character
  2296.         /enc encs indx get def            % Get the indxth encoding
  2297.         sbs barlen 8 mul enc putinterval  % Put encoded digit into sbs
  2298.         txt barlen [barcode barlen 1 sub 1 getinterval xpos textpos textfont textsize] put
  2299.     } {
  2300.         % Put the end character
  2301.         /enc encs indx get def                  % Get the indxth encoding
  2302.         sbs barlen 8 mul 8 sub enc putinterval  % Put encoded digit into sbs
  2303.         txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textpos textfont textsize] put
  2304.     } ifelse
  2305.  
  2306.     % Return the arguments
  2307.     /retval 1 dict def
  2308.     retval (sbs) [sbs {48 sub} forall] put
  2309.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  2310.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  2311.     includetext {
  2312.         retval (txt) txt put
  2313.     } if
  2314.     retval (opt) useropts put
  2315.     retval
  2316.  
  2317.     end
  2318.  
  2319. } bind def
  2320. /rationalizedCodabar load 0 1 dict put
  2321. % --END ENCODER rationalizedCodabar--
  2322.  
  2323. % --BEGIN ENCODER onecode--
  2324. % --DESC: United States Postal Service OneCode
  2325. % --EXAM: 0123456709498765432101234567891
  2326. /onecode {
  2327.  
  2328.     0 begin
  2329.  
  2330.     /options exch def              % We are given an option string
  2331.     /useropts options def
  2332.     /barcode exch def              % We are given a barcode string
  2333.  
  2334.     /height 0.175 def
  2335.     
  2336.     % Parse the input options
  2337.     options {
  2338.         token false eq {exit} if dup length string cvs (=) search
  2339.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2340.     } loop
  2341.     
  2342.     /height height cvr def
  2343.  
  2344.     /barlen barcode length def
  2345.  
  2346.     /normalize {
  2347.         /base exch def
  2348.         /num exch def
  2349.         num length 1 sub -1 1 {
  2350.             /i exch def        
  2351.             num i 1 sub 2 copy get num i get base idiv add put
  2352.             num i num i get base mod put
  2353.         } for
  2354.         { %loop - extend input as necessary
  2355.             num 0 get base lt {exit} if
  2356.             /num [0 num {} forall] def        
  2357.             num 0 num 0 get num 1 get base idiv add put
  2358.             num 1 num 1 get base mod put
  2359.         } loop
  2360.         % Trim leading zeros
  2361.         /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def   
  2362.         num length 0 eq {/num [0] def} if
  2363.         num
  2364.     } bind def
  2365.  
  2366.     /bigadd {
  2367.         2 copy length exch length
  2368.         2 copy sub abs /offset exch def
  2369.         lt {exch} if
  2370.         /a exch def /b exch def    
  2371.         0 1 b length 1 sub {
  2372.             dup a exch offset add 2 copy get b 5 -1 roll get add put
  2373.         } for
  2374.         a
  2375.     } bind def
  2376.  
  2377.     % Conversion of data fields into binary data
  2378.     barlen 20 eq {[0]} if
  2379.     barlen 25 eq {[1]} if
  2380.     barlen 29 eq {[1 0 0 0 0 1]} if
  2381.     barlen 31 eq {[1 0 0 0 1 0 0 0 0 1]} if
  2382.     /binval exch [barcode 20 barlen 20 sub getinterval {48 sub} forall] bigadd def
  2383.     /binval [binval {} forall barcode 0 get 48 sub] def
  2384.     /binval [binval {5 mul} forall] [barcode 1 get 48 sub] bigadd 10 normalize def
  2385.     /binval [binval {} forall barcode 2 18 getinterval {48 sub} forall] def
  2386.  
  2387.     % Conversion of binary data into byte array
  2388.     /bytes 13 array def
  2389.     /bintmp [binval {} forall] def
  2390.     12 -1 0 {
  2391.         /i exch def
  2392.         0 1 bintmp length 2 sub {
  2393.             /j exch def
  2394.             bintmp j 1 add 2 copy get bintmp j get 256 mod 10 mul add put
  2395.             bintmp j bintmp j get 256 idiv put
  2396.         } for
  2397.         bytes i bintmp bintmp length 1 sub get 256 mod put
  2398.         bintmp bintmp length 1 sub 2 copy get 256 idiv put    
  2399.     } for
  2400.  
  2401.     % Generation of 11-bit CRC on byte array
  2402.     /fcs 2047 def
  2403.     /dat bytes 0 get 5 bitshift def
  2404.     6 {
  2405.         fcs dat xor 1024 and 0 ne {
  2406.             /fcs fcs 1 bitshift 3893 xor def 
  2407.         } {
  2408.             /fcs fcs 1 bitshift def
  2409.         } ifelse
  2410.         /fcs fcs 2047 and def
  2411.         /dat dat 1 bitshift def
  2412.     } repeat
  2413.     1 1 12 {
  2414.         bytes exch get 3 bitshift /dat exch def    
  2415.         8 {        
  2416.             fcs dat xor 1024 and 0 ne {
  2417.                 /fcs fcs 1 bitshift 3893 xor def 
  2418.             } {
  2419.                 /fcs fcs 1 bitshift def
  2420.             } ifelse
  2421.             /fcs fcs 2047 and def
  2422.             /dat dat 1 bitshift def
  2423.         } repeat
  2424.     } for
  2425.  
  2426.     % Conversion from binary data to codewords
  2427.     /codewords 10 array def
  2428.     9 -1 0 {
  2429.         /i exch def
  2430.         i 9 eq {
  2431.             /b 636 def
  2432.         } {
  2433.             /b 1365 def
  2434.         } ifelse
  2435.         0 1 binval length 2 sub {
  2436.             /j exch def
  2437.             binval j 1 add 2 copy get binval j get b mod 10 mul add put
  2438.             binval j binval j get b idiv put
  2439.         } for   
  2440.         codewords i binval binval length 1 sub get b mod put
  2441.         binval binval length 1 sub 2 copy get b idiv put
  2442.     } for
  2443.  
  2444.     % Inserting additional information into codewords
  2445.     codewords 9 codewords 9 get 2 mul put
  2446.     fcs 1024 and 0 ne {
  2447.         codewords 0 codewords 0 get 659 add put
  2448.     } if
  2449.  
  2450.     % Conversion from codewords to characters
  2451.     /tab513 1287 dict def
  2452.     /lo 0 def
  2453.     /hi 1286 def
  2454.     0 1 8191 {   
  2455.         { % no loop - provides common exit point
  2456.             /i exch def
  2457.             /onbits 0 def
  2458.             0 1 12 {           
  2459.                 i exch 1 exch bitshift and 0 ne {
  2460.                     /onbits onbits 1 add def
  2461.                 } if
  2462.             } for
  2463.             onbits 5 ne {exit} if
  2464.             /j i def
  2465.             /rev 0 def
  2466.             16 {            
  2467.                 /rev rev 1 bitshift j 1 and or def
  2468.                 /j j -1 bitshift def                
  2469.             } repeat          
  2470.             /rev rev -3 bitshift def            
  2471.             rev i lt {exit} if
  2472.             rev i eq {
  2473.                 tab513 hi i put
  2474.                 /hi hi 1 sub def
  2475.             } {
  2476.                 tab513 lo i put
  2477.                 tab513 lo 1 add rev put
  2478.                 /lo lo 2 add def                      
  2479.             } ifelse
  2480.             exit
  2481.         } loop
  2482.     } for
  2483.  
  2484.     /tab213 78 dict def
  2485.     /lo 0 def
  2486.     /hi 77 def
  2487.     0 1 8191 {   
  2488.         { % no loop - provides common exit point
  2489.             /i exch def
  2490.             /onbits 0 def
  2491.             0 1 12 {           
  2492.                 i exch 1 exch bitshift and 0 ne {
  2493.                     /onbits onbits 1 add def
  2494.                 } if
  2495.             } for
  2496.             onbits 2 ne {exit} if
  2497.             /j i def
  2498.             /rev 0 def
  2499.             16 {            
  2500.                 /rev rev 1 bitshift j 1 and or def
  2501.                 /j j -1 bitshift def                
  2502.             } repeat          
  2503.             /rev rev -3 bitshift def            
  2504.             rev i lt {exit} if
  2505.             rev i eq {
  2506.                 tab213 hi i put
  2507.                 /hi hi 1 sub def
  2508.             } {
  2509.                 tab213 lo i put
  2510.                 tab213 lo 1 add rev put
  2511.                 /lo lo 2 add def                      
  2512.             } ifelse
  2513.             exit
  2514.         } loop
  2515.     } for
  2516.  
  2517.     /chars 10 array def
  2518.     0 1 9 {
  2519.         /i exch def
  2520.         codewords i get dup 1286 le {
  2521.             tab513 exch get 
  2522.         } {
  2523.             tab213 exch 1287 sub get
  2524.         } ifelse
  2525.         chars i 3 -1 roll put
  2526.     } for
  2527.  
  2528.     9 -1 0 {
  2529.         /i exch def
  2530.         2 i exp cvi fcs and 0 ne {
  2531.             chars i chars i get 8191 xor put
  2532.         } if
  2533.     } for
  2534.  
  2535.     % Conversion from characters to the OneCode encoding
  2536.     /barmap [
  2537.         7 2 4 3    1 10 0 0   9 12 2 8   5 5 6 11   8 9 3 1
  2538.         0 1 5 12   2 5 1 8    4 4 9 11   6 3 8 10   3 9 7 6
  2539.         5 11 1 4   8 5 2 12   9 10 0 2   7 1 6 7    3 6 4 9
  2540.         0 3 8 6    6 4 2 7    1 1 9 9    7 10 5 2   4 0 3 8
  2541.         6 2 0 4    8 11 1 0   9 8 3 12   2 6 7 7    5 1 4 10
  2542.         1 12 6 9   7 3 8 0    5 8 9 7    4 6 2 10   3 4 0 5
  2543.         8 4 5 7    7 11 1 9   6 0 9 6    0 6 4 8    2 1 3 2
  2544.         5 9 8 12   4 11 6 1   9 5 7 4    3 3 1 2    0 7 2 0
  2545.         1 3 4 1    6 10 3 5   8 7 9 4    2 11 5 6   0 8 7 12
  2546.         4 2 8 1    5 10 3 0   9 3 0 9    6 5 2 4    7 8 1 7
  2547.         5 0 4 5    2 3 0 10   6 12 9 2   3 11 1 6   8 8 7 9
  2548.         5 4 0 11   1 5 2 2    9 1 4 12   8 3 6 6    7 0 3 7
  2549.         4 7 7 5    0 12 1 11  2 9 9 0    6 8 5 3    3 10 8 2
  2550.     ] def
  2551.  
  2552.     /bbs 65 array def    
  2553.     /bhs 65 array def
  2554.     0 1 64 {
  2555.         /i exch def
  2556.         /dec chars barmap i 4 mul get get 2 barmap i 4 mul 1 add get exp cvi and 0 ne def
  2557.         /asc chars barmap i 4 mul 2 add get get 2 barmap i 4 mul 3 add get exp cvi and 0 ne def
  2558.         dec not asc not and {
  2559.             bbs i 3 height mul 8 div put
  2560.             bhs i 2 height mul 8 div put
  2561.         } if
  2562.         dec not asc and {
  2563.             bbs i 3 height mul 8 div put
  2564.             bhs i 5 height mul 8 div put        
  2565.         } if
  2566.         dec asc not and {
  2567.             bbs i 0 height mul 8 div put
  2568.             bhs i 5 height mul 8 div put        
  2569.         } if
  2570.         dec asc and {
  2571.             bbs i 0 height mul 8 div put
  2572.             bhs i 8 height mul 8 div put        
  2573.         } if
  2574.     } for
  2575.     
  2576.     /retval 4 dict def
  2577.     retval (bbs) bbs put
  2578.     retval (bhs) bhs put
  2579.     retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put    
  2580.     retval (opt) useropts put
  2581.     retval
  2582.  
  2583.     end
  2584.  
  2585. } bind def
  2586. /onecode load 0 1 dict put
  2587. % --END ENCODER onecode--
  2588.  
  2589. % --BEGIN ENCODER postnet--
  2590. % --DESC: United States Postal Service Postnet
  2591. % --EXAM: 012345
  2592. /postnet {
  2593.  
  2594.     % Thanks to Ross McFarland
  2595.  
  2596.     0 begin
  2597.  
  2598.     /options exch def              % We are given an option string
  2599.     /useropts options def
  2600.     /barcode exch def              % We are given a barcode string
  2601.  
  2602.     /includetext false def          % Enable/disable text
  2603.     /includecheckintext false def
  2604.     /textfont /Courier def
  2605.     /textsize 10 def
  2606.     /textpos -7 def
  2607.     /height 0.125 def
  2608.     
  2609.     % Parse the input options
  2610.     options {
  2611.         token false eq {exit} if dup length string cvs (=) search
  2612.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2613.     } loop
  2614.     
  2615.     /textfont textfont cvlit def
  2616.     /textsize textsize cvr def
  2617.     /textpos textpos cvr def
  2618.     /height height cvr def
  2619.     
  2620.     /barlen barcode length def
  2621.  
  2622.     % Create an array containing the character mappings
  2623.     /encs
  2624.     [ (55222) (22255) (22525) (22552) (25225)
  2625.       (25252) (25522) (52225) (52252) (52522)
  2626.       (5) (5)
  2627.     ] def
  2628.  
  2629.     % Create a string of the available characters
  2630.     /barchars (0123456789) def
  2631.  
  2632.     /bhs barlen 5 mul 7 add array def
  2633.     /txt barlen 1 add array def
  2634.  
  2635.     % Put start character
  2636.     /enc encs 10 get def
  2637.     /heights enc length array def
  2638.     0 1 enc length 1 sub {
  2639.         /j exch def
  2640.         heights j enc j 1 getinterval cvi height mul 5 div put
  2641.     } for
  2642.     bhs 0 heights putinterval   % Put encoded digit into sbs
  2643.  
  2644.     /checksum 0 def
  2645.     0 1 barlen 1 sub {
  2646.         /i exch def
  2647.         % Lookup the encoding for the each barcode character
  2648.         barcode i 1 getinterval barchars exch search
  2649.         pop                                 % Discard true leaving pre
  2650.         length /indx exch def               % indx is the length of pre
  2651.         pop pop                             % Discard seek and post
  2652.         /enc encs indx get def              % Get the indxth encoding
  2653.         /heights enc length array def
  2654.         0 1 enc length 1 sub {
  2655.             /j exch def
  2656.             heights j enc j 1 getinterval cvi height mul 5 div put
  2657.         } for
  2658.         bhs i 5 mul 1 add heights putinterval   % Put encoded digit into sbs
  2659.         txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textpos textfont textsize] put
  2660.         /checksum checksum indx add def     % checksum+=indx
  2661.     } for
  2662.  
  2663.     % Put the checksum character
  2664.     /checksum 10 checksum 10 mod sub 10 mod def
  2665.     /enc encs checksum get def
  2666.     /heights enc length array def
  2667.     0 1 enc length 1 sub {
  2668.         /j exch def
  2669.         heights j enc j 1 getinterval cvi height mul 5 div put
  2670.     } for
  2671.     bhs barlen 5 mul 1 add heights putinterval  
  2672.     
  2673.     includecheckintext {
  2674.         txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textpos textfont textsize] put
  2675.     } {
  2676.         txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textpos textfont textsize] put
  2677.     } ifelse
  2678.     
  2679.     % Put end character
  2680.     /enc encs 11 get def
  2681.     /heights enc length array def
  2682.     0 1 enc length 1 sub {
  2683.         /j exch def
  2684.         heights j enc j 1 getinterval cvi height mul 5 div put
  2685.     } for
  2686.     bhs barlen 5 mul 6 add heights putinterval  
  2687.  
  2688.     /retval 1 dict def
  2689.     retval (bhs) bhs put
  2690.     retval (bbs) [bhs length {0} repeat] put
  2691.     retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
  2692.     includetext {
  2693.         retval (txt) txt put
  2694.     } if
  2695.     retval (opt) useropts put
  2696.     retval
  2697.  
  2698.     end
  2699.  
  2700. } bind def
  2701. /postnet load 0 1 dict put
  2702. % --END ENCODER postnet--
  2703.  
  2704. % --BEGIN ENCODER royalmail--
  2705. % --DESC: Royal Mail 4 State Customer Code (RM4SCC)
  2706. % --EXAM: LE28HS9Z
  2707. /royalmail {
  2708.  
  2709.     0 begin
  2710.  
  2711.     /options exch def              % We are given an option string
  2712.     /useropts options def
  2713.     /barcode exch def              % We are given a barcode string
  2714.  
  2715.     /includetext false def          % Enable/disable text
  2716.     /includecheckintext false def
  2717.     /textfont /Courier def
  2718.     /textsize 10 def
  2719.     /textpos -7 def
  2720.     /height 0.175 def
  2721.     
  2722.     % Parse the input options
  2723.     options {
  2724.         token false eq {exit} if dup length string cvs (=) search
  2725.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2726.     } loop
  2727.     
  2728.     /textfont textfont cvlit def
  2729.     /textsize textsize cvr def
  2730.     /textpos textpos cvr def
  2731.     /height height cvr def
  2732.     
  2733.     % Create an array containing the character mappings
  2734.     /encs
  2735.     [ (3300) (2211) (2301) (2310) (3201) (3210) 
  2736.       (1122) (0033) (0123) (0132) (1023) (1032) 
  2737.       (1302) (0213) (0303) (0312) (1203) (1212) 
  2738.       (1320) (0231) (0321) (0330) (1221) (1230) 
  2739.       (3102) (2013) (2103) (2112) (3003) (3012) 
  2740.       (3120) (2031) (2121) (2130) (3021) (3030) 
  2741.       (2) (3)
  2742.     ] def
  2743.  
  2744.     % Create a string of the available characters
  2745.     /barchars (ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS) def
  2746.  
  2747.     /barlen barcode length def
  2748.     /encstr barlen 4 mul 6 add string def
  2749.     /txt barlen 1 add array def
  2750.  
  2751.     % Put start character
  2752.     encstr 0 encs 36 get putinterval
  2753.     
  2754.     /checksumrow 0 def
  2755.     /checksumcol 0 def
  2756.     0 1 barlen 1 sub {
  2757.         /i exch def
  2758.         % Lookup the encoding for the each barcode character
  2759.         barcode i 1 getinterval barchars exch search
  2760.         pop                                 % Discard true leaving pre
  2761.         length /indx exch def               % indx is the length of pre
  2762.         pop pop                             % Discard seek and post
  2763.         /enc encs indx get def              % Get the indxth encoding
  2764.         encstr i 4 mul 1 add enc putinterval
  2765.         txt i [barcode i 1 getinterval i 4 mul 1 add 3.312 mul textpos textfont textsize] put
  2766.         /checksumrow checksumrow indx 6 idiv add def
  2767.         /checksumcol checksumcol indx 6 mod add def 
  2768.     } for
  2769.  
  2770.     % Put the checksum character
  2771.     /checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def
  2772.     /enc encs checksum get def
  2773.     encstr barlen 4 mul 1 add enc putinterval
  2774.     includecheckintext {
  2775.         txt barlen [barchars checksum 1 getinterval barlen 4 mul 1 add 3.312 mul textpos textfont textsize] put
  2776.     } {
  2777.         txt barlen [( ) barlen 4 mul 1 add 3.312 mul textpos textfont textsize] put
  2778.     } ifelse
  2779.     
  2780.     % Put end character
  2781.     encstr barlen 4 mul 5 add encs 37 get putinterval  
  2782.  
  2783.     /bbs encstr length array def    
  2784.     /bhs encstr length array def
  2785.     0 1 encstr length 1 sub {
  2786.         /i exch def
  2787.         /enc encstr i 1 getinterval def
  2788.         enc (0) eq {
  2789.             bbs i 3 height mul 8 div put
  2790.             bhs i 2 height mul 8 div put
  2791.         } if
  2792.         enc (1) eq {
  2793.             bbs i 0 height mul 8 div put
  2794.             bhs i 5 height mul 8 div put
  2795.         } if
  2796.         enc (2) eq {
  2797.             bbs i 3 height mul 8 div put
  2798.             bhs i 5 height mul 8 div put
  2799.         } if
  2800.         enc (3) eq {
  2801.             bbs i 0 height mul 8 div put
  2802.             bhs i 8 height mul 8 div put
  2803.         } if
  2804.     } for
  2805.     
  2806.     /retval 4 dict def
  2807.     retval (bbs) bbs put
  2808.     retval (bhs) bhs put
  2809.     retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
  2810.     includetext {
  2811.         retval (txt) txt put
  2812.     } if
  2813.     retval (opt) useropts put
  2814.     retval
  2815.  
  2816.     end
  2817.  
  2818. } bind def
  2819. /royalmail load 0 1 dict put
  2820. % --END ENCODER royalmail--
  2821.  
  2822. % --BEGIN ENCODER auspost--
  2823. % --DESC: AusPost 4 State Customer Code
  2824. % --EXAM: 5956439111ABA 9
  2825. /auspost {
  2826.  
  2827.     0 begin
  2828.  
  2829.     /options exch def              % We are given an option string
  2830.     /useropts options def
  2831.     /barcode exch def              % We are given a barcode string
  2832.  
  2833.     /includetext false def         % Enable/disable text
  2834.     /textfont /Courier def
  2835.     /textsize 10 def
  2836.     /textpos -7 def
  2837.     /height 0.175 def
  2838.     /custinfoenc (character) def
  2839.     
  2840.     % Parse the input options
  2841.     options {
  2842.         token false eq {exit} if dup length string cvs (=) search
  2843.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2844.     } loop
  2845.     
  2846.     /textfont textfont cvlit def
  2847.     /textsize textsize cvr def
  2848.     /textpos textpos cvr def
  2849.     /height height cvr def
  2850.  
  2851.     % Create an array containing the character mappings
  2852.     /encs
  2853.     [ (000) (001) (002) (010) (011) (012) (020) (021)
  2854.       (022) (100) (101) (102) (110) (111) (112) (120)
  2855.       (121) (122) (200) (201) (202) (210) (211) (212)
  2856.       (220) (221) (222) (300) (301) (302) (310) (311)
  2857.       (312) (320) (321) (322) (023) (030) (031) (032)
  2858.       (033) (103) (113) (123) (130) (131) (132) (133)
  2859.       (203) (213) (223) (230) (231) (232) (233) (303)
  2860.       (313) (323) (330) (331) (332) (333) (003) (013)
  2861.       (00) (01) (02) (10) (11) (12) (20) (21) (22) (30)
  2862.       (13) (3)
  2863.     ] def
  2864.  
  2865.     % Create a string of the available characters
  2866.     /barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def
  2867.     
  2868.     /barlen barcode length def
  2869.     barcode 0 2 getinterval (11) eq {37} if
  2870.     barcode 0 2 getinterval (59) eq {52} if
  2871.     barcode 0 2 getinterval (62) eq {67} if
  2872.     /encstr exch string def
  2873.     /txt barlen 2 sub array def
  2874.  
  2875.     % Put start character
  2876.     encstr 0 encs 74 get putinterval
  2877.  
  2878.     % Encode the FCC
  2879.     0 1 1 {
  2880.         /i exch def       
  2881.         encs barcode i 1 getinterval cvi 64 add get
  2882.         encstr i 2 mul 2 add 3 2 roll putinterval
  2883.     } for
  2884.     
  2885.     % Encode the DPID
  2886.     2 1 9 {
  2887.         /i exch def       
  2888.         encs barcode i 1 getinterval cvi 64 add get
  2889.         encstr i 2 mul 2 add 3 2 roll putinterval
  2890.         txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textpos textfont textsize] put
  2891.     } for
  2892.     
  2893.     % Encode the customer information   
  2894.     custinfoenc (numeric) eq {
  2895.         0 1 barlen 11 sub {
  2896.             /i exch def
  2897.             encs barcode i 10 add 1 getinterval cvi 64 add get
  2898.             encstr i 2 mul 22 add 3 2 roll putinterval
  2899.             txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textpos textfont textsize] put
  2900.         } for        
  2901.         /ciflen barlen 10 sub 2 mul def
  2902.     } {
  2903.         0 1 barlen 11 sub {
  2904.             /i exch def           
  2905.             barcode i 10 add 1 getinterval barchars exch search
  2906.             pop                                
  2907.             length /indx exch def           
  2908.             pop pop                            
  2909.             /enc encs indx get def          
  2910.             encstr i 3 mul 22 add enc putinterval
  2911.             txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textpos textfont textsize] put
  2912.         } for        
  2913.         /ciflen barlen 10 sub 3 mul def
  2914.     } ifelse
  2915.  
  2916.     % Add any filler characters
  2917.     22 ciflen add 1 encstr length 14 sub {        
  2918.         encstr exch encs 75 get putinterval
  2919.     } for
  2920.     
  2921.     % Create the 64x64 Reed-Solomon table
  2922.     /rstable 64 64 mul array def
  2923.     rstable 0 [ 64 {0} repeat ] putinterval
  2924.     rstable 64 [ 0 1 63 {} for ] putinterval
  2925.     /prev 1 def
  2926.     64 {       
  2927.         /next prev 1 bitshift def
  2928.         next 64 and 0 ne {
  2929.             /next next 67 xor def
  2930.         } if        
  2931.         0 1 63 {
  2932.             /j exch def
  2933.             /nextcell {rstable 64 next mul j add} def
  2934.             nextcell rstable 64 prev mul j add get 1 bitshift put
  2935.             nextcell get 64 and 0 ne {
  2936.                 nextcell nextcell get 67 xor put
  2937.             } if
  2938.         } for
  2939.         /prev next def
  2940.     } repeat
  2941.     
  2942.     % Calculate the Reed-Solomon codes for triples
  2943.     /rscodes encstr length 16 sub 3 idiv 4 add array def
  2944.     rscodes 0 [ 4 {0} repeat ] putinterval
  2945.     2 3 encstr length 16 sub {
  2946.         /i exch def
  2947.         rscodes rscodes length i 2 sub 3 idiv sub 1 sub
  2948.         encstr i 1 getinterval cvi 16 mul
  2949.         encstr i 1 add 1 getinterval cvi 4 mul add
  2950.         encstr i 2 add 1 getinterval cvi add        
  2951.         put
  2952.     } for    
  2953.     rscodes length 5 sub -1 0 {
  2954.        /i exch def
  2955.        0 1 4 {
  2956.            /j exch def
  2957.            rscodes i j add rscodes i j add get
  2958.            rstable 64 [48 17 29 30 1] j get mul rscodes i 4 add get add get
  2959.            xor put
  2960.        } for
  2961.     } for
  2962.     /checkcode (000000000000) def
  2963.     0 1 3 {
  2964.         /i exch def
  2965.         /enc rscodes 3 i sub get 4 3 string cvrs def
  2966.         checkcode i 3 mul 3 enc length sub add enc putinterval
  2967.     } for
  2968.     
  2969.     % Put checkcode and end characters
  2970.     encstr encstr length 14 sub checkcode putinterval
  2971.     encstr encstr length 2 sub encs 74 get putinterval 
  2972.  
  2973.     /bbs encstr length array def    
  2974.     /bhs encstr length array def
  2975.     0 1 encstr length 1 sub {
  2976.         /i exch def
  2977.         /enc encstr i 1 getinterval def
  2978.         enc (0) eq {
  2979.             bbs i 0 height mul 8 div put
  2980.             bhs i 8 height mul 8 div put
  2981.         } if
  2982.         enc (1) eq {
  2983.             bbs i 3 height mul 8 div put
  2984.             bhs i 5 height mul 8 div put
  2985.         } if
  2986.         enc (2) eq {
  2987.             bbs i 0 height mul 8 div put
  2988.             bhs i 5 height mul 8 div put
  2989.         } if
  2990.         enc (3) eq {
  2991.             bbs i 3 height mul 8 div put
  2992.             bhs i 2 height mul 8 div put
  2993.         } if
  2994.     } for   
  2995.     
  2996.     /retval 4 dict def
  2997.     retval (bbs) bbs put
  2998.     retval (bhs) bhs put
  2999.     retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
  3000.     includetext {
  3001.         retval (txt) txt put
  3002.     } if
  3003.     retval (opt) useropts put
  3004.     retval
  3005.  
  3006.     end
  3007.  
  3008. } bind def
  3009. /auspost load 0 1 dict put
  3010. % --END ENCODER auspost--
  3011.  
  3012. % --BEGIN ENCODER kix--
  3013. % --DESC: Royal Dutch TPG Post KIX 4-State Barcode
  3014. % --EXAM: 1231FZ13XHS
  3015. /kix {
  3016.  
  3017.     0 begin
  3018.  
  3019.     /options exch def              % We are given an option string
  3020.     /useropts options def
  3021.     /barcode exch def              % We are given a barcode string
  3022.  
  3023.     /includetext false def          % Enable/disable text
  3024.     /includecheckintext false def
  3025.     /textfont /Courier def
  3026.     /textsize 10 def
  3027.     /textpos -7 def
  3028.     /height 0.175 def
  3029.     
  3030.     % Parse the input options
  3031.     options {
  3032.         token false eq {exit} if dup length string cvs (=) search
  3033.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3034.     } loop
  3035.     
  3036.     /textfont textfont cvlit def
  3037.     /textsize textsize cvr def
  3038.     /textpos textpos cvr def
  3039.     /height height cvr def
  3040.     
  3041.     % Create an array containing the character mappings
  3042.     /encs
  3043.     [ (0033) (0123) (0132) (1023) (1032) (1122)
  3044.       (0213) (0303) (0312) (1203) (1212) (1302) 
  3045.       (0231) (0321) (0330) (1221) (1230) (1320)
  3046.       (2013) (2103) (2112) (3003) (3012) (3102)
  3047.       (2031) (2121) (2130) (3021) (3030) (3120) 
  3048.       (2211) (2301) (2310) (3201) (3210) (3300) 
  3049.     ] def
  3050.  
  3051.     % Create a string of the available characters
  3052.     /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
  3053.  
  3054.     /barlen barcode length def
  3055.     /encstr barlen 4 mul string def
  3056.     /txt barlen array def
  3057.     
  3058.     0 1 barlen 1 sub {
  3059.         /i exch def
  3060.         % Lookup the encoding for the each barcode character
  3061.         barcode i 1 getinterval barchars exch search
  3062.         pop                                 % Discard true leaving pre
  3063.         length /indx exch def               % indx is the length of pre
  3064.         pop pop                             % Discard seek and post
  3065.         /enc encs indx get def              % Get the indxth encoding
  3066.         encstr i 4 mul enc putinterval
  3067.         txt i [barcode i 1 getinterval i 4 mul 3.312 mul textpos textfont textsize] put
  3068.     } for
  3069.  
  3070.     /bbs encstr length array def    
  3071.     /bhs encstr length array def
  3072.     0 1 encstr length 1 sub {
  3073.         /i exch def
  3074.         /enc encstr i 1 getinterval def
  3075.         enc (0) eq {
  3076.             bbs i 3 height mul 8 div put
  3077.             bhs i 2 height mul 8 div put
  3078.         } if
  3079.         enc (1) eq {
  3080.             bbs i 0 height mul 8 div put
  3081.             bhs i 5 height mul 8 div put
  3082.         } if
  3083.         enc (2) eq {
  3084.             bbs i 3 height mul 8 div put
  3085.             bhs i 5 height mul 8 div put
  3086.         } if
  3087.         enc (3) eq {
  3088.             bbs i 0 height mul 8 div put
  3089.             bhs i 8 height mul 8 div put
  3090.         } if
  3091.     } for
  3092.     
  3093.     /retval 4 dict def
  3094.     retval (bbs) bbs put
  3095.     retval (bhs) bhs put
  3096.     retval (sbs) [bhs length 1 sub {1.44 1.872} repeat 1.44] put
  3097.     includetext {
  3098.         retval (txt) txt put
  3099.     } if
  3100.     retval (opt) useropts put
  3101.     retval
  3102.  
  3103.     end
  3104.  
  3105. } bind def
  3106. /kix load 0 1 dict put
  3107. % --END ENCODER kix--
  3108.  
  3109. % --BEGIN ENCODER msi--
  3110. % --DESC: MSI Modified Plessey
  3111. % --EXAM: 0123456789
  3112. /msi {
  3113.  
  3114.     0 begin                 % Confine variables to local scope
  3115.  
  3116.     /options exch def       % We are given an option string
  3117.     /useropts options def
  3118.     /barcode exch def       % We are given a barcode string
  3119.  
  3120.     /includecheck false def  % Enable/disable checkdigit
  3121.     /includetext false def   % Enable/disable text
  3122.     /includecheckintext false def
  3123.     /textfont /Courier def
  3124.     /textsize 10 def
  3125.     /textpos -7 def
  3126.     /height 1 def
  3127.     
  3128.     % Parse the input options
  3129.     options {
  3130.         token false eq {exit} if dup length string cvs (=) search
  3131.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3132.     } loop
  3133.     
  3134.     /textfont textfont cvlit def
  3135.     /textsize textsize cvr def
  3136.     /textpos textpos cvr def
  3137.     /height height cvr def
  3138.     
  3139.     % Create an array containing the character mappings
  3140.     /encs
  3141.     [ (13131313) (13131331) (13133113) (13133131) (13311313)
  3142.       (13311331) (13313113) (13313131) (31131313) (31131331)
  3143.       (31) (131)
  3144.     ] def
  3145.  
  3146.     % Create a string of the available characters
  3147.     /barchars (0123456789) def
  3148.  
  3149.     /barlen barcode length def     % Length of the code
  3150.  
  3151.     includecheck {
  3152.         /sbs barlen 8 mul 13 add string def
  3153.         /txt barlen 1 add array def
  3154.     } {
  3155.         /sbs barlen 8 mul 5 add string def
  3156.         /txt barlen array def
  3157.     } ifelse
  3158.  
  3159.  
  3160.     % Put start character
  3161.     sbs 0 encs 10 get putinterval
  3162.     /checksum 0 def
  3163.  
  3164.     0 1 barlen 1 sub {
  3165.         /i exch def
  3166.         % Lookup the encoding for the each barcode character
  3167.         barcode i 1 getinterval barchars exch search
  3168.         pop                                % Discard true leaving pre
  3169.         length /indx exch def              % indx is the length of pre
  3170.         pop pop                            % Discard seek and post
  3171.         /enc encs indx get def             % Get the indxth encoding
  3172.         sbs i 8 mul 2 add enc putinterval  % Put encoded digit into sbs
  3173.         txt i [barcode i 1 getinterval i 16 mul 4 add textpos textfont textsize] put
  3174.         barlen i sub 2 mod 0 eq {
  3175.             /checksum indx checksum add def
  3176.         } {
  3177.             /checksum indx 2 mul dup 10 idiv add checksum add def
  3178.         } ifelse
  3179.     } for
  3180.  
  3181.     % Put the checksum and end characters
  3182.     includecheck {
  3183.         /checksum 10 checksum 10 mod sub 10 mod def
  3184.         sbs barlen 8 mul 2 add encs checksum get putinterval
  3185.         includecheckintext {
  3186.             txt barlen [barchars checksum 1 getinterval barlen 16 mul 4 add textpos textfont textsize] put
  3187.         } {
  3188.             txt barlen [( ) barlen 16 mul 4 add textpos textfont textsize] put
  3189.         } ifelse
  3190.         sbs barlen 8 mul 10 add encs 11 get putinterval
  3191.     } {
  3192.         sbs barlen 8 mul 2 add encs 11 get putinterval
  3193.     } ifelse
  3194.  
  3195.     % Return the arguments
  3196.     /retval 1 dict def
  3197.     retval (sbs) [sbs {48 sub} forall] put
  3198.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  3199.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  3200.     includetext {
  3201.         retval (txt) txt put
  3202.     } if
  3203.     retval (opt) useropts put
  3204.     retval
  3205.  
  3206.     end
  3207.  
  3208. } bind def
  3209. /msi load 0 1 dict put
  3210. % --END ENCODER msi--
  3211.  
  3212. % --BEGIN ENCODER plessey--
  3213. % --DESC: Plessey
  3214. % --EXAM: 01234ABCD
  3215. /plessey {
  3216.  
  3217.     0 begin                  % Confine variables to local scope
  3218.  
  3219.     /options exch def        % We are given an option string
  3220.     /useropts options def
  3221.     /barcode exch def        % We are given a barcode string
  3222.  
  3223.     /includetext false def    % Enable/disable text
  3224.     /includecheckintext false def
  3225.     /textfont /Courier def
  3226.     /textsize 10 def
  3227.     /textpos -7 def
  3228.     /height 1 def
  3229.     
  3230.     % Parse the input options
  3231.     options {
  3232.         token false eq {exit} if dup length string cvs (=) search
  3233.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3234.     } loop
  3235.     
  3236.     /textfont textfont cvlit def
  3237.     /textsize textsize cvr def
  3238.     /textpos textpos cvr def
  3239.     /height height cvr def
  3240.     
  3241.     % Create an array containing the character mappings
  3242.     /encs
  3243.     [ (13131313) (31131313) (13311313) (31311313)
  3244.       (13133113) (31133113) (13313113) (31313113)
  3245.       (13131331) (31131331) (13311331) (31311331)
  3246.       (13133131) (31133131) (13313131) (31313131)
  3247.       (31311331) (331311313)
  3248.     ] def
  3249.  
  3250.     % Create a string of the available characters
  3251.     /barchars (0123456789ABCDEF) def
  3252.  
  3253.     /barlen barcode length def     % Length of the code
  3254.     /sbs barlen 8 mul 33 add string def
  3255.     /txt barlen 2 add array def
  3256.     /checkbits barlen 4 mul 8 add array def
  3257.     checkbits barlen 4 mul [ 0 0 0 0 0 0 0 0 ] putinterval
  3258.  
  3259.     % Put start character
  3260.     sbs 0 encs 16 get putinterval
  3261.  
  3262.     0 1 barlen 1 sub {
  3263.         /i exch def
  3264.         % Lookup the encoding for the each barcode character
  3265.         barcode i 1 getinterval barchars exch search
  3266.         pop                                % Discard true leaving pre
  3267.         length /indx exch def              % indx is the length of pre
  3268.         pop pop                            % Discard seek and post
  3269.         /enc encs indx get def             % Get the indxth encoding
  3270.         sbs i 8 mul 8 add enc putinterval  % Put encoded digit into sbs
  3271.         txt i [barcode i 1 getinterval i 16 mul 16 add textpos textfont textsize] put
  3272.         checkbits i 4 mul [
  3273.                 indx 1 and
  3274.                 indx -1 bitshift 1 and
  3275.                 indx -2 bitshift 1 and
  3276.                 indx -3 bitshift
  3277.         ] putinterval
  3278.     } for
  3279.  
  3280.     % Checksum is last 8 bits of a CRC using a salt
  3281.     /checksalt [ 1 1 1 1 0 1 0 0 1 ] def
  3282.     0 1 barlen 4 mul 1 sub {
  3283.         /i exch def
  3284.         checkbits i get 1 eq {
  3285.             0 1 8 {
  3286.                 /j exch def
  3287.                 checkbits i j add checkbits i j add get checksalt j get xor put
  3288.             } for
  3289.         } if
  3290.     } for
  3291.  
  3292.     % Calculate the value of the checksum digits
  3293.     /checkval 0 def
  3294.     0 1 7 {
  3295.         /i exch def
  3296.         /checkval checkval 2 7 i sub exp cvi checkbits barlen 4 mul i add get mul add def
  3297.     } for
  3298.  
  3299.     % Put the checksum characters
  3300.     /checksum1 checkval -4 bitshift def
  3301.     /checksum2 checkval 15 and def
  3302.     sbs barlen 8 mul 8 add encs checksum1 get putinterval
  3303.     sbs barlen 8 mul 16 add encs checksum2 get putinterval
  3304.     includecheckintext {
  3305.         txt barlen [barchars checksum1 1 getinterval barlen 16 mul 16 add textpos textfont textsize] put
  3306.         txt barlen 1 add [barchars checksum2 1 getinterval barlen 1 add 16 mul 16 add textpos textfont textsize] put
  3307.     } {
  3308.         txt barlen [( ) barlen 16 mul 16 add textpos textfont textsize] put
  3309.         txt barlen 1 add [( ) barlen 1 add 16 mul 16 add textpos textfont textsize] put
  3310.     } ifelse
  3311.  
  3312.     % Put end character
  3313.     sbs barlen 8 mul 24 add encs 17 get putinterval
  3314.  
  3315.     % Return the arguments
  3316.     /retval 1 dict def
  3317.     retval (sbs) [sbs {48 sub} forall] put
  3318.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  3319.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
  3320.     includetext {
  3321.         retval (txt) txt put
  3322.     } if
  3323.     retval (opt) useropts put
  3324.     retval
  3325.  
  3326.     end
  3327.  
  3328. } bind def
  3329. /plessey load 0 1 dict put
  3330. % --END ENCODER plessey--
  3331.  
  3332. % --BEGIN ENCODER raw--
  3333. % --DESC: Raw bar space succession for custom symbologies 
  3334. % --EXAM: 331132131313411122131311333213114131131221323
  3335. /raw {
  3336.  
  3337.     0 begin                  % Confine variables to local scope
  3338.  
  3339.     /options exch def        % We are given an option string
  3340.     /useropts options def
  3341.     /sbs exch def        % We are given a barcode string
  3342.  
  3343.     /height 1 def
  3344.  
  3345.     % Parse the input options
  3346.     options {
  3347.         token false eq {exit} if dup length string cvs (=) search
  3348.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3349.     } loop
  3350.     /height height cvr def
  3351.  
  3352.     % Return the arguments
  3353.     /retval 1 dict def
  3354.     retval (sbs) [sbs {48 sub} forall] put
  3355.     retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
  3356.     retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put 
  3357.     retval (opt) useropts put
  3358.     retval
  3359.  
  3360.     end
  3361.  
  3362. } bind def
  3363. /raw load 0 1 dict put
  3364. % --END ENCODER raw--
  3365.  
  3366. % --BEGIN ENCODER symbol--
  3367. % --DESC: Miscellaneous symbols
  3368. % --EXAM: fima
  3369. /symbol {
  3370.  
  3371.     0 begin            % Confine variables to local scope
  3372.  
  3373.     /options exch def  % We are given an option string
  3374.     /barcode exch def  % We are given a barcode string
  3375.  
  3376.     barcode (fima) eq {
  3377.         /sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def
  3378.         /bhs [.625 .625 .625 .625 .625] def
  3379.         /bbs [0 0 0 0 0] def
  3380.     } if
  3381.  
  3382.     barcode (fimb) eq {
  3383.         /sbs [2.25 6.75 2.25 2.25 2.25 6.25 2.25 2.25 2.25 6.75 2.25] def
  3384.         /bhs [.625 .625 .625 .625 .625 .625] def
  3385.         /bbs [0 0 0 0 0 0] def
  3386.     } if
  3387.  
  3388.     barcode (fimc) eq {
  3389.         /sbs [2.25 2.25 2.25 6.75 2.25 6.75 2.25 6.75 2.25 2.25 2.25] def
  3390.         /bhs [.625 .625 .625 .625 .625 .625] def
  3391.         /bbs [0 0 0 0 0 0] def
  3392.     } if
  3393.     
  3394.     barcode (fimd) eq {
  3395.         /sbs [2.25 2.25 2.25 2.25 2.25 6.75 2.25 6.75 2.25 2.25 2.25 2.25 2.25] def
  3396.         /bhs [.625 .625 .625 .625 .625 .625 .625] def
  3397.         /bbs [0 0 0 0 0 0 0] def
  3398.     } if
  3399.     
  3400.     % Return the arguments
  3401.     /retval 4 dict def
  3402.     retval (sbs) sbs put
  3403.     retval (bhs) bhs put
  3404.     retval (bbs) bbs put
  3405.     retval (opt) options put
  3406.     retval
  3407.  
  3408.     end
  3409.  
  3410. } bind def
  3411. /symbol load 0 1 dict put
  3412. % --END ENCODER symbol--
  3413.  
  3414. % --BEGIN RENDERER--
  3415. /barcode {
  3416.  
  3417.     0 begin          % Confine variables to local scope
  3418.  
  3419.     /args exch def   % We are given some arguments
  3420.  
  3421.     % Default options
  3422.     /sbs [] def
  3423.     /bhs [] def
  3424.     /bbs [] def
  3425.     /txt [] def
  3426.     /barcolor (unset) def
  3427.     /textcolor (unset) def
  3428.     /bordercolor (unset) def
  3429.     /backgroundcolor (unset) def
  3430.     /inkspread 0.15 def
  3431.     /width 0 def
  3432.     /barratio 1 def
  3433.     /spaceratio 1 def
  3434.     /showborder false def
  3435.     /borderleft 10 def
  3436.     /borderright 10 def
  3437.     /bordertop 1 def
  3438.     /borderbottom 1 def
  3439.     /borderwidth 0.5 def
  3440.     /guardwhitespace false def
  3441.     /guardleftpos 0 def
  3442.     /guardleftypos 0 def
  3443.     /guardrightpos 0 def
  3444.     /guardrightypos 0 def
  3445.     /guardwidth 6 def
  3446.     /guardheight 7 def
  3447.     
  3448.     % Apply the renderer options
  3449.     args {exch cvlit exch def} forall
  3450.        
  3451.     % Parse the user options   
  3452.     opt {
  3453.         token false eq {exit} if dup length string cvs (=) search
  3454.         true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3455.     } loop
  3456.  
  3457.     /barcolor barcolor cvlit def
  3458.     /textcolor textcolor cvlit def
  3459.     /bordercolor bordercolor cvlit def
  3460.     /backgroundcolor backgroundcolor cvlit def
  3461.     /inkspread inkspread cvr def
  3462.     /width width cvr def
  3463.     /barratio barratio cvr def
  3464.     /spaceratio spaceratio cvr def
  3465.     /borderleft borderleft cvr def
  3466.     /borderright borderright cvr def
  3467.     /bordertop bordertop cvr def
  3468.     /borderbottom borderbottom cvr def
  3469.     /borderwidth borderwidth cvr def
  3470.     /guardleftpos guardleftpos cvr def
  3471.     /guardleftypos guardleftypos cvr def
  3472.     /guardrightpos guardrightpos cvr def
  3473.     /guardrightypos guardrightypos cvr def
  3474.     /guardwidth guardwidth cvr def
  3475.     /guardheight guardheight cvr def
  3476.     
  3477.     % Create bar elements and put them into the bars array
  3478.     /bars sbs length 1 add 2 idiv array def
  3479.     /x 0.00 def /maxh 0 def
  3480.     0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
  3481.         /i exch def
  3482.         i 2 mod 0 eq {           % i is even
  3483.             /d sbs i get barratio mul barratio sub 1 add def  % d=digit*r-r+1 
  3484.             /h bhs i 2 idiv get 72 mul def  % Height from bhs
  3485.             /c d 2 div x add def            % Centre of the bar = x + d/2
  3486.             /y bbs i 2 idiv get 72 mul def  % Baseline from bbs
  3487.             /w d inkspread sub def          % bar width = digit - inkspread
  3488.             bars i 2 idiv [h c y w] put     % Add the bar entry
  3489.             h maxh gt {/maxh h def} if
  3490.         } {
  3491.             /d sbs i get spaceratio mul spaceratio sub 1 add def  % d=digit*r-r+1 
  3492.         } ifelse
  3493.         /x x d add def  % x+=d
  3494.     } for
  3495.  
  3496.     gsave
  3497.  
  3498.     currentpoint translate
  3499.  
  3500.     % Force symbol to given width
  3501.     width 0 ne {
  3502.         width 72 mul x div 1 scale
  3503.     } if
  3504.  
  3505.     % Display the border and background
  3506.     newpath
  3507.     borderleft neg borderbottom neg moveto
  3508.     x borderleft add borderright add 0 rlineto
  3509.     0 maxh borderbottom add bordertop add rlineto
  3510.     x borderleft add borderright add neg 0 rlineto
  3511.     0 maxh borderbottom add bordertop add neg rlineto    
  3512.     closepath
  3513.     backgroundcolor (unset) ne {
  3514.         gsave
  3515.         (<      >) dup 1 backgroundcolor putinterval cvx exec {255 div} forall setrgbcolor
  3516.         fill
  3517.         grestore  
  3518.     } if     
  3519.     showborder {
  3520.         gsave
  3521.         bordercolor (unset) ne {
  3522.             (<      >) dup 1 bordercolor putinterval cvx exec {255 div} forall setrgbcolor
  3523.         } if
  3524.         borderwidth setlinewidth stroke
  3525.         grestore
  3526.     } if    
  3527.    
  3528.     % Display the bars for elements in the bars array
  3529.     gsave
  3530.     barcolor (unset) ne {
  3531.         (<      >) dup 1 barcolor putinterval cvx exec {255 div} forall setrgbcolor
  3532.     } if
  3533.     bars {
  3534.         {} forall
  3535.         newpath setlinewidth moveto 0 exch rlineto stroke
  3536.     } forall
  3537.     grestore
  3538.     
  3539.     % Display the text for elements in the text array
  3540.     textcolor (unset) ne {
  3541.         (<      >) dup 1 textcolor putinterval cvx exec {255 div} forall setrgbcolor
  3542.     } if
  3543.     /s 0 def /f () def
  3544.     txt {
  3545.         {} forall
  3546.         2 copy s ne exch f ne or {
  3547.             2 copy /s exch def /f exch def            
  3548.             exch findfont exch scalefont setfont          
  3549.         } {
  3550.             pop pop
  3551.         } ifelse
  3552.         moveto show
  3553.     } forall
  3554.  
  3555.     % Display the guard elements
  3556.     guardwhitespace {
  3557.         0.75 setlinewidth
  3558.         guardleftpos 0 ne {
  3559.             newpath
  3560.             guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
  3561.             guardwidth neg guardheight -2 div rlineto
  3562.             guardwidth guardheight -2 div rlineto
  3563.             stroke            
  3564.         } if
  3565.         guardrightpos 0 ne {
  3566.             newpath
  3567.             guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
  3568.             guardwidth guardheight -2 div rlineto
  3569.             guardwidth neg guardheight -2 div rlineto
  3570.             stroke            
  3571.         } if
  3572.     } if
  3573.     
  3574.     grestore
  3575.     
  3576.     end
  3577.  
  3578. } bind def
  3579. /barcode load 0 1 dict put
  3580. % --END RENDERER--
  3581.  
  3582. % --END TEMPLATE--
  3583.