1 /*
2  * FIG : Facility for Interactive Generation of figures
3  * Copyright (c) 1985-1988 by Supoj Sutanthavibul
4  * Parts Copyright (c) 1989-2015 by Brian V. Smith
5  * Parts Copyright (c) 1991 by Paul King
6  * Parts Copyright (c) 2016-2020 by Thomas Loimer
7  *
8  * Any party obtaining a copy of these files is granted, free of charge, a
9  * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
10  * nonexclusive right and license to deal in this software and documentation
11  * files (the "Software"), including without limitation the rights to use,
12  * copy, modify, merge, publish, distribute, sublicense and/or sell copies of
13  * the Software, and to permit persons who receive copies from any such
14  * party to do so, with the only requirement being that the above copyright
15  * and this permission notice remain intact.
16  *
17  */
18 
19 #ifndef OBJECT_H
20 #define OBJECT_H
21 
22 #if defined HAVE_CONFIG_H && !defined VERSION
23 #include "config.h"
24 #endif
25 
26 #include <sys/types.h>
27 #include <X11/Intrinsic.h>	/* includes X11/Xlib.h, which includes X11/X.h */
28 #include "resources.h"
29 
30 /* values to signify color used for transparent GIF color */
31 
32 #define CANVAS_BG		-7	/* use canvas background color */
33 #define DARK_GRAY		-6	/* pseudo color to Greek small text */
34 #define MED_GRAY		-5	/* pseudo colors to gray out inactive layers */
35 #define LT_GRAY			-4
36 #define TRANSP_BACKGROUND	-3	/* use background of figure as transp color */
37 #define TRANSP_NONE		-2	/* no transp color */
38 #define COLOR_NONE		-2	/* no background color (exporting) */
39 
40 /* DEFAULT is used for many things - font, color etc */
41 
42 #define DEFAULT		      (-1)
43 
44 #define SOLID_LINE		0
45 #define DASH_LINE		1
46 #define DOTTED_LINE		2
47 #define DASH_DOT_LINE		3
48 #define DASH_2_DOTS_LINE	4
49 #define DASH_3_DOTS_LINE	5
50 
51 #define RUBBER_LINE		11
52 #define PANEL_LINE		12
53 
54 #define BLACK			0
55 #define BLUE			1
56 #define GREEN			2
57 #define CYAN			3
58 #define RED			4
59 #define MAGENTA			5
60 #define YELLOW			6
61 #define WHITE			7
62 #define GREEN4			12
63 
64 /* defaults for line attributes */
65 
66 #define DEF_BOXRADIUS		7
67 #define DEF_DASHLENGTH		4
68 #define DEF_DOTGAP		3
69 
70 /* arrowhead defaults */
71 
72 #define DEF_ARROW_WID		4.0
73 #define DEF_ARROW_HT		8.0
74 
75 /** VERY IMPORTANT:  The f_line, f_spline and f_arc objects all must have the
76 		components up to and including the arrows in the same order.
77 		This is for the get/put_generic_arrows() in e_edit.c.
78 		In addition, the f_line and f_spline objects must have the
79 		components up to and including the f_points in the same order.
80 **/
81 
82 /***********************************************************************/
83 /* NOTE: If you change this you must change _pic_names in e_edit.c too */
84 /***********************************************************************/
85 
86 /* These values are used internally, so changing them doesn't
87    affect any Fig files */
88 
89 enum pictypes {
90 	T_PIC_NONE,
91 	T_PIC_EPS,
92 	T_PIC_PDF,
93 	T_PIC_GIF,
94 #ifdef HAVE_JPEG
95 	T_PIC_JPEG,
96 #endif
97 	T_PIC_PCX,
98 #ifdef HAVE_PNG
99 	T_PIC_PNG,
100 #endif
101 	T_PIC_PPM,
102 	T_PIC_TIF,
103 	T_PIC_XBM,
104 #ifdef USE_XPM
105 	T_PIC_XPM,
106 #endif
107 	LAST_PIC
108 };
109 
110 #define NUM_PIC_TYPES LAST_PIC-1
111 
112 /* structure to contain a point */
113 typedef struct f_pos {
114 	int x, y;
115 } F_pos;
116 
117 struct _pics {
118 	char *file;
119 	time_t time_stamp;	/* to see if the file has changed */
120 	unsigned char *bitmap;
121 	enum pictypes subtype;
122 	int size_x, size_y;	/* picture size (fig units) */
123 	F_pos bit_size;		/* size of bitmap in pixels */
124 	struct Cmap cmap[MAX_COLORMAP_SIZE];	/* for GIF/XPM/JPEG files */
125 	int numcols;		/* number of colors in cmap */
126 	int transp;		/* transparent color
127 				   (TRANSP_NONE if none) for GIFs */
128 	int refcount;		/* number of references to picture */
129 	struct _pics *prev;
130 	struct _pics *next;
131 };
132 
133 /*******************/
134 /* point structure */
135 /*******************/
136 
137 typedef struct f_point {
138 	int x, y;
139 	struct f_point *next;
140 } F_point;
141 
142 /***********************/
143 /* Arrowhead structure */
144 /***********************/
145 
146 typedef struct f_arrow {
147 	int type;
148 	int style;
149 	float thickness;
150 	float wd;
151 	float ht;
152 } F_arrow;
153 
154 
155 /******************/
156 /* Ellipse object */
157 /******************/
158 
159 typedef struct f_ellipse {
160 	int tagged;
161 	int distrib;
162 	int type;
163 #define T_ELLIPSE_BY_RAD	1
164 #define T_ELLIPSE_BY_DIA	2
165 #define T_CIRCLE_BY_RAD		3
166 #define T_CIRCLE_BY_DIA		4
167 	int style;
168 	int thickness;
169 	Color pen_color;
170 	Color fill_color;
171 	int fill_style;
172 	int depth;
173 	int pen_style;
174 	float style_val;
175 	float angle;		/* in radians */
176 	int direction;
177 #define UNFILLED	-1
178 	struct f_pos center;
179 	struct f_pos radiuses;
180 	struct f_pos start;
181 	struct f_pos end;
182 	char *comments;
183 	struct f_ellipse *next;
184 } F_ellipse;
185 
186 /* SEE NOTE AT TOP BEFORE CHANGING ANYTHING IN THE f_arc STRUCTURE */
187 
188 /**************/
189 /* Arc object */
190 /**************/
191 
192 typedef struct f_arc {
193 	int tagged;
194 	int distrib;
195 	int type;
196 	/* note: these arc types are the internal values */
197 	/* in the file, they are open=1, wedge=2, elliptical=3 */
198 #define T_OPEN_ARC		0
199 #define T_PIE_WEDGE_ARC		1
200 #define T_ELLIPTICAL		2
201 	int style;
202 	int thickness;
203 	Color pen_color;
204 	Color fill_color;
205 	int fill_style;
206 	int depth;
207 	int pen_style;
208 	float style_val;
209 	struct f_arrow *for_arrow;
210 	struct f_arrow *back_arrow;
211 	int cap_style;
212 #define CAP_BUTT	0
213 #define CAP_ROUND	1
214 #define CAP_PROJECT	2
215 
216 /* THE PRECEDING VARS MUST BE IN THE SAME ORDER IN f_arc, f_line and f_spline */
217 
218 	float angle;		/* for elliptical arcs, new for V4.0 */
219 	int direction;
220 	struct {
221 		float x, y;
222 	} center;
223 	struct f_pos point[3];
224 	char *comments;
225 	struct f_arc *next;
226 } F_arc;
227 
228 
229 #define PicSuccess	1
230 #define FileInvalid    -2
231 /************************************/
232 /* Picture sub-type for Line object */
233 /************************************/
234 
235 typedef struct f_pic {
236 	struct _pics *pic_cache; /* picture repository (bitmap, refcount etc) */
237 	Boolean new;		/* set when creating object, cleared when
238 				   Done is clicked in edit operation */
239 	int flipped;
240 	float hw_ratio;
241 	Pixmap mask;		/* for GIF transparency */
242 	Color color;		/* only used for XBM */
243 	Pixmap pixmap;		/* pixmap created for canvas */
244 	int pix_rotation,
245 	    pix_width,		/* current width of pixmap (pixels) */
246 	    pix_height,		/* current height of pixmap (pixels) */
247 	    pix_flipped;
248 } F_pic;
249 
250 extern char EMPTY_PIC[];
251 
252 /* SEE NOTE AT TOP BEFORE CHANGING ANYTHING IN THE f_line STRUCTURE */
253 
254 /***************/
255 /* Line object */
256 /***************/
257 
258 typedef struct f_line {
259 	int tagged;
260 	int distrib;
261 	int type;
262 #define T_POLYLINE	1
263 #define T_BOX		2
264 #define T_POLYGON	3
265 #define T_ARCBOX	4
266 #define T_PICTURE	5
267 	int style;
268 	int thickness;
269 	Color pen_color;
270 	Color fill_color;
271 	int fill_style;
272 	int depth;
273 	int pen_style;
274 	float style_val;
275 	struct f_arrow *for_arrow;
276 	struct f_arrow *back_arrow;
277 	int cap_style;		/* line cap style - Butt, Round, Bevel */
278 
279 /* THE PRECEDING VARS MUST BE IN THE SAME ORDER IN f_arc, f_line and f_spline */
280 
281 	struct f_point *points;	/* this must immediately follow cap_style */
282 
283 /* THE PRECEDING VARS MUST BE IN THE SAME ORDER IN f_line and f_spline */
284 
285 	int join_style;		/* join style - Miter, Round, Bevel */
286 #define JOIN_MITER	0
287 #define JOIN_ROUND	1
288 #define JOIN_BEVEL	2
289 	int radius;		/* corner radius for T_ARCBOX */
290 	F_pic *pic;		/* picture object, if type = T_PICTURE */
291 	char *comments;
292 	struct f_line *next;
293 } F_line;
294 
295 /***************/
296 /* Text object */
297 /***************/
298 
299 typedef struct f_text {
300 	int tagged;
301 	int distrib;
302 	int type;
303 #define T_LEFT_JUSTIFIED	0
304 #define T_CENTER_JUSTIFIED	1
305 #define T_RIGHT_JUSTIFIED	2
306 	int font;
307 	XFontStruct *fontstruct;
308 	float zoom;		/* to keep track of when it needs rescaling */
309 	int size;		/* point size */
310 	Color color;
311 	int depth;
312 	float angle;		/* in radians */
313 
314 	int flags;
315 #define RIGID_TEXT		1
316 #define SPECIAL_TEXT		2
317 #define PSFONT_TEXT		4
318 #define HIDDEN_TEXT		8
319 	int ascent;		/* Fig units */
320 	int length;		/* Fig units */
321 	int descent;		/* from XTextExtents(), not in file */
322 	int base_x;
323 	int base_y;
324 	int pen_style;
325 	char *cstring;
326 	char *comments;
327 	struct f_text *next;
328 } F_text;
329 
330 /* text macros */
331 
332 #define MAXFONT(T)	(psfont_text(T) ? NUM_FONTS : NUM_LATEX_FONTS)
333 
334 #define rigid_text(t)	(t->flags == DEFAULT \
335 				|| (t->flags & RIGID_TEXT))
336 
337 #define special_text(t)	((t->flags != DEFAULT \
338 				&& (t->flags & SPECIAL_TEXT)))
339 
340 #define psfont_text(t)	(t->flags != DEFAULT \
341 				&& (t->flags & PSFONT_TEXT))
342 
343 #define hidden_text(t)	(t->flags != DEFAULT \
344 				&& (t->flags & HIDDEN_TEXT))
345 
346 #define text_length(t)	(hidden_text(t) ? hidden_text_length : t->length)
347 
348 #define using_ps	(cur_textflags & PSFONT_TEXT)
349 
350 
351 /* SEE NOTE AT TOP BEFORE CHANGING ANYTHING IN THE f_spline STRUCTURE */
352 
353 /*****************/
354 /* Spline object */
355 /*****************/
356 
357 #define int_spline(s)		(s->type & 0x2)
358 #define x_spline(s)	        (s->type & 0x4)
359 #define approx_spline(s)	(!(int_spline(s)|x_spline(s)))
360 #define closed_spline(s)	(s->type & 0x1)
361 #define open_spline(s)		(!(s->type & 0x1))
362 
363 #define S_SPLINE_ANGULAR 0.0
364 #define S_SPLINE_APPROX 1.0
365 #define S_SPLINE_INTERP (-0.5)
366 
367 typedef struct f_spline {
368 	int tagged;
369 	int distrib;
370 	int type;
371 #define T_OPEN_APPROX	0
372 #define T_CLOSED_APPROX 1
373 #define T_OPEN_INTERP	2
374 #define T_CLOSED_INTERP 3
375 #define T_OPEN_XSPLINE  4
376 #define T_CLOSED_XSPLINE  5
377 	int style;
378 	int thickness;
379 	Color pen_color;
380 	Color fill_color;
381 	int fill_style;
382 	int depth;
383 	int pen_style;
384 	float style_val;
385 	struct f_arrow *for_arrow;
386 	struct f_arrow *back_arrow;
387 	int cap_style;
388 
389 /* THE PRECEDING VARS MUST BE IN THE SAME ORDER IN f_arc, f_line and f_spline */
390 
391 	/*
392 	 * "points" are control points. Shape factors are stored in "sfactors".
393 	 */
394 	struct f_point *points;	/* this must immediately follow cap_style */
395 
396 /* THE PRECEDING VARS MUST BE IN THE SAME ORDER IN f_line and f_spline */
397 
398 	struct f_shape *sfactors;
399 	char *comments;
400 	struct f_spline *next;
401 } F_spline;
402 
403 /**************************************/
404 /* Shape factor structure for splines */
405 /**************************************/
406 
407 typedef struct f_shape {
408 	double s;
409 	struct f_shape *next;
410 } F_sfactor;
411 
412 
413 /*******************/
414 /* Compound object */
415 /*******************/
416 
417 typedef struct f_compound {
418 	int tagged;
419 	int distrib;
420 	struct f_pos nwcorner;
421 	struct f_pos secorner;
422 	struct f_line *lines;
423 	struct f_ellipse *ellipses;
424 	struct f_spline *splines;
425 	struct f_text *texts;
426 	struct f_arc *arcs;
427 	char *comments;
428 	struct f_compound *parent;	/* for "open/close compound" */
429 	struct f_compound *GABPtr;	/* Where original compound came from */
430 	Boolean draw_parent;
431 	struct f_compound *compounds;
432 	struct f_compound *next;
433 } F_compound;
434 
435 typedef struct f_linkinfo {
436 	struct f_line *line;
437 	struct f_point *endpt;
438 	struct f_point *prevpt;
439 	int two_pts;
440 	struct f_linkinfo *next;
441 } F_linkinfo;
442 
443 
444 /* separate the "type" and the "style" from the cur_arrowtype */
445 #define ARROW_TYPE(x)	((x)==0? 0 : ((x)+1)/2)
446 #define ARROW_STYLE(x)	((x)==0? 0 : ((x)+1)%2)
447 
448 #define ARROW_SIZE	sizeof(struct f_arrow)
449 #define POINT_SIZE	sizeof(struct f_point)
450 #define CONTROL_SIZE	sizeof(struct f_shape)
451 #define ELLOBJ_SIZE	sizeof(struct f_ellipse)
452 #define ARCOBJ_SIZE	sizeof(struct f_arc)
453 #define LINOBJ_SIZE	sizeof(struct f_line)
454 #define TEXOBJ_SIZE	sizeof(struct f_text)
455 #define SPLOBJ_SIZE	sizeof(struct f_spline)
456 #define COMOBJ_SIZE	sizeof(struct f_compound)
457 #define PIC_SIZE	sizeof(struct f_pic)
458 #define LINKINFO_SIZE	sizeof(struct f_linkinfo)
459 
460 /**********************  object codes  **********************/
461 
462 #define O_COLOR_DEF	0
463 #define O_ELLIPSE	1
464 #define O_POLYLINE	2
465 #define O_SPLINE	3
466 #define O_TXT		4
467 #define O_ARC		5
468 #define O_COMPOUND	6
469 #define O_END_COMPOUND	-O_COMPOUND
470 /* pseudo-object O_FIGURE only for edit panel */
471 #define O_FIGURE	17777
472 #define O_ALL_OBJECT	99
473 
474 /********************* object masks for update  ************************/
475 
476 #define M_NONE			0x0000
477 #define M_POLYLINE_POLYGON	0x0001
478 #define M_POLYLINE_LINE		0x0002
479 #define M_POLYLINE_BOX		0x0004	/* includes ARCBOX */
480 #define M_SPLINE_O_APPROX	0x0008
481 #define M_SPLINE_C_APPROX	0x0010
482 #define M_SPLINE_O_INTERP	0x0020
483 #define M_SPLINE_C_INTERP	0x0040
484 #define M_SPLINE_O_XSPLINE      0x0080
485 #define M_SPLINE_C_XSPLINE      0x0100
486 #define M_TEXT_NORMAL		0x0200
487 #define M_TEXT_HIDDEN		0x0400
488 #define M_ARC			0x0800
489 #define M_ELLIPSE		0x1000
490 #define M_COMPOUND		0x2000
491 
492 #define M_TEXT		(M_TEXT_HIDDEN | M_TEXT_NORMAL)
493 #define M_SPLINE_O	(M_SPLINE_O_APPROX | M_SPLINE_O_INTERP | M_SPLINE_O_XSPLINE)
494 #define M_SPLINE_C	(M_SPLINE_C_APPROX | M_SPLINE_C_INTERP | M_SPLINE_C_XSPLINE)
495 #define M_SPLINE_APPROX (M_SPLINE_O_APPROX | M_SPLINE_C_APPROX)
496 #define M_SPLINE_INTERP (M_SPLINE_O_INTERP | M_SPLINE_C_INTERP)
497 #define M_SPLINE_XSPLINE (M_SPLINE_O_XSPLINE | M_SPLINE_C_XSPLINE)
498 #define M_SPLINE	(M_SPLINE_APPROX | M_SPLINE_INTERP | M_SPLINE_XSPLINE)
499 #define M_POLYLINE	(M_POLYLINE_LINE | M_POLYLINE_POLYGON | M_POLYLINE_BOX)
500 #define M_VARPTS_OBJECT (M_POLYLINE_LINE | M_POLYLINE_POLYGON | M_SPLINE)
501 #define M_OPEN_OBJECT	(M_POLYLINE_LINE | M_SPLINE_O | M_ARC)
502 #define M_ROTATE_ANGLE	(M_VARPTS_OBJECT | M_ARC | M_TEXT | M_COMPOUND | M_ELLIPSE)
503 #define M_OBJECT	(M_ELLIPSE | M_POLYLINE | M_SPLINE | M_TEXT | M_ARC)
504 #define M_NO_TEXT	(M_ELLIPSE | M_POLYLINE | M_SPLINE | M_COMPOUND | M_ARC)
505 #define M_ALL		(M_OBJECT | M_COMPOUND)
506 
507 #define M_ANGLEMEAS_OBJECT  (M_POLYLINE_LINE | M_POLYLINE_POLYGON | M_ARC)
508 #define M_LENMEAS_OBJECT    (M_POLYLINE_LINE | M_POLYLINE_POLYGON | M_POLYLINE_BOX | M_ARC | M_ELLIPSE)
509 #define M_AREAMEAS_OBJECT   (M_POLYLINE_POLYGON | M_POLYLINE_BOX | M_ARC | M_ELLIPSE)
510 #define M_TANGENT_OBJECT    (M_VARPTS_OBJECT | M_POLYLINE_BOX | M_ARC | M_ELLIPSE)
511 
512 /************************  Objects  **********************/
513 
514 extern F_compound objects;
515 
516 /************  global working pointers ************/
517 
518 extern F_line *cur_l, *new_l, *old_l;
519 extern F_arc *cur_a, *new_a, *old_a;
520 extern F_ellipse *cur_e, *new_e, *old_e;
521 extern F_text *cur_t, *new_t, *old_t;
522 extern F_spline *cur_s, *new_s, *old_s;
523 extern F_compound *cur_c, *new_c, *old_c;
524 extern F_point *first_point, *cur_point;
525 extern F_linkinfo *cur_links;
526 
527 #endif				/* OBJECT_H */
528