home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / bbs / libdisks / d700t799 / disk792.lha / ModHPLJD / ModHPLJD.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-01-08  |  10.9 KB  |  200 lines

  1. /*
  2.                     ModHPLJD - Modify HP_LaserJet Driver
  3.                       Version 1.01  -  September 1992
  4.                       Copyright © Michael Tanzer 1992
  5.  
  6. +-------------------------------------------------------------------------+
  7. |                             N O T I C E                                 |
  8. |                                                                         |
  9. | Freely distributable.  Not to be used for commercial purposes without   |
  10. | written consent from the author.  Not to be distributed without this    |
  11. | notice and copyright information intact.  Not be distributed with any   |
  12. | modification to the contents of this file excluding preparation for     |
  13. | distribution (such as packing).                                         |
  14. |                                                                         |
  15. | This product is distributed on an 'as-is' basis, with no warranty of    |
  16. | any kind, either express or implied.  No responsibility whatsoever is   |
  17. | assumed by the author for the use of this product, nor for any results  |
  18. | of its use.  No claim whatsoever is made as to this product's accuracy, |
  19. | usefulness, completeness, nor suitability to any purpose.               |
  20. |                                                                         |
  21. | The author can be reached by telephone at +61 3 387 6589,               |
  22. |                           by facsimile at +61 3 388 1863,               |
  23. |                        or by post at P.O. Box 289                       |
  24. |                                      Carlton North VIC 3054             |
  25. |                                      Australia                          |
  26. |                                                                         |
  27. +-------------------------------------------------------------------------+
  28.  
  29.   Note:  This is a heavily-documented Rexx program.  Be careful not to
  30.          modify it unless you have read it thoroughly and understand it.
  31.          It was tested under Workbench 2.04 using the version of the
  32.          HP_LaserJet driver that was packaged with that release.
  33.  
  34.  
  35.  Well, you've bought yourself a Hewlett Packard LaserJet printer, hooked
  36.  it up to your trusty Amiga and created some great-looking output with a
  37.  desk-top publishing program or some other graphic-dumping software, and
  38.  you're happy with your new purchase.  Then you crank up the old word
  39.  processor to see what those internal fonts will do for your correspon-
  40.  dence.  You select CG Times from the printer menu and print off a page
  41.  of text.  You go to admire your work and what do you find?  Courier!
  42.  Very nice looking Courier, but if you wanted Courier, you wouldn't have
  43.  thrown out that clunky old typewriter.  You check the printer menu
  44.  again - yes, you did select Times, and you know you saved the choice.
  45.  You do an 07 RESET and check the menu again just to make sure - yes,
  46.  there it is, Times.  You try printing the page again and this time it
  47.  comes out in Times.  What's going on here?  After a lot of stuffing
  48.  around, you discover that every time you boot your machine, the first
  49.  thing you print with your word processor comes out in Courier; after
  50.  the first page you can reset the printer and get Times from then on.
  51.  
  52.  Here's your problem: the HP_LaserJet printer driver you're using sends
  53.  an 'initialise' string to the printer in front of your first line of
  54.  text every time it's loaded, i.e. after every boot-up and after any
  55.  other printer driver has been in use.  This init string tells the prin-
  56.  ter to use (you guessed it) Courier - 12 point, 10 pitch Courier.
  57.  
  58.  What can you do?  Every time you want to use your word processor, you
  59.  can print off some garbage page just to get the init out of the way,
  60.  then reset the printer and start using Times.  What a waste of time,
  61.  toner and paper!
  62.  
  63.  And another thing: every once in a while, you want to use a large type-
  64.  face, 24 points for example.  If you print at six lines per inch, the
  65.  characters in one line overlap those in the next.  And the only other
  66.  option is using eight lines per inch, which would cause even worse over-
  67.  lapping.
  68.  
  69.  Fortunately, there is a solution!  You can create a modified version
  70.  of the HP_LaserJet driver which contains an init string that doesn't
  71.  override the selections you have made on the printer menu, and allows
  72.  you to specify fewer lines per inch.  How can you accomplish this?  One
  73.  way is to get the code for the driver, learn some PCL, change the init
  74.  string and re-compile the driver.  Sounds like a lot of work, doesn't
  75.  it?  Another way is to get a good hex editor, learn some PCL, find the
  76.  init string in the driver, change it and store the modified driver.
  77.  Still sounds like a lot of work.  How about this: read the rest of this
  78.  file, make a simple choice as instructed and type RX MODHPLJD from the
  79.  shell.  Isn't that better?  Even a Commodore rep could do it!
  80.  
  81.  By the way, you can use this routine even if you prefer Univers, Line
  82.  Printer, or Courier.  In fact, you can use any internal font you like.
  83.  I would suggest that you stick to upright, medium fonts because you
  84.  can usually select boldface and italics from your word processor.
  85.  
  86.  All right, let's get started.  We'll begin by deciding how many lines
  87.  per inch we want.  We'll set the Rexx variable 'lpi' to indicate our
  88.  choice.  I generally use 6 lpi myself, so I have set 'lpi' to '6'.  If
  89.  you use a 24 point font, you would probably want to set this variable
  90.  to '3'.  Note that there are some limitations; you must choose a value
  91.  from the following list: 1 2 3 4 6 8.  I don't think this is too severe
  92.  a restriction.
  93. */
  94.  
  95. lpi = '6'                           /* Lines per inch: 1 2 3 4 6 or 8 */
  96.  
  97. /*
  98.  The next two variables specify the name of the existing driver and the
  99.  the name of the driver we are creating.  My own preference is to create
  100.  the name of the new driver by adding the number of lines per inch (from
  101.  the previous paragraph) to the name of the old driver.  That is, since
  102.  we are using HP_LaserJet as input, I have set the 'outfile' variable so
  103.  that the new driver will be called 'HP_LaserJet_6lpi'.  This way I can
  104.  easily identify the drivers I have created and what their respective
  105.  characteristics are.  If you have a better idea, feel free to use it.
  106. */
  107.  
  108. infile = 'HP_LaserJet'                      /* Name of the old driver */
  109. outfile = infile'_'lpi'lpi'                 /* Name of the new driver */
  110.  
  111. /*
  112.  If you are running under WorkBench 2.04 with the WB2.04 version of the
  113.  HP_LaserJet driver, you are ready to run this routine.  If not, you
  114.  might like to read on so that if this routine doesn't work properly for
  115.  you, you will have some idea about how it might be fixed.  Assuming you
  116.  are ready to proceed, here is what to do next:
  117.  
  118.  Make sure that this file is in the directory to which REXX: has been
  119.  assigned.  Then open a shell and type RX MODHPLJD.  The result will be
  120.  a new driver in your DEVS:printers directory.  If you have not changed
  121.  this file, the name of the new driver will be HP_LaserJet_6lpi.  Open
  122.  the Prefs drawer from the WorkBench, double-click the Printer icon, and
  123.  click on the new name.  Then click on either Save or Use, depending on
  124.  how confident you feel.  You can always go back to the old driver.
  125.  
  126.  Now you should be able to turn on your printer and print something.  If
  127.  this routine has worked properly, you will get output in whatever font
  128.  you chose from the printer menu at your choice of lines per inch.
  129.  
  130.  This is the end of the narration.  The rest of this file contains the
  131.  Rexx code necessary to perform the actual modification of the driver.
  132. */
  133.  
  134.  
  135.  
  136.  
  137. /* Define the old init string */
  138. oldinit = '1b266440'x   ||,           /* Disable underline            */
  139.           '1b266c3644'x ||,           /* 6 lines per inch             */
  140.           '1b28733062'x ||,           /* Medium weight                */
  141.           '313068'x     ||,           /* 10 characters per inch       */
  142.           '3171'x       ||,           /* (see note below)             */
  143.           '3070'x       ||,           /* Fixed spacing                */
  144.           '3073'x       ||,           /* Upright style                */
  145.           '3374'x       ||,           /* Courier                      */
  146.           '3075'x       ||,           /* (see note below)             */
  147.           '313256'x                   /* 12 point                     */
  148.  
  149. /* Define the new init string; must be same length as old init string */
  150. newinit = '1b45'x       ||,           /* Reset                        */
  151.           '1b266440'x   ||,           /* Disable underline            */
  152.           '1b266c'x||lpi||'44'x ||,   /* 'lpi' lines per inch         */
  153.           '1b28733171'x ||,           /* (see note below)             */
  154.           '3171'x       ||,           /* (see note below)             */
  155.           '3171'x       ||,           /* (see note below)             */
  156.           '3171'x       ||,           /* (see note below)             */
  157.           '3171'x       ||,           /* (see note below)             */
  158.           '3171'x       ||,           /* (see note below)             */
  159.           '3171'x       ||,           /* (see note below)             */
  160.           '3055'x                     /* (see note below)             */
  161.  
  162. /*
  163. Note: The commands '1b28733151'x and '1b28733055'x are not documented in
  164. the HP LaserJet IIIP Printer User's Manual.  I have included them in the
  165. newinit string (in combined form) in case they serve some valuable function
  166. under circumstances that I am unable to duplicate, and because they serve
  167. to pad out the length of the string to the 30 bytes required by the driver.
  168. If you know the purpose of these commands, I would like to hear from you.
  169. */
  170.  
  171. /* Do the bizzo */
  172. call pragma('D','DEVS:printers')      /* Change to printers directory */
  173. call open 'input',infile,'R'          /* Open the old driver as input */
  174. if ~result then do                    /* Handle error                 */
  175.   say 'Unable to open' infile 'for input.'
  176.   exit 99
  177.   end
  178. call open 'output',outfile,'W'        /* Open the output file         */
  179. if ~result then do                    /* Handle error                 */
  180.   say 'Unable to open' outfile 'for output.'
  181.   exit 98
  182.   end
  183. driver = readch('input',65535)        /* Read the driver              */
  184. length = length(driver)               /* Save the length              */
  185. disp = pos(oldinit,driver)            /* Displacement to init string  */
  186. if disp=0 then do                     /* Handle init string not found */
  187.   say 'Unable to locate init string in' infile'.'
  188.   exit 97
  189.   end
  190. driver = overlay(newinit,driver,disp) /* Replace init string          */
  191. call writech('output',driver)         /* Write the new driver         */
  192. if result~=length then do             /* Handle error                 */
  193.   say 'Error writing' outfile 'to disk.'
  194.   exit 96
  195.   end
  196. call close 'input'                    /* Close input file             */
  197. call close 'output'                   /* Close output file            */
  198. say outfile 'created.'                /* Type the good news           */
  199. exit                                  /* ...and to all a good night!  */
  200.