-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgeom_text.c
228 lines (195 loc) · 5.06 KB
/
geom_text.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "db.h"
#include "xwin.h"
#include "token.h"
#include "rubber.h"
#include "opt_parse.h"
#include "rlgetc.h"
#include <string.h>
// DB_TAB dbtab;
DB_TEXT dbtext;
static double x1, y1;
char str[BUFSIZE];
void draw_text();
OPTS topts;
int add_annotation();
/* [:Mmirror] [:Rrot] [:Yyxratio] [:Zslant] [:Fsize] "string" xy EOC" */
void add_note(LEXER *lp, int *layer) {
add_annotation(lp, layer, NOTE_MODE);
}
void add_text(LEXER *lp, int *layer) {
add_annotation(lp, layer, TEXT_MODE);
}
int add_annotation(lp, layer, mode)
LEXER *lp;
int *layer;
int mode; // NOTE_MODE for note, TEXT_MODE for text
{
enum {START,NUM1,END} state = START;
char *word;
int done=0;
TOKEN token;
int debug=0;
int nargs=0;
char *type;
int numadd = 0;
double xold=0.0, yold=0.0;
opt_set_defaults( &topts );
topts.font_size = db_get_font_size(); /* get default from FSIze command */
topts.slant = db_get_text_slant(); /* get default from TSLant command */
topts.font_num = mode; /* default note mode=NOTE_MODE, text=TEXT_MODE */
str[0] = '\0';
while (!done) {
rl_saveprompt();
if (mode==TEXT_MODE) {
rl_setprompt("ADD_TEXT> ");
type="TEXT";
} else {
rl_setprompt("ADD_NOTE> ");
type="NOTE";
}
token = token_look(lp, &word);
if (debug) printf("got %s: %s\n", tok2str(token), word);
if (token==CMD) {
state=END;
}
switch(state) {
case START: /* get option or first xy pair */
db_checkpoint(lp);
if (token == OPT ) {
token_get(lp, &word);
if (nargs > 1) {
rubber_clear_callback();
}
if ((mode == TEXT_MODE) && opt_parse(word, TEXT_OPTS, &topts) == -1) {
state = END;
} else if ((mode == NOTE_MODE) && opt_parse(word, NOTE_OPTS, &topts) == -1) {
state = END;
} else {
state = START;
}
if (nargs > 1) {
rubber_set_callback(draw_text);
nargs++;
}
} else if (token == NUMBER) {
state = NUM1;
} else if (token == QUOTE) {
nargs++;
if (debug) printf("nargs = %d\n", nargs);
if (nargs > 1) {
rubber_clear_callback();
}
token_get(lp,&word);
strncpy(str,word,BUFSIZE);
rubber_set_callback(draw_text);
state = START;
} else if (token == EOL) {
token_get(lp, &word); /* just eat it up */
state = START;
} else if (token == EOC || token == CMD) {
state = END; /* error */
} else {
token_err(type, lp, "expected OPT or NUMBER", token);
state = END;
}
break;
case NUM1: /* get pair of xy coordinates */
if (token == NUMBER) {
if (getnum(lp, "TEXT", &x1, &y1)) {
if (strlen(str) == 0) {
printf("ADD %s: no string given\n", type);
state = START;
} else {
if (numadd && xold == x1 && yold == y1) {
printf(" suppressing double click\n");
} else {
rubber_clear_callback();
if (mode == TEXT_MODE) {
db_add_text(currep, *layer, opt_copy(&topts),
strsave(str), x1, y1);
} else {
db_add_note(currep, *layer, opt_copy(&topts),
strsave(str), x1, y1);
}
rubber_set_callback(draw_text);
need_redraw++;
}
xold=x1; yold=y1;
numadd++;
state = START;
}
} else {
state = END;
}
} else if (token == EOL) {
token_get(lp, &word); /* just ignore it */
} else if (token == EOC || token == CMD) {
printf(" cancelling ADD %s\n", type);
state = END;
} else {
token_err(type, lp, "expected NUMBER", token);
state = END;
}
break;
case END:
default:
if (token == EOC || token == CMD) {
;
} else {
token_flush_EOL(lp);
}
/* FIXME, maybe I need a rubber_cleanup() which does */
/* a clear_callback only if needed? Bailing out from*/
/* a bad option leaves a "ghost" on the screen */
rubber_clear_callback();
done++;
break;
}
}
rl_restoreprompt();
return(1);
}
void draw_text(double x2, double y2, int count)
{
static double xold, yold;
int debug=0;
static BOUNDS bb;
static DB_DEFLIST dbdeflist;
bb.init=0;
/* DB_TAB dbtab; */
/* DB_DEFLIST dbdeflist; */
/* DB_text dbtext; */
// dbtab.dbhead = &dbdeflist;
// dbtab.next = NULL;
// dbtab.name = "callback";
dbdeflist.u.t = &dbtext;
dbdeflist.type = TEXT;
dbtext.layer=1;
dbtext.opts=&topts;
dbtext.text=str;
if (debug) {printf("in draw_text\n");}
if (count == 0) { /* first call */
jump(&bb, D_RUBBER); /* draw new shape */
dbtext.x=x2;
dbtext.y=y2;
do_text(&dbdeflist, &bb, D_RUBBER);
} else if (count > 0) { /* intermediate calls */
jump(&bb, D_RUBBER); /* erase old shape */
dbtext.x=xold;
dbtext.y=yold;
do_text(&dbdeflist, &bb, D_RUBBER);
jump(&bb, D_RUBBER); /* draw new shape */
dbtext.x=x2;
dbtext.y=y2;
do_text(&dbdeflist, &bb, D_RUBBER);
} else { /* last call, cleanup */
jump(&bb, D_RUBBER); /* erase old shape */
dbtext.x=xold;
dbtext.y=yold;
do_text(&dbdeflist, &bb, D_RUBBER);
}
/* save old values */
xold=x2;
yold=y2;
jump(&bb, D_RUBBER);
}