home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / DRIVERS / HPDXY.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  7KB  |  467 lines

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