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

  1. From: kirkaas@oahu.cs.ucla.edu (paul kirkaas)
  2. Newsgroups: alt.sources
  3. Subject: [tex] DVI driver with compaction for HP Desk Jet +
  4. Message-ID: <1990May23.082106.6953@math.lsa.umich.edu>
  5. Date: 23 May 90 08:21:06 GMT
  6.  
  7. Archive-name: dvidjp/22-May-90
  8. Original-posting-by: kirkaas@oahu.cs.ucla.edu (paul kirkaas)
  9. Original-subject: DVI driver with compaction for HP Desk Jet +
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.text.tex.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. /*
  16. I just got myself a brand new HP Desk Jet Plus printer to use with TeX.
  17. I and a number of other people asked the net for sources to one of the many
  18. DeskJet drivers which must be out there, but there was no response.  I
  19. searched all the archives I could find, with similarly unsuccessful
  20. results.
  21.  
  22. So I took the dvijet driver from the Beebe release and modified it for
  23. the desk jet plus.  It might be called (as by some) a "vanilla" driver
  24. because it doesn't use downloadable fonts, but downloadable fonts
  25. requires an extra memory cartridge -- for that I would have just
  26. as soon bought the IIp.   I did include some memory compaction, though,
  27. which reduces file size and transfer time by 50 - 70 %  So it's not
  28. quite vanilla.  The various compaction schemes can be switched off
  29. at compile time if the old Desk Jet doesn't support them (I have no
  30. idea) or if any of them prove buggy (possible).
  31.  
  32. I include the modified source below, as I am guessing there are
  33. others out there on the net who would find it useful.  Perhaps some
  34. kind soul will even archive it.  It requires the rest of the
  35. Beebe driver code, which is commonly available -- eg,
  36. at ymir.claremont.edu & utah ... whatever.
  37.  
  38. Hope this is helpful.  Sorry if this isn't the place I'm supposed to post
  39. source, but it's the best way I know to reach people who might find
  40. this useful.
  41.  
  42. Paul Kirkaas
  43. kirkaas@cs.ucla.edu
  44.  
  45. ----------------------------------------------------------
  46. /* -*-C-*- dvidjp.c */
  47. /*-->dvidjp*/
  48. /**********************************************************************/
  49. /******************************* dvidjp *******************************/
  50. /**********************************************************************/
  51.  
  52. /* Driver for HP DeskJet Plus printer -- modified from
  53.  * Beebe Laser Jet driver
  54.  * by Paul Kirkaas (kirkaas@cs.ucla.edu) 22 May 1990
  55.  *
  56.  * Employs 3 types of data compaction for greater efficiency --
  57.  * up to 60 - 70% reduction in output file size.  Each compaction 
  58.  * scheme can be switched on or off independently by defining any
  59.  * or all of:
  60.  *
  61.  * XOFF -- X offset -- instead of a string of leading zeros, offset
  62.  *     by appropriate amount.  Minimal savings when used  with
  63.  *    COMPACTION mode set.
  64.  *
  65.  * YOFF -- Y offset -- compress multiple blank lines into a single
  66.  *    y skip command.
  67.  *
  68.  * COMPACTION -- Uses mode 2 compaction on Desk Jet Plus -- this is
  69.  *    the trickiest but most effective compression modification.
  70.  *    This is the likliest part to have a bug.
  71.  *    Lots of cleaning up can be done here.
  72.  *
  73.  * If you have an old Desk Jet (not a Plus) it may not have
  74.  * all these abilities -- try undfining some of these switches.
  75.  *
  76.  * It should run straight with the Beebe driver set; you might
  77.  * have to make some adjustments.
  78.  *
  79.  * Please let me know if you make any improvements or repairs.
  80.  * Thanks
  81.  *
  82.  * Good Luck.
  83.  */
  84.  
  85. #include "dvihead.h"
  86.  
  87. /**********************************************************************/
  88. /************************  Device Definitions  ************************/
  89. /**********************************************************************/
  90.  
  91. /* All output-device-specific definitions go here.  This section must
  92. be changed when modifying a dvi driver for use on a new device */
  93.  
  94. #undef HPLASERJET
  95. #define  HPLASERJET       1        /* conditional compilation flag */
  96. #define  HPDESKJET       1        /* conditional compilation flag */
  97.         /* Include the following line for Y offsets*/
  98. #define YOFF    1
  99.         /* Include the following line for using temporary X offsets*/
  100. #define XOFF    1
  101.         /* Include the following line for Mode 2 Compaction */
  102. #define    COMPACTION    1    
  103.  
  104. #define VERSION_NO    "2.10"        /* DVI driver version number */
  105.  
  106. #ifdef COMPACTION
  107. #define  DEVICE_ID    "Hewlett-Packard Desk Jet plus (from LaserJet)\n\
  108.     WITH Data Compaction for faster I/O"
  109. #else
  110. #define  DEVICE_ID    "Hewlett-Packard Desk Jet plus (from LaserJet)\n\
  111.     with-OUT Data Compaction I/O"
  112. #endif COMPACTION
  113.                 /* this string is printed at runtime */
  114. #ifdef COMPACTION
  115. #define OUTFILE_EXT    "djp"
  116. #else
  117. #define OUTFILE_EXT    "dj"
  118. #endif COMPACTION
  119.  
  120. #define  DEFAULT_RESOLUTION 300        /* default dots/inch on HP Desk Jet */
  121.  
  122. #define  BYTE_SIZE        8        /* output file byte size */
  123.  
  124. #undef STDRES
  125. #define STDRES  1            /* 0 for low-resolution devices */
  126.  
  127. #define  XDPI        300        /* HP Laser Jet horizontal dots/inch */
  128. #define  XPSIZE        8        /* horizontal paper size in inches */
  129.  
  130. #define  XSIZE        (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
  131.                 (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
  132.                     /* number of horizontal dots; */
  133.                     /* MUST BE multiple of */
  134.                     /* 2*HOST_WORD_SIZE */
  135. #define  XWORDS        ((XSIZE + HOST_WORD_SIZE - 1)/HOST_WORD_SIZE)
  136.                     /* number of words in rows  */
  137.                     /* of bitmap array */
  138.  
  139. #define  YDPI        300        /* HP Laser Jet vertical dots/inch */
  140.  
  141. #define  YPSIZE        11        /* vertical paper size in inches */
  142. #define  YSIZE        (YDPI*YPSIZE)    /* number of vertical dots */
  143.  
  144. /* The printer bit map (must have an even number of columns). */
  145.  
  146. #define XBIT ((1+2*XWORDS)/2)
  147. #define YBIT YSIZE
  148. #if    (IBM_PC_LATTICE | IBM_PC_MICROSOFT | IBM_PC_WIZARD)
  149. #undef SEGMEM
  150. #define SEGMEM 1 /* ( ((long)XBIT * (long)YBIT) > 65536L ) */
  151. #endif
  152.  
  153. #include "bitmap.h"
  154.  
  155. #include "main.h"
  156. #undef STDMAG
  157. #undef RESOLUTION
  158. #define STDMAG 1500
  159. #define    RESOLUTION    (((float)STDMAG)/5.0)    /* dots per inch */
  160. #include "abortrun.h"
  161. #include "actfact.h"
  162. #include "alldone.h"
  163. #include "chargf.h"
  164. #include "charpk.h"
  165. #include "charpxl.h"
  166. #include "clrbmap.h"
  167. #include "clrrow.h"
  168. #include "dbgopen.h"
  169.  
  170. /*-->devinit*/
  171. /**********************************************************************/
  172. /****************************** devinit *******************************/
  173. /**********************************************************************/
  174.  
  175. void
  176. devinit(argc,argv)        /* initialize device */
  177. int argc;
  178. char *argv[];
  179. {
  180.     (void)getbmap();
  181.     OUTS("\033E");    /* printer reset */
  182.     OUTS("\033&l0L");    /* Disable perforation skip */
  183.     OUTS("\033*rB");    /* End graphics */
  184.     OUTS("\033*t300R");    /* printer resolution */
  185. #ifdef COMPACTION
  186.     OUTS("\033*b2M");    /* Select Compacted Graphics Mode Two */
  187. #else
  188.     OUTS("\033*b0M");    /* Select Full Graphics Mode */
  189. #endif COMPACTION
  190.     OUTS("\033*r0A");    /* Start graphics, at leftmost position */
  191. }
  192.  
  193. /*-->devterm*/
  194. /**********************************************************************/
  195. /****************************** devterm *******************************/
  196. /**********************************************************************/
  197.  
  198. void
  199. devterm()            /* terminate device */
  200. {
  201.     OUTS("\033E");    /* printer reset*/
  202. }
  203.  
  204. #include "dvifile.h"
  205. #include "dviinit.h"
  206. #include "dviterm.h"
  207. #include "dispchar.h"
  208. #include "f20open.h"
  209. #include "fatal.h"
  210. #include "fillrect.h"
  211. #include "findpost.h"
  212. #include "fixpos.h"
  213. #include "fontfile.h"
  214. #include "fontsub.h"
  215. #include "getbmap.h"
  216. #include "getbytes.h"
  217. #include "getfntdf.h"
  218. #include "getpgtab.h"
  219. #include "initglob.h"
  220. #include "inch.h"
  221. #include "loadchar.h"
  222. #include "movedown.h"
  223. #include "moveover.h"
  224. #include "moveto.h"
  225. #include "nosignex.h"
  226. #include "openfont.h"
  227. #include "option.h"
  228.  
  229. /*-->outline*/
  230. /**********************************************************************/
  231. /****************************** outline *******************************/
  232. /**********************************************************************/
  233.  
  234. void
  235. outline(pbit)
  236. UNSIGN32 *pbit;                /* pointer to raster line */
  237.  
  238. /*************************************************************************
  239. Use machine-specific coding here for efficiency.  For TOPS-20, we encode
  240. 9 bytes from every pair  of 36-bit words.
  241.  
  242. For each raster line on the paper, the Laser Jet expects a binary  8-bit
  243. byte stream of the form
  244.  
  245.     <ESC>*bnnnWxxxxxxx ... xxxxxxx
  246.                <--- nnn bytes --->
  247.  
  248. where each byte contains, in order from high to low bit, a left-to-right
  249. bit pattern.  No  end-of-line marker  is required;  the escape  sequence
  250. automatically causes a new raster line to be started.
  251. *************************************************************************/
  252.  
  253. {
  254.     register UNSIGN32 w_even,w_odd;
  255.     register UNSIGN32 *p;
  256.     register BYTE *pbuf;
  257.     BYTE buf[1+(XSIZE+7)/8];        /* space for EOS + n 8-bit bytes */
  258.     register INT16 i,last_word;
  259.     int ic,jc;            /* just counters */
  260.     unsigned char * endb;    /* pointer to end of buf */
  261. #ifdef COMPACTION
  262.     unsigned char greystr[129]; /* Max length of 127 in compacted mode 2 */
  263.     unsigned char * greyp;    /* Pointer to greystr[]  */
  264.     unsigned char outstr[999];    /* Compacted mode 2 output string */
  265.     unsigned char * outp;    /* Pointer to outstr[]  */
  266.     unsigned char * endob;    /* pointer to end of outstr */
  267.     unsigned char cmp;        /* Comparison variable */
  268.     int outsz;            /* Size of outstr -- since includes NULLs */
  269.     int count;
  270.     int gcnt;    /* Length of grey runs */
  271.  
  272. #endif COMPACTION
  273.  
  274.  
  275. #if    IBM_PC_MICROSOFT
  276.     for (last_word = XBIT - 1;
  277.     (last_word >= 1) && (*(UNSIGN32*)normaddr(pbit,last_word) == 0);
  278.     --last_word)
  279.         ;                /* trim white space a word at a time */
  280. #else
  281.     p = pbit + XBIT - 1;        /* point to last word on line */
  282.     for (last_word = XBIT - 1; (last_word >= 1) && (*p == 0); --last_word)
  283.         --p;                /* trim white space a word at a time */
  284. #endif
  285.  
  286.     p = pbit;
  287.     pbuf = &buf[0];
  288.     for (i = 0; i <= last_word; i += 2)    /* loop over trimmed raster */
  289.     {
  290.         w_even = (*p++);
  291.         w_odd = (*p++);
  292.  
  293. #if    (HOST_WORD_SIZE == 36)
  294.     *pbuf++ = (BYTE)( (w_even >> 28) & 0xff);
  295.     *pbuf++ = (BYTE)( (w_even >> 20) & 0xff);
  296.     *pbuf++ = (BYTE)( (w_even >> 12) & 0xff);
  297.     *pbuf++ = (BYTE)( (w_even >>  4) & 0xff);
  298.     *pbuf++ = (BYTE)( ((w_even <<  4) | (w_odd >> 32)) & 0xff);
  299.     *pbuf++ = (BYTE)( (w_odd  >> 24) & 0xff);
  300.     *pbuf++ = (BYTE)( (w_odd  >> 16) & 0xff);
  301.     *pbuf++ = (BYTE)( (w_odd  >>  8) & 0xff);
  302.     *pbuf++ = (BYTE)( (w_odd       ) & 0xff);
  303. #else /* HOST_WORD_SIZE == 32 */
  304.     /* encode 8 bytes at a time on 32-bit machines */
  305.     *pbuf++ = (BYTE)( (w_even >> 24) & 0xff);
  306.     *pbuf++ = (BYTE)( (w_even >> 16) & 0xff);
  307.     *pbuf++ = (BYTE)( (w_even >>  8) & 0xff);
  308.     *pbuf++ = (BYTE)( (w_even      ) & 0xff);
  309.     *pbuf++ = (BYTE)( (w_odd  >> 24) & 0xff);
  310.     *pbuf++ = (BYTE)( (w_odd  >> 16) & 0xff);
  311.     *pbuf++ = (BYTE)( (w_odd  >>  8) & 0xff);
  312.     *pbuf++ = (BYTE)( (w_odd       ) & 0xff);
  313. #endif
  314.  
  315.     }
  316.  
  317.     *pbuf = '\0';            /* trailing EOS marker */
  318.  
  319.     last_word |= 1;            /* make last_word ODD */
  320.     for (i = ((last_word+1)*HOST_WORD_SIZE)/8;
  321.         (*(--pbuf) == '\0') && (i > 1); --i)
  322.     ;    /* trim trailing zero bytes, leaving at least one */
  323.     last_word = i;
  324. #ifdef XOFF
  325.     /* Trim leading zero bytes & do appropriate Temporary X offset */
  326.     OUTS("\033*b"); /* Set up for raster transfer */
  327.     pbuf=buf;
  328.     for (ic=0; !buf[ic] && ic<last_word ; ic++, pbuf++)
  329.     ;
  330.     if (ic>10) /* Do an X-shift */
  331.     {
  332.         OUTF("%dx",8*ic); /* Shift by 8*ic # of blank pixels */
  333.     }
  334.     else    /* don't bother */
  335.     { pbuf = buf; ic = 0; }
  336.  
  337.     endb = &buf[last_word];
  338.  
  339. #ifdef COMPACTION
  340.     greyp = greystr;
  341.     outp = outstr;
  342.     outsz = gcnt = 0;
  343.     endb = &buf[last_word];
  344.     while (pbuf <= endb)
  345.     {
  346.       cmp = *pbuf;
  347.       for (count = 0; count<127 && pbuf<=endb && cmp==*pbuf; count ++, pbuf++)
  348.     ;
  349.       if (count==0){printf("DANGER DANGER ***COUNT IS ZERO***!!!\n");exit(0);}
  350.       if (count <= 3) /* No run yet -- just put them in greystr */
  351.     {
  352.       gcnt += count;
  353.       for (jc = 0; jc < count ; jc ++)
  354.         {
  355.         *greyp = cmp;
  356.         greyp++;
  357.         }
  358.       if (gcnt >= 124)  /* Can't have more than 127, so ... */
  359.         {
  360.         outstr[outsz] = gcnt-1;
  361.         outsz++;
  362.         for (jc = 0; jc < gcnt; jc ++)
  363.           {
  364.             outstr[outsz + jc] = greystr[jc];
  365.           }
  366.         outsz += gcnt;
  367.         gcnt = 0;
  368.         greyp = greystr;
  369.         continue;
  370.         }
  371.     }
  372.       else /* We have a run of 4 or more */
  373.     {
  374.         if (gcnt) /* Flush our accumilated grey */
  375.         {
  376.         outstr[outsz] = gcnt-1;
  377.         outsz++;
  378.         for (jc = 0; jc < gcnt; jc ++)
  379.           {
  380.             outstr[outsz + jc] = greystr[jc];
  381.           }
  382.         outsz += gcnt;
  383.         gcnt = 0;
  384.         greyp = greystr;
  385.         }
  386.         outstr[outsz] = (unsigned char) (1-count); /* Is this cast right? */
  387.         outsz ++;
  388.         outstr[outsz] = cmp;
  389.         outsz++;
  390.     }
  391.     }
  392.     if (gcnt) /* Flush our accumilated grey */
  393.       {
  394.     outstr[outsz] = gcnt-1;
  395.     outsz++;
  396.     for (jc = 0; jc < gcnt; jc ++)
  397.       {
  398.         outstr[outsz + jc] = greystr[jc];
  399.       }
  400.     outsz += gcnt;
  401.     gcnt = 0;
  402.     greyp = greystr;
  403.       }
  404.     OUTF("%dW",outsz); /* How much is coming ... */
  405.     endob = outstr + outsz -1; /* End of the outstr */ 
  406.     for (outp = outstr; outp <= endob; outp++ )
  407.         OUTC(*outp);
  408.  
  409. #else
  410.     OUTF("%dW",(int)last_word-ic); /* How much is coming ... */
  411.     /* cannot use fprintf with %s format because of
  412.                    NUL's in string, and it is slow anyway */
  413.     for (i = ic; i < last_word; ++pbuf,++i)
  414.         OUTC(*pbuf);
  415. #endif COMPACTION
  416. #else
  417.     OUTF("\033*b%dW",(int)last_word);
  418.     pbuf = &buf[0];    /* cannot use fprintf with %s format because of
  419.                    NUL's in string, and it is slow anyway */
  420.     for (i = 0; i < last_word; ++pbuf,++i)
  421.         OUTC(*pbuf);
  422. #endif XOFF
  423. }
  424.  
  425. /*-->prtbmap*/
  426. /**********************************************************************/
  427. /****************************** prtbmap *******************************/
  428. /**********************************************************************/
  429.  
  430. void
  431. prtbmap()
  432.  
  433. {
  434.     register UNSIGN32 *p;
  435.     register INT16 j,k,ybottom,ytop;
  436. #ifdef YOFF
  437.     int ycnt = 0;
  438. #endif YOFF
  439.  
  440.     if (DBGOPT(DBG_PAGE_DUMP))
  441.     {
  442.     INT16 k1,k2,k3;
  443.  
  444.     for (k3 = 0; k3 < XBIT; (k3 += 7, ++p))
  445.     {    /*  print bitmap 7 words at a pass */
  446.         k1 = k3;
  447.         k2 = MIN(XBIT,k1+7);
  448.         (void)printf("prtbmap()...bitmap words %d..%d",k1,k2-1);
  449.         NEWLINE(stdout);
  450.         (void)printf("     ");
  451.         for (k = k1; k < k2; ++k)
  452.             (void)printf("%10d",k*HOST_WORD_SIZE);
  453.         NEWLINE(stdout);
  454.         for (j = YBIT-1; j >= 0; --j)
  455.         {
  456.             p = BITMAP(j,0);
  457.         for (k = 0; k < XBIT; (++k,++p))
  458.         {
  459.                 if (*p)    /* print non-blank raster line */
  460.             {
  461.                 p = BITMAP(j,k1);
  462.             (void)printf("%5d:",j);
  463.             for (k = k1; k < k2; (++k,++p))
  464.                 (void)printf(" %09lx",*p);
  465.             NEWLINE(stdout);
  466.             break;    /* exit loop over k */
  467.             }
  468.         }
  469.         }
  470.     }
  471.     }
  472.  
  473.     (void)clearerr(plotfp);
  474.  
  475. #if    ZAPTHISOUT
  476.     k = -1;        /* find top non-zero raster */
  477.     for (j = YBIT-1; (j > 0) && (k < 0); --j)  /* loop over raster lines */
  478.     {
  479.     p = BITMAP(j,XBIT-1);
  480.     for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  481.         --p;        /* trim white space */
  482.     }
  483.     ytop = j;
  484. #else
  485.     ytop = YBIT-1;
  486. #endif
  487.  
  488.     k = -1;        /* find bottom non-zero raster */
  489.     for (j = 0; (j < ytop) && (k < 0); ++j) /* loop over raster lines */
  490.     {
  491.  
  492. #if    IBM_PC_MICROSOFT
  493.     for (k = XBIT - 1;((k >= 0) && (*BITMAP(j,k) == 0));--k)
  494.         ;        /* trim white space */
  495. #else
  496.     p = BITMAP(j,XBIT-1);
  497.     for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  498.         --p;        /* trim white space */
  499. #endif
  500.  
  501.     }
  502.     ybottom = MAX(0,j-1);
  503.  
  504. #if    ZAPTHISOUT
  505.     for (j = ytop; (j >= ybottom); --j)
  506.         {
  507.     OUTF("%5d:",(int)j);
  508.         for (k = 0; k < XBIT; ++k)
  509.             OUTF(" %9x",*BITMAP(j,k));
  510.     NEWLINE(plotfp);
  511.         }
  512. #endif
  513.  
  514.  
  515. #ifdef YOFF
  516.     ycnt = 0;
  517.     for (j = ytop; (j >= ybottom) ; --j)    /* loop over raster lines */
  518.       {
  519.     if (isNul (BITMAP(j,0)))
  520.       ycnt ++;
  521.     else
  522.     {
  523.         if (ycnt) OUTF("\033*p+%dY",ycnt);
  524.         outline(BITMAP(j,0));
  525.         ycnt = 0;
  526.     }
  527.       }
  528. #else
  529.     for (j = ytop; (j >= ybottom) ; --j)    /* loop over raster lines */
  530.     outline(BITMAP(j,0));
  531. #endif YOFF
  532.  
  533.     OUTS("\033*rB\f");            /* end raster graphics, eject page */
  534.  
  535.     (void)fflush(plotfp);
  536.     if (DISKFULL(plotfp))
  537.     (void)fatal("Output error -- disk storage probably full");
  538. }
  539. #ifdef YOFF
  540. isNul (pbit) UNSIGN32 *pbit;    
  541. {
  542.   UNSIGN32 * p;
  543. #if    IBM_PC_MICROSOFT
  544.   int last_word;
  545.   for (last_word = XBIT - 1;
  546.     (last_word >= 1) && (*(UNSIGN32*)normaddr(pbit,last_word) == 0);
  547.     --last_word)
  548.         ;                /* trim white space a word at a time */
  549.    if (last_word <=1) return 1;
  550.    return 0;
  551. #else
  552.   p = pbit + XBIT - 1;        /* point to last word on line */
  553.   while ( !*p && p>pbit ) p--;
  554.   if (p==pbit) return 1;
  555.   return 0;
  556. #endif IBM_PC_MICROSOFT
  557. }
  558. #endif YOFF
  559.  
  560. #include "outrow.h"
  561. #include "prtpage.h"
  562. #include "readfont.h"
  563. #include "readgf.h"
  564. #include "readpk.h"
  565. #include "readpost.h"
  566. #include "readpxl.h"
  567. #include "reldfont.h"
  568. #include "rulepxl.h"
  569. #include "setchar.h"
  570. #include "setfntnm.h"
  571. #include "setrule.h"
  572. #include "signex.h"
  573. #include "skgfspec.h"
  574. #include "skipfont.h"
  575. #include "skpkspec.h"
  576. #include "special.h"
  577. #include "strchr.h"
  578. #include "strcm2.h"
  579. #include "strid2.h"
  580. #include "strrchr.h"
  581. #include "tctos.h"
  582. #include "usage.h"
  583. #include "warning.h"
  584. --
  585. Paul Kirkaas
  586. kirkaas@cs.ucla.edu
  587.