home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1212 < prev    next >
Internet Message Format  |  1990-12-28  |  5KB

  1. From: mjj@stda.jhuapl.edu (Marshall Jose)
  2. Newsgroups: alt.sources
  3. Subject: [comp.periphs.printers] Re: Universal bar code and USPS bar code
  4. Message-ID: <11767@stag.math.lsa.umich.edu>
  5. Date: 20 Apr 90 16:28:44 GMT
  6.  
  7. Archive-name: upc/19-Apr-90
  8. Original-posting-by: mjj@stda.jhuapl.edu (Marshall Jose)
  9. Original-subject: Re: Universal bar code and USPS bar code
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [This is an experimental alt.sources re-posting from the newsgroup(s)
  13. comp.periphs.printers. Comments on this service to emv@math.lsa.umich.edu 
  14. (Edward Vielmetti).]
  15.  
  16.  
  17. In article <29057@cup.portal.com> John_A_Pham@cup.portal.com writes:
  18. >    I'm looking for any algorithms or references to algorithms on how
  19. >to print universal bar code or USPS bar code.
  20.  
  21. Here's one which appeared here a while back.  Works only with PostScript,
  22. though I suppose you could reverse-engineer it.
  23.  
  24. # To recover, type "sh archive"
  25. echo restoring upc
  26. sed 's/^X//' > upc <<\XxXxXxXxXx-EOF-XxXxXxXxXx
  27. X#!/bin/sh
  28. X# upc -- print upc code with PostScript
  29. X# usage:  upc prod code-5 code-5
  30. X# prod is the product type (zero for store items)
  31. X# code-5 is a five digit code (needs two of these)
  32. X
  33. X# Copyright (C) 1986 by Pipeline Associates, Inc.
  34. X# Permission is granted to use and distribute as long as this copyright
  35. X# notice remains intact and it is distributed free of charge.
  36. X
  37. XUPCFONT=./upc.pro
  38. XX=1    # x coordinate of lower right corner (in inches)
  39. XY=1    # x coordinate of lower right corner (in inches)
  40. X
  41. X# calculate checksum
  42. Xsum=`echo "$2
  43. X$3
  44. X$2
  45. X$3" | sed "
  46. X    1s/\(.\)\(.\)\(.\)\(.\)\(.\)/a=$1 + \2 + \4/
  47. X    2s/\(.\)\(.\)\(.\)\(.\)\(.\)/b=\1 + \3 + \5/
  48. X    3s/\(.\)\(.\)\(.\)\(.\)\(.\)/c=\1 + \3 + \5/
  49. X    4s/\(.\)\(.\)\(.\)\(.\)\(.\)/s=(a+b)*3+c+\2+\4;(10-(s%10))%10/" | bc`
  50. X
  51. Xcat $UPCFONT
  52. Xecho "$X 72 mul $Y 72 mul translate /UPC findfont 50 scalefont setfont
  53. X0 0 moveto
  54. X(| |$1$2 | | ) show
  55. Xswitch
  56. X($3$sum) show
  57. Xswitch
  58. X(| |) show
  59. Xshowpage"
  60. XxXxXxXxXx-EOF-XxXxXxXxXx
  61. echo restoring upc.pro
  62. sed 's/^X//' > upc.pro <<\XxXxXxXxXx-EOF-XxXxXxXxXx
  63. X%%
  64. X%%  Universal Product Code font
  65. X%%  Copyright (C) 1986 by Pipeline Associates, Inc.
  66. X%%  Permission is granted to use and distribute as long as this copyright
  67. X%%  notice remains intact and it is distributed free of charge.
  68. X%%
  69. X/UPCFontDict 8 dict def
  70. X/workdict 25 dict def
  71. X%% load up drawing procedures
  72. Xworkdict begin
  73. X    /gray 0 def
  74. X    /d1 {
  75. X        1.3 setlinewidth
  76. X        1 0 moveto 1 100 lineto stroke
  77. X        2 0 translate
  78. X    } bind def
  79. X    /d2 {
  80. X        3.3 setlinewidth
  81. X        2 0 moveto 2 100 lineto stroke
  82. X        4 0 translate
  83. X    } bind def
  84. X    /d3 {
  85. X        5.3 setlinewidth
  86. X        3 0 moveto 3 100 lineto stroke
  87. X        6 0 translate
  88. X    } bind def
  89. X    /d4 {
  90. X        7.3 setlinewidth
  91. X        4 0 moveto 4 100 lineto stroke
  92. X        8 0 translate
  93. X    } bind def
  94. X    /cline1 {
  95. X        1 gray sub setgray
  96. X        d1
  97. X    } bind def
  98. X    /cline2 {
  99. X        1 gray sub setgray
  100. X        d2
  101. X    } bind def
  102. X    /cline3 {
  103. X        1 gray sub setgray
  104. X        d3
  105. X    } bind def
  106. X    /cline4 {
  107. X        1 gray sub setgray
  108. X        d4
  109. X    } bind def
  110. X    /line1 {
  111. X        gray setgray
  112. X        d1
  113. X    } bind def
  114. X    /line2 {
  115. X        gray setgray
  116. X        d2
  117. X    } bind def
  118. X    /line3 {
  119. X        gray setgray
  120. X        d3
  121. X    } bind def
  122. X    /line4 {
  123. X        gray setgray
  124. X        d4
  125. X    } bind def
  126. Xend
  127. X/switch {
  128. X    workdict begin /gray 1 gray sub def end
  129. X    } def
  130. X
  131. XUPCFontDict begin
  132. X/FontType 3 def
  133. X/FontMatrix [.01 0 0 .015 0 0] def
  134. X/FontBBox [0 0 10 100] def
  135. X/Encoding 128 array def
  136. X/Widths 128 array def
  137. X
  138. X%% fill the Encoding array with the procs to run for each character
  139. X0 1 127 {Encoding exch /.notdef put} for
  140. XEncoding (0) 0 get /zero put
  141. XEncoding (1) 0 get /one put
  142. XEncoding (2) 0 get /two put
  143. XEncoding (3) 0 get /three put
  144. XEncoding (4) 0 get /four put
  145. XEncoding (5) 0 get /five put
  146. XEncoding (6) 0 get /six put
  147. XEncoding (7) 0 get /seven put
  148. XEncoding (8) 0 get /eight put
  149. XEncoding (9) 0 get /nine put
  150. XEncoding ( ) 0 get /space put
  151. XEncoding (|) 0 get /bar put
  152. X
  153. XWidths (0) 0 get 14 put
  154. XWidths (1) 0 get 14 put
  155. XWidths (2) 0 get 14 put
  156. XWidths (3) 0 get 14 put
  157. XWidths (4) 0 get 14 put
  158. XWidths (5) 0 get 14 put
  159. XWidths (6) 0 get 14 put
  160. XWidths (7) 0 get 14 put
  161. XWidths (8) 0 get 14 put
  162. XWidths (9) 0 get 14 put
  163. XWidths ( ) 0 get 2 put
  164. XWidths (|) 0 get 2 put
  165. X
  166. X%% define the procs
  167. X/CharProcs 20 dict def
  168. XCharProcs /.notdef {} put
  169. XCharProcs /zero {
  170. X    cline3 line2 cline1 line1
  171. X} put
  172. XCharProcs /one {
  173. X    cline2 line2 cline2 line1
  174. X} put
  175. XCharProcs /two {
  176. X    cline2 line1 cline2 line2
  177. X} put
  178. XCharProcs /three {
  179. X    cline1 line4 cline1 line1
  180. X} put
  181. XCharProcs /four {
  182. X    cline1 line1 cline3 line2
  183. X} put
  184. XCharProcs /five {
  185. X    cline1 line2 cline3 line1
  186. X} put
  187. XCharProcs /six {
  188. X    cline1 line1 cline1 line4
  189. X} put
  190. XCharProcs /seven {
  191. X    cline1 line3 cline1 line2
  192. X} put
  193. XCharProcs /eight {
  194. X    cline1 line2 cline1 line3
  195. X} put
  196. XCharProcs /nine {
  197. X    cline3 line1 cline1 line2
  198. X} put
  199. XCharProcs /space {
  200. X} put
  201. XCharProcs /bar {
  202. X    line1
  203. X} put
  204. X%% BuildChar is called by PS whenever a character is to be imaged out
  205. X%% of UPC
  206. X/BuildChar {
  207. X workdict begin
  208. X  /char exch def
  209. X  /fontdict exch def
  210. X  /charname fontdict /Encoding get char get def
  211. X  /charproc fontdict /CharProcs get charname get def
  212. X  /charwidth fontdict /Widths get char get def
  213. X  charwidth 0 setcharwidth
  214. X  gsave
  215. X    charproc
  216. X  grestore
  217. X end
  218. X} bind def
  219. Xend
  220. X%% register font in postscript font machinery
  221. X/UPC UPCFontDict definefont pop
  222. XxXxXxXxXx-EOF-XxXxXxXxXx
  223.  
  224. Marshall Jose  WA3VPZ
  225. mjj%stda@aplcen.apl.jhu.edu  ||  ...mimsy!aplcen!aplvax!mjj
  226.