home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_02 / hpljii.trm < prev    next >
Text File  |  1991-02-05  |  7KB  |  236 lines

  1. /* GNUPLOT - hpljii.trm */
  2. /*
  3.  * Copyright (C) 1990   
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *  hpljii_75dpi, hpljii_100dpi, hpljii_150dpi, hpljii_300dpi
  21.  *
  22.  * AUTHORS
  23.  *  John Engels
  24.  *  Russell Lang
  25.  *
  26.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  27.  * 
  28.  */
  29.  
  30. /* The following HP laserjet series II driver uses generic bit mapped graphics
  31.    routines from bitmap.c to build up a bit map in memory.  The driver
  32.    interchanges colomns and lines in order to access entire lines
  33.    easily and returns the lines to get bits in the right order :
  34.    (x,y) -> (y,XMAX-1-x). */
  35. /* This interchange is done by calling b_makebitmap() with reversed 
  36.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  37.    will then perform the interchange before each pixel is plotted */
  38. /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
  39.    of Jyrki Yli-Nokari */
  40.  
  41. #ifdef HPLJII
  42.  
  43. /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
  44.    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
  45.  
  46. #define HPLJII_DPP (hplj_dpp)   /* dots per pixel */
  47. #define HPLJII_PPI (300/HPLJII_DPP) /* pixel per inch */
  48. #define HPLJII_XMAX (8*(unsigned int)(xsize*1920/HPLJII_DPP/8.0+0.9))
  49. #define HPLJII_YMAX (8*(unsigned int)(ysize*1920/HPLJII_DPP/8.0+0.9))
  50. #define HPLJII_300PPI_XMAX (1920/1)
  51. #define HPLJII_300PPI_YMAX (1920/1)
  52. #define HPLJII_150PPI_XMAX (1920/2)
  53. #define HPLJII_150PPI_YMAX (1920/2)
  54. #define HPLJII_100PPI_XMAX (1920/3)
  55. #define HPLJII_100PPI_YMAX (1920/3)
  56. #define HPLJII_75PPI_XMAX (1920/4)
  57. #define HPLJII_75PPI_YMAX (1920/4)
  58.  
  59. #define HPLJII_XLAST (HPLJII_XMAX-1)
  60. #define HPLJII_YLAST (HPLJII_YMAX-1)
  61.  
  62. #define HPLJII_VCHAR (HPLJII_PPI/6) /* Courier font with 6 lines per inch */
  63. #define HPLJII_HCHAR (HPLJII_PPI/10) /* Courier font with 10 caracters
  64.                                         per inch */
  65. #define HPLJII_300PPI_VCHAR (300/6)
  66. #define HPLJII_300PPI_HCHAR (300/10)
  67. #define HPLJII_150PPI_VCHAR (150/6)
  68. #define HPLJII_150PPI_HCHAR (150/10)
  69. #define HPLJII_100PPI_VCHAR (100/6)
  70. #define HPLJII_100PPI_HCHAR (100/10)
  71. #define HPLJII_75PPI_VCHAR (75/6)
  72. #define HPLJII_75PPI_HCHAR (75/10)
  73.  
  74. #define HPLJII_300PPI_VTIC 8 /* Use smaller tics with greater resolution */
  75. #define HPLJII_300PPI_HTIC 8
  76. #define HPLJII_150PPI_VTIC 6
  77. #define HPLJII_150PPI_HTIC 6
  78. #define HPLJII_100PPI_VTIC 6
  79. #define HPLJII_100PPI_HTIC 6
  80. #define HPLJII_75PPI_VTIC 5
  81. #define HPLJII_75PPI_HTIC 5
  82.  
  83. #define HPLJII_PUSH_CURSOR fprintf(outfile,"\033&f0S") /* Save current
  84.                   cursor position */
  85. #define HPLJII_POP_CURSOR fprintf(outfile,"\033&f1S") /* Restore
  86.                   cursor position */
  87. #define HPLJII_COURIER fprintf(outfile,"\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D")
  88.          /* be sure to use courier font with 6lpi and 10cpi */
  89.  
  90. static int hplj_dpp;
  91. /* bm_pattern not appropriate for 300ppi graphics */
  92. static unsigned int b_300ppi_pattern[] = {0xffff, 0x1111,
  93.         0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff};
  94.  
  95. HPLJIIinit()
  96. {
  97. #ifdef vms
  98.    reopen_binary();
  99. #endif /* vms */
  100. #ifdef PC
  101.    reopen_binary();
  102. #endif /* PC */
  103. }
  104.  
  105. HPLJII_300PPIgraphics()
  106. {
  107.    hplj_dpp = 1;
  108.    HPLJIIgraphics();
  109. }
  110.  
  111. HPLJII_150PPIgraphics()
  112. {
  113.    hplj_dpp = 2;
  114.    HPLJIIgraphics();
  115. }
  116.  
  117. HPLJII_100PPIgraphics()
  118. {
  119.    hplj_dpp = 3;
  120.    HPLJIIgraphics();
  121. }
  122.  
  123. HPLJII_75PPIgraphics()
  124. {
  125.    hplj_dpp = 4;
  126.    HPLJIIgraphics();
  127. }
  128.  
  129. HPLJIIgraphics()
  130. {
  131.    HPLJII_COURIER;
  132.    HPLJII_PUSH_CURSOR;
  133.    /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  134.       setting b_rastermode to TRUE */
  135.    b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  136.    b_rastermode = TRUE;
  137. }
  138.  
  139.  
  140. /* HPLJIItext by rjl - no compression */
  141. HPLJIItext()
  142. {
  143.   register int x,j,row;
  144.  
  145.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  146.    HPLJII_POP_CURSOR;
  147.    fprintf(outfile, "\033*r1A");
  148.  
  149.    /* dump bitmap in raster mode */
  150.    for (x = b_xsize-1; x >= 0; x--) {
  151.       row = (b_ysize/8)-1;
  152.       fprintf(outfile, "\033*b2m%dW", b_ysize/8);
  153.       for (j = row; j >= 0; j--) {
  154.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  155.       }
  156.    }
  157.    fprintf(outfile, "\033*rB");
  158.  
  159.    b_freebitmap();
  160.  
  161. #ifndef vms  /* most vms spoolers add a formfeed character */
  162.    fprintf(outfile,"\f");
  163. #endif /* not vms */
  164. }
  165.  
  166.  
  167.  
  168. HPLJIIlinetype(linetype)
  169. int linetype;
  170. {
  171.  
  172.    if (hplj_dpp == 1) {
  173.       if (linetype>=7)
  174.           linetype %= 7;
  175.       /* b_pattern not appropriate for 300ppi graphics */
  176.       b_linemask = b_300ppi_pattern[linetype+2];
  177.       b_maskcount=0;
  178.    }
  179.    else {
  180.       b_setlinetype(linetype);
  181.    }
  182. }
  183.  
  184. #define HPLJIImove b_move
  185. #define HPLJIIvector b_vector
  186. #define HPLJIItext_angle b_text_angle
  187.  
  188. HPLJIIput_text(x,y,str)
  189. unsigned int x, y;
  190. char *str;
  191. {
  192.    switch (b_angle) {
  193.       case 0:
  194.          y -= HPLJII_VCHAR/5;
  195.          HPLJII_POP_CURSOR;
  196.          HPLJII_PUSH_CURSOR;
  197.          /* (0,0) is the upper left point of the paper */
  198.          fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  199.                                          ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  200.          fputs(str, outfile);
  201. /*       for (; *str; ++str, x += HPLJII_HCHAR)
  202.             HPLJIIputc (x, y, *str, b_angle);*/
  203.          break;
  204.       case 1:
  205.          y += (HPLJII_HCHAR-2*HPLJII_VCHAR)/2;
  206.          y += (HPLJII_VCHAR+HPLJII_HCHAR)*strlen(str)/2;
  207.          for (; *str; ++str, y -= HPLJII_VCHAR)
  208.             HPLJIIputc (x, y, *str, b_angle);
  209.          break;
  210.    }
  211. }
  212.  
  213. HPLJIIputc(x,y,c,angle)
  214. unsigned int x,y;
  215. int angle;
  216. char c;
  217. {
  218.    HPLJII_POP_CURSOR;
  219.    HPLJII_PUSH_CURSOR;
  220.    /* (0,0) is the upper left point of the paper */
  221.    fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  222.                                    ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  223.    fputc(c, outfile);
  224. }
  225.  
  226.  
  227. HPLJIIreset()
  228. {
  229. #ifdef vms
  230.    fflush_binary();
  231. #endif /* vms */
  232. }
  233.  
  234. #endif /* HPLJII */
  235.  
  236.