home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY2 / LJLBAR.ZIP / LJLBAR39.BAS
BASIC Source File  |  1990-04-04  |  13KB  |  291 lines

  1. '00 ─────────────────────────────────────────────── Font39LandDownload sub.
  2.  
  3. 'This group of routines with the function FNCode39$ defines the 128 characters
  4. 'of the Code 39 barcode set, and downloads them to the HP Laserjet II printer
  5. 'as an alternate character set.  This character set is for use in the landscape
  6. 'mode only.  The printer is reset by the sub Font39LandDownload, and landscape
  7. 'mode is then selected, the font set is then formated, and downloaded.  The
  8. 'function FNCode39$ is used to toggle between Code 39 and normal text sent to
  9. 'the printer.
  10.  
  11. 'Note:    This code does not check printer ready status (online,paper,etc).
  12.  
  13. 'PB 2.0 - Walter Haase
  14. 'TB 1.0 - Kent Walker
  15.  
  16.  Sub Font39LandDownload
  17.     Local A%,B%,C%,D%
  18.     Lprint Chr$(27);"E";        'reset the printer
  19.     Lprint Chr$(27);"&l1O";        'select landscape mode
  20.     Lprint Chr$(27);"*c0F";        'delete all current soft fonts
  21.     Lprint Chr$(27);"*c1D";        'select font #1 for definition
  22.     Lprint Chr$(27);")s64W";    'issue descriptor command
  23.  
  24.     'build font descriptor block (fixed-length of 64 bytes, reserved bytes
  25.     'are set to null)
  26.  
  27.     Lprint Chr$(0);            'byte 0 is null
  28.     Lprint Chr$(64);        'set font descriptor size (64 bytes)
  29.     Lprint Chr$(0);            'reserved  - 1 byte
  30.     Lprint Chr$(0);            'set font type to 7 bit (default)
  31.     Lprint Chr$(0);Chr$(0);        'reserved  - 2 bytes
  32.     Lprint Chr$(0);Chr$(&H32);    'set baseline distance (12/72*300=32h)
  33.     Lprint Chr$(0);Chr$(&HFF);    'set cell width  (255d)
  34.     Lprint Chr$(0);Chr$(&HFF);    'set cell height (255d)
  35.     Lprint Chr$(1);            'set orientation to landscape
  36.     Lprint Chr$(0);            'set spacing to fixed (default)
  37.     Lprint Chr$(0);Chr$(25);    'set symbol set to Code 39
  38.     Lprint Chr$(&H01);Chr$(&H04);    'set pitch 4.6 cpi (26/120*1200=104h)
  39.     Lprint Chr$(&H01);Chr$(&H60);    'set height 21.1 (21/72*1200=160h)
  40.     Lprint Chr$(0);Chr$(0);        'set xHeight (HPLJ ignores)
  41.     Lprint Chr$(0);            'set width type (HPLJ ignores)
  42.     Lprint Chr$(0);            'set style to upright (0, 1 is Italic)
  43.     Lprint Chr$(0);            'set stroke weight medium (-7 to +7)
  44.     Lprint Chr$(0);            'set typeface (default)
  45.     Lprint Chr$(0);            'reserved - 1 byte
  46.     Lprint Chr$(0);            'set Serif style (HPLJ ignores)
  47.     Lprint Chr$(0);Chr$(0);        'reserved - 2 bytes
  48.     Lprint Chr$(0);            'set underline distance (default)
  49.     Lprint Chr$(0);            'set underline height (HPLJ ignores)
  50.     Lprint Chr$(0);Chr$(0);        'set text height (HPLJ ignores)
  51.     Lprint Chr$(0);Chr$(0);        'set text width (HPLJ ignores)
  52.     Lprint String$(4,Chr$(0));    'reserved - 4 bytes
  53.     Lprint Chr$(0);            'set pitch extended  (default)
  54.     Lprint Chr$(0);            'set height extended (default)
  55.     Lprint String$(6,Chr$(0));    'reserved - 6 bytes
  56.     Lprint "CODE 39         ";    'issue font name (16 bytes padded)
  57.  
  58.     'end of font descriptor block
  59.  
  60.     'below are listed the four combinations of wid/narrow bar/space masks
  61.     'used in the 128 character Code 39 set
  62.  
  63.     A%=1                'define narrow bar, narrow space mask
  64.     B%=2                'define narrow bar, wide space mask
  65.     C%=3                'define wide bar, narrow space mask
  66.     D%=4                'define wide bar, wide space mask
  67.  
  68.     'define 128 character set masks, and perform character format
  69.  
  70.     Call Format(0,A%,B%,B%,B%,A%,D%,A%,A%,A%,C%)    '0   NUL    (%U)
  71.     Call Format(1,B%,B%,B%,A%,A%,C%,A%,B%,A%,C%)    '1   SOH    ($A)
  72.     Call Format(2,B%,B%,B%,A%,A%,A%,C%,B%,A%,C%)    '2   STX    ($B)
  73.     Call Format(3,B%,B%,B%,A%,A%,C%,C%,B%,A%,A%)    '3   ETX    ($C)
  74.     Call Format(4,B%,B%,B%,A%,A%,A%,A%,D%,A%,C%)    '4   EOT    ($D)
  75.     Call Format(5,B%,B%,B%,A%,A%,C%,A%,D%,A%,A%)    '5   ENQ    ($E)
  76.     Call Format(6,B%,B%,B%,A%,A%,A%,C%,D%,A%,A%)    '6   ACK    ($F)
  77.     Call Format(7,B%,B%,B%,A%,A%,A%,A%,B%,C%,C%)    '7   BEL    ($G)
  78.     Call Format(8,B%,B%,B%,A%,A%,C%,A%,B%,C%,A%)    '8   BS        ($H)
  79.     Call Format(9,B%,B%,B%,A%,A%,A%,C%,B%,C%,A%)    '9   HT        ($I)
  80.     Call Format(10,B%,B%,B%,A%,A%,A%,A%,D%,C%,A%)    '10  LF        ($J)
  81.     Call Format(11,B%,B%,B%,A%,A%,C%,A%,A%,B%,C%)    '11  VT        ($K)
  82.     Call Format(12,B%,B%,B%,A%,A%,A%,C%,A%,B%,C%)    '12  FF        ($L)
  83.     Call Format(13,B%,B%,B%,A%,A%,C%,C%,A%,B%,A%)    '13  CR        ($M)
  84.     Call Format(14,B%,B%,B%,A%,A%,A%,A%,C%,B%,C%)    '14  SO        ($N)
  85.     Call Format(15,B%,B%,B%,A%,A%,C%,A%,C%,B%,A%)    '15  SI        ($O)
  86.     Call Format(16,B%,B%,B%,A%,A%,A%,C%,C%,B%,A%)    '16  DLE    ($P)
  87.     Call Format(17,B%,B%,B%,A%,A%,A%,A%,A%,D%,C%)    '17  DC1    ($Q)
  88.     Call Format(18,B%,B%,B%,A%,A%,C%,A%,A%,D%,A%)    '18  DC2    ($R)
  89.     Call Format(19,B%,B%,B%,A%,A%,A%,C%,A%,D%,A%)    '19  DC3    ($S)
  90.     Call Format(20,B%,B%,B%,A%,A%,A%,A%,C%,D%,A%)    '20  DC4    ($T)
  91.     Call Format(21,B%,B%,B%,A%,A%,D%,A%,A%,A%,C%)    '21  NAK    ($U)
  92.     Call Format(22,B%,B%,B%,A%,A%,B%,C%,A%,A%,C%)    '22  SYN    ($V)
  93.     Call Format(23,B%,B%,B%,A%,A%,D%,C%,A%,A%,A%)    '23  ETB    ($W)
  94.     Call Format(24,B%,B%,B%,A%,A%,B%,A%,C%,A%,C%)    '24  CAN    ($X)
  95.     Call Format(25,B%,B%,B%,A%,A%,D%,A%,C%,A%,A%)    '25  EM        ($Y)
  96.     Call Format(26,B%,B%,B%,A%,A%,B%,C%,C%,A%,A%)    '26  SUB    ($Z)
  97.     Call Format(27,A%,B%,B%,B%,A%,C%,A%,B%,A%,C%)    '27  ESC    (%A)
  98.     Call Format(28,A%,B%,B%,B%,A%,A%,C%,B%,A%,C%)    '28  FS        (%B)
  99.     Call Format(29,A%,B%,B%,B%,A%,C%,C%,B%,A%,A%)    '29  GS        (%C)
  100.     Call Format(30,A%,B%,B%,B%,A%,A%,A%,D%,A%,C%)    '30  RS        (%D)
  101.     Call Format(31,A%,B%,B%,B%,A%,C%,A%,D%,A%,A%)    '31  US        (%E)
  102.     Call Format(32,0,0,0,0,0,B%,C%,A%,C%,A%)    '32  SPACE
  103.     Call Format(33,B%,B%,A%,B%,A%,C%,A%,B%,A%,C%)    '33  !        (/A)
  104.     Call Format(34,B%,B%,A%,B%,A%,A%,C%,B%,A%,C%)    '34  "        (/B)
  105.     Call Format(35,B%,B%,A%,B%,A%,C%,C%,B%,A%,A%)    '35  #        (/C)
  106.     Call Format(36,0,0,0,0,0,B%,B%,B%,A%,A%)    '36  $
  107.     Call Format(37,0,0,0,0,0,A%,B%,B%,B%,A%)    '37  %
  108.     Call Format(38,B%,B%,A%,B%,A%,A%,C%,D%,A%,A%)    '38  &        (/F)
  109.     Call Format(39,B%,B%,A%,B%,A%,A%,A%,B%,C%,C%)    '39  '        (/G)
  110.     Call Format(40,B%,B%,A%,B%,A%,C%,A%,B%,C%,A%)    '40  (        (/H)
  111.     Call Format(41,B%,B%,A%,B%,A%,A%,C%,B%,C%,A%)    '41  )        (/I)
  112.     Call Format(42,0,0,0,0,0,B%,A%,C%,C%,A%)    '42  *
  113.     Call Format(43,0,0,0,0,0,B%,A%,B%,B%,A%)    '43  +
  114.     Call Format(44,B%,B%,A%,B%,A%,A%,C%,A%,B%,C%)    '44  ,        (/L)
  115.     Call Format(45,0,0,0,0,0,B%,A%,A%,C%,C%)    '45  -
  116.     Call Format(46,0,0,0,0,0,D%,A%,A%,C%,A%)    '46  .
  117.     Call Format(47,0,0,0,0,0,B%,B%,A%,B%,A%)    '47  /
  118.     Call Format(48,0,0,0,0,0,A%,B%,C%,C%,A%)    '48  0
  119.     Call Format(49,0,0,0,0,0,C%,B%,A%,A%,C%)    '49  1
  120.     Call Format(50,0,0,0,0,0,A%,D%,A%,A%,C%)    '50  2
  121.     Call Format(51,0,0,0,0,0,C%,D%,A%,A%,A%)    '51  3
  122.     Call Format(52,0,0,0,0,0,A%,B%,C%,A%,C%)    '52  4
  123.     Call Format(53,0,0,0,0,0,C%,B%,C%,A%,A%)    '53  5
  124.     Call Format(54,0,0,0,0,0,A%,D%,C%,A%,A%)    '54  6
  125.     Call Format(55,0,0,0,0,0,A%,B%,A%,C%,C%)    '55  7
  126.     Call Format(56,0,0,0,0,0,C%,B%,A%,C%,A%)    '56  8
  127.     Call Format(57,0,0,0,0,0,A%,D%,A%,C%,A%)    '57  9
  128.     Call Format(58,B%,B%,A%,B%,A%,B%,C%,C%,A%,A%)    '58  :        (/Z)
  129.     Call Format(59,A%,B%,B%,B%,A%,A%,C%,D%,A%,A%)    '59  ;        (%F)
  130.     Call Format(60,A%,B%,B%,B%,A%,A%,A%,B%,C%,C%)    '60  <        (%G)
  131.     Call Format(61,A%,B%,B%,B%,A%,C%,A%,B%,C%,A%)    '61  =        (%H)
  132.     Call Format(62,A%,B%,B%,B%,A%,A%,C%,B%,C%,A%)    '62  >        (%I)
  133.     Call Format(63,A%,B%,B%,B%,A%,A%,A%,D%,C%,A%)    '63  ?        (%J)
  134.     Call Format(64,A%,B%,B%,B%,A%,B%,C%,A%,A%,C%)    '64  @        (%V)
  135.     Call Format(65,0,0,0,0,0,C%,A%,B%,A%,C%)    '65  A
  136.     Call Format(66,0,0,0,0,0,A%,C%,B%,A%,C%)    '66  B
  137.     Call Format(67,0,0,0,0,0,C%,C%,B%,A%,A%)    '67  C
  138.     Call Format(68,0,0,0,0,0,A%,A%,D%,A%,C%)    '68  D
  139.     Call Format(69,0,0,0,0,0,C%,A%,D%,A%,A%)    '69  E
  140.     Call Format(70,0,0,0,0,0,A%,C%,D%,A%,A%)    '70  F
  141.     Call Format(71,0,0,0,0,0,A%,A%,B%,C%,C%)    '71  G
  142.     Call Format(72,0,0,0,0,0,C%,A%,B%,C%,A%)    '72  H
  143.     Call Format(73,0,0,0,0,0,A%,C%,B%,C%,A%)    '73  I
  144.     Call Format(74,0,0,0,0,0,A%,A%,D%,C%,A%)    '74  J
  145.     Call Format(75,0,0,0,0,0,C%,A%,A%,B%,C%)    '75  K
  146.     Call Format(76,0,0,0,0,0,A%,C%,A%,B%,C%)    '76  L
  147.     Call Format(77,0,0,0,0,0,C%,C%,A%,B%,A%)    '77  M
  148.     Call Format(78,0,0,0,0,0,A%,A%,C%,B%,C%)    '78  N
  149.     Call Format(79,0,0,0,0,0,C%,A%,C%,B%,A%)    '79  O
  150.     Call Format(80,0,0,0,0,0,A%,C%,C%,B%,A%)    '80  P
  151.     Call Format(81,0,0,0,0,0,A%,A%,A%,D%,C%)    '81  Q
  152.     Call Format(82,0,0,0,0,0,C%,A%,A%,D%,A%)    '82  R
  153.     Call Format(83,0,0,0,0,0,A%,C%,A%,D%,A%)    '83  S
  154.     Call Format(84,0,0,0,0,0,A%,A%,C%,D%,A%)    '84  T
  155.     Call Format(85,0,0,0,0,0,D%,A%,A%,A%,C%)    '85  U
  156.     Call Format(86,0,0,0,0,0,B%,C%,A%,A%,C%)    '86  V
  157.     Call Format(87,0,0,0,0,0,D%,C%,A%,A%,A%)    '87  W
  158.     Call Format(88,0,0,0,0,0,B%,A%,C%,A%,C%)    '88  X
  159.     Call Format(89,0,0,0,0,0,D%,A%,C%,A%,A%)    '89  Y
  160.     Call Format(90,0,0,0,0,0,B%,C%,C%,A%,A%)    '90  Z
  161.     Call Format(91,A%,B%,B%,B%,A%,C%,A%,A%,B%,C%)    '91  [        (%K)
  162.     Call Format(92,A%,B%,B%,B%,A%,A%,C%,A%,B%,C%)    '92  \        (%L)
  163.     Call Format(93,A%,B%,B%,B%,A%,C%,C%,A%,B%,A%)    '93  ]        (%M)
  164.     Call Format(94,A%,B%,B%,B%,A%,A%,A%,C%,B%,C%)    '94  ^        (%N)
  165.     Call Format(95,A%,B%,B%,B%,A%,C%,A%,C%,B%,A%)    '95  _        (%O)
  166.     Call Format(96,A%,B%,B%,B%,A%,D%,C%,A%,A%,A%)    '96  `        (%W)
  167.     Call Format(97,B%,A%,B%,B%,A%,C%,A%,B%,A%,C%)    '97  a        (+A)
  168.     Call Format(98,B%,A%,B%,B%,A%,A%,C%,B%,A%,C%)    '98  b        (+B)
  169.     Call Format(99,B%,A%,B%,B%,A%,C%,C%,B%,A%,A%)    '99  c        (+C)
  170.     Call Format(100,B%,A%,B%,B%,A%,A%,A%,D%,A%,C%)    '100 d        (+D)
  171.     Call Format(101,B%,A%,B%,B%,A%,C%,A%,D%,A%,A%)    '101 e        (+E)
  172.     Call Format(102,B%,A%,B%,B%,A%,A%,C%,D%,A%,A%)    '102 f        (+F)
  173.     Call Format(103,B%,A%,B%,B%,A%,A%,A%,B%,C%,C%)    '103 g        (+G)
  174.     Call Format(104,B%,A%,B%,B%,A%,C%,A%,B%,C%,A%)    '104 h        (+H)
  175.     Call Format(105,B%,A%,B%,B%,A%,A%,C%,B%,C%,A%)    '105 i        (+I)
  176.     Call Format(106,B%,A%,B%,B%,A%,A%,A%,D%,C%,A%)    '106 j        (+J)
  177.     Call Format(107,B%,A%,B%,B%,A%,C%,A%,A%,B%,C%)    '107 k        (+K)
  178.     Call Format(108,B%,A%,B%,B%,A%,A%,C%,A%,B%,C%)    '108 l        (+L)
  179.     Call Format(109,B%,A%,B%,B%,A%,C%,C%,A%,B%,A%)    '109 m        (+M)
  180.     Call Format(110,B%,A%,B%,B%,A%,A%,A%,C%,B%,C%)    '110 n        (+N)
  181.     Call Format(111,B%,A%,B%,B%,A%,C%,A%,C%,B%,A%)    '111 o        (+O)
  182.     Call Format(112,B%,A%,B%,B%,A%,A%,C%,C%,B%,A%)    '112 p        (+P)
  183.     Call Format(113,B%,A%,B%,B%,A%,A%,A%,A%,D%,C%)    '113 q        (+Q)
  184.     Call Format(114,B%,A%,B%,B%,A%,C%,A%,A%,D%,A%)    '114 r        (+R)
  185.     Call Format(115,B%,A%,B%,B%,A%,A%,C%,A%,D%,A%)    '115 s        (+S)
  186.     Call Format(116,B%,A%,B%,B%,A%,A%,A%,C%,D%,A%)    '116 t        (+T)
  187.     Call Format(117,B%,A%,B%,B%,A%,D%,A%,A%,A%,C%)    '117 u        (+U)
  188.     Call Format(118,B%,A%,B%,B%,A%,B%,C%,A%,A%,C%)    '118 v        (+V)
  189.     Call Format(119,B%,A%,B%,B%,A%,D%,C%,A%,A%,A%)    '119 w        (+W)
  190.     Call Format(120,B%,A%,B%,B%,A%,B%,A%,C%,A%,C%)    '120 x        (+X)
  191.     Call Format(121,B%,A%,B%,B%,A%,D%,A%,C%,A%,A%)    '121 y        (+Y)
  192.     Call Format(122,B%,A%,B%,B%,A%,B%,C%,C%,A%,A%)    '122 z        (+Z)
  193.     Call Format(123,A%,B%,B%,B%,A%,A%,C%,C%,B%,A%)    '123 {        (%P)
  194.     Call Format(124,A%,B%,B%,B%,A%,A%,A%,A%,D%,C%)    '124 |        (%Q)
  195.     Call Format(125,A%,B%,B%,B%,A%,C%,A%,A%,D%,A%)    '125 }        (%R)
  196.     Call Format(126,A%,B%,B%,B%,A%,A%,C%,A%,D%,A%)    '126 ~        (%S)
  197.     Call Format(127,A%,B%,B%,B%,A%,A%,A%,C%,D%,A%)    '127 DEL    (%T)
  198.  
  199.     Lprint Chr$(27);"*c5F";        'make soft font permanent
  200.  End Sub
  201.  
  202.  Sub Format(AsciiValue%,A%,B%,C%,D%,E%,F%,G%,H%,I%,J%)
  203.  
  204.     Lprint Chr$(27);"*c";AsciiValue%;"E";    'assign character A,B,C,D, etc
  205.     Lprint Chr$(27);"(s731W";        'issue char. descriptor command
  206.  
  207.     'build char. format descriptor block (reserved bytes are set to null)
  208.  
  209.     Lprint Chr$(4);            'set format (4 for HPLJ)
  210.     Lprint Chr$(0);            'set continuation flag (default)
  211.     Lprint Chr$(14);        'set descriptor size (14 for HPLJ)
  212.     Lprint Chr$(1);            'set class (1 for HPLJ)
  213.     Lprint Chr$(1);            'set orientation to landscape
  214.     Lprint Chr$(0);            'reserved - 1 byte
  215.     Lprint Chr$(&HFF);Chr$(&HCE);    'set left offset to -50 (FFCEh)
  216.     Lprint Chr$(0);Chr$(&H42);    'set top  offset to +66 (0042h)
  217.     Lprint Chr$(0);Chr$(&H58);    'set char. width  to 88 dots (11 bytes)
  218.     Lprint Chr$(0);Chr$(&H41);    'set char. heigth to 65 dots
  219.     Lprint Chr$(0);Chr$(0);        'set delta X (default)
  220.                     'bytes 16 - 64 character data
  221.  
  222.     'note that the following are sent in REVERSE order; this is because
  223.     'landscape fonts are defined in raster scan order
  224.  
  225.     Call Decode(J%)        'send standard Code 39 masks
  226.     Call Decode(I%)
  227.     Call Decode(H%)
  228.     Call Decode(G%)
  229.     Call Decode(F%)
  230.  
  231.     If A%>0 Then        'is it a special Code 39 mask ?
  232.         Call Decode(E%)    'if yes; then use $,%,+, or / masks
  233.         Call Decode(D%)
  234.         Call Decode(C%)
  235.         Call Decode(B%)
  236.         Call Decode(A%)
  237.     End If
  238.  End Sub
  239.  
  240.  Sub Decode(Mask%)        'calculates byte pixel patterns from masks
  241.     Select Case Mask%
  242.         Case=1            'narrow bar, narrow space - 2 bytes
  243.             Call Download(&B00000000)
  244.             Call Download(&B11111111)
  245.         Case=2            'narrow bar, wide space      - 2 bytes
  246.                 Call Download(&B00000000)
  247.             Call Download(&B00000000)
  248.             Call Download(&B11111111)
  249.             Case=3            'wide bar, narrow space      - 3 bytes
  250.                 Call Download(&B00000000)
  251.             Call Download(&B11111111)
  252.             Call Download(&B11111111)
  253.             Case=4            'wide bar, wide space      - 4 bytes
  254.                 Call Download(&B00000000)
  255.             Call Download(&B00000000)
  256.             Call Download(&B11111111)
  257.             Call Download(&B11111111)
  258.     End Select
  259.  End Sub
  260.  
  261.  Sub Download(BitPattern%)        'downloads bit patterns to printer
  262.     Local A%,B%
  263.     For A%=1 To 5
  264.         For B%=1 To 11
  265.             Lprint Chr$(BitPattern%);
  266.         Next B%
  267.     Next A%
  268.  End Sub
  269.  
  270.  Def FNCode39$(Text$)            'builds Code 39 ASCII strings
  271.     If Len(Text$)<1 Then
  272.         FNCode39$=""
  273.         Exit Def
  274.     Else
  275.         FNCode39$=Chr$(14)+"*"+Text$+"*"+Chr$(15)
  276.     End If
  277.  End Def
  278.  
  279.  'Demo starts here...
  280.  
  281.  Width"LPT1:",32767            'set printer graphics width
  282.  
  283.  Call Font39LandDownload        'download fonts to the HPLJ-II printer
  284.  Lprint Chr$(27);")1X";            'select Code 39 as secondary font
  285.  Lprint Chr$(15);            'select characters from primary font
  286.  Lprint                    'do a blank line
  287.  Lprint FNCode39$("THIS IS A TEST");    'print some Code 39 stuff for test
  288.  Lprint                    'do a blank line
  289.  Lprint"THIS IS A TEST"            'print some ASCII text for test
  290.  Lprint Chr$(12);            'eject the page
  291.