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-2018 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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 #include "mode.h"
23 
24 #include <X11/Xlib.h>
25 
26 #include "resources.h"
27 #include "object.h"
28 #include "u_fonts.h"
29 #include "w_indpanel.h"
30 #include "w_msgpanel.h"
31 #include "w_setup.h"
32 
33 int	cur_mode = F_NULL;
34 int	cur_halign = ALIGN_NONE;
35 int	cur_valign = ALIGN_NONE;
36 int	manhattan_mode = 0;
37 int	mountain_mode = 0;
38 int	latexline_mode = 0;
39 int	latexarrow_mode = 0;
40 int	autoforwardarrow_mode = 0;
41 int	autobackwardarrow_mode = 0;
42 int	cur_gridtype, cur_gridmode, cur_gridunit, old_gridunit, grid_unit;
43 int	cur_pointposn;
44 int	posn_rnd[NUM_GRID_UNITS][P_GRID4 + 1] = {
45 		{ 0, PPCM/10, PPCM/5, PPCM/2, PPCM, PPCM*2},	/*   mm  mode */
46 		{ 0, PPI/16, PPI/8, PPI/4, PPI/2, PPI},		/* 1/16" mode */
47 		{ 0, PPI/20, PPI/10, PPI/5, PPI/2, PPI},	/* 1/10" mode */
48 };
49 int	grid_spacing[NUM_GRID_UNITS][GRID_4] = {
50 		{ PPCM/5, PPCM/2, PPCM, PPCM*2},    /* 2mm, 5mm, 10mm, 20mm */
51 		{ PPI/8, PPI/4, PPI/2, PPI},	    /* 1/8", 1/4", 1/2", 1" */
52 		{ PPI/10, PPI/5, PPI/2, PPI},	    /* 1/10", 1/5", 1/2", 1" */
53 };
54 
55 /* the first entry in each unit category is only used for point positioning */
56 char	*grid_name[NUM_GRID_UNITS][GRID_4+1] = {
57 		{ "1 mm", "2 mm", "5 mm", "10 mm", "20 mm"},
58 		{ "1/16 inch", "1/8 inch", "1/4 inch", "1/2 inch", "1 inch"},
59 		{ "0.05 inch", "0.1 inch", "0.2 inch", "0.5 inch", "1.0 inch"},
60 };
61 
62 float	cur_rotnangle = 90.0;
63 int	cur_linkmode = 0;
64 int	cur_numsides = 6;
65 int	cur_numcopies = 1;
66 int	cur_numxcopies = 0;
67 int	cur_numycopies = 0;
68 int	action_on = 0;
69 int	highlighting = 0;
70 int	aborting = 0;
71 int	anypointposn = 0;
72 int	figure_modified = 0;
73 char	cur_fig_units[200];
74 char	cur_library_dir[PATH_MAX];
75 char	cur_image_editor[PATH_MAX];
76 char	cur_spellchk[PATH_MAX];
77 char	cur_browser[PATH_MAX];
78 char	cur_pdfviewer[PATH_MAX];
79 Boolean	warnexist = False;
80 
81 /**********************	 global mode variables	************************/
82 
83 int	num_point;
84 int	min_num_points;
85 
86 /***************************  Export Settings  ****************************/
87 
88 int	cur_exp_lang;		/* gets initialized in main.c */
89 Boolean	batch_exists = False;
90 char	batch_file[PATH_MAX];
91 
92 /*******************************************************************/
93 /* If you change the order of the lang_items[] you must change the */
94 /* order of the lang_texts[] and the LANG_xxx items in mode.h      */
95 /*******************************************************************/
96 
97 char	*lang_items[] = {
98 	"ps",
99 	"eps",
100 	"pdf",
101 	"pspdf",
102 	"box",
103 	"latex",
104 	"pict2e",
105 	"tikz",
106 	"pstricks",
107 	"epic",
108 	"eepic",
109 	"eepicemu",
110 	"pstex",
111 	"pdftex",
112 	"pspdftex",
113 	"pictex",
114 	"cgm",
115 	"emf",
116 	"dxf",
117 	"gbx",
118 	"ibmgl",
119 	"map",
120 	"textyl",
121 	"tpic",
122 	"pic",
123 	"mf",
124 	"mp",
125 	"tk",
126 	"ptk",
127 	"shape",
128 	"svg",
129 /* bitmap formats start here */
130 	"gif", "jpeg", "pcx", "png", "ppm", "sld", "tiff", "xbm",
131 #ifdef USE_XPM
132 	"xpm",
133 #endif /* USE_XPM */
134 };
135 
136 char	*lang_texts[] = {
137 	"Postscript                       ",
138 	"EPS (Encapsulated Postscript)    ",
139 	"PDF (Portable Document Format)   ",
140 	"EPS and PDF (two files)          ",
141 	"LaTeX box (figure boundary)      ",
142 	"LaTeX picture                    ",
143 	"LaTeX picture + pict2e macros    ",
144 	"TeX/LaTeX + tikz macros          ",
145 	"LaTeX + pstricks macros          ",
146 	"LaTeX picture + epic macros      ",
147 	"LaTeX picture + eepic macros     ",
148 	"LaTeX picture + eepicemu macros  ",
149 	"Combined PS/LaTeX (both parts)   ",
150 	"Combined PDF/LaTeX (both parts)  ",
151 	"Combined PS/PDF/LaTeX (3 parts)  ",
152 	"PiCTeX macros                    ",
153 	"CGM (Computer Graphics Metafile) ",
154 	"EMF (Enhanced Metafile)          ",
155 	"DXF (Drawing Interchange Format) ",
156 	"GBX (Gerber, RS-247-X)           ",
157 	"HPGL/2 or IBM-GL                 ",
158 	"HTML Image Map                   ",
159 	"Textyl \\special commands         ",
160 	"TPIC                             ",
161 	"PIC                              ",
162 	"MF  (MetaFont)                   ",
163 	"MP  (MetaPost)                   ",
164 	"Tk  (Tcl/Tk toolkit)             ",
165 	"PTk (Perl/Tk toolkit)            ",
166 	"SHAPE (ShapePar definition )     ",
167 	"SVG (Scalable Vector Graphics)   ",
168 
169 	/*** bitmap formats follow ***/
170 	/* if you move GIF, change FIRST_BITMAP_LANG in mode.h */
171 
172 	"GIF (Graphics Interchange Format)",
173 	"JPEG (Joint Photo. Expert Group) ",
174 	"PCX (PC Paintbrush)              ",
175 	"PNG (Portable Network Graphics)  ",
176 	"PPM (Portable Pixmap)            ",
177 	"SLD (AutoCad Slide)              ",
178 	"TIFF (no compression)            ",
179 	"XBM (X11 Bitmap)                 ",
180 #ifdef USE_XPM
181 	"XPM (X11 Pixmap)                 ",
182 #endif /* USE_XPM */
183 };
184 
185 /***************************  Mode Settings  ****************************/
186 
187 int	cur_objmask = M_NONE;
188 int	cur_updatemask = I_UPDATEMASK;
189 int	new_objmask = M_NONE;
190 /* start depth at 50 to make it easier to put new objects on top without
191    having to remember to increase the depth at startup */
192 int	cur_depth = DEF_DEPTH;
193 
194 /***************************  Texts ****************************/
195 
196 int	hidden_text_length;
197 float	cur_textstep = 1.0;
198 int	cur_fontsize = DEF_FONTSIZE;
199 int	cur_latex_font	= 0;
200 int	cur_ps_font	= 0;
201 int	cur_textjust	= T_LEFT_JUSTIFIED;
202 int	cur_textflags	= PSFONT_TEXT;
203 
204 /***************************  Lines ****************************/
205 
206 int	cur_linewidth	= 1;
207 int	cur_linestyle	= SOLID_LINE;
208 int	cur_joinstyle	= JOIN_MITER;
209 int	cur_capstyle	= CAP_BUTT;
210 float	cur_dashlength	= DEF_DASHLENGTH;
211 float	cur_dotgap	= DEF_DOTGAP;
212 float	cur_styleval	= 0.0;
213 Color	cur_pencolor	= BLACK;
214 Color	cur_fillcolor	= WHITE;
215 int	cur_boxradius	= DEF_BOXRADIUS;
216 int	cur_fillstyle	= UNFILLED;
217 int	cur_arrowmode	= L_NOARROWS;
218 int	cur_arrowtype	= 0;
219 float	cur_arrowthick	= 1.0;		/* pixels */
220 float	cur_arrowwidth	= DEF_ARROW_WID;/* pixels */
221 float	cur_arrowheight	= DEF_ARROW_HT;	/* pixels */
222 float	cur_arrow_multthick = 1.0;	/* when using multiple of width */
223 float	cur_arrow_multwidth = DEF_ARROW_WID;
224 float	cur_arrow_multheight = DEF_ARROW_HT;
225 Boolean	use_abs_arrowvals = False;	/* start with values prop. to width */
226 int	cur_arctype	= T_OPEN_ARC;
227 float	cur_tangnormlen = 1.0;		/* current tangent/normal line length */
228 
229 /*************************** Dimension lines ****************************/
230 
231 int	cur_dimline_thick = 1;		/* main line and tick thickness */
232 int	cur_dimline_style = SOLID_LINE;	/* main line style */
233 int	cur_dimline_color = BLACK;	/* color */
234 int	cur_dimline_leftarrow = 2;	/* arrow type (black triangle) */
235 int	cur_dimline_rightarrow = 2;	/* other end */
236 float	cur_dimline_arrowlength = DEF_ARROW_HT;	/* as a multiple of line thickness */
237 float	cur_dimline_arrowwidth = DEF_ARROW_WID;	/* as a multiple of line thickness */
238 Boolean	cur_dimline_ticks = True;	/* Include ticks */
239 int	cur_dimline_tickthick = 1;	/* thickness of ticks */
240 int	cur_dimline_boxthick = 1;	/* thickness of text box line */
241 int	cur_dimline_boxcolor = WHITE;	/* start with white-filled text box */
242 int	cur_dimline_textcolor = BLACK;	/* text color */
243 int	cur_dimline_font = 0;		/* Times Roman */
244 int	cur_dimline_fontsize = DEF_FONTSIZE; /* size of text */
245 int	cur_dimline_psflag = 1;
246 Boolean	cur_dimline_fixed = False;	/* text is adjusted to report line length */
247 int	cur_dimline_prec = 1;		/* number of dec points in
248 					   dimension line text */
249 
250 /**************************** Miscellaneous *****************************/
251 
252 float	cur_elltextangle = 0.0;		/* text/ellipse input angle */
253 char	EMPTY_PIC[8]	= "<empty>";
254 
255 /***************************  File Settings  ****************************/
256 
257 char	cur_file_dir[PATH_MAX];
258 char	cur_export_dir[PATH_MAX];
259 char	cur_filename[PATH_MAX] = "";
260 char	save_filename[PATH_MAX] = "";	/* to undo load */
261 char	file_header[32];
262 char	cut_buf_name[PATH_MAX];		/* path of .xfig cut buffer file */
263 char	xfigrc_name[PATH_MAX];		/* path of .xfigrc file */
264 
265 /*************************** routines ***********************/
266 
267 void
reset_modifiedflag(void)268 reset_modifiedflag(void)
269 {
270 	figure_modified = 0;
271 }
272 
273 void
set_modifiedflag(void)274 set_modifiedflag(void)
275 {
276 	figure_modified = 1;
277 }
278 
279 void
set_action_on(void)280 set_action_on(void)
281 {
282 	action_on = 1;
283 }
284 
285 void
reset_action_on(void)286 reset_action_on(void)
287 {
288 	action_on = 0;
289 	/* reset this so next show_linelengths will work properly */
290 	first_lenmsg = True;
291 }
292