home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / gnuplot1.10A / part02 / hpljet.trm < prev    next >
Encoding:
Text File  |  1989-09-09  |  6.2 KB  |  233 lines

  1. /*
  2. ** Hewlett-Packard Laserjet
  3. ** Driver written and copyrighted 1987 by
  4. ** Jyrki Yli-Nokari (jty@intrin.UUCP)
  5. ** Intrinsic, Ltd.
  6. ** 
  7. ** You may use this code for anything you like as long as
  8. ** you are not selling it and the credit is given and
  9. ** this message retained.
  10. */
  11.  
  12. /*
  13. ** Here is the GNUPLOT HP Laserjet driver I promised to send to the net.
  14. ** Following is a set of diffs to the GNUPLOT version V1.1 term.c
  15. ** In case you don't have the patch program, you must insert the diffs
  16. ** by hand. This should be fairly easy with a proper editor
  17. ** since they are almost in one piece.
  18. **
  19. ** Also there are some fixes to the HP26xx driver that was in the
  20. ** V1.1 distribution.
  21. **
  22. ** To get the laserjet driver, add -DHPLJET to TERMFLAGS in Makefile
  23. ** (/DHPLJET in make.msc and HPLJET in compile.com).
  24. **
  25. ** The driver consists of two parts: general raster plotting routines
  26. ** (#ifdef RASTER) and the laserjet driver using them (#ifdef HPLJET).
  27. **
  28. ** The laserjet driver contains actually three different "terminal types":
  29. ** laserjet1, laserjet2 and laserjet3. The difference between them is the size
  30. ** of the picture "laserjet3" being the biggest.
  31. */
  32.  
  33. /*
  34. ** NOTE:
  35. ** When sending the plot to the laserjet there must be absolutely
  36. ** NO character translation done by the operating system.
  37. ** Normally, in UNIX, the (operating system) terminal driver
  38. ** translates newlines to CR/LF pairs. This is called the "cooked mode".
  39. ** Some operating systems might add CR/LF pairs if they think there
  40. ** is a too long line. ALL THIS IS STRICTLY PROHIBITED.
  41. ** ALL DATA TO THE LASERJET MUST BE SENT WHEN THE LINE IS IN RAW MODE.
  42. **
  43.  
  44. /*
  45. ** The laserjet math is a pain since we have to deal with
  46. ** decipoints (720/inch), dots (300/inch), pixels (100-300/inch),
  47. ** characters (10/inch horiz., 6/inch vertic.) and the size of
  48. ** the plottable surface in A4 (about 7.8 inches horizontally).
  49. ** On top of this we also support different plot sizes!
  50. */
  51.  
  52. #define HPLJET_PIXSIZE    (hpljet_pixel)
  53.         /* Laserjet pixel size in laserjet minimum dots */
  54. #define HPLJET_PPI (300/HPLJET_PIXSIZE)
  55.         /* Laserjet raster scaling factor, Pixels Per Inch */
  56. #define HPLJET_WIDTH 5600
  57.         /* ~ Number of horizontal decipoints in A4 */
  58. #define HPLJET_IN2DP(x) (720*(x))
  59.         /* convert INches TO DeciPoints */
  60. #define HPLJET_PX2DP(x) (HPLJET_IN2DP(x)/HPLJET_PPI)
  61.         /* convert PiXels TO DeciPoints */
  62. #define HPLJET_HC2DP(x) (72*(x))
  63.         /* convert Horizontal Characters TO DeciPoints */
  64. #define HPLJET_VC2DP(x) (120*(x))
  65.         /* convert Vertical Characters TO DeciPoints */
  66. #define HPLJET_LMARG ((HPLJET_WIDTH - HPLJET_PX2DP(HPLJETXMAX))/2)
  67.         /* Picture left margin in decipoints */
  68. #define HPLJET_RMARG ((HPLJET_WIDTH + HPLJET_PX2DP(HPLJETXMAX))/2)
  69.         /* Picture right margin in decipoints */
  70. #define HPLJETXMAX 640
  71.         /* Number of pixels in X-axis */
  72. #define HPLJETYMAX 640
  73.         /* Number of pixels in Y-axis */
  74. #define HPLJETXLAST (HPLJETXMAX - 1)
  75.         /* Last valid X-pixel value */
  76. #define HPLJETYLAST (HPLJETYMAX - 1)
  77.         /* Last valid Y-pixel value */
  78.  
  79. #define HPLJETVCHAR    (HPLJET_PPI/6)
  80.         /* Vertical pixel size of the character font */
  81. #define HPLJETHCHAR    (HPLJET_PPI/10)
  82.         /* Horizontal pixel size of the character font */
  83. #define HPLJET1VCHAR    (300/6)
  84.         /* Vertical pixel size of the character font */
  85. #define HPLJET1HCHAR    (300/10)
  86.         /* Horizontal pixel size of the character font */
  87. #define HPLJET2VCHAR    (150/6)
  88.         /* Vertical pixel size of the character font */
  89. #define HPLJET2HCHAR    (150/10)
  90.         /* Horizontal pixel size of the character font */
  91. #define HPLJET3VCHAR    (100/6)
  92.         /* Vertical pixel size of the character font */
  93. #define HPLJET3HCHAR    (100/10)
  94.         /* Horizontal pixel size of the character font */
  95. /*
  96. ** (I guess) VTIC and HTIC are used as
  97. ** "small units that look like equal length".
  98. ** They determine (at least) the length of "bars" in axises and
  99. ** the size of plotting symbols.
  100. */
  101. #define HPLJETVTIC        6
  102. #define HPLJETHTIC        6
  103.  
  104. /*
  105. ** We use laserjet1, laserjet2 and laserjet3 for different
  106. ** pixel sizes of the picture (1 is the smallest).
  107. ** The size of the text, however, remains the same.
  108. ** These three terminal types use mostly the same
  109. ** functions, only the init-function determines the size of the picture.
  110. ** Also, the h_char and v_char are different, but they are
  111. ** not used.
  112. */
  113.  
  114. /*
  115. ** Initialize (once) for graphics
  116. */
  117. static int hpljet_pixel = 3;
  118.  
  119. HPLJET1init()
  120. {
  121.     hpljet_pixel = 1;
  122. }
  123.  
  124. HPLJET2init()
  125. {
  126.     hpljet_pixel = 2;
  127. }
  128.  
  129. HPLJET3init()
  130. {
  131.     hpljet_pixel = 3;
  132. }
  133.  
  134. HPLJETmove(x, y)
  135. {
  136.     r_move((unsigned)x, (unsigned)y);
  137. }
  138.  
  139. HPLJETvector(x, y)
  140. {
  141.     r_draw((unsigned)x, (unsigned)y, (pixel)1);
  142. }
  143.  
  144. /*
  145. ** Enter graphics mode:
  146. **    - allocate raster buffer
  147. **    - set resolution
  148. */
  149. HPLJETgraphics()
  150. {
  151.     r_makeraster(HPLJETXMAX, HPLJETYMAX);
  152.     fprintf(outfile,"\033*t%dR", HPLJET_PPI);
  153. /*                                 1
  154. **    1. Set resolution pixels/inch
  155. */
  156. }
  157.  
  158. /*
  159. ** (re-)enter text mode,
  160. ** output raster and deallocate it.
  161. */
  162. HPLJETtext()
  163. {
  164.     int x, y;
  165.     unsigned v, i;
  166.  
  167.     fprintf(outfile, "\033&a%dH\033&a%dV", HPLJET_LMARG, HPLJET_VC2DP(2));
  168.     fprintf(outfile, "\033*r1A");
  169.     for (y = r_ysize-1; y >= 0; y--) {
  170.         fprintf(outfile, "\033*b%dW", r_xsize/8);
  171.         for (x = 0; x < r_xsize; x += 8) {
  172.             v = 0;
  173.             for (i = 0; i < 8; i++) {
  174.                 v = (v << 1) | r_getpixel((unsigned)x + i, (unsigned)y);
  175.             }
  176.             putc((char)v, outfile);
  177.         }
  178.     }
  179.     r_freeraster();
  180.     fprintf(outfile, "\033*rB\f");
  181. }
  182.  
  183. /*
  184. ** Select line type [-2:8]
  185. ** line types:
  186. **    -2 = border line
  187. **    -1 = x/y axis line
  188. **    0-8 = function plot lines.
  189. **    Dummy function here.
  190. */
  191. HPLJETlinetype(linetype)
  192. int linetype;
  193. {
  194. }
  195.  
  196. /*
  197. ** Put text "str" to the lower right corner of the screen.
  198. ** "row" is the row number [0:1].
  199. ** Actually in the laserjet, put the text above the upper right corner.
  200. */
  201. HPLJETlrput_text(row,str)
  202. unsigned int row;
  203. char str[];
  204. {
  205.     
  206.     fprintf(outfile, "\033&a%dH\033&a%dV",
  207.             HPLJET_RMARG - HPLJET_HC2DP(strlen(str)), HPLJET_VC2DP(row));
  208.     fputs(str, outfile);
  209. }
  210.  
  211. /*
  212. ** Put text "str" to the upper left corner of the screen.
  213. ** "row" is the (serial) number of function to be plotted.
  214. ** Actually in the laserjet, put the text under the lower left corner.
  215. */
  216. HPLJETulput_text(row,str)
  217. unsigned int row;
  218. char str[];
  219. {
  220.     fprintf(outfile, "\033&a%dH\033&a%dV",
  221.             HPLJET_LMARG,
  222.             HPLJET_VC2DP(row+3)+HPLJET_PX2DP(HPLJETYMAX));
  223.     fputs(str, outfile);
  224. }
  225.  
  226. /*
  227. ** RETURN to normal mode (exit gnuplot)
  228. */
  229. HPLJETreset()
  230. {
  231. }
  232.  
  233.