Update to groff 1.19.2.
[dragonfly.git] / contrib / groff-1.19 / src / preproc / pic / object.h
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
6 This file is part of groff.
7
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with groff; see the file COPYING.  If not, write to the Free Software
20 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21
22 struct place;
23
24 enum 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
39 struct bounding_box;
40
41 struct 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
70 typedef position (object::*corner)();
71
72 struct place {
73   object *obj;
74   double x, y;
75 };
76
77 struct string_list;
78
79 class path {
80   position pos;
81   corner crn;
82   string_list *label_list;
83   path *ypath;
84   int is_position;
85 public:
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
96 struct object_list {
97   object *head;
98   object *tail;
99   object_list();
100   void append(object *);
101   void wrap_up_block(object_list *);
102 };
103
104 declare_ptable(place)
105
106 // these go counterclockwise
107 enum direction {
108   RIGHT_DIRECTION,
109   UP_DIRECTION,
110   LEFT_DIRECTION,
111   DOWN_DIRECTION
112   };
113
114 struct graphics_state {
115   double x, y;
116   direction dir;
117 };
118
119 struct saved_state : public graphics_state {
120   saved_state *prev;
121   PTABLE(place) *tbl;
122 };
123
124
125 struct 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
136 const unsigned long IS_DOTTED = 01;
137 const unsigned long IS_DASHED = 02;
138 const unsigned long IS_CLOCKWISE = 04;
139 const unsigned long IS_INVISIBLE = 020;
140 const unsigned long HAS_LEFT_ARROW_HEAD = 040;
141 const unsigned long HAS_RIGHT_ARROW_HEAD = 0100;
142 const unsigned long HAS_SEGMENT = 0200;
143 const unsigned long IS_SAME = 0400;
144 const unsigned long HAS_FROM = 01000;
145 const unsigned long HAS_AT = 02000;
146 const unsigned long HAS_WITH = 04000;
147 const unsigned long HAS_HEIGHT = 010000;
148 const unsigned long HAS_WIDTH = 020000;
149 const unsigned long HAS_RADIUS = 040000;
150 const unsigned long HAS_TO = 0100000;
151 const unsigned long IS_CHOPPED = 0200000;
152 const unsigned long IS_DEFAULT_CHOPPED = 0400000;
153 const unsigned long HAS_THICKNESS = 01000000;
154 const unsigned long IS_FILLED = 02000000;
155 const unsigned long IS_DEFAULT_FILLED = 04000000;
156 const unsigned long IS_ALIGNED = 010000000;
157 const unsigned long IS_SHADED = 020000000;
158 const unsigned long IS_OUTLINED = 040000000;
159
160 struct segment {
161   int is_absolute;
162   position pos;
163   segment *next;
164   segment(const position &, int, segment *);
165 };
166
167 class rectangle_object;
168 class graphic_object;
169 class linear_object;
170
171 struct 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
216 object *make_object(object_spec *, position *, direction *);
217
218 object *make_mark_object();
219 object *make_command_object(char *, const char *, int);
220
221 int lookup_variable(const char *name, double *val);
222 void define_variable(const char *name, double val);
223
224 void print_picture(object *);
225