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