1// -*- C++ -*-
2/* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004
3   Free Software Foundation, Inc.
4     Written by James Clark (jjc@jclark.com)
5
6This file is part of groff.
7
8groff is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12
13groff is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License along
19with groff; see the file COPYING.  If not, write to the Free Software
20Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21
22struct place;
23
24enum object_type {
25  OTHER_OBJECT,
26  BOX_OBJECT,
27  CIRCLE_OBJECT,
28  ELLIPSE_OBJECT,
29  ARC_OBJECT,
30  SPLINE_OBJECT,
31  LINE_OBJECT,
32  ARROW_OBJECT,
33  MOVE_OBJECT,
34  TEXT_OBJECT,
35  BLOCK_OBJECT,
36  MARK_OBJECT
37  };
38
39struct bounding_box;
40
41struct object {
42  object *prev;
43  object *next;
44  object();
45  virtual ~object();
46  virtual position origin();
47  virtual double width();
48  virtual double radius();
49  virtual double height();
50  virtual position north();
51  virtual position south();
52  virtual position east();
53  virtual position west();
54  virtual position north_east();
55  virtual position north_west();
56  virtual position south_east();
57  virtual position south_west();
58  virtual position start();
59  virtual position end();
60  virtual position center();
61  virtual place *find_label(const char *);
62  virtual void move_by(const position &);
63  virtual int blank();
64  virtual void update_bounding_box(bounding_box *);
65  virtual object_type type() = 0;
66  virtual void print();
67  virtual void print_text();
68};
69
70typedef position (object::*corner)();
71
72struct place {
73  object *obj;
74  double x, y;
75};
76
77struct string_list;
78
79class path {
80  position pos;
81  corner crn;
82  string_list *label_list;
83  path *ypath;
84  int is_position;
85public:
86  path(corner = 0);
87  path(position);
88  path(char *, corner = 0);
89  ~path();
90  void append(corner);
91  void append(char *);
92  void set_ypath(path *);
93  int follow(const place &, place *) const;
94};
95
96struct object_list {
97  object *head;
98  object *tail;
99  object_list();
100  void append(object *);
101  void wrap_up_block(object_list *);
102};
103
104declare_ptable(place)
105
106// these go counterclockwise
107enum direction {
108  RIGHT_DIRECTION,
109  UP_DIRECTION,
110  LEFT_DIRECTION,
111  DOWN_DIRECTION
112  };
113
114struct graphics_state {
115  double x, y;
116  direction dir;
117};
118
119struct saved_state : public graphics_state {
120  saved_state *prev;
121  PTABLE(place) *tbl;
122};
123
124
125struct text_item {
126  text_item *next;
127  char *text;
128  adjustment adj;
129  const char *filename;
130  int lineno;
131
132  text_item(char *, const char *, int);
133  ~text_item();
134};
135
136const unsigned long IS_DOTTED = 01;
137const unsigned long IS_DASHED = 02;
138const unsigned long IS_CLOCKWISE = 04;
139const unsigned long IS_INVISIBLE = 020;
140const unsigned long HAS_LEFT_ARROW_HEAD = 040;
141const unsigned long HAS_RIGHT_ARROW_HEAD = 0100;
142const unsigned long HAS_SEGMENT = 0200;
143const unsigned long IS_SAME = 0400;
144const unsigned long HAS_FROM = 01000;
145const unsigned long HAS_AT = 02000;
146const unsigned long HAS_WITH = 04000;
147const unsigned long HAS_HEIGHT = 010000;
148const unsigned long HAS_WIDTH = 020000;
149const unsigned long HAS_RADIUS = 040000;
150const unsigned long HAS_TO = 0100000;
151const unsigned long IS_CHOPPED = 0200000;
152const unsigned long IS_DEFAULT_CHOPPED = 0400000;
153const unsigned long HAS_THICKNESS = 01000000;
154const unsigned long IS_FILLED = 02000000;
155const unsigned long IS_DEFAULT_FILLED = 04000000;
156const unsigned long IS_ALIGNED = 010000000;
157const unsigned long IS_SHADED = 020000000;
158const unsigned long IS_OUTLINED = 040000000;
159
160struct segment {
161  int is_absolute;
162  position pos;
163  segment *next;
164  segment(const position &, int, segment *);
165};
166
167class rectangle_object;
168class graphic_object;
169class linear_object;
170
171struct object_spec {
172  unsigned long flags;
173  object_type type;
174  object_list oblist;
175  PTABLE(place) *tbl;
176  double dash_width;
177  position from;
178  position to;
179  position at;
180  position by;
181  path *with;
182  text_item *text;
183  double height;
184  double radius;
185  double width;
186  double segment_width;
187  double segment_height;
188  double start_chop;
189  double end_chop;
190  double thickness;
191  double fill;
192  char *shaded;
193  char *outlined;
194  direction dir;
195  segment *segment_list;
196  position segment_pos;
197  int segment_is_absolute;
198
199  object_spec(object_type);
200  ~object_spec();
201  object *make_object(position *, direction *);
202  graphic_object *make_box(position *, direction *);
203  graphic_object *make_block(position *, direction *);
204  graphic_object *make_text(position *, direction *);
205  graphic_object *make_ellipse(position *, direction *);
206  graphic_object *make_circle(position *, direction *);
207  linear_object *make_line(position *, direction *);
208  linear_object *make_arc(position *, direction *);
209  graphic_object *make_linear(position *, direction *);
210  graphic_object *make_move(position *, direction *);
211  int position_rectangle(rectangle_object *p, position *curpos,
212			 direction *dirp);
213};
214
215
216object *make_object(object_spec *, position *, direction *);
217
218object *make_mark_object();
219object *make_command_object(char *, const char *, int);
220
221int lookup_variable(const char *name, double *val);
222void define_variable(const char *name, double val);
223
224void print_picture(object *);
225
226