23
24
static RGBA_Color last_color;
26
static double t, b, l, r;
28
static double cur_x, cur_y;
25
30
int set_graph_stuff(void)
27
xincr = (float)(r - l) / 100.;
29
xincr = -xincr; /* mod: shapiro 13 jun 1991 */
30
yincr = (float)(b - t) / 100.;
32
yincr = -yincr; /* mod: shapiro 13 jun 1991 */
32
D_get_dst(&t, &b, &l, &r);
35
xincr = (r - l) / 100.;
37
xincr = -xincr; /* mod: shapiro 13 jun 1991 */
38
yincr = (b - t) / 100.;
40
yincr = -yincr; /* mod: shapiro 13 jun 1991 */
34
45
rotation = 0.0; /* init */
39
50
int set_text_size(void)
41
52
if (hsize >= 0. && vsize >= 0. && hsize <= 100. && vsize <= 100.) {
42
R_text_size((int)(hsize * xincr), (int)(vsize * yincr));
43
G_debug(3, "text size initialized to [%d,%d] pixels",
44
(int)(hsize * xincr), (int)(vsize * yincr));
49
int do_draw(char *buff)
53
if (2 != sscanf(buff, "%*s %f %f", &xper, &yper)) {
54
G_warning(_("Problem parsing coordinates [%s]"), buff);
59
/* skip check: clips segments if map coordinate is out of region.
60
if( xper < D_get_u_west() ||
61
yper < D_get_u_south() ||
62
xper > D_get_u_east() ||
63
yper > D_get_u_north() )
66
R_cont_abs((int)(D_u_to_d_col(xper) + 0.5),
67
(int)(D_u_to_d_row(yper) + 0.5));
70
if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
72
R_cont_abs(l + (int)(xper * xincr), b - (int)(yper * yincr));
78
int do_move(char *buff)
82
if (2 != sscanf(buff, "%*s %f %f", &xper, &yper)) {
83
G_warning(_("Problem parsing coordinates [%s]"), buff);
88
R_move_abs((int)(D_u_to_d_col(xper) + 0.5),
89
(int)(D_u_to_d_row(yper) + 0.5));
91
if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
93
R_move_abs(l + (int)(xper * xincr), b - (int)(yper * yincr));
99
int do_color(char *buff)
53
D_text_size(hsize * xincr, vsize * yincr);
54
G_debug(3, "text size initialized to [%.1f,%.1f]",
55
hsize * xincr, vsize * yincr);
60
int do_draw(const char *str)
64
if (2 != sscanf(str, "%*s %f %f", &xper, &yper)) {
65
G_warning(_("Problem parsing coordinates [%s]"), str);
69
D_line_abs(cur_x, cur_y, xper, yper);
76
int do_move(const char *str)
80
if (2 != sscanf(str, "%*s %f %f", &xper, &yper)) {
81
G_warning(_("Problem parsing coordinates [%s]"), str);
85
D_pos_abs(xper, yper);
92
int do_color(const char *str)
101
94
char in_color[64];
102
95
int R, G, B, color = 0;
104
if (1 != sscanf(buff, "%*s %s", in_color)) {
97
if (1 != sscanf(str, "%*s %s", in_color)) {
105
98
G_warning(_("Unable to read color"));
117
110
if (color == 1) {
118
R_RGB_color(R, G, B);
111
D_RGB_color(R, G, B);
119
112
/* store for backup */
120
113
set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
122
115
if (color == 2) { /* color == 'none' */
123
116
R = D_translate_color(DEFAULT_BG_COLOR);
125
118
/* store for backup */
126
119
set_last_color(0, 0, 0, RGBA_COLOR_NONE);
131
int do_linewidth(char *buff)
124
int do_linewidth(const char *str)
133
int width; /* in pixels */
135
if (1 != sscanf(buff, "%*s %d", &width)) {
136
G_warning(_("Problem parsing command [%s]"), buff);
128
if (1 != sscanf(str, "%*s %lf", &width)) {
129
G_warning(_("Problem parsing command [%s]"), str);
140
133
D_line_width(width);
141
G_debug(3, "line width set to %d pixels", width);
134
G_debug(3, "line width set to %.1f", width);
194
176
/* this check is here so you can use the "polyline" command
195
177
to make an unfilled polygon */
196
178
if (!strcmp(origcmd, "polygon"))
197
R_polygon_abs(xarray, yarray, num);
179
D_polygon_abs(xarray, yarray, num);
199
R_polyline_abs(xarray, yarray, num);
181
D_polyline_abs(xarray, yarray, num);
202
184
return (to_return);
205
int do_size(char *buff)
187
int do_size(const char *str)
207
189
float xper, yper;
210
ret = sscanf(buff, "%*s %f %f", &xper, &yper);
192
ret = sscanf(str, "%*s %f %f", &xper, &yper);
212
194
if (ret != 2 && ret != 1) {
213
G_warning(_("Problem parsing command [%s]"), buff);
195
G_warning(_("Problem parsing command [%s]"), str);
221
203
if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
224
R_text_size((int)(xper * xincr), (int)(yper * yincr));
225
G_debug(3, "text size set to [%d,%d] pixels",
226
(int)(xper * xincr), (int)(yper * yincr));
206
D_text_size(xper * xincr, yper * yincr);
207
G_debug(3, "text size set to [%.1f,%.1f]",
208
xper * xincr, yper * yincr);
231
int do_rotate(char *buff)
213
int do_rotate(const char *str)
233
if (1 != sscanf(buff, "%*s %lf", &rotation)) {
234
G_warning(_("Problem parsing command [%s]"), buff);
215
if (1 != sscanf(str, "%*s %lf", &rotation)) {
216
G_warning(_("Problem parsing command [%s]"), str);
238
R_text_rotation((float)rotation);
220
D_text_rotation(rotation);
239
221
G_debug(3, "rotation set to %.1f degrees", rotation);
244
int do_text(char *buff)
226
int do_text(const char *str)
228
const char *ptr = str;
249
230
/* skip to beginning of actual text */
250
for (; *ptr != ' '; ptr++) ;
251
for (; *ptr == ' '; ptr++) ;
231
for (; *ptr != ' '; ptr++)
233
for (; *ptr == ' '; ptr++)
264
247
to_alloc = coors_allocated;
265
while (num >= to_alloc)
249
to_alloc = num + CHUNK;
268
if (coors_allocated == 0) {
269
xarray = (int *)falloc(to_alloc, sizeof(int));
270
yarray = (int *)falloc(to_alloc, sizeof(int));
273
xarray = (int *)frealloc((char *)xarray,
274
to_alloc, sizeof(int), coors_allocated);
275
yarray = (int *)frealloc((char *)yarray,
276
to_alloc, sizeof(int), coors_allocated);
251
xarray = G_realloc(xarray, to_alloc * sizeof(double));
252
yarray = G_realloc(yarray, to_alloc * sizeof(double));
279
254
coors_allocated = to_alloc;
284
int do_icon(char *buff)
259
int do_icon(const char *str)
286
261
double xper, yper;
291
if (4 != sscanf(buff, "%*s %c %d %lf %lf", &type, &size, &xper, &yper)) {
292
G_warning(_("Problem parsing command [%s]"), buff);
266
if (4 != sscanf(str, "%*s %c %lf %lf %lf", &type, &size, &xper, &yper)) {
267
G_warning(_("Problem parsing command [%s]"), str);
297
ix = (int)(D_u_to_d_col(xper) + 0.5);
298
iy = (int)(D_u_to_d_row(yper) + 0.5);
299
/* size in map units too? currently in percentage.
300
use "size * D_get_u_to_d_yconv()" to convert? */
303
if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
306
ix = l + (int)(xper * xincr);
307
iy = b - (int)(yper * yincr);
310
switch (type & 0177) {
277
switch (type & 0x7F) {
312
R_move_abs(ix - size, iy - size);
313
R_cont_abs(ix - size, iy + size);
314
R_cont_abs(ix + size, iy + size);
315
R_cont_abs(ix + size, iy - size);
316
R_cont_abs(ix - size, iy - size);
279
D_move_abs(ix - size, iy - size);
280
D_cont_abs(ix - size, iy + size);
281
D_cont_abs(ix + size, iy + size);
282
D_cont_abs(ix + size, iy - size);
283
D_cont_abs(ix - size, iy - size);
319
R_move_abs(ix - size, iy - size);
320
R_cont_abs(ix + size, iy + size);
321
R_move_abs(ix - size, iy + size);
322
R_cont_abs(ix + size, iy - size);
286
D_move_abs(ix - size, iy - size);
287
D_cont_abs(ix + size, iy + size);
288
D_move_abs(ix - size, iy + size);
289
D_cont_abs(ix + size, iy - size);
326
R_move_abs(ix, iy - size);
327
R_cont_abs(ix, iy + size);
328
R_move_abs(ix - size, iy);
329
R_cont_abs(ix + size, iy);
293
D_move_abs(ix, iy - size);
294
D_cont_abs(ix, iy + size);
295
D_move_abs(ix - size, iy);
296
D_cont_abs(ix + size, iy);
335
int do_symbol(char *buff)
306
int do_symbol(const char *str)
337
308
double xper, yper;
342
313
char *line_color_str, *fill_color_str;
347
318
line_color = G_malloc(sizeof(RGBA_Color));
348
319
fill_color = G_malloc(sizeof(RGBA_Color));
350
symb_name = G_malloc(sizeof(char) * strlen(buff) + 1); /* well, it won't be any bigger than this */
351
line_color_str = G_malloc(sizeof(char) * strlen(buff) + 1);
352
fill_color_str = G_malloc(sizeof(char) * strlen(buff) + 1);
321
symb_name = G_malloc(strlen(str) + 1); /* well, it won't be any bigger than this */
322
line_color_str = G_malloc(strlen(str) + 1);
323
fill_color_str = G_malloc(strlen(str) + 1);
354
G_debug(3, "do_symbol() [%s]", buff);
325
G_debug(3, "do_symbol() [%s]", str);
356
327
/* set default colors so colors are optional */
357
328
strcpy(line_color_str, DEFAULT_FG_COLOR);
358
329
strcpy(fill_color_str, "grey");
361
(buff, "%*s %s %d %lf %lf %s %s", symb_name, &size, &xper, &yper,
332
(str, "%*s %s %lf %lf %lf %s %s", symb_name, &size, &xper, &yper,
362
333
line_color_str, fill_color_str) < 4) {
363
G_warning(_("Problem parsing command [%s]"), buff);
334
G_warning(_("Problem parsing command [%s]"), str);
368
ix = (int)(D_u_to_d_col(xper) + 0.5);
369
iy = (int)(D_u_to_d_row(yper) + 0.5);
370
/* consider size in map units too? maybe as percentage of display?
371
perhaps use "size * D_get_u_to_d_yconv()" to convert */
374
if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
376
ix = l + (int)(xper * xincr);
377
iy = b - (int)(yper * yincr);
380
342
/* parse line color */
381
343
ret = G_str_to_color(line_color_str, &R, &G, &B);
423
385
/* restore previous d.graph draw color */
424
386
if (last_color.a == RGBA_COLOR_OPAQUE)
425
R_RGB_color(last_color.r, last_color.g, last_color.b);
387
D_RGB_color(last_color.r, last_color.g, last_color.b);
426
388
else if (last_color.a == RGBA_COLOR_NONE)
427
D_raster_use_color(D_parse_color(DEFAULT_BG_COLOR, 0));
389
D_use_color(D_parse_color(DEFAULT_BG_COLOR, 0));
428
390
else /* unset or bad */
429
R_RGB_color(line_color->r, line_color->g, line_color->b);
391
D_RGB_color(line_color->r, line_color->g, line_color->b);
431
393
G_free(symb_name);
432
394
G_free(line_color_str);