home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / graphics-0.17 / plot2ps / drawline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  4.5 KB  |  127 lines

  1. /* plot2ps, a utility for converting Unix plot files into postscript.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4. Plot2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY.  No author or distributor accepts responsibility to anyone for the
  6. consequences of using it or for whether it serves any particular purpose or
  7. works at all, unless he says so in writing.  Refer to the GNU General Public
  8. License for full details.
  9.  
  10. Everyone is granted permission to copy, modify and redistribute plot2ps, but
  11. only under the conditions described in the GNU General Public License.  A copy
  12. of this license is supposed to have been given to you along with plot2ps so
  13. you can know your rights and responsibilities.  It should be in a file named
  14. COPYING.  Among other things, the copyright notice and this notice must be
  15. preserved on all copies.  */
  16.  
  17. /* This file is the draw_line routine, which is used by the other plot library
  18.    routines. Coordinates are accumulated in the arrays line_x and line_y.
  19.    The number of points accumulated is stored in PointsInLine. When draw_line
  20.    is called it outputs any accumulated points.  PointsInLine is set to one
  21.    with the first point replaced by the last point of the previous line - so
  22.    that the next line can be a continuation of the previous one. */
  23.  
  24. #include "sys-defines.h"
  25. #include "libplot.h"
  26.  
  27.  
  28. /* plot (3) routines ___________________________________________ */
  29.  
  30. double x_input_min = 0.; /* minimum input x coordinate */
  31. double y_input_min = 0.; /* minimum input y coordinate */
  32. double x_output_min = 0.; /* minimum output x coordinate */
  33. /* Center the plot on the page (11"-8.5")/2 72*dpi /.8 = 90 dots */
  34. double y_output_min = 112.; /* minimum output y coordinate */
  35. /* 8.5 in * 72dpi = 612 dots range: */
  36. /* 8.5 in * 72dpi /.8 = 765 dots range: */
  37. double x_output_max = 765.; /* maximum-minimum output x coordinate */
  38. /* 90 min + 612 range +  = 702 dots max */
  39. /* 112 min + 765 range +  = 877 dots max */
  40. double y_output_max = 877.; /* maximum-minimum output y coordinate */
  41. double scaleup = 10.; /* input to output scaleing for both x and y */
  42.  
  43. int last_x=0, last_y = 0; /* location of the last coordinates used */
  44.  
  45. /* the scaling and rotation part of a postscript transformation matrix */
  46. double text_transformation_matrix[4] =
  47. {
  48.   1., 0., 0., 1.
  49. };
  50.  
  51. /* Note: define MAX_NO_OF_POINTS according to the number of
  52.    points the postscript device can handle.  Experimentation has
  53.    shown 150 to be reasonable */
  54.  
  55. #define MAX_NO_OF_POINTS 150
  56. int line_x[MAX_NO_OF_POINTS];
  57. int line_y[MAX_NO_OF_POINTS];
  58.  
  59. /* We accumulate coordinates untill we either have enought points
  60.    or the line is broken.  The counter tells us whether we have
  61.    accumulated points and how many */
  62.  
  63. int PointsInLine=0;
  64.  
  65. /* this bit vector represents the line style (eg. dashed) for
  66.    idraw.  We intitialize it to all ones which represents a solid
  67.    line. */
  68. long line_type_bit_vector = 65535;
  69.  
  70. /* this is a string that should conatain a postscript vector
  71.    argument for the postscript setdash command.  This is allocted
  72.    in the open(3) function. */
  73. char *line_type_setdash;
  74.  
  75. /* the current length of the above buffer */
  76. int line_type_setdash_length;
  77.  
  78. /* one greater than the length in number of bits in the dash pattern.  */
  79.  
  80. int line_type_setdash_bits=0;
  81.  
  82. /* LINE_WIDTH is the interger value of width of lines drawn. */
  83.  
  84. int line_width = 0;
  85.  
  86.  
  87. /* draw a line using all the accumulated points if there are any. */
  88.  
  89. int
  90. draw_line ()
  91. {
  92.   if (PointsInLine > 1 )
  93.     {
  94.       int i;
  95.       fputs ("Begin %I MLine\n", stdout);
  96.       printf("%%I b %d\n", line_type_bit_vector);
  97.       printf ("%d 0 0 [ %s ] %d SetB\n", line_width, line_type_setdash,
  98.           line_type_setdash_bits);
  99.       printf ("%%I cfg Black\n%g %g %g SetCFg\n",
  100.           fgcolor_red, fgcolor_green, fgcolor_blue);
  101.       fputs ("%I cbg White\n1 1 1 SetCBg\n", stdout);
  102.       if (fill_level == -1.)
  103.     {
  104.       printf ("%%I p\nnone SetP\n");
  105.     }
  106.       else
  107.     {
  108.       printf ("%%I p\n%g SetP\n", fill_level);
  109.     }
  110.       printf ("%%I t\n[ %g 0 0 %g %g %g ] concat\n", 1./scaleup, 1./scaleup,
  111.           x_output_min, y_output_min);
  112.       printf("%%I %d\n", PointsInLine);
  113.       for (i=0; i<PointsInLine; i++)
  114.     {
  115.       printf ("%d %d\n", line_x[i], line_y[i]);
  116.       set_range (line_x[i]/scaleup, line_y[i]/scaleup);
  117.     }
  118.       printf ("%d MLine\nEnd\n\n", PointsInLine);
  119.  
  120.       /* leave the last point as the first point of the next line */
  121.       line_x[0] = line_x [PointsInLine - 1];
  122.       line_y[0] = line_y [PointsInLine - 1];
  123.       PointsInLine = 1;
  124.     }
  125.   return 0;
  126. }
  127.