home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / ps / barcode < prev    next >
Text File  |  1991-04-10  |  3KB  |  98 lines

  1.  
  2. %WARNING: EXTREMELY LARGE WASTE OF BANDWIDTH AHEAD
  3. %  For anyone who has a need for it, here's a handy little PostScript UPC
  4. %  generator.
  5.  
  6. % --------- CUT HERE --------- (or don't - it'll run anyway!)
  7.  
  8. %The following code is used to generate a UPC-A barcode.
  9. %
  10. %calling sequence:
  11. %    string *Barcode* --
  12. %where string is a 10-digit string of numerics.
  13. %
  14. %Example:
  15. %    (0123456789) Barcode
  16. %
  17. %Output will be in the form of a UPC barcode bounded by the square (0,0)-(1,1)
  18. %Scale and position as necessary before calling.
  19. %
  20. %This code is freely redistributable and is copyright 1991 Ronald L. Parker.
  21. %Universal Product Code, UPC, and the barcode itself may be someone's
  22. %trademarks or property.  If this is the case, I assume no responsibility for
  23. %any damages, in any form, that the use of this code may cause.  Whoever DOES
  24. %own the UPC code - don't come looking for me, I have no money anyway.
  25.  
  26. /bar % width color bar --
  27.        % width is in 'modules' 1-4
  28.        % color: 0=black, 1=white, just like setgray
  29. {
  30. /BarColor exch def
  31. /BarWidth exch def
  32.  
  33. /Tempwidth BarWidth 95 div def
  34. 0 .1 moveto 0 1 lineto Tempwidth 1 lineto Tempwidth .1 lineto closepath
  35. BarColor setgray fill
  36. Tempwidth 0 translate
  37. } def
  38.  
  39. /dochar % string dochar -- 
  40.         % string is one character, must be supported.
  41. {
  42. /ToOutput exch def
  43.  
  44. ToOutput 66 eq {1 Dark bar 1 Light bar 1 Dark bar} if
  45. ToOutput 69 eq {1 Light bar 1 Dark bar 1 Light bar} if
  46. ToOutput 77 eq {1 Light bar 1 Dark bar 1 Light bar 1 Dark bar 1 Light bar
  47.                  /Dark 1 def /Light 0 def} if
  48. ToOutput 48 eq {3 Light bar 2 Dark bar 1 Light bar 1 Dark bar} if
  49. ToOutput 49 eq {2 Light bar 2 Dark bar 2 Light bar 1 Dark bar} if
  50. ToOutput 50 eq {2 Light bar 1 Dark bar 2 Light bar 2 Dark bar} if
  51. ToOutput 51 eq {1 Light bar 4 Dark bar 1 Light bar 1 Dark bar} if
  52. ToOutput 52 eq {1 Light bar 1 Dark bar 3 Light bar 2 Dark bar} if
  53. ToOutput 53 eq {1 Light bar 2 Dark bar 3 Light bar 1 Dark bar} if
  54. ToOutput 54 eq {1 Light bar 1 Dark bar 1 Light bar 4 Dark bar} if
  55. ToOutput 55 eq {1 Light bar 3 Dark bar 1 Light bar 2 Dark bar} if
  56. ToOutput 56 eq {1 Light bar 2 Dark bar 1 Light bar 3 Dark bar} if
  57. ToOutput 57 eq {3 Light bar 1 Dark bar 1 Light bar 2 Dark bar} if
  58. } def
  59.  
  60. /Barcode % string code --
  61. {
  62. gsave
  63. /BarString exch def
  64. /NewString 15 string def
  65. /Dark 0 def
  66. /Light 1 def
  67. NewString 2 BarString 0 5 getinterval putinterval
  68. NewString 8 BarString 5 5 getinterval putinterval
  69. NewString 0 (B0) putinterval
  70. NewString 7 (M) putinterval
  71. NewString 14 (E) putinterval
  72. /CheckSum 0 def
  73. 0 1 9 {dup BarString exch 1 getinterval cvi exch 2 mod 2 mul 1 add mul
  74.        CheckSum add /CheckSum exch def} for
  75. CheckSum 10 mod 10 exch sub /CheckSum exch def
  76. NewString 13 CheckSum cvi 1 string cvs putinterval
  77. NewString {dochar} forall
  78. 1 setgray
  79. -1 0 translate 10 95 div .1 moveto 45 95 div .1 lineto 45 95 div .2 lineto
  80.                10 95 div .2 lineto closepath fill
  81.                50 95 div .1 moveto 85 95 div .1 lineto 85 95 div .2 lineto
  82.                50 95 div .2 lineto closepath fill
  83. 0 setgray
  84. BarFont findfont [7 95 div 0 0 .2 0 0] makefont setfont
  85. 0 1 4 {dup 7 mul 10 add 95 div 0 moveto BarString exch 1 getinterval show} for
  86. 5 1 9 {dup 7 mul 15 add 95 div 0 moveto BarString exch 1 getinterval show} for
  87. grestore
  88. } def
  89.  
  90. % This is the preferred font for UPC barcodes:
  91. %/BarFont /OCR-B def
  92.  
  93. % This is what I use as I don't have OCR-B or any standard Adobe fonts.
  94. % You may insert your own favorite font here.
  95. /BarFont /SansSerif def
  96.  
  97.  
  98.