File: f_openpl.c

package info (click to toggle)
plotutils 2.0-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,964 kB
  • ctags: 2,522
  • sloc: ansic: 38,416; sh: 1,853; yacc: 856; makefile: 181; lex: 144
file content (75 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* This file contains the openpl method, which is a standard part of
   libplot.  It opens a Plotter object.

   For FigPlotter objects, we print out the fig header, and initialize the
   buffer in which we'll store all genuine objects.  There is only one
   class of non-genuine objects; ``color pseudo-objects'', which are
   handled separately.  The closepl() routine will write out the color
   pseudo-objects first, as xfig demands, and then write out the stored
   genuine objects.

   We also determine the page size and the location on the page of the
   graphics display, so that we'll be able to work out the map from user
   coordinates to device coordinates in space.c. */

#include "sys-defines.h"
#include "plot.h"
#include "extern.h"

int
#ifdef _HAVE_PROTOS
_f_openpl (void)
#else
_f_openpl ()
#endif
{
  const char *length_s, *pagesize;
  const Pagedata *pagedata;

  if (_plotter->open)
    {
      _plotter->error ("openpl: invalid operation");
      return -1;
    }

  /* initialize certain data members from values of relevant class variables */

  length_s = (const char *)_get_plot_param ("MAX_LINE_LENGTH");
  {
    int local_length;
    
    if (sscanf (length_s, "%d", &local_length) <= 0 || local_length <= 0)
      {
	_plotter->error ("bad MAX_LINE_LENGTH parameter, can't initialize");
	return -1;
      }
    else
      _plotter->max_unfilled_polyline_length = local_length;
  }

  /* determine page type i.e. determine the range of device coordinates
   over which the graphics display will extend (and hence the
   transformation from user to device coordinates). */
  pagesize = (const char *)_get_plot_param ("PAGESIZE");
  pagedata = _pagetype(pagesize);
  if (pagedata == NULL)
    {
      _plotter->error ("bad PAGESIZE variable, can't initialize");
      return -1;
    }
  _plotter->display_coors = pagedata->fig;
  _plotter->fig_use_metric = pagedata->metric;

  /* prepare the buffer in which we'll store all [genuine] objects */
  _initialize_buffer (&_plotter->outbuf);

  /* flag device as open */
  _plotter->open = true;
  _plotter->opened = true;

  /* create drawing state, add it as the first member of the linked list */
  _plotter->savestate();			

  return 0;
}