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