home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / avogl.tar.gz / avogl.tar / vogl / drivers / hpdxy.c < prev    next >
C/C++ Source or Header  |  1992-09-22  |  6KB  |  439 lines

  1. /*
  2.  *    DXY & HPGL Driver for vogl.
  3.  */
  4. #include <stdio.h>
  5. #include "vogl.h"
  6.  
  7. extern FILE    *_voutfile();
  8.  
  9. static int    plotlstx, plotlsty;    /* position of last draw */
  10.  
  11. static FILE    *fp;
  12.  
  13. #define    P_RESET        0
  14. #define    P_MOVE        1
  15. #define    P_DRAW        2
  16. #define    P_TXTSIZE    3
  17. #define    P_BEGTXT    4
  18. #define    P_ENDTXT    5
  19. #define    P_PEN        6
  20.  
  21. /*
  22.  * basic commands for hpgl
  23.  */
  24. static char    *hpgl[] = {
  25.     "DF;\n",
  26.     "PU %d %d;\n",
  27.     "PD %d %d;\n",
  28.     "SI %.4f %.4f;\n",
  29.     "LB",
  30.     "\003\n",
  31.     "SP %d;\n"
  32. };
  33.  
  34. /*
  35.  * basic commands for dxy
  36.  */
  37. static char    *dxy[] = {
  38.     "",
  39.     "M %d,%d\n",
  40.     "D %d,%d\n",
  41.     "S %d\n",
  42.     "P",
  43.     "\n",
  44.     "J %d\n"
  45. };
  46.  
  47. static char    **plotcmds;
  48.  
  49. /*
  50.  * noop
  51.  *
  52.  *      do nothing but return-1
  53.  */
  54. static int
  55. noop()
  56. {
  57.     return(-1);
  58. }
  59.  
  60. /*
  61.  * HPGL_init
  62.  *
  63.  *    set up hp plotter. Returns 1 on success.
  64.  */
  65.  
  66. static int
  67. HPGL_A4_init()
  68. {
  69.     /*
  70.      * A4 paper
  71.      */
  72.     vdevice.sizeX = vdevice.sizeY = 7320;
  73.  
  74.     vdevice.sizeSx = 10200;
  75.     vdevice.sizeSy = 7320;
  76.  
  77.     return(HPGL_common_init(-3660, 3660, -3660, 3660));
  78. }
  79.  
  80. static int
  81. HPGL_A3_init()
  82. {
  83.     /*
  84.      * A3 paper
  85.      */
  86.     vdevice.sizeX = vdevice.sizeY = 10560;
  87.  
  88.     vdevice.sizeSx = 14720; 
  89.     vdevice.sizeSy = 10560; 
  90.  
  91.     return(HPGL_common_init(-5280, 5280, -5280, 5280));
  92. }
  93.  
  94. static int
  95. HPGL_A2_init()
  96. {
  97.     /*
  98.      * A2 paper
  99.      */
  100.     vdevice.sizeX = vdevice.sizeY = 13440;
  101.  
  102.     vdevice.sizeSx = 18734;
  103.     vdevice.sizeSy = 13440;
  104.  
  105.     return(HPGL_common_init(-6720, 6720, -6720, 6720));
  106. }
  107.  
  108. static int
  109. HPGL_A1_init()
  110. {
  111.     /*
  112.      * A1 paper
  113.      */
  114.     vdevice.sizeX = vdevice.sizeY = 21360;
  115.  
  116.     vdevice.sizeSx = 29774;
  117.     vdevice.sizeSy = 21360;
  118.  
  119.     return(HPGL_common_init(-10680, 10680, -10680, 10680));
  120. }
  121.  
  122. /*
  123.  * HPGL_common_init()
  124.  *
  125.  * Performs the common parts of HPGL initialization.
  126.  */
  127. static int
  128. HPGL_common_init(minx, maxx, miny, maxy)
  129.     int    minx, maxx, miny, maxy;
  130. {
  131.     vdevice.depth = 4;
  132.  
  133.     fp = _voutfile();
  134.  
  135.     /*
  136.      * The next line is for serial lines if you need to set modes
  137.      */
  138.     fprintf(fp, "\033.(;\033.I81;;17;\033.N;19:IN;");
  139.  
  140.     /*
  141.      * Cause scaling to be 0 to maxX maxY.
  142.      */
  143.     fprintf(fp, "IP %d,%d,%d,%d;", minx, miny, maxx, maxy);
  144.  
  145.     fprintf(fp, "SC 0,%d,0,%d;", vdevice.sizeX, vdevice.sizeY);
  146.  
  147.     plotcmds = hpgl;
  148.     plotlstx = -1111111;
  149.     plotlsty = -1111111;
  150.  
  151.     return(1);
  152. }
  153.  
  154. /*
  155.  * DXY_init
  156.  *
  157.  *    set up dxy plotter. Returns 1 on success.
  158.  */
  159. static int
  160. DXY_init()
  161. {
  162.     fp = _voutfile();
  163.  
  164.     vdevice.sizeX = vdevice.sizeY = 1920; 
  165.  
  166.     vdevice.sizeSx = 2668; 
  167.     vdevice.sizeSy = 1920; 
  168.  
  169.     plotcmds = dxy;
  170.     plotlstx = -1;
  171.     plotlsty = -1;
  172.  
  173.     fprintf(fp, plotcmds[P_RESET]);
  174.  
  175.     return(1);
  176. }
  177.  
  178. /*
  179.  * PLOT_draw
  180.  *
  181.  *    print the commands to draw a line from the current graphics position
  182.  * to (x, y).
  183.  */
  184. static
  185. PLOT_draw(x, y)
  186.     int    x, y;
  187. {
  188.     if (plotlstx != vdevice.cpVx || plotlsty != vdevice.cpVy)
  189.         fprintf(fp, plotcmds[P_MOVE], vdevice.cpVx, vdevice.cpVy);
  190.  
  191.     fprintf(fp, plotcmds[P_DRAW], x, y);
  192.     plotlstx = x;
  193.     plotlsty = y;
  194. }
  195.  
  196. /*
  197.  * PLOT_exit
  198.  *
  199.  *    exit from vogl printing the command to put away the pen and flush
  200.  * the buffer.
  201.  */
  202. static
  203. PLOT_exit()
  204. {
  205.     fprintf(fp, plotcmds[P_PEN], 0);
  206.     fflush(fp);
  207.  
  208.     if (fp != stdout)
  209.         fclose(fp);
  210. }
  211.  
  212. /*
  213.  * PLOT_color
  214.  *
  215.  *    change the current pen number.
  216.  */
  217. static
  218. PLOT_color(i)
  219.     int    i;
  220.     fprintf(fp, plotcmds[P_PEN], i);
  221. }
  222.  
  223. /*
  224.  * HPGL_font
  225.  *
  226.  *    load in large or small
  227.  */
  228. static int
  229. HPGL_font(font)
  230.     char    *font;
  231. {
  232.     if (strcmp(font, "small") == 0) {
  233.         vdevice.hwidth = 97.01;    /* Size in plotter resolution units */
  234.         vdevice.hheight = vdevice.hwidth * 2.0;
  235.         fprintf(fp, plotcmds[P_TXTSIZE], 0.16, 0.32);
  236.     } else if (strcmp(font, "large") == 0) {
  237.         vdevice.hwidth = 145.5;
  238.         vdevice.hheight = vdevice.hwidth * 2.0;
  239.         fprintf(fp, plotcmds[P_TXTSIZE], 0.24, 0.48);
  240.     } else 
  241.         return(0);
  242.  
  243.     return(1);
  244. }
  245.  
  246. /*
  247.  * DXY_font
  248.  *
  249.  *    load in large or small.
  250.  */
  251. static int
  252. DXY_font(font)
  253.     char    *font;
  254. {
  255.     if (strcmp(font, "small") == 0) {
  256.         vdevice.hwidth = 24.25;
  257.         vdevice.hheight = vdevice.hwidth * 2.0;
  258.         fprintf(fp, plotcmds[P_TXTSIZE], 3);
  259.     } else if (strcmp(font, "large") == 0) {
  260.         vdevice.hwidth = 36.375;
  261.         vdevice.hheight = vdevice.hwidth * 2.0;
  262.         fprintf(fp, plotcmds[P_TXTSIZE], 5);
  263.     } else 
  264.         return(0);
  265.  
  266.     return(1);
  267. }
  268.  
  269. /*
  270.  * PLOT_char
  271.  *
  272.  *    draw a character.
  273.  */
  274. static
  275. PLOT_char(c)
  276.     char    c;
  277. {
  278.     int    dy, dx;
  279.  
  280.     if (plotlstx != vdevice.cpVx || plotlsty != vdevice.cpVy)
  281.         fprintf(fp, plotcmds[P_MOVE], vdevice.cpVx, vdevice.cpVy);
  282.  
  283.     fprintf(fp, plotcmds[P_BEGTXT]);
  284.  
  285.     fprintf(fp, "%c", c);
  286.  
  287.     fprintf(fp, plotcmds[P_ENDTXT]);
  288.  
  289.     plotlstx = plotlsty = -1111111;
  290. }
  291.  
  292. /*
  293.  * PLOT_string
  294.  *
  295.  *    output a string.
  296.  */
  297. static
  298. PLOT_string(s)
  299.     char    *s;
  300. {
  301.     int        dy, dx;
  302.  
  303.     if (plotlstx != vdevice.cpVx || plotlsty != vdevice.cpVy)
  304.         fprintf(fp, plotcmds[P_MOVE], vdevice.cpVx, vdevice.cpVy);
  305.  
  306.     fprintf(fp, plotcmds[P_BEGTXT]);
  307.  
  308.     fputs(s, fp);
  309.  
  310.     fprintf(fp, plotcmds[P_ENDTXT]);
  311.  
  312.     plotlstx = plotlsty = -1111111;
  313. }
  314.  
  315. /*
  316.  * PLOT_fill
  317.  *
  318.  *      "fill" a polygon
  319.  */
  320. static
  321. PLOT_fill(n, x, y)
  322.     int     n, x[], y[];
  323. {
  324.     int     i;
  325.  
  326.     if (plotlstx != x[0] || plotlsty != y[0])
  327.         fprintf(fp, plotcmds[P_MOVE], x[0], y[0]);
  328.  
  329.     for (i = 1; i < n; i++)
  330.         fprintf(fp, plotcmds[P_DRAW], x[i], y[i]);
  331.  
  332.     fprintf(fp, plotcmds[P_DRAW], x[0], y[0]);
  333.  
  334.     plotlstx = vdevice.cpVx = x[n - 1];
  335.     plotlsty = vdevice.cpVy = y[n - 1];
  336. }
  337.  
  338. static DevEntry hpgldev = {
  339.     "hpgl",
  340.     "large",
  341.     "small",
  342.     noop,
  343.     PLOT_char,
  344.     noop,
  345.     noop,
  346.     PLOT_color,
  347.     PLOT_draw,
  348.     PLOT_exit,
  349.     PLOT_fill,
  350.     HPGL_font,
  351.     noop,
  352.     noop,
  353.     HPGL_A2_init,
  354.     noop,
  355.     noop,
  356.     PLOT_string
  357. };
  358.  
  359. /*
  360.  * _HPGL_devcpy
  361.  *
  362.  *    copy the HPGL device into vdevice.dev.
  363.  */
  364. _HPGL_A2_devcpy()
  365. {
  366. /* if you don't have structure assignment ...
  367.     char    *dev, *tdev, *edev;
  368.  
  369.     dev = (char *)&hpgldev;
  370.     tdev = (char *)&vdevice.dev;
  371.     edev = dev + sizeof(Device);
  372.  
  373.     while (dev != edev)
  374.         *tdev++ = *dev++;
  375. */
  376.     vdevice.dev = hpgldev;
  377. }
  378.  
  379. _HPGL_A3_devcpy()
  380. {
  381.     vdevice.dev = hpgldev;
  382.     vdevice.dev.Vinit = HPGL_A3_init;
  383. }
  384.  
  385. _HPGL_A4_devcpy()
  386. {
  387.     vdevice.dev = hpgldev;
  388.     vdevice.dev.Vinit = HPGL_A4_init;
  389. }
  390.  
  391. _HPGL_A1_devcpy()
  392. {
  393.     vdevice.dev = hpgldev;
  394.     vdevice.dev.Vinit = HPGL_A1_init;
  395. }
  396.  
  397. static DevEntry dxydev = {
  398.     "dxy",
  399.     "large",
  400.     "small",
  401.     noop,
  402.     PLOT_char,
  403.     noop,
  404.     noop,
  405.     PLOT_color,
  406.     PLOT_draw,
  407.     PLOT_exit,
  408.     PLOT_fill,
  409.     DXY_font,
  410.     noop,
  411.     noop,
  412.     DXY_init,
  413.     noop,
  414.     noop,
  415.     PLOT_string,
  416.     noop,
  417. };
  418.  
  419. /*
  420.  * _DXY_devcpy
  421.  *
  422.  *    copy the DXY device into vdevice.dev.
  423.  */
  424. _DXY_devcpy()
  425. {
  426. /* if you don't have structure assignment ...
  427.     char    *dev, *tdev, *edev;
  428.  
  429.     dev = (char *)&dxydev;
  430.     tdev = (char *)&vdevice.dev;
  431.     edev = dev + sizeof(DevEntry);
  432.  
  433.     while (dev != edev)
  434.         *tdev++ = *dev++;
  435. */
  436.     vdevice.dev = dxydev;
  437. }
  438.