Imported Upstream version 1.22.4
[platform/upstream/groff.git] / src / preproc / pic / object.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2018 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 3 of the License, or
10 (at your option) any later 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
18 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
19
20 struct place;
21
22 enum object_type {
23   OTHER_OBJECT,
24   BOX_OBJECT,
25   CIRCLE_OBJECT,
26   ELLIPSE_OBJECT,
27   ARC_OBJECT,
28   SPLINE_OBJECT,
29   LINE_OBJECT,
30   ARROW_OBJECT,
31   MOVE_OBJECT,
32   TEXT_OBJECT,
33   BLOCK_OBJECT,
34   MARK_OBJECT
35   };
36
37 struct bounding_box;
38
39 struct object {
40   object *prev;
41   object *next;
42   object();
43   virtual ~object();
44   virtual position origin();
45   virtual double width();
46   virtual double radius();
47   virtual double height();
48   virtual position north();
49   virtual position south();
50   virtual position east();
51   virtual position west();
52   virtual position north_east();
53   virtual position north_west();
54   virtual position south_east();
55   virtual position south_west();
56   virtual position start();
57   virtual position end();
58   virtual position center();
59   virtual place *find_label(const char *);
60   virtual void move_by(const position &);
61   virtual int blank();
62   virtual void update_bounding_box(bounding_box *);
63   virtual object_type type() = 0;
64   virtual void print();
65   virtual void print_text();
66 };
67
68 typedef position (object::*corner)();
69
70 struct place {
71   object *obj;
72   double x, y;
73 };
74
75 struct string_list;
76
77 class path {
78   position pos;
79   corner crn;
80   string_list *label_list;
81   path *ypath;
82   int is_position;
83 public:
84   path(corner = 0);
85   path(position);
86   path(char *, corner = 0);
87   ~path();
88   void append(corner);
89   void append(char *);
90   void set_ypath(path *);
91   int follow(const place &, place *) const;
92 };
93
94 struct object_list {
95   object *head;
96   object *tail;
97   object_list();
98   void append(object *);
99   void wrap_up_block(object_list *);
100 };
101
102 declare_ptable(place)
103
104 // these go counterclockwise
105 enum direction {
106   RIGHT_DIRECTION,
107   UP_DIRECTION,
108   LEFT_DIRECTION,
109   DOWN_DIRECTION
110   };
111
112 struct graphics_state {
113   double x, y;
114   direction dir;
115 };
116
117 struct saved_state : public graphics_state {
118   saved_state *prev;
119   PTABLE(place) *tbl;
120 };
121
122
123 struct text_item {
124   text_item *next;
125   char *text;
126   adjustment adj;
127   const char *filename;
128   int lineno;
129
130   text_item(char *, const char *, int);
131   ~text_item();
132 };
133
134 const unsigned long IS_DOTTED          =         01;
135 const unsigned long IS_DASHED          =         02;
136 const unsigned long IS_CLOCKWISE       =         04;
137 const unsigned long IS_INVISIBLE       =        020;
138 const unsigned long HAS_LEFT_ARROW_HEAD =       040;
139 const unsigned long HAS_RIGHT_ARROW_HEAD =     0100;
140 const unsigned long HAS_SEGMENT        =       0200;
141 const unsigned long IS_SAME            =       0400;
142 const unsigned long HAS_FROM           =      01000;
143 const unsigned long HAS_AT             =      02000;
144 const unsigned long HAS_WITH           =      04000;
145 const unsigned long HAS_HEIGHT         =     010000;
146 const unsigned long HAS_WIDTH          =     020000;
147 const unsigned long HAS_RADIUS         =     040000;
148 const unsigned long HAS_TO             =    0100000;
149 const unsigned long IS_CHOPPED         =    0200000;
150 const unsigned long IS_DEFAULT_CHOPPED =    0400000;
151 const unsigned long HAS_THICKNESS      =   01000000;
152 const unsigned long IS_FILLED          =   02000000;
153 const unsigned long IS_DEFAULT_FILLED  =   04000000;
154 const unsigned long IS_ALIGNED         =  010000000;
155 const unsigned long IS_SHADED          =  020000000;
156 const unsigned long IS_OUTLINED        =  040000000;
157 const unsigned long IS_XSLANTED        = 0100000000;
158 const unsigned long IS_YSLANTED        = 0200000000;
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   double xslanted;
193   double yslanted;
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