Пример #1
0
int read_info(void)
{
    char buf[1024];
    char *key, *data;
    int fontsize;
    double x, y;
    int r, g, b, ret;
    PSCOLOR color, bgcolor, border;

    fontsize = 0;
    set_color(&color, 0, 0, 0);
    set_color(&bgcolor, 255, 255, 255);
    unset_color(&border);
    x = y = 0.0;

    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("where")) {
	    if (sscanf(data, "%lf %lf", &x, &y) != 2) {
		x = y = 0.0;
		error(key, data, _("illegal where request"));
	    }
	    else
		continue;
	}

	if (KEY("fontsize")) {
	    fontsize = atoi(data);
	    if (fontsize < 4 || fontsize > 50)
		fontsize = 0;
	    continue;
	}

	if (KEY("color")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&color, r, g, b);
	    else if (ret == 2)  /* i.e. "none" */
		/* unset_color(&color); */
		error(key, data, _("Unsupported color request"));
	    else
		error(key, data, _("illegal color request"));

	    continue;
	}

	if (KEY("background")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&bgcolor, r, g, b);
	    else if (ret == 2)  /* i.e. "none" */
		unset_color(&bgcolor);
	    else
		error(key, data, _("illegal bgcolor request"));

	    continue;
	}

	if (KEY("border")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&border, r, g, b);
	    else if (ret == 2)  /* i.e. "none" */
		unset_color(&border);
	    else
		error(key, data, _("illegal border color request"));

	    continue;
	}

	if (KEY("font")) {
	    get_font(data);
	    m_info.font = G_store(data);
	    continue;
	}
	error(key, data, _("illegal mapinfo sub-request"));
    }
    m_info.x = x;
    m_info.y = y;
    m_info.color = color;
    m_info.bgcolor = bgcolor;
    m_info.border = border;
    if (fontsize)
	m_info.fontsize = fontsize;

    return 0;
}
Пример #2
0
int read_text(char *east, char *north, char *text)
{
    PSCOLOR color, hcolor, background, border;
    int r, g, b;
    int ret;
    int xoffset;
    int yoffset;
    float size;
    int fontsize;
    double width;
    double hwidth;
    double rotate;
    int xref, yref;
    int opaque;
    char t1[128];
    char buf[1024];
    char *key, *data;
    FILE *fd;
    char fontname[128];

    set_color(&color, 0, 0, 0);	/* black */
    unset_color(&hcolor);
    unset_color(&background);
    unset_color(&border);
    opaque = TRUE;
    size = 0.0;
    fontsize = 0;
    xoffset = 0;
    yoffset = 0;
    width = 1.;
    hwidth = 0.;
    rotate = 0.0;
    xref = CENTER;
    yref = CENTER;
    G_strcpy(fontname, "Helvetica");

    while (*text == ' ' || *text == '\t')
	text++;
    if (*text == '\\')
	text++;
    if (*text == 0) {
	error("text", "", "no text given");
	gobble_input();
	return 0;
    }

    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("font")) {
	    get_font(data);
	    strcpy(fontname, data);
	    continue;
	}

	if (KEY("color")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&color, r, g, b);
	    else if (ret == 2)
		error(key, data, "primary color cannot be \"none\"");
	    else
		error(key, data, "illegal color request");

	    continue;
	}

	if (KEY("hcolor")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&hcolor, r, g, b);
	    else if (ret == 2)
		unset_color(&hcolor);
	    else
		error(key, data, "illegal hcolor request");

	    if (color_none(&hcolor) || hwidth <= 0.)
		hwidth = 0.;
	    continue;
	}

	if (KEY("background")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&background, r, g, b);
	    else if (ret == 2) {
		unset_color(&background);
		opaque = FALSE;
	    }
	    else
		error(key, data, "illegal background color request");

	    continue;
	}

	if (KEY("border")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&border, r, g, b);
	    else if (ret == 2)
		unset_color(&border);
	    else
		error(key, data, "illegal border color request");

	    continue;
	}

	if (KEY("opaque")) {
	    opaque = yesno(key, data);
	    continue;
	}

	if (KEY("width")) {
	    width = -1.;
	    *t1 = 0;
	    if (sscanf(data, "%lf%1s", &width, t1) < 1 || width < 0.) {
		width = 1.;
		error(key, data, "illegal width request");
	    }
	    if (t1 && t1[0] == 'i')
		width = width / 72.0;
	    continue;
	}

	if (KEY("hwidth")) {
	    hwidth = -1.;
	    *t1 = 0;
	    if (sscanf(data, "%lf%1s", &hwidth, t1) < 1 || hwidth < 0.) {
		hwidth = 0.;
		error(key, data, "illegal width request");
	    }
	    if (t1 && t1[0] == 'i')
		hwidth = hwidth / 72.0;
	    continue;
	}

	if (KEY("size")) {
	    double x;

	    if (!scan_resolution(data, &x)) {
		size = 0.0;
		error(key, data, "illegal size request");
	    }
	    else
		size = x;
	    continue;
	}

	if (KEY("fontsize")) {
	    if (sscanf(data, "%d", &fontsize) != 1 || fontsize <= 0) {
		error(key, data, "illegal fontsize request");
	    }
	    else
		continue;
	}

	if (KEY("xoffset")) {
	    *t1 = 0;
	    if (sscanf(data, "%d%1s", &xoffset, t1) != 1 || *t1) {
		xoffset = 0;
		error(key, data, "illegal request (text)");
	    }
	    continue;
	}

	if (KEY("yoffset")) {
	    *t1 = 0;
	    if (sscanf(data, "%d%1s", &yoffset, t1) != 1 || *t1) {
		yoffset = 0;
		error(key, data, "illegal request (text)");
	    }
	    continue;
	}

	if (KEY("rotate")) {
	    if (sscanf(data, "%lf", &rotate) != 1) {
		rotate = 0.0;
		error(key, data, "illegal rotate request");
	    }
	    continue;
	}

	if (KEY("ref")) {
	    if (!scan_ref(data, &xref, &yref)) {
		xref = CENTER;
		yref = CENTER;
		error(key, data, "illegal ref request");
	    }
	    continue;
	}

	error(key, data, "illegal request (text)");
    }

    /* if file doesn't exist create it and close it */
    if (labels.other == NULL) {
	labels.other = G_tempfile();
	if ((fd = fopen(labels.other, "w")) != NULL)
	    fclose(fd);
    }

    /* open file in append mode */
    fd = fopen(labels.other, "a");
    if (fd == NULL) {
	error("misc labels file", "", "can't open");
	return 1;
    }

    /* write the file */
    fprintf(fd, "font: %s\n", fontname);
    fprintf(fd, "east: %s\n", east);
    fprintf(fd, "north: %s\n", north);
    fprintf(fd, "xoffset: %d\n", xoffset);
    fprintf(fd, "yoffset: %d\n", yoffset);
    fprintf(fd, "width: %f\n", width);
    fprintf(fd, "hwidth: %f\n", hwidth);
    fprintf(fd, "size: %f\n", size);
    fprintf(fd, "fontsize: %d\n", fontsize);
    fprintf(fd, "opaque: %s\n", opaque ? "yes" : "no");
    if (rotate != 0)
	fprintf(fd, "rotate: %f\n", rotate);

    fprintf(fd, "color: ");
    if (!color_none(&color))
	fprintf(fd, "%d:%d:%d\n", color.r, color.g, color.b);
    else
	fprintf(fd, "black\n");

    fprintf(fd, "hcolor: ");
    if (!color_none(&hcolor))
	fprintf(fd, "%d:%d:%d\n", hcolor.r, hcolor.g, hcolor.b);
    else
	fprintf(fd, "none\n");

    fprintf(fd, "background: ");
    if (!color_none(&background))
	fprintf(fd, "%d:%d:%d\n", background.r, background.g, background.b);
    else
	fprintf(fd, "none\n");


    fprintf(fd, "border: ");
    if (!color_none(&border))
	fprintf(fd, "%d:%d:%d\n", border.r, border.g, border.b);
    else
	fprintf(fd, "none\n");

    fprintf(fd, "ref: ");
    switch (yref) {
    case UPPER:
	fprintf(fd, "upper");
	break;
    case LOWER:
	fprintf(fd, "lower");
	break;
    case CENTER:
	fprintf(fd, "center");
	break;
    }
    switch (xref) {
    case LEFT:
	fprintf(fd, " left");
	break;
    case RIGHT:
	fprintf(fd, " right");
	break;
    case CENTER:
	fprintf(fd, "%s", (xref == CENTER) ? "" : " center");
	break;
    }
    fprintf(fd, "\n");
    fprintf(fd, "text:%s\n\n", text);
    fclose(fd);

    return 0;
}
Пример #3
0
int read_vpoints(char *name, char *mapset)
{
    char fullname[100];
    char buf[1024];
    char *key, *data;
    double width, size, scale, rotate;
    int itmp, vec;
    int r, g, b;
    int ret;
    struct Map_info Map;

    vector_alloc();		/* allocate space */

    sprintf(fullname, "%s in %s", name, mapset);

    Vect_set_open_level(2);
    Vect_set_fatal_error(GV_FATAL_PRINT);
    if (2 > Vect_open_old(&Map, name, mapset)) {
	error(fullname, "", "can't open vector map");
	gobble_input();
	return 0;
    }
    Vect_close(&Map);

    vec = vector.count;

    vector.layer[vec].type = VPOINTS;
    vector.layer[vec].name = G_store(name);
    vector.layer[vec].mapset = G_store(mapset);
    vector.layer[vec].ltype = GV_POINT;
    vector.layer[vec].masked = 0;

    vector.layer[vec].field = 1;
    vector.layer[vec].cats = NULL;
    vector.layer[vec].where = NULL;

    vector.layer[vec].width = 1.;
    set_color(&(vector.layer[vec].color), 0, 0, 0);
    set_color(&(vector.layer[vec].fcolor), 255, 0, 0);
    vector.layer[vec].rgbcol = NULL;

    vector.layer[vec].label = NULL;
    vector.layer[vec].lpos = -1;
    vector.layer[vec].symbol = G_store("basic/diamond");

    vector.layer[vec].size = 6.0;
    vector.layer[vec].sizecol = NULL;
    vector.layer[vec].scale = 1.0;

    vector.layer[vec].rotate = 0.0;
    vector.layer[vec].rotcol = NULL;
    vector.layer[vec].epstype = 0;


    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("masked")) {
	    vector.layer[vec].masked = yesno(key, data);
	    if (vector.layer[vec].masked)
		PS.mask_needed = 1;
	    continue;
	}

	if (KEY("type")) {
	    G_strip(data);
	    vector.layer[vec].ltype = 0;

	    if (strstr(data, "point"))
		vector.layer[vec].ltype |= GV_POINT;

	    if (strstr(data, "centroid"))
		vector.layer[vec].ltype |= GV_CENTROID;

	    continue;
	}

	if (KEY("layer")) {
	    G_strip(data);
	    vector.layer[vec].field = atoi(data);
	    continue;
	}

	if (KEY("cats")) {
	    G_strip(data);
	    vector.layer[vec].cats = G_store(data);
	    continue;
	}

	if (KEY("where")) {
	    G_strip(data);
	    vector.layer[vec].where = G_store(data);
	    continue;
	}

	if (KEY("width")) {
	    width = -1.;
	    *mapset = 0;
	    if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) {
		width = 1.;
		error(key, data, "illegal width (vpoints)");
		continue;
	    }
	    if (mapset[0] == 'i')
		width = width / 72.;
	    vector.layer[vec].width = width;
	    continue;
	}

	if (KEY("color")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&(vector.layer[vec].color), r, g, b);
	    else if (ret == 2)
		unset_color(&(vector.layer[vec].color));
	    else
		error(key, data, "illegal color request");

	    continue;
	}

	if (KEY("fcolor")) {	/* fill color */
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&(vector.layer[vec].fcolor), r, g, b);
	    else if (ret == 2)
		unset_color(&(vector.layer[vec].fcolor));
	    else
		error(key, data, "illegal color request (vpoints)");

	    continue;
	}

	if (KEY("rgbcolumn")) {
	    G_strip(data);
	    vector.layer[vec].rgbcol = G_store(data);
	    continue;
	}

	if (KEY("label")) {	/* map legend label */
	    G_strip(data);
	    vector.layer[vec].label = G_store(data);
	    continue;
	}

	if (KEY("lpos")) {
	    if (sscanf(data, "%d", &itmp) < 1 || itmp < 0) {
		itmp = -1;
		error(key, data, "illegal lpos");
		continue;
	    }
	    vector.layer[vec].lpos = itmp;
	    continue;
	}

	if (KEY("symbol")) {
	    /* TODO: test here if isymbol exists */
	    vector.layer[vec].symbol = G_store(data);
	    continue;
	}

	if (KEY("eps")) {
	    char *cc;

	    G_chop(data);
	    vector.layer[vec].epspre = G_store(data);

	    /* epstype: 0 - no eps, 1 - common eps, 2 - eps for each category */
	    vector.layer[vec].epstype = 1;

	    /* find dynamic filename by cat number character */
	    /* pre is filename before the $, suf is filename after the $ */
	    cc = (char *)strchr(vector.layer[vec].epspre, '$');
	    if (cc != NULL) {
		*cc = '\0';
		vector.layer[vec].epssuf = G_store(cc + sizeof(char));
		vector.layer[vec].epstype = 2;

		G_debug(2, "epstype=%d, pre=[%s], suf=[%s]",
			vector.layer[vec].epstype, vector.layer[vec].epspre,
			vector.layer[vec].epssuf);
	    }
	    else {
		G_debug(2, "epstype=%d, eps file=[%s]",
			vector.layer[vec].epstype, vector.layer[vec].epspre);
	    }
	    continue;
	}

	if (KEY("size")) {
	    if (sscanf(data, "%lf", &size) != 1 || size <= 0.0) {
		size = 1.0;
		error(key, data, "illegal size request (vpoints)");
	    }
	    vector.layer[vec].size = size;
	    continue;
	}

	/* 
	   GRASS 6.3: sizecol renamed to sizecolumn
	   remove sizecol test and the warning in GRASS7
	 */
	if (KEY("sizecol")) {
	    G_warning(_("The mapping instruction <%s> will be renamed to <%s> "
		       "in future versions of GRASS. Please use <%s> instead."),
		      "sizecol", "sizecolumn", "sizecolumn");
	}
	if (KEY("sizecol") || KEY("sizecolumn")) {
	    G_strip(data);
	    vector.layer[vec].sizecol = G_store(data);
	    continue;
	}

	if (KEY("scale")) {
	    if (sscanf(data, "%lf", &scale) != 1 || scale <= 0.0) {
		scale = 1.0;
		error(key, data, "illegal scale request (vpoints)");
	    }
	    vector.layer[vec].scale = scale;
	    continue;
	}

	if (KEY("rotate")) {
	    if (sscanf(data, "%lf", &rotate) != 1) {
		rotate = 0.0;
		error(key, data, "illegal rotation request (vpoints)");
	    }
	    vector.layer[vec].rotate = rotate;
	    continue;
	}

	if (KEY("rotatecolumn")) {
	    G_strip(data);
	    vector.layer[vec].rotcol = G_store(data);
	    continue;
	}

	error(key, "", "illegal request (vpoints)");
    }

    vector.count++;
    return 1;
}
Пример #4
0
int read_vlines(char *name, char *mapset)
{
    char fullname[GNAME_MAX];
    char buf[1024];
    char *key, *data, *dp;
    double width;
    int itmp, vec;
    int r, g, b;
    int ret;
    struct Map_info Map;

    vector_alloc();		/* allocate space */

    sprintf(fullname, "%s in %s", name, mapset);

    Vect_set_open_level(2);
    Vect_set_fatal_error(GV_FATAL_PRINT);
    if (2 > Vect_open_old(&Map, name, mapset)) {
	error(fullname, "", "can't open vector map");
	gobble_input();
	return 0;
    }
    Vect_close(&Map);

    vec = vector.count;

    vector.layer[vec].type = VLINES;
    vector.layer[vec].name = G_store(name);
    vector.layer[vec].mapset = G_store(mapset);
    vector.layer[vec].ltype = GV_LINE;
    vector.layer[vec].masked = 0;

    vector.layer[vec].field = 1;
    vector.layer[vec].cats = NULL;
    vector.layer[vec].where = NULL;

    vector.layer[vec].width = 1.;
    vector.layer[vec].cwidth = 0.;
    vector.layer[vec].offset = 0.;
    vector.layer[vec].coffset = 0.;
    set_color(&(vector.layer[vec].color), 0, 0, 0);
    vector.layer[vec].rgbcol = NULL;
    vector.layer[vec].linestyle = NULL;
    vector.layer[vec].linecap = LINECAP_BUTT;
    vector.layer[vec].ref = LINE_REF_CENTER;
    vector.layer[vec].hwidth = 0.;
    unset_color(&(vector.layer[vec].hcolor));
    vector.layer[vec].label = NULL;
    vector.layer[vec].lpos = -1;
    vector.layer[vec].pwidth = 1.;


    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("masked")) {
	    vector.layer[vec].masked = yesno(key, data);
	    if (vector.layer[vec].masked)
		PS.mask_needed = 1;
	    continue;
	}

	if (KEY("type")) {
	    G_strip(data);
	    vector.layer[vec].ltype = 0;

	    if (strstr(data, "line"))
		vector.layer[vec].ltype |= GV_LINE;

	    if (strstr(data, "boundary"))
		vector.layer[vec].ltype |= GV_BOUNDARY;

	    continue;
	}

	if (KEY("layer")) {
	    G_strip(data);
	    vector.layer[vec].field = atoi(data);
	    continue;
	}

	if (KEY("cats")) {
	    G_strip(data);
	    vector.layer[vec].cats = G_store(data);
	    continue;
	}

	if (KEY("where")) {
	    G_strip(data);
	    vector.layer[vec].where = G_store(data);
	    continue;
	}

	if (KEY("style")) {
	    G_strip(data);
	    if (strcmp(data, "solid") == 0) {
		vector.layer[vec].linestyle = NULL;
		continue;
	    }
	    else if (strcmp(data, "dashed") == 0) {
		vector.layer[vec].linestyle = G_store("000000111");
		continue;
	    }
	    else if (strcmp(data, "dotted") == 0) {
		vector.layer[vec].linestyle = G_store("100000");
		continue;
	    }
	    else if (strcmp(data, "dashdotted") == 0) {
		vector.layer[vec].linestyle = G_store("000000111011111");
		continue;
	    }
	    for (dp = data; *dp; dp++)
		if (*dp < '0' || *dp > '9')
		    break;
	    if (*dp != 0 || dp == data) {
		error(key, data, "illegal line style (vlines)");
		continue;
	    }
	    vector.layer[vec].linestyle = G_store(data);
	    continue;
	}

	if (KEY("linecap")) {
	    G_strip(data);
	    if (strcmp(data, "butt") == 0) {
		vector.layer[vec].linecap = LINECAP_BUTT;
		continue;
	    }
	    else if (strcmp(data, "round") == 0) {
		vector.layer[vec].linecap = LINECAP_ROUND;
		continue;
	    }
	    else if (strcmp(data, "extended_butt") == 0) {
		vector.layer[vec].linecap = LINECAP_EXTBUTT;
		continue;
	    }
	    else
		error(key, data, "illegal line cap (vlines)");		
	    continue;
	}

	if (KEY("width")) {
	    width = -1.;
	    *mapset = 0;
	    if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) {
		width = 1.;
		error(key, data, "illegal width (vlines)");
		continue;
	    }
	    if (mapset[0] == 'i')
		width = width / 72.;
	    vector.layer[vec].width = width;
	    continue;
	}

	if (KEY("cwidth")) {
	    width = -1.;
	    *mapset = 0;
	    if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) {
		width = 1.;
		error(key, data, "illegal cwidth (vlines)");
		continue;
	    }
	    if (mapset[0] == 'i')
		width = width / 72.;
	    vector.layer[vec].cwidth = width;
	    continue;
	}

	if (KEY("offset")) {
	    *mapset = 0;
	    if (sscanf(data, "%lf%s", &width, mapset) < 1) {
		width = 0.;
		error(key, data, "illegal offset (vlines)");
		continue;
	    }
	    if (mapset[0] == 'i')
		width = width / 72.;
	    vector.layer[vec].offset = width;
	    continue;
	}

	if (KEY("coffset")) {
	    *mapset = 0;
	    if (sscanf(data, "%lf%s", &width, mapset) < 1) {
		width = 0.;
		error(key, data, "illegal coffset (vlines)");
		continue;
	    }
	    if (mapset[0] == 'i')
		width = width / 72.;
	    vector.layer[vec].coffset = width;
	    continue;
	}

	if (KEY("hwidth")) {
	    width = -1.;
	    if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) {
		width = 0.;
		error(key, data, "illegal hwidth (vlines)");
		continue;
	    }
	    if (mapset[0] == 'i')
		width = width / 72.;
	    vector.layer[vec].hwidth = width;
	    continue;
	}

	if (KEY("color")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&(vector.layer[vec].color), r, g, b);
	    else if (ret == 2)
		unset_color(&(vector.layer[vec].color));
	    else
		error(key, data, "illegal color request (vlines)");

	    continue;
	}

	if (KEY("rgbcolumn")) {
	    G_strip(data);
	    vector.layer[vec].rgbcol = G_store(data);
	    continue;
	}

	if (KEY("hcolor")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&(vector.layer[vec].hcolor), r, g, b);
	    else if (ret == 2)
		unset_color(&(vector.layer[vec].hcolor));
	    else
		error(key, data, "illegal hcolor request (vlines)");

	    continue;
	}

	if (KEY("label")) {	/* map legend label */
	    G_strip(data);
	    vector.layer[vec].label = G_store(data);
	    continue;
	}

	if (KEY("lpos")) {
	    if (sscanf(data, "%d", &itmp) < 1 || itmp < 0) {
		itmp = -1;
		error(key, data, "illegal lpos (vlines)");
		continue;
	    }
	    vector.layer[vec].lpos = itmp;
	    continue;
	}

	if (KEY("ref")) {
	    G_strip(data);
	    if (strcmp(data, "left") == 0) {
		vector.layer[vec].ref = LINE_REF_LEFT;
		continue;
	    }
	    if (strcmp(data, "right") == 0) {
		vector.layer[vec].ref = LINE_REF_RIGHT;
		continue;
	    }
	    error(key, data, "illegal ref request (vlines)");
	    continue;
	}

	if (KEY("scale")) {
	    G_strip(data);
	    vector.layer[vec].scale = atof(data);
	    continue;
	}
	error(key, "", "illegal request (vlines)");
    }

    vector.count++;
    return 1;
}