[GRASS-SVN] r70842 - grass/branches/releasebranch_7_2/display/d.text

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 5 21:06:41 PDT 2017


Author: hcho
Date: 2017-04-05 21:06:41 -0700 (Wed, 05 Apr 2017)
New Revision: 70842

Modified:
   grass/branches/releasebranch_7_2/display/d.text/main.c
Log:
d.text: Backport r70839, r70840, r70841

Modified: grass/branches/releasebranch_7_2/display/d.text/main.c
===================================================================
--- grass/branches/releasebranch_7_2/display/d.text/main.c	2017-04-06 02:19:45 UTC (rev 70841)
+++ grass/branches/releasebranch_7_2/display/d.text/main.c	2017-04-06 04:06:41 UTC (rev 70842)
@@ -71,9 +71,10 @@
 };
 
 static void set_color(char *);
-static int get_coordinates(double *, double *, double *, double *,
-			   struct rectinfo, char **, char, char);
-static void draw_text(char *, double *, double *, double, char *, double, char, int, int, int);
+static void get_coordinates(double *, double *, double *, double *,
+			    struct rectinfo, char **, char, char);
+static void draw_text(char *, double *, double *, double, char *, double, char,
+		      int, int, int);
 
 int main(int argc, char **argv)
 {
@@ -272,19 +273,15 @@
     flag.s->description = _("Font size is height in pixels");
     flag.s->guisection = _("Font settings");
 
+    G_option_exclusive(opt.line, opt.at, NULL);
+    G_option_exclusive(flag.p, flag.g, NULL);
 
     /* check command line */
     if (G_parser(argc, argv))
 	exit(1);
 
-    /* parse and check options and flags */
-
-    if ((opt.line->answer && opt.at->answer) ||
-	(flag.p->answer && flag.g->answer))
-	G_fatal_error(_("Please choose only one placement method"));
-
+    /* parse options */
     text = opt.text->answer;
-
     line = (opt.line->answer ? atoi(opt.line->answer) : 1);
 
     /* calculate rotation angle in radian */
@@ -310,10 +307,10 @@
     if (opt.charset->answer)
 	D_encoding(opt.charset->answer);
 
-    D_setup_unity(0);
+    D_setup(0);
 
     /* figure out where to put text */
-    D_get_src(&win.t, &win.b, &win.l, &win.r);
+    D_get_dst(&win.t, &win.b, &win.l, &win.r);
 
     if (flag.s->answer)
 	size = atof(opt.size->answer);
@@ -330,17 +327,18 @@
 	bg_color = D_parse_color(opt.bgcolor->answer, TRUE);
 	if (bg_color == 0) /* ie color="none" */
 	    do_background = 0;
-    } else
+    }
+    else {
 	do_background = 0;
+	bg_color = 0;
+    }
     set_color(opt.fgcolor->answer);
 
     orig_x = orig_y = 0;
 
-    if (opt.at->answer) {
-	if (get_coordinates(&x, &y, &east, &north,
-			    win, opt.at->answers,
-			    flag.p->answer, flag.g->answer))
-	    G_fatal_error(_("Invalid coordinates"));
+    if (opt.at->answers) {
+	get_coordinates(&x, &y, &east, &north, win, opt.at->answers,
+			flag.p->answer, flag.g->answer);
 	orig_x = x;
 	orig_y = y;
     }
@@ -581,51 +579,45 @@
 	}
 	D_use_color(color);
     }
-
-
-    return;
 }
 
-static int
-get_coordinates(double *x, double *y, double *east, double *north,
-		struct rectinfo win, char **at, char pixel,
-		char geocoor)
+static void get_coordinates(double *x, double *y, double *east, double *north,
+			    struct rectinfo win, char **at, char pixel,
+			    char geocoor)
 {
     double e, n;
 
-    if (at) {
-	e = atof(at[0]);
-	n = atof(at[1]);
-	if (pixel) {
-	    *x = e + win.l;
-	    *y = n + win.t;
-	    e = D_d_to_u_col(*x);
-	    n = D_d_to_u_row(*y);
-	}
-	else if (geocoor) {
-	    *x = D_u_to_d_col(e);
-	    *y = D_u_to_d_row(n);
-	}
-	else {
-	    *x = win.l + (win.r - win.l) * e / 100.0;
-	    *y = win.t + (win.b - win.t) * (100.0 - n) / 100.0;
-	    e = D_d_to_u_col(*x);
-	    n = D_d_to_u_row(*y);
-	}
+    if (!at)
+	G_fatal_error(_("Invalid coordinates"));
+
+    e = atof(at[0]);
+    n = atof(at[1]);
+    if (pixel) {
+	*x = e + win.l;
+	*y = n + win.t;
+	e = D_d_to_u_col(*x);
+	n = D_d_to_u_row(*y);
     }
-    else
-	return 1;
+    else if (geocoor) {
+	*x = D_u_to_d_col(e);
+	*y = D_u_to_d_row(n);
+    }
+    else {
+	*x = win.l + (win.r - win.l) * e / 100.0;
+	*y = win.t + (win.b - win.t) * (100.0 - n) / 100.0;
+	e = D_d_to_u_col(*x);
+	n = D_d_to_u_row(*y);
+    }
 
     if (east)
 	*east = e;
     if (north)
 	*north = n;
-
-    return 0;
 }
 
-static void draw_text(char *text, double *x, double *y, double size, char *align,
-		      double rotation, char bold, int do_background, int fg_color, int bg_color)
+static void draw_text(char *text, double *x, double *y, double size,
+		      char *align, double rotation, char bold,
+		      int do_background, int fg_color, int bg_color)
 {
     double w, h;
     double t, b, l, r;
@@ -639,6 +631,10 @@
 	D_text_rotation(0.0);
 
     D_get_text_box(text, &t, &b, &l, &r);
+    t = D_u_to_d_row(t);
+    b = D_u_to_d_row(b);
+    l = D_u_to_d_col(l);
+    r = D_u_to_d_col(r);
 
     if (rotation != 0.0)
 	D_text_rotation(rotation * 180.0 / M_PI);
@@ -687,27 +683,25 @@
     }
 
     if (do_background) {
- 	pl = *x - size/2; /* some pixels margin for both sides */
- 	pt = *y + size/2;
- 	pr = *x + w + size/2;
- 	pb = *y - h - size/2;
+ 	pl = D_d_to_u_col(*x - size/2); /* some pixels margin for both sides */
+ 	pt = D_d_to_u_row(*y + size/2);
+ 	pr = D_d_to_u_col(*x + w + size/2);
+ 	pb = D_d_to_u_row(*y - h - size/2);
 	D_use_color(bg_color);
  	D_box_abs(pl, pt, pr, pb);    /* draw the box */
  	D_use_color(fg_color); /* restore */
     }
 
-    D_pos_abs(*x, *y);
+    D_pos_abs(D_d_to_u_col(*x), D_d_to_u_row(*y));
     D_text(text);
 
     if (bold) {
-	D_pos_abs(*x, *y + 1);
+	D_pos_abs(D_d_to_u_col(*x), D_d_to_u_row(*y + 1));
 	D_text(text);
-	D_pos_abs(*x + 1, *y);
+	D_pos_abs(D_d_to_u_col(*x + 1), D_d_to_u_row(*y));
 	D_text(text);
     }
 
     *x += w * c;
     *y -= w * s;
-
-    return;
 }



More information about the grass-commit mailing list