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