[GRASS-SVN] r33070 - in grass/trunk/display: d.histogram d.labels d.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 25 14:08:57 EDT 2008


Author: glynn
Date: 2008-08-25 14:08:57 -0400 (Mon, 25 Aug 2008)
New Revision: 33070

Added:
   grass/trunk/display/d.vect/utils.c
Modified:
   grass/trunk/display/d.histogram/bar.c
   grass/trunk/display/d.histogram/main.c
   grass/trunk/display/d.histogram/pie.c
   grass/trunk/display/d.labels/do_labels.c
   grass/trunk/display/d.vect/attr.c
   grass/trunk/display/d.vect/label.c
   grass/trunk/display/d.vect/local_proto.h
   grass/trunk/display/d.vect/plot.h
   grass/trunk/display/d.vect/plot1.c
   grass/trunk/display/d.vect/topo.c
   grass/trunk/display/d.vect/zcoor.c
Log:
Eliminate R_* functions in favour of D_* equivalents (part 2)


Modified: grass/trunk/display/d.histogram/bar.c
===================================================================
--- grass/trunk/display/d.histogram/bar.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.histogram/bar.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -66,8 +66,8 @@
     char txt[1024];
     char tic_name[80];
 
-    /* get coordinates of current screen window, in pixels */
-    D_get_dst(&t, &b, &l, &r);
+    /* get coordinates of current screen window */
+    D_get_src(&t, &b, &l, &r);
 
     /* create axis lines, to be drawn later */
     height = b - t;
@@ -234,7 +234,7 @@
 					   0.5 * xscale + j + 1);
 			    y_box[0] = y_box[3] = yoffset;
 			    y_box[1] = y_box[2] = bar_height;
-			    R_polygon_abs(x_box, y_box, 4);
+			    D_polygon_abs(x_box, y_box, 4);
 			}
 		    }
 		    else {	/* 1-color bar */
@@ -248,7 +248,7 @@
 				       0.5 * xscale);
 			y_box[0] = y_box[3] = yoffset;
 			y_box[1] = y_box[2] = bar_height;
-			R_polygon_abs(x_box, y_box, 4);
+			D_polygon_abs(x_box, y_box, 4);
 		    }
 		}		/* fp */
 		else {		/* 1-color bar for int data or null */
@@ -262,7 +262,7 @@
 				   0.5 * xscale);
 		    y_box[0] = y_box[3] = yoffset;
 		    y_box[1] = y_box[2] = bar_height;
-		    R_polygon_abs(x_box, y_box, 4);
+		    D_polygon_abs(x_box, y_box, 4);
 		}
 	    }
 	    else {
@@ -285,8 +285,8 @@
 		    xoffset + (i - dist_stats->mincat) * xscale;
 		y_box[0] = yoffset;
 		y_box[1] = bar_height;
-		R_move_abs(x_box[0], y_box[0]);
-		R_cont_abs(x_box[1], y_box[1]);
+		D_move_abs(x_box[0], y_box[0]);
+		D_cont_abs(x_box[1], y_box[1]);
 	    }
 	}
 
@@ -299,9 +299,9 @@
 	    && !(nodata && i == dist_stats->mincat + 1)) {
 	    /* draw a numbered tic-mark */
 	    D_raster_use_color(color);
-	    R_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale,
+	    D_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale,
 		       b - ORIGIN_Y * (b - t));
-	    R_cont_rel(0, BIG_TIC * (b - t));
+	    D_cont_rel(0, BIG_TIC * (b - t));
 	    if (nodata && i == dist_stats->mincat)
 		sprintf(txt, "null");
 	    else if (is_fp) {
@@ -322,16 +322,16 @@
 		R_text_size(text_width, text_height);
 		R_get_text_box(txt, &tt, &tb, &tl, &tr);
 	    }
-	    R_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale - (tr - tl) / 2,
+	    D_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale - (tr - tl) / 2,
 		       b - XNUMS_Y * (b - t));
 	    R_text(txt);
 	}
 	else if (rem(i, tic_unit) == (float)0) {
 	    /* draw a tic-mark */
 	    D_raster_use_color(color);
-	    R_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale,
+	    D_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale,
 		       b - ORIGIN_Y * (b - t));
-	    R_cont_rel(0, SMALL_TIC * (b - t));
+	    D_cont_rel(0, SMALL_TIC * (b - t));
 	}
     }
 
@@ -344,7 +344,7 @@
     text_width = (r - l) * TEXT_WIDTH;
     R_text_size(text_width, text_height);
     R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
-    R_move_abs(l + (r - l) / 2 - (tr - tl) / 2,
+    D_move_abs(l + (r - l) / 2 - (tr - tl) / 2,
 	       b - LABEL_1 * (b - t));
     D_raster_use_color(color);
     R_text(xlabel);
@@ -377,8 +377,8 @@
     for (i = stat_start; i <= stat_finis; i += tic_unit) {
 	if (rem(i, tic_every) == (float)0) {
 	    /* draw a tic-mark */
-	    R_move_abs(x_line[0], yoffset - yscale * i);
-	    R_cont_rel((-(r - l) * BIG_TIC), 0);
+	    D_move_abs(x_line[0], yoffset - yscale * i);
+	    D_cont_rel((-(r - l) * BIG_TIC), 0);
 
 	    /* draw a tic-mark number */
 	    sprintf(txt, "%d", (int)(i / tic_unit));
@@ -392,14 +392,14 @@
 		R_text_size(text_width, text_height);
 		R_get_text_box(txt, &tt, &tb, &tl, &tr);
 	    }
-	    R_move_abs(l + (r - l) * YNUMS_X - (tr - tl) / 2,
+	    D_move_abs(l + (r - l) * YNUMS_X - (tr - tl) / 2,
 		       yoffset - (yscale * i + 0.5 * (tt - tb)));
 	    R_text(txt);
 	}
 	else if (rem(i, tic_unit) == (float)0) {
 	    /* draw a tic-mark */
-	    R_move_abs(x_line[0], yoffset - yscale * i);
-	    R_cont_rel(-(r - l) * SMALL_TIC, 0);
+	    D_move_abs(x_line[0], yoffset - yscale * i);
+	    D_cont_rel(-(r - l) * SMALL_TIC, 0);
 	}
     }
 
@@ -421,14 +421,14 @@
     text_width = (r - l) * TEXT_WIDTH;
     R_text_size(text_width, text_height);
     R_get_text_box(ylabel, &tt, &tb, &tl, &tr);
-    R_move_abs(l + (r - l) / 2 - (tr - tl) / 2,
+    D_move_abs(l + (r - l) / 2 - (tr - tl) / 2,
 	       b - LABEL_2 * (b - t));
     D_raster_use_color(color);
     R_text(ylabel);
 
     /* draw x and y axis lines */
     D_raster_use_color(color);
-    R_polyline_abs(x_line, y_line, 3);
+    D_polyline_abs(x_line, y_line, 3);
 
     return 0;
 }

Modified: grass/trunk/display/d.histogram/main.c
===================================================================
--- grass/trunk/display/d.histogram/main.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.histogram/main.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -193,8 +193,8 @@
     if (R_open_driver() != 0)
 	G_fatal_error(_("No graphics device selected"));
 
-    D_setup(0);			/* 0 = don't clear frame */
-    D_get_dst(&t, &b, &l, &r);
+    D_setup_unity(0);			/* 0 = don't clear frame */
+    D_get_src(&t, &b, &l, &r);
 
     /* clear the frame, if requested to do so */
     if (strcmp(bg_opt->answer, "none") != 0)
@@ -206,7 +206,7 @@
     text_width = (r - l) * 0.05 * 0.50;
     R_text_size(text_width, text_height);
     R_get_text_box(title, &tt, &tb, &tl, &tr);
-    R_move_abs(l + (r - l) / 2 - (tr - tl) / 2,
+    D_move_abs(l + (r - l) / 2 - (tr - tl) / 2,
 	       t + (b - t) * 0.07);
     D_raster_use_color(color);
     R_text(title);

Modified: grass/trunk/display/d.histogram/pie.c
===================================================================
--- grass/trunk/display/d.histogram/pie.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.histogram/pie.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -70,8 +70,8 @@
     char tic_name[80];
     DCELL dmin, dmax, range_dmin, range_dmax, dval;
 
-    /* get coordinates of current screen window, in pixels */
-    D_get_dst(&t, &b, &l, &r);
+    /* get coordinates of current screen window */
+    D_get_src(&t, &b, &l, &r);
 
     /* create legend box border, to be drawn later */
     height = b - t;
@@ -311,7 +311,7 @@
 				       0.5 * xscale + j + 1);
 			y_box[0] = y_box[3] = y_box[4] = y_line[0];
 			y_box[1] = y_box[2] = bar_height;
-			R_polygon_abs(x_box, y_box, 4);
+			D_polygon_abs(x_box, y_box, 4);
 		    }
 		}
 		else {		/* draw 1-color bar, color is already set */
@@ -324,7 +324,7 @@
 				   0.5 * xscale);
 		    y_box[0] = y_box[3] = y_box[4] = y_line[0];
 		    y_box[1] = y_box[2] = bar_height;
-		    R_polygon_abs(x_box, y_box, 4);
+		    D_polygon_abs(x_box, y_box, 4);
 		}
 	    }
 	    else {		/* color is already set for 1-color bar */
@@ -334,8 +334,8 @@
 		    xoffset + (i - dist_stats->mincat) * xscale;
 		y_box[0] = yoffset;
 		y_box[1] = bar_height;
-		R_move_abs((int)x_box[0], (int)y_box[0]);
-		R_cont_abs((int)x_box[1], (int)y_box[1]);
+		D_move_abs((int)x_box[0], (int)y_box[0]);
+		D_cont_abs((int)x_box[1], (int)y_box[1]);
 	    }
 	}
 
@@ -348,10 +348,10 @@
 	    && !(nodata && i == dist_stats->mincat + 1)) {
 	    /* draw a numbered tic-mark */
 	    R_standard_color(color);
-	    R_move_abs((int)
+	    D_move_abs((int)
 		       (xoffset + (i - dist_stats->mincat) * xscale -
 			0.5 * xscale), (int)(b - BAR_Y1 * (height)));
-	    R_cont_rel((int)0, (int)(BIG_TIC * (height)));
+	    D_cont_rel((int)0, (int)(BIG_TIC * (height)));
 	    if (nodata && i == dist_stats->mincat)
 		sprintf(txt, "null");
 	    else if (is_fp)
@@ -368,7 +368,7 @@
 		R_text_size(text_width, text_height);
 		R_get_text_box(txt, &tt, &tb, &tl, &tr);
 	    }
-	    R_move_abs((int)
+	    D_move_abs((int)
 		       (xoffset + (i - dist_stats->mincat) * xscale -
 			0.5 * xscale - (tr - tl) / 2),
 		       (int)(b - XNUMS_Y * (height)));
@@ -377,10 +377,10 @@
 	else if (rem(i, tic_unit) == (float)0) {
 	    /* draw a tic-mark */
 	    R_standard_color((int)color);
-	    R_move_abs((int)
+	    D_move_abs((int)
 		       (xoffset + (i - dist_stats->mincat) * xscale -
 			0.5 * xscale), (int)(b - BAR_Y1 * (height)));
-	    R_cont_rel((int)0, (int)(SMALL_TIC * (height)));
+	    D_cont_rel((int)0, (int)(SMALL_TIC * (height)));
 	}
     }
 
@@ -392,7 +392,7 @@
 
     /* draw border around legend bar */
     R_standard_color((int)color);
-    R_polyline_abs(x_line, y_line, 5);
+    D_polyline_abs(x_line, y_line, 5);
 
     /* draw the x-axis label */
     if (tic_unit != 1)
@@ -403,7 +403,7 @@
     text_width = (width) * TEXT_WIDTH;
     R_text_size(text_width, text_height);
     R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
-    R_move_abs((int)(l + (width) / 2 - (tr - tl) / 2),
+    D_move_abs((int)(l + (width) / 2 - (tr - tl) / 2),
 	       (int)(b - LABEL * (height)));
     R_standard_color((int)color);
     R_text(xlabel);

Modified: grass/trunk/display/d.labels/do_labels.c
===================================================================
--- grass/trunk/display/d.labels/do_labels.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.labels/do_labels.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -1,6 +1,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <math.h>
 #include <grass/gis.h>
 #include <grass/display.h>
 #include <grass/raster.h>
@@ -167,6 +168,7 @@
     char line[256];
     char *lptr, *tptr;
     double line_size;
+    double d_text_size;
     double text_size;
     double X, Y, Y0;
     double T, B, L, R;
@@ -178,30 +180,31 @@
     double ll_x, ll_y, ul_x, ul_y, lr_x, lr_y, ur_x, ur_y, text_x, text_y;
 
     G_debug(3, "Doing '%s'", text);
-    X  = D_u_to_d_col(east);
-    Y0 = D_u_to_d_row(north);
+    X  = east;
+    Y0 = north;
 
     /* Set font */
     R_font(font);
 
     /* Set text size */
     if (fontsize) {
-	text_size = fontsize;
-	line_size =
-	    (D_d_to_u_row(0.0) - D_d_to_u_row((double)fontsize)) * 1.2;
+	d_text_size = fontsize;
+	text_size = fontsize * D_get_d_to_u_yconv();
     }
     else {
-	text_size = D_u_to_d_row(0.0) - D_u_to_d_row(size);
-	line_size = size * 1.2;
+	d_text_size = fabs(size * D_get_u_to_d_yconv());
+	text_size = size;
     }
 
-    R_text_size(text_size, text_size);
+    line_size = text_size * 1.2;
 
+    R_text_size(d_text_size, d_text_size);
+
     /* Find extent of all text (assume ref point is upper left) */
-    T = 999999;
-    B = 0;
-    L = 999999;
-    R = 0;
+    T = -1e300;
+    B = 1e300;
+    L = 1e300;
+    R = -1e300;
 
     /* Scan to beginning of text string */
     for (tptr = text; *tptr != ':'; tptr++) ;
@@ -232,19 +235,18 @@
 
 	G_debug(3, "line %d ='%s'", n_lines, line);
 
-	Y = (int)(D_u_to_d_row
-		  (north - (line_size * 1.2) - ((n_lines - 1) * line_size)));
-	R_move_abs(X, Y);
+	Y = north - (line_size * 1.2) - ((n_lines - 1) * line_size);
+	D_move_abs(X, Y);
 	R_text_rotation(0.0);	/* reset */
-	R_get_text_box(line, &t, &b, &l, &r);
+	D_get_text_box(line, &t, &b, &l, &r);
 
-	if (t < T)
+	if (T < t)
 	    T = t;
-	if (b > B)
+	if (B > b)
 	    B = b;
-	if (l < L)
+	if (L > l)
 	    L = l;
-	if (r > R)
+	if (R < r)
 	    R = r;
 
 	if ((*tptr == '\0') || (*tptr == NL))
@@ -261,13 +263,13 @@
 	width = 0.;
 
     /* Expand border 1/2 of text size */
-    T = T - (text_size * 0.2) - .5;
-    B = B + (text_size * 0.2) + .5;
-    L = L - (text_size * 0.2) - .5;
-    R = R + (text_size * 0.2) + .5;
+    T = T + (text_size * 0.2);
+    B = B - (text_size * 0.2);
+    L = L - (text_size * 0.2);
+    R = R + (text_size * 0.2);
 
-    Xoffset = xoffset;
-    Yoffset = -yoffset;
+    Xoffset =  D_get_d_to_u_xconv() * xoffset;
+    Yoffset = -D_get_d_to_u_yconv() * yoffset;
     X_just_offset = 0;
     Y_just_offset = 0;
 
@@ -310,37 +312,33 @@
 
     /* skip labels which will go offscreen (even partially) */
     for (i = 0; i < 5; i++) {
-	if ((xarr[i] > D_get_d_east()) || (xarr[i] < D_get_d_west()))
+	if ((xarr[i] > D_get_u_east()) || (xarr[i] < D_get_u_west()))
 	    return 0;
-	if ((yarr[i] < D_get_d_north()) || (yarr[i] > D_get_d_south()))
+	if ((yarr[i] > D_get_u_north()) || (yarr[i] < D_get_u_south()))
 	    return 0;
-	if ((xarr[i] < 0) || (yarr[i] < 0))
-	    return 0;
     }
 
 #ifdef OUTPUT_ASCII
     fprintf(stdout, "L 5\n");
-    for (i = 0; i < 5; i++) {
-	fprintf(stdout, " %f %f\n", D_d_to_u_col(xarr[i]),
-		D_d_to_u_row(yarr[i]));
-    }
+    for (i = 0; i < 5; i++)
+	fprintf(stdout, " %f %f\n", xarr[i], yarr[i]);
     /* d.labels labfile | v.in.ascii -n out=labbox format=standard */
 #endif
 
     /* draw boxes */
     if (RGBA_has_color(&background)) {
 	set_color_from_RGBA(&background);
-	R_polygon_abs(xarr, yarr, 5);
+	D_polygon_abs(xarr, yarr, 5);
     }
     if (RGBA_has_color(&border)) {
 	set_color_from_RGBA(&border);
-	R_line_width((int)(width + 0.5));
-	R_polyline_abs(xarr, yarr, 5);
-	R_line_width(1);	/* reset to default. note a value of 0 is valid and slightly thinner and 1 can be ugly */
+	R_line_width(width);
+	D_polyline_abs(xarr, yarr, 5);
+	R_line_width(0);
     }
 
     /* Set font rotation */
-    R_text_rotation((float)rotation);
+    R_text_rotation(rotation);
     G_debug(3, "  rotation = %.2f", rotation);
 
     /**** draw highlighted text background ****/
@@ -366,30 +364,29 @@
 	    *lptr = '\0';
 
 	    /* figure out text placement */
-	    Y = (int)(D_u_to_d_row
-		      (north - (line_size * 1.2) - ((i - 1) * line_size)));
+	    Y = north - (line_size * 1.2) - ((i - 1) * line_size);
 	    text_x = X + X_just_offset;	/* reset after G_rotate_around_point_int() */
 	    text_y = Y + Y_just_offset;
 	    G_rotate_around_point(X, Y0, &text_x, &text_y, -1 * rotation);
 
 	    for (j = 1; j <= highlight_width; j++) {
 		/* smear it around. probably a better way (knight's move? rand?) */
-		R_move_abs(text_x + Xoffset, text_y + Yoffset + j);
+		D_move_abs(text_x + Xoffset, text_y + Yoffset + j);
 		R_text(line);
-		R_move_abs(text_x + Xoffset, text_y + Yoffset - j);
+		D_move_abs(text_x + Xoffset, text_y + Yoffset - j);
 		R_text(line);
-		R_move_abs(text_x + Xoffset + j, text_y + Yoffset);
+		D_move_abs(text_x + Xoffset + j, text_y + Yoffset);
 		R_text(line);
-		R_move_abs(text_x + Xoffset - j, text_y + Yoffset);
+		D_move_abs(text_x + Xoffset - j, text_y + Yoffset);
 		R_text(line);
 
-		R_move_abs(text_x + Xoffset + j, text_y + Yoffset + j);
+		D_move_abs(text_x + Xoffset + j, text_y + Yoffset + j);
 		R_text(line);
-		R_move_abs(text_x + Xoffset - j, text_y + Yoffset - j);
+		D_move_abs(text_x + Xoffset - j, text_y + Yoffset - j);
 		R_text(line);
-		R_move_abs(text_x + Xoffset + j, text_y + Yoffset - j);
+		D_move_abs(text_x + Xoffset + j, text_y + Yoffset - j);
 		R_text(line);
-		R_move_abs(text_x + Xoffset - j, text_y + Yoffset + j);
+		D_move_abs(text_x + Xoffset - j, text_y + Yoffset + j);
 		R_text(line);
 	    }
 
@@ -423,13 +420,12 @@
 	*lptr = '\0';
 
 	/* figure out text placement */
-	Y = (int)(D_u_to_d_row
-		  (north - (line_size * 1.2) - ((i - 1) * line_size)));
+	Y = north - (line_size * 1.2) - ((i - 1) * line_size);
 	text_x = X + X_just_offset;	/* reset after G_rotate_around_point_int() */
 	text_y = Y + Y_just_offset;
 	G_rotate_around_point(X, Y0, &text_x, &text_y, -1 * rotation);
 
-	R_move_abs(text_x + Xoffset, text_y + Yoffset);
+	D_move_abs(text_x + Xoffset, text_y + Yoffset);
 	R_text(line);
 
 	if ((*tptr == '\0') || (*tptr == NL))

Modified: grass/trunk/display/d.vect/attr.c
===================================================================
--- grass/trunk/display/d.vect/attr.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/attr.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -5,18 +5,15 @@
 #include <grass/raster.h>
 #include <grass/dbmi.h>
 #include <grass/glocale.h>
+#include "local_proto.h"
 #include "plot.h"
 
 int attr(struct Map_info *Map, int type, char *attrcol,
-	 struct cat_list *Clist, LATTR * lattr, int chcat)
+	 struct cat_list *Clist, LATTR *lattr, int chcat)
 {
     int i, ltype, more;
-    double xl, yl;
     struct line_pnts *Points;
     struct line_cats *Cats;
-    int X, Y, Xoffset, Yoffset;
-    double xarr[5], yarr[5];
-    double T, B, L, R;
     int cat;
     char buf[2000];
     struct field_info *fi;
@@ -139,69 +136,7 @@
 		ncats++;
 	    }
 
-	    if ((ltype & GV_POINTS) || Points->n_points == 1)
-		/* point/centroid or line/boundary with one coor */
-	    {
-		X = (int)(D_u_to_d_col(Points->x[0]));
-		Y = (int)(D_u_to_d_row(Points->y[0]));
-	    }
-	    else if (Points->n_points == 2) {	/* line with two coors */
-		xl = (Points->x[0] + Points->x[1]) / 2;
-		yl = (Points->y[0] + Points->y[1]) / 2;
-		X = (int)(D_u_to_d_col(xl));
-		Y = (int)(D_u_to_d_row(yl));
-	    }
-	    else {
-		i = Points->n_points / 2;
-		X = (int)(D_u_to_d_col(Points->x[i]));
-		Y = (int)(D_u_to_d_row(Points->y[i]));
-	    }
-
-	    X = X + 0.5 * lattr->size;
-	    Y = Y + 1.5 * lattr->size;
-
-	    R_move_abs(X, Y);
-	    R_get_text_box(db_get_string(&text), &T, &B, &L, &R);
-
-	    /* Expand border 1/2 of text size */
-	    T = T - lattr->size / 2;
-	    B = B + lattr->size / 2;
-	    L = L - lattr->size / 2;
-	    R = R + lattr->size / 2;
-
-	    Xoffset = 0;
-	    Yoffset = 0;
-	    if (lattr->xref == LCENTER)
-		Xoffset = -(R - L) / 2;
-	    if (lattr->xref == LRIGHT)
-		Xoffset = -(R - L);
-	    if (lattr->yref == LCENTER)
-		Yoffset = -(B - T) / 2;
-	    if (lattr->yref == LBOTTOM)
-		Yoffset = -(B - T);
-
-	    if (lattr->has_bgcolor || lattr->has_bcolor) {
-		xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
-		xarr[2] = xarr[3] = R + Xoffset;
-		yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
-		yarr[1] = yarr[2] = T + Yoffset;
-
-		if (lattr->has_bgcolor) {
-		    R_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
-				lattr->bgcolor.B);
-		    R_polygon_abs(xarr, yarr, 5);
-		}
-
-		if (lattr->has_bcolor) {
-		    R_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
-				lattr->bcolor.B);
-		    R_polyline_abs(xarr, yarr, 5);
-		}
-		R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
-	    }
-
-	    R_move_abs(X + Xoffset, Y + Yoffset);
-	    R_text(db_get_string(&text));
+	    show_label_line(Points, ltype, lattr, db_get_string(&text));
 	}
     }
 

Modified: grass/trunk/display/d.vect/label.c
===================================================================
--- grass/trunk/display/d.vect/label.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/label.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -3,18 +3,15 @@
 #include <grass/display.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
+#include "local_proto.h"
 #include "plot.h"
 
 int label(struct Map_info *Map, int type, int do_area,
-	  struct cat_list *Clist, LATTR * lattr, int chcat)
+	  struct cat_list *Clist, LATTR *lattr, int chcat)
 {
     int i, ltype;
-    double xl, yl;
     struct line_pnts *Points;
     struct line_cats *Cats;
-    int X, Y, Xoffset, Yoffset;
-    double xarr[5], yarr[5];
-    double T, B, L, R;
     int cat;
     char text[100];
 
@@ -70,28 +67,6 @@
 	}
 
 	if (Vect_cat_get(Cats, lattr->field, &cat)) {
-	    if ((ltype & GV_POINTS) || Points->n_points == 1)
-		/* point/centroid or line/boundary with one coor */
-	    {
-		X = (int)(D_u_to_d_col(Points->x[0]));
-		Y = (int)(D_u_to_d_row(Points->y[0]));
-	    }
-	    else if (Points->n_points == 2) {	/* line with two coors */
-		xl = (Points->x[0] + Points->x[1]) / 2;
-		yl = (Points->y[0] + Points->y[1]) / 2;
-		X = (int)(D_u_to_d_col(xl));
-		Y = (int)(D_u_to_d_row(yl));
-	    }
-	    else {
-		i = Points->n_points / 2;
-		X = (int)(D_u_to_d_col(Points->x[i]));
-		Y = (int)(D_u_to_d_row(Points->y[i]));
-	    }
-
-	    X = X + 0.5 * lattr->size;
-	    Y = Y + 1.5 * lattr->size;
-
-	    R_move_abs(X, Y);
 	    text[0] = '\0';
 	    for (i = 0; i < Cats->n_cats; i++) {
 		G_debug(3, "cat lab: field = %d, cat = %d", Cats->field[i],
@@ -103,47 +78,7 @@
 		    sprintf(text, "%s%d", text, Cats->cat[i]);
 		}
 	    }
-	    R_get_text_box(text, &T, &B, &L, &R);
-
-	    /* Expand border 1/2 of text size */
-	    T = T - lattr->size / 2;
-	    B = B + lattr->size / 2;
-	    L = L - lattr->size / 2;
-	    R = R + lattr->size / 2;
-
-	    Xoffset = 0;
-	    Yoffset = 0;
-	    if (lattr->xref == LCENTER)
-		Xoffset = -(R - L) / 2;
-	    if (lattr->xref == LRIGHT)
-		Xoffset = -(R - L);
-	    if (lattr->yref == LCENTER)
-		Yoffset = -(B - T) / 2;
-	    if (lattr->yref == LBOTTOM)
-		Yoffset = -(B - T);
-
-	    if (lattr->has_bgcolor || lattr->has_bcolor) {
-		xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
-		xarr[2] = xarr[3] = R + Xoffset;
-		yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
-		yarr[1] = yarr[2] = T + Yoffset;
-
-		if (lattr->has_bgcolor) {
-		    R_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
-				lattr->bgcolor.B);
-		    R_polygon_abs(xarr, yarr, 5);
-		}
-
-		if (lattr->has_bcolor) {
-		    R_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
-				lattr->bcolor.B);
-		    R_polyline_abs(xarr, yarr, 5);
-		}
-		R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
-	    }
-
-	    R_move_abs(X + Xoffset, Y + Yoffset);
-	    R_text(text);
+	    show_label_line(Points, ltype, lattr, text);
 	}
     }
 

Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/local_proto.h	2008-08-25 18:08:57 UTC (rev 33070)
@@ -1,5 +1,6 @@
 #include <grass/symbol.h>
 #include <grass/colors.h>
+#include "plot.h"
 
 FILE *open_vect(char *, char *);
 int close_vect(FILE *);
@@ -17,3 +18,5 @@
 int test_bg_color(const char *);
 void plot_polygon(double *, double *, int);
 void plot_polyline(double *, double *, int);
+void show_label(double *, double *, LATTR *, const char *);
+void show_label_line(const struct line_pnts *, int, LATTR *, const char *);

Modified: grass/trunk/display/d.vect/plot.h
===================================================================
--- grass/trunk/display/d.vect/plot.h	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/plot.h	2008-08-25 18:08:57 UTC (rev 33070)
@@ -1,5 +1,9 @@
+
+#ifndef PLOT_H_
+#define PLOT_H_
 /* TODO: should use 24bit instead of 16 colors, maybe implement
    predefined color tables? */
+
 struct rgb_color
 {
     unsigned char R, G, B;
@@ -39,3 +43,6 @@
 #define RENDER_DPL	4
 
 extern int render;
+
+#endif
+

Modified: grass/trunk/display/d.vect/plot1.c
===================================================================
--- grass/trunk/display/d.vect/plot1.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/plot1.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -88,7 +88,6 @@
     double *x, *y;
     struct line_pnts *Points, *PPoints;
     struct line_cats *Cats;
-    double msize;
     double x0, y0;
 
     struct field_info *fi = NULL;
@@ -131,8 +130,6 @@
 	fill_color->a = RGBA_COLOR_NONE;
 
 
-    msize = size * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0));	/* do it better */
-
     Points = Vect_new_line_struct();
     PPoints = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();

Modified: grass/trunk/display/d.vect/topo.c
===================================================================
--- grass/trunk/display/d.vect/topo.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/topo.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -2,18 +2,20 @@
 #include <grass/Vect.h>
 #include <grass/display.h>
 #include <grass/raster.h>
-#include "plot.h"
 #include <grass/glocale.h>
+#include "local_proto.h"
+#include "plot.h"
 
-int topo(struct Map_info *Map, int type, int do_area, LATTR * lattr)
+int topo(struct Map_info *Map, int type, int do_area, LATTR *lattr)
 {
-    int i, ltype, num, el;
-    double xl, yl;
+    int ltype, num, el;
     struct line_pnts *Points;
     struct line_cats *Cats;
-    double X, Y, T, B, L, R, Xoffset, Yoffset, xarr[5], yarr[5];
     char text[50];
+    LATTR lattr2 = *lattr;
 
+    lattr2.xref = lattr->xref == LRIGHT ? LLEFT : LRIGHT;
+
     G_debug(1, "display topo:");
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
@@ -47,71 +49,8 @@
 	if (!(type & ltype))
 	    continue;		/* used for both lines and labels */
 
-
-	if ((ltype & GV_POINTS) || Points->n_points == 1)
-	    /* point/centroid or line/boundary with one coor */
-	{
-	    X = D_u_to_d_col(Points->x[0]);
-	    Y = D_u_to_d_row(Points->y[0]);
-	}
-	else if (Points->n_points == 2) {	/* line with two coors */
-	    xl = (Points->x[0] + Points->x[1]) / 2;
-	    yl = (Points->y[0] + Points->y[1]) / 2;
-	    X = D_u_to_d_col(xl);
-	    Y = D_u_to_d_row(yl);
-	}
-	else {
-	    i = Points->n_points / 2;
-	    X = D_u_to_d_col(Points->x[i]);
-	    Y = D_u_to_d_row(Points->y[i]);
-	}
-
-	X = X + 0.5 * lattr->size;
-	Y = Y + 1.5 * lattr->size;
-
-	R_move_abs(X, Y);
 	sprintf(text, "%d", el);
-	R_get_text_box(text, &T, &B, &L, &R);
-
-	/* Expand border 1/2 of text size */
-	T = T - lattr->size / 2;
-	B = B + lattr->size / 2;
-	L = L - lattr->size / 2;
-	R = R + lattr->size / 2;
-
-	Xoffset = 0;
-	Yoffset = 0;
-	if (lattr->xref == LCENTER)
-	    Xoffset = -(R - L) / 2;
-	if (lattr->xref == LRIGHT)
-	    Xoffset = -(R - L);
-	if (lattr->yref == LCENTER)
-	    Yoffset = -(B - T) / 2;
-	if (lattr->yref == LBOTTOM)
-	    Yoffset = -(B - T);
-
-	if (lattr->has_bgcolor || lattr->has_bcolor) {
-	    xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
-	    xarr[2] = xarr[3] = R + Xoffset;
-	    yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
-	    yarr[1] = yarr[2] = T + Yoffset;
-
-	    if (lattr->has_bgcolor) {
-		R_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
-			    lattr->bgcolor.B);
-		R_polygon_abs(xarr, yarr, 5);
-	    }
-
-	    if (lattr->has_bcolor) {
-		R_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
-			    lattr->bcolor.B);
-		R_polyline_abs(xarr, yarr, 5);
-	    }
-	    R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
-	}
-
-	R_move_abs(X + Xoffset, Y + Yoffset);
-	R_text(text);
+	show_label_line(Points, ltype, lattr, text);
     }
 
     num = Vect_get_num_nodes(Map);
@@ -119,64 +58,16 @@
 
     /* Nodes */
     for (el = 1; el <= num; el++) {
+	double X, Y;
 	if (!Vect_node_alive(Map, el))
 	    continue;
-	Vect_get_node_coor(Map, el, &xl, &yl, NULL);
+	Vect_get_node_coor(Map, el, &X, &Y, NULL);
 	G_debug(3, "node = %d", el);
-
-	X = D_u_to_d_col(xl);
-	Y = D_u_to_d_row(yl);
-
-	X = X + 0.5 * lattr->size;
-	Y = Y + 1.5 * lattr->size;
-
-	R_move_abs(X, Y);
 	sprintf(text, "n%d", el);
-	R_get_text_box(text, &T, &B, &L, &R);
 
-	/* Expand border 1/2 of text size */
-	T = T - lattr->size / 2;
-	B = B + lattr->size / 2;
-	L = L - lattr->size / 2;
-	R = R + lattr->size / 2;
+	show_label(&X, &Y, &lattr2, text);
 
-	Xoffset = 0;
-	Yoffset = 0;
-
-	/*      
-	   if (lattr->xref == LCENTER) Xoffset = -(R - L) / 2 ;
-	   if (lattr->xref == LRIGHT ) Xoffset = -(R - L) ;
-	 */
-	Xoffset = -(R - L);
-	if (lattr->yref == LCENTER)
-	    Yoffset = -(B - T) / 2;
-	if (lattr->yref == LBOTTOM)
-	    Yoffset = -(B - T);
-
-
-	if (lattr->has_bgcolor || lattr->has_bcolor) {
-	    xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
-	    xarr[2] = xarr[3] = R + Xoffset;
-	    yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
-	    yarr[1] = yarr[2] = T + Yoffset;
-
-	    if (lattr->has_bgcolor) {
-		R_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
-			    lattr->bgcolor.B);
-		R_polygon_abs(xarr, yarr, 5);
-	    }
-
-	    if (lattr->has_bcolor) {
-		R_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
-			    lattr->bcolor.B);
-		R_polyline_abs(xarr, yarr, 5);
-	    }
-	    R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
-	}
-
-	R_move_abs(X + Xoffset, Y + Yoffset);
-	R_text(text);
-	D_plot_icon(xl, yl, G_ICON_BOX, 0, 10);
+	D_plot_icon(X, Y, G_ICON_BOX, 0, 10);
     }
 
     Vect_destroy_line_struct(Points);

Added: grass/trunk/display/d.vect/utils.c
===================================================================
--- grass/trunk/display/d.vect/utils.c	                        (rev 0)
+++ grass/trunk/display/d.vect/utils.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -0,0 +1,85 @@
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include <grass/display.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+#include "plot.h"
+
+void show_label(double *px, double *py, LATTR *lattr, const char *text)
+{
+    double X = *px, Y = *py;
+    int Xoffset, Yoffset;
+    double xarr[5], yarr[5];
+    double T, B, L, R;
+
+    X = X + D_get_d_to_u_xconv() * 0.5 * lattr->size;
+    Y = Y + D_get_d_to_u_yconv() * 1.5 * lattr->size;
+
+    D_move_abs(X, Y);
+    D_get_text_box(text, &T, &B, &L, &R);
+
+    /* Expand border 1/2 of text size */
+    T = T - D_get_d_to_u_yconv() * lattr->size / 2;
+    B = B + D_get_d_to_u_yconv() * lattr->size / 2;
+    L = L - D_get_d_to_u_xconv() * lattr->size / 2;
+    R = R + D_get_d_to_u_xconv() * lattr->size / 2;
+
+    Xoffset = 0;
+    Yoffset = 0;
+    if (lattr->xref == LCENTER)
+	Xoffset = -(R - L) / 2;
+    if (lattr->xref == LRIGHT)
+	Xoffset = -(R - L);
+    if (lattr->yref == LCENTER)
+	Yoffset = -(B - T) / 2;
+    if (lattr->yref == LBOTTOM)
+	Yoffset = -(B - T);
+
+    if (lattr->has_bgcolor || lattr->has_bcolor) {
+	xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
+	xarr[2] = xarr[3] = R + Xoffset;
+	yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
+	yarr[1] = yarr[2] = T + Yoffset;
+
+	if (lattr->has_bgcolor) {
+	    R_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
+			lattr->bgcolor.B);
+	    D_polygon_abs(xarr, yarr, 5);
+	}
+
+	if (lattr->has_bcolor) {
+	    R_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
+			lattr->bcolor.B);
+	    D_polyline_abs(xarr, yarr, 5);
+	}
+	R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
+    }
+
+    D_move_abs(X + Xoffset, Y + Yoffset);
+    R_text(text);
+}
+
+void show_label_line(const struct line_pnts *Points, int ltype, LATTR *lattr, const char *text)
+{
+    double X, Y;
+
+    if ((ltype & GV_POINTS) || Points->n_points == 1)
+	/* point/centroid or line/boundary with one coor */
+    {
+	X = Points->x[0];
+	Y = Points->y[0];
+    }
+    else if (Points->n_points == 2) {	/* line with two coors */
+	X = (Points->x[0] + Points->x[1]) / 2;
+	Y = (Points->y[0] + Points->y[1]) / 2;
+    }
+    else {
+	int i = Points->n_points / 2;
+	X = Points->x[i];
+	Y = Points->y[i];
+    }
+
+    show_label(&X, &Y, lattr, text);
+}
+

Modified: grass/trunk/display/d.vect/zcoor.c
===================================================================
--- grass/trunk/display/d.vect/zcoor.c	2008-08-25 17:55:22 UTC (rev 33069)
+++ grass/trunk/display/d.vect/zcoor.c	2008-08-25 18:08:57 UTC (rev 33070)
@@ -4,15 +4,15 @@
 #include <grass/Vect.h>
 #include <grass/display.h>
 #include <grass/raster.h>
+#include "local_proto.h"
 #include "plot.h"
 
-int zcoor(struct Map_info *Map, int type, LATTR * lattr)
+int zcoor(struct Map_info *Map, int type, LATTR *lattr)
 {
     int num, el;
     double xl, yl, zl;
     struct line_pnts *Points;
     struct line_cats *Cats;
-    double X, Y, T, B, L, R, Xoffset, Yoffset, xarr[5], yarr[5];
     char text[50];
 
     G_debug(1, "display zcoor:");
@@ -39,56 +39,8 @@
 	Vect_get_node_coor(Map, el, &xl, &yl, &zl);
 	G_debug(3, "node = %d", el);
 
-	X = D_u_to_d_col(xl);
-	Y = D_u_to_d_row(yl);
-
-	X = X + 0.5 * lattr->size;
-	Y = Y + 1.5 * lattr->size;
-
-	R_move_abs(X, Y);
 	sprintf(text, "%.2f", zl);
-	R_get_text_box(text, &T, &B, &L, &R);
-
-	/* Expand border 1/2 of text size */
-	T = T - lattr->size / 2;
-	B = B + lattr->size / 2;
-	L = L - lattr->size / 2;
-	R = R + lattr->size / 2;
-
-	Xoffset = 0;
-	Yoffset = 0;
-
-	if (lattr->xref == LCENTER)
-	    Xoffset = -(R - L) / 2;
-	if (lattr->xref == LRIGHT)
-	    Xoffset = -(R - L);
-	if (lattr->yref == LCENTER)
-	    Yoffset = -(B - T) / 2;
-	if (lattr->yref == LBOTTOM)
-	    Yoffset = -(B - T);
-
-	if (lattr->has_bgcolor || lattr->has_bcolor) {
-	    xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
-	    xarr[2] = xarr[3] = R + Xoffset;
-	    yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
-	    yarr[1] = yarr[2] = T + Yoffset;
-
-	    if (lattr->has_bgcolor) {
-		R_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
-			    lattr->bgcolor.B);
-		R_polygon_abs(xarr, yarr, 5);
-	    }
-
-	    if (lattr->has_bcolor) {
-		R_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
-			    lattr->bcolor.B);
-		R_polyline_abs(xarr, yarr, 5);
-	    }
-	    R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
-	}
-
-	R_move_abs(X + Xoffset, Y + Yoffset);
-	R_text(text);
+	show_label(&xl, &yl, lattr, text);
     }
 
     Vect_destroy_line_struct(Points);



More information about the grass-commit mailing list