Пример #1
0
int do_grid(void)
{
    double g, e1, e2;
    int j;

    if (PS.grid <= 0)
	return 1;

    /* set color and set line width to 1 */
    set_ps_color(&PS.grid_color);
    set_line_width(PS.grid_width);

    /* draw horizontal lines in 3 pieces -- lat-lon lines must not
     * extend more than half the globe
     * start with first grid line just south of the window north
     */
    e1 = (PS.w.east * 2 + PS.w.west) / 3;
    e2 = (PS.w.west * 2 + PS.w.east) / 3;

    g = floor(PS.w.north / PS.grid) * PS.grid;
    for (j = 0; g >= PS.w.south; j++, g -= PS.grid) {
	if (g == PS.w.north || g == PS.w.south)
	    continue;

	start_line(PS.w.east, g);
	sec_draw = 0;
	G_plot_line(PS.w.east, g, e1, g);
	fprintf(PS.fp, " D ");

	start_line(e1, g);
	sec_draw = 0;
	G_plot_line(e1, g, e2, g);
	fprintf(PS.fp, " D ");

	start_line(e2, g);
	sec_draw = 0;
	G_plot_line(e2, g, PS.w.west, g);
	fprintf(PS.fp, " D\n");
    }

    /* vertical lines */
    /* start with first grid line just west of the window east */
    g = floor(PS.w.east / PS.grid) * PS.grid;
    for (j = 0; g > PS.w.west; j++, g -= PS.grid) {
	if (g == PS.w.east || g == PS.w.west)
	    continue;
	start_line(g, PS.w.north);
	sec_draw = 0;
	G_plot_line(g, PS.w.north, g, PS.w.south);
	if (j & 1)
	    fprintf(PS.fp, " D\n");
	else
	    fprintf(PS.fp, " D ");
    }

    return 0;
}
Пример #2
0
int ps_outline(void)
{
    /* let user know what's happenning */
    G_message(_("Outlining areas in raster map <%s in %s> ..."),
	      PS.cell_name, PS.cell_mapset);

    /* set the outline color and width */
    set_ps_color(&PS.outline_color);
    set_line_width(PS.outline_width);

    /* create temporary vector map containing outlines */
    o_io_init();
    map_type = o_open_file(PS.cell_name);
    draw_outline();
    o_close_file();

    return 0;
}
Пример #3
0
int do_map_header(char *date)
{
    char temp[100];

    /* set color and font */
    set_ps_color(&hdr.color);
    fontsize = (double)hdr.fontsize;
    fprintf(PS.fp, "(%s) FN %.1f SF\n", hdr.font, fontsize);

    /* set start of first line */
    dy = 1.2 * fontsize;
    y = 72.0 * (PS.page_height - PS.top_marg) - fontsize - 1.5;

    if (hdr.fp == NULL) {

	if (PS.celltitle[0]) {
	    fprintf(PS.fp, "/t (TITLE:  %s) def\n", PS.celltitle);
	    fprintf(PS.fp, "t SW pop %.1f XS D2 t exch %.1f MS\n",
		    72 * PS.page_width, y);
	    y -= dy;
	}
	strcpy(temp, G_myname());
	G_strip(temp);
	if (*temp == 0)
	    strcpy(temp, G_location());
	fprintf(PS.fp, "/t (LOCATION:  %s) def\n", temp);
	fprintf(PS.fp, "t SW pop %.1f XS D2 t exch %.1f MS\n",
		72 * PS.page_width, y);
	y -= 0.25 * dy;
	if (PS.min_y > y)
	    PS.min_y = y;
	return 0;
    }

    x = 72.0 * PS.left_marg + 1.5;
    read_header_file(date);
    y -= 0.25 * dy;
    if (PS.min_y > y)
	PS.min_y = y;

    return 0;
}
Пример #4
0
int do_grid_cross(void)
{
    double g_north, g_east;
    int j, k;

    if (PS.grid <= 0)
	return 1;

    /* set color and set line width to 1 */
    set_ps_color(&PS.grid_color);
    set_line_width(PS.grid_width);

    g_north = floor(PS.w.north / PS.grid) * PS.grid;
    g_east = floor(PS.w.east / PS.grid) * PS.grid;
    for (j = 0; g_north >= PS.w.south; j++, g_north -= PS.grid) {
	for (k = 0; g_east > PS.w.west; k++, g_east -= PS.grid) {

	    if (g_north == PS.w.north || g_north == PS.w.south)
		continue;
	    if (g_east == PS.w.east || g_east == PS.w.west)
		continue;

	    start_line(g_east - PS.grid_cross, g_north);
	    G_plot_line(g_east - PS.grid_cross, g_north,
			g_east + PS.grid_cross, g_north);
	    fprintf(PS.fp, " D ");
	    start_line(g_east, g_north - PS.grid_cross);
	    G_plot_line(g_east, g_north - PS.grid_cross, g_east,
			g_north + PS.grid_cross);
	    fprintf(PS.fp, " D ");
	}
	g_east = floor(PS.w.east / PS.grid) * PS.grid;
    }

    return 0;
}
Пример #5
0
/* plot areas */
int PS_vareas_plot(struct Map_info *P_map, int vec)
{
    int na, area, ret;
    double e, w, n, s, aw, shift;
    double llx, lly, urx, ury, sc;
    char pat[50];
    struct line_cats *Cats;
    struct bound_box box;
    struct varray *Varray = NULL;
    PSCOLOR color;
    int centroid;

    /* rgbcol */
    dbCatValArray cvarr_rgb;

    fprintf(PS.fp, "1 setlinejoin\n");	/* set line join to round */

    Cats = Vect_new_cats_struct();

    /* Create vector array if required */
    if (vector.layer[vec].cats != NULL || vector.layer[vec].where != NULL) {
	Varray = Vect_new_varray(Vect_get_num_areas(P_map));
	if (vector.layer[vec].cats != NULL) {
	    ret =
		Vect_set_varray_from_cat_string(P_map,
						vector.layer[vec].field,
						vector.layer[vec].cats,
						GV_AREA, 1, Varray);
	}
	else {
	    ret = Vect_set_varray_from_db(P_map, vector.layer[vec].field,
					  vector.layer[vec].where, GV_AREA, 1,
					  Varray);
	}
	G_debug(3, "%d items selected for vector %d", ret, vec);
	if (ret == -1)
	    G_fatal_error(_("Cannot load data from table"));
    }

    /* load attributes if rgbcol used */
    if (vector.layer[vec].rgbcol != NULL) {
	load_catval_array_rgb(P_map, vec, &cvarr_rgb);
    }

    shift = 0;
    /* read and plot areas */
    na = Vect_get_num_areas(P_map);
    for (area = 1; area <= na; area++) {
	G_debug(4, "area = %d", area);

	if (Varray != NULL && Varray->c[area] == 0)
	    continue;		/* is not in array */

	if (!Vect_area_alive(P_map, area))
	    continue;

	centroid = Vect_get_area_centroid(P_map, area);
	G_debug(4, "centroid = %d", centroid);
	if (centroid < 1)  /* area is an island */
	    continue;

	Vect_get_area_box(P_map, area, &box);
	n = box.N;
	s = box.S;
	e = box.E;
	w = box.W;
	if (PS.w.proj == PROJECTION_LL) {
	    aw = G_adjust_easting(w, &PS.w);
	    if (aw > PS.w.east)
		aw -= 360.0;
	    shift = aw - w;
	    e += shift;
	    w += shift;
	}
	/* check if in window */
	if (n < PS.w.south || s > PS.w.north || e < PS.w.west ||
	    w > PS.w.east)
	    continue;

	fprintf(PS.fp, "NP\n");
	if (PS.w.proj == PROJECTION_LL) {
	    /* plot area while in window */
	    while (e > PS.w.west) {
		ret = plot_area(P_map, area, shift);
		if (ret != 1)
		    return 0;
		shift -= 360.0;
		e -= 360.0;
	    }
	}
	else {
	    ret = plot_area(P_map, area, shift);
	    if (ret != 1)
		return 0;
	}

	if (vector.layer[vec].pat != NULL ||
	    (!color_none(&vector.layer[vec].fcolor) ||
	     vector.layer[vec].rgbcol != NULL)) {

	    if (vector.layer[vec].rgbcol != NULL) {
		/* load fill color from rgbcol */
		/* if data column is empty or cat is missing don't fill */
		if (get_ps_color_rgbcol_varea(P_map, vec, area, &cvarr_rgb, &color) != 1)
		    return 0;
	    }
	    else {
		color = vector.layer[vec].fcolor;
	    }

	    if (vector.layer[vec].pat != NULL) {	/* use pattern */
		sc = vector.layer[vec].scale;
		/* DEBUG */
		/*
		   printf("\n eps pattern = %s\n", vector.layer[vec].eps);
		   printf("       scale = %f\n", vector.layer[vec].scale);
		 */
		/* load pattern */
		eps_bbox(vector.layer[vec].pat, &llx, &lly, &urx, &ury);
		sprintf(pat, "APATTEPS%d", vec);
		pat_save(PS.fp, vector.layer[vec].pat, pat);
		fprintf(PS.fp,
			"<<  /PatternType 1\n    /PaintType 1\n    /TilingType 1\n");
		fprintf(PS.fp, "    /BBox [%f %f %f %f]\n", llx * sc,
			lly * sc, urx * sc, ury * sc);
		fprintf(PS.fp, "    /XStep %f\n    /YStep %f\n",
			(urx - llx) * sc, (ury - lly) * sc);
		fprintf(PS.fp, "    /PaintProc\n      { begin\n");
		fprintf(PS.fp, "        %f %f scale\n", sc, sc);

		set_ps_color(&color);

		fprintf(PS.fp, "        %.8f W\n", vector.layer[vec].pwidth);
		fprintf(PS.fp, "        %s\n", pat);
		fprintf(PS.fp, "        end\n");
		fprintf(PS.fp, "      } bind\n>>\n");
		sprintf(pat, "APATT%d", vec);
		fprintf(PS.fp, " matrix\n makepattern /%s exch def\n", pat);
		fprintf(PS.fp, "/Pattern setcolorspace\n %s setcolor\n", pat);
	    }
	    else {
		set_ps_color(&color);
	    }

	    fprintf(PS.fp, "F\n");
	}
	if (vector.layer[vec].width > 0 &&
	    !(color_none(&vector.layer[vec].color))) {
	    fprintf(PS.fp, "%.8f W\n", vector.layer[vec].width);
	    set_ps_color(&(vector.layer[vec].color));
	    fprintf(PS.fp, "stroke\n");
	}
    }
    fprintf(PS.fp, "\n");
    fprintf(PS.fp, "0 setlinejoin\n");	/* reset line join to miter */
    return 1;
}
Пример #6
0
int do_grid_numbers(void)
{
    double g;
    char num_text[50];
    int grid, vy, vx, hy = 0, hx = 0;
    int first, len, x, y, last_bottom, last_right;
    int rounded_grid, margin;

    if (PS.grid <= 0 || PS.grid_numbers <= 0)
	return 1;
    grid = PS.grid * PS.grid_numbers;

    /* round grid to multiple of 10 */
    rounded_grid = 1;
    if (PS.w.proj != PROJECTION_LL) {
	sprintf(num_text, "%d", PS.grid);
	len = strlen(num_text);
	while (len-- && num_text[len] == '0')
	    rounded_grid *= 10;
	if (rounded_grid == 10)
	    rounded_grid = 1;
    }

    /* initialize */
    set_font_name(PS.grid_font);
    set_font_size(PS.grid_fontsize);
    set_ps_color(&PS.grid_numbers_color);
    first = 1;

    /* horizontal grid numbers
     * these numbers only appear on the left edge of the first panel.
     * center the numbers on each grid line.
     * suppress number if it falls off the map or would overlay the previous
     *  label
     */
    margin = (int)(0.2 * (double)PS.grid_fontsize + 0.5);
    if (margin < 2)
	margin = 2;
    fprintf(PS.fp, "/mg %d def\n", margin);
    g = floor(PS.w.north / grid) * grid;
    last_bottom = (int)PS.map_top;
    first = 1;
    /* x = XCONV(PS.w.west); */

    for (; g > PS.w.south; g -= grid) {
	/*y = YCONV(g); */

	G_plot_where_xy(PS.w.west, g, &vx, &vy);
	x = (double)vx / 10.;
	y = (double)vy / 10.;

	if (y + PS.grid_fontsize > last_bottom)
	    continue;
	if (y - PS.grid_fontsize < (int)PS.map_bot)
	    continue;
	sprintf(num_text, "%s", format_northing(g, rounded_grid));
	text_box_path(x, y, LEFT, CENTER, num_text, PS.grid_fontsize, 0);
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
	set_ps_color(&PS.grid_numbers_color);
	fprintf(PS.fp, "TIB\n");
	last_bottom = y - PS.grid_fontsize;
	if (first) {
	    first = 0;
	    hy = y + (int)(0.5 * (double)PS.grid_fontsize + 0.5) + margin;
	    hx = x + 0.7 * strlen(num_text) * PS.grid_fontsize + 2 * margin;
	}
    }

    /* vertical grid numbers 
     * center the numbers on each grid line.
     * suppress number if it falls of the map or would overlay the previous
     *  label
     */
    g = floor(PS.w.west / grid) * grid;
    last_right = (int)PS.map_left;
    /* y = YCONV(PS.w.north); */
    for (; g < PS.w.east; g += grid) {
	/* x = XCONV(g); */

	G_plot_where_xy(g, PS.w.north, &vx, &vy);
	x = (double)vx / 10.;
	y = (double)vy / 10.;

	if (x - PS.grid_fontsize < last_right)
	    continue;
	if (x + PS.grid_fontsize > (int)PS.map_right)
	    continue;
	sprintf(num_text, "%s", format_easting(g, rounded_grid));
	vy = y - 0.7 * strlen(num_text) * PS.grid_fontsize - 2 * margin;
	vx = x - (int)(0.5 * (double)PS.grid_fontsize + 0.5) - margin;
	if (vx < hx && vy < hy)
	    continue;
	fprintf(PS.fp, "ZB (%s) PB 90 rotate\n", num_text);
	fprintf(PS.fp, "%d br sub bl add mg add\n", y);
	fprintf(PS.fp, "%d bt bb sub D2 add mg sub neg TR TB\n", x);
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
	set_ps_color(&PS.grid_numbers_color);
	fprintf(PS.fp, "TIB\n");
	last_right = x + PS.grid_fontsize;
    }

    return 0;
}
Пример #7
0
static int output(char *line, char *date)
{
    char text[1024];
    char fmt[30];
    char *buf;

    buf = line;
    *text = 0;
    while (*buf) {
	if (*buf == '%') {
	    buf++;
	    if (*buf == '%')
		strcat(text, "%");
	    else if (*buf == 'n') {
		if (*text)
		    show_text(x, y, text);
		y -= dy;
		return 0;
	    }
	    else if (*buf == '_') {
		fprintf(PS.fp, "BW ");
		draw_line(x, y + 0.2 * fontsize,
			  72.0 * (PS.page_width - PS.right_marg),
			  y + 0.2 * fontsize);
		y -= dy;
		set_ps_color(&hdr.color);
		return 0;
	    }
	    else {
		buf = get_format(buf, fmt);
		append('s', fmt);
		switch (*buf) {
		case 'd':
		    apply(date, fmt, text);
		    break;
		case 'l':
		    apply(G_location(), fmt, text);
		    break;
		case 'L':
		    apply(G_myname(), fmt, text);
		    break;
		case 'c':
		    if (PS.cell_fd >= 0) {
			char name[100];

			sprintf(name, "<%s> in mapset <%s>",
				PS.cell_name, PS.cell_mapset);
			apply(name, fmt, text);
		    }
		    else
			apply("none", fmt, text);
		    break;
		case 'm':
		    apply(G_mapset(), fmt, text);
		    break;
		case 'u':
		    apply(G_whoami(), fmt, text);
		    break;
		case 'x':
		    apply(G_mask_info(), fmt, text);
		    break;
		case 0:
		    continue;
		}
	    }
	}
	else
	    append(*buf, text);
	buf++;
    }
    if (*text)
	show_text(x, y, text);
    y -= dy;

    return 0;
}
Пример #8
0
int do_vectors(int after_masking)
{
    int n, z, lz, dig;
    struct Map_info Map;
    char dashes[100], buf[20], *ptr;

    n = vector.count;
    while (n-- > 0) {
	if (vector.layer[n].type == VPOINTS)
	    continue;
	if (after_masking && vector.layer[n].masked)
	    continue;
	if (!after_masking && !vector.layer[n].masked)
	    continue;

	G_message(_("Reading vector map <%s in %s> ..."),
		  vector.layer[n].name, vector.layer[n].mapset);

	Vect_set_open_level(2);
	Vect_set_fatal_error(GV_FATAL_PRINT);
	if (2 >
	    Vect_open_old(&Map, vector.layer[n].name,
			  vector.layer[n].mapset)) {
	    char name[100];

	    sprintf(name, "%s in %s", vector.layer[n].name,
		    vector.layer[n].mapset);
	    error("vector map", name, "can't open");
	    continue;
	}

	if (vector.layer[n].type == VAREAS) {
	    PS_vareas_plot(&Map, n);
	}
	else if (vector.layer[n].type == VLINES) {
	    fprintf(PS.fp, "[] 0 setdash\n");
	    if (vector.layer[n].hwidth &&
		vector.layer[n].ref == LINE_REF_CENTER) {
		set_ps_color(&(vector.layer[n].hcolor));
		fprintf(PS.fp, "%.8f W\n",
			vector.layer[n].width + 2. * vector.layer[n].hwidth);
		PS_vlines_plot(&Map, n, LINE_DRAW_HIGHLITE);
		Vect_rewind(&Map);
	    }

	    fprintf(PS.fp, "%.8f W\n", vector.layer[n].width);
	    set_ps_color(&(vector.layer[n].color));

	    if (vector.layer[n].linecap >= 0) {
		G_debug(1, "Line cap: '%d'", vector.layer[n].linecap);
		fprintf(PS.fp, "%d setlinecap\n",vector.layer[n].linecap);		 
	    }

	    dashes[0] = '[';
	    dashes[1] = 0;
	    lz = 0;
	    if (vector.layer[n].linestyle != NULL) {
		G_debug(1, "Line style: '%s'", vector.layer[n].linestyle);
		G_strip(vector.layer[n].linestyle);
		ptr = vector.layer[n].linestyle;
		while (*ptr && (*ptr < '1' || *ptr > '9')) {
		    lz++;
		    ptr++;
		}
		if (lz) {
		    sprintf(buf, "%d ", lz);
		    strcat(dashes, buf);
		}
		while (*ptr) {
		    dig = 0;
		    while (*ptr >= '1' && *ptr <= '9') {
			dig++;
			ptr++;
		    }
		    if (dig) {
			sprintf(buf, "%d ", dig);
			strcat(dashes, buf);
		    }
		    z = 0;
		    while (*ptr && (*ptr < '1' || *ptr > '9')) {
			z++;
			ptr++;
		    }
		    if (z) {
			sprintf(buf, "%d ", z);
			strcat(dashes, buf);
		    }
		}
	    }
	    sprintf(buf, "] %d", lz);
	    strcat(dashes, buf);
	    fprintf(PS.fp, "%s setdash\n", dashes);
	    vector.layer[n].setdash = G_store(dashes);
	    if (vector.layer[n].linestyle != NULL)
		G_debug(1, "Dash style: '%s setdash'", dashes);
	    PS_vlines_plot(&Map, n, LINE_DRAW_LINE);
	}

	Vect_close(&Map);
	fprintf(PS.fp, "[] 0 setdash\n");
    }

    return 0;
}