[GRASS-SVN] r42179 - grass/branches/releasebranch_6_4/display/d.text.new

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 8 16:37:25 EDT 2010


Author: neteler
Date: 2010-05-08 16:37:23 -0400 (Sat, 08 May 2010)
New Revision: 42179

Modified:
   grass/branches/releasebranch_6_4/display/d.text.new/description.html
   grass/branches/releasebranch_6_4/display/d.text.new/main.c
Log:
backport background text color

Modified: grass/branches/releasebranch_6_4/display/d.text.new/description.html
===================================================================
--- grass/branches/releasebranch_6_4/display/d.text.new/description.html	2010-05-08 20:22:11 UTC (rev 42178)
+++ grass/branches/releasebranch_6_4/display/d.text.new/description.html	2010-05-08 20:37:23 UTC (rev 42179)
@@ -21,6 +21,12 @@
 (where <EM>color</EM> is one of the available colors) causes text appearing on 
 subsequent lines to be drawn in that color. 
 
+
+<DT><B>.G</B> <EM>color</EM>
+<DD>
+(where <EM>color</EM> is one of the available colors) causes the background of text
+appearing on subsequent lines to be drawn in that color.
+
 <DT><B>.S </B> <EM>size</EM>
 <DD>
 (where <EM>size</EM> is a percentage within the range 0 to
@@ -67,12 +73,13 @@
 
 
 <pre>
-    <B>d.text</B> << EOF
-    .C yellow 
-    .S 4 
-    .B 1
-    This is a test of d.text
-    EOF
+<B>d.text</B> << EOF
+.C yellow
+.G grey
+.S 4 
+.B 1
+This is a test of d.text
+EOF
 </pre>
 
 

Modified: grass/branches/releasebranch_6_4/display/d.text.new/main.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.text.new/main.c	2010-05-08 20:22:11 UTC (rev 42178)
+++ grass/branches/releasebranch_6_4/display/d.text.new/main.c	2010-05-08 20:37:23 UTC (rev 42179)
@@ -4,7 +4,7 @@
  * MODULE:       d.text
  *
  * AUTHOR(S):    James Westervelt, US Army CERL
- *               Updated by Huidae Cho
+ *               Updated by Huidae Cho, Markus Neteler
  *
  * PURPOSE:      display text in active frame
  *
@@ -21,6 +21,7 @@
  *
  *      .F {font|path}[:charset]                font
  *      .C {color_name|RR:GG:BB|0xRRGGBB}       color
+ *      .G {color_name|RR:GG:BB|0xRRGGBB}       background color
  *      .S [+|-]size[p]                         text size
  *                                              +/-: relative size
  *                                              p: size in pixels
@@ -73,7 +74,7 @@
 static void set_color(char *);
 static int get_coordinates(int *, int *, double *, double *,
 			   struct rectinfo, char **, char, char, char);
-static void draw_text(char *, int *, int *, int, char *, double, char);
+static void draw_text(char *, int *, int *, int, char *, double, char, int, int, int);
 
 int main(int argc, char **argv)
 {
@@ -82,7 +83,8 @@
     {
 	struct Option *text;
 	struct Option *size;
-	struct Option *color;
+	struct Option *fgcolor;
+	struct Option *bgcolor;
 	struct Option *line;
 	struct Option *at;
 	struct Option *rotation;
@@ -131,6 +133,7 @@
     int prev_x, prev_y;
     int set_x, set_y;
     double east, north;
+    int do_background, fg_color, bg_color;
 
     /* initialize the GIS calls */
     G_gisinit(argv[0]);
@@ -155,15 +158,23 @@
     opt.size->description =
 	_("Height of letters in percentage of available frame height");
 
-    opt.color = G_define_option();
-    opt.color->key = "color";
-    opt.color->type = TYPE_STRING;
-    opt.color->answer = DEFAULT_COLOR;
-    opt.color->required = NO;
-    opt.color->description =
+    opt.fgcolor = G_define_option();
+    opt.fgcolor->key = "color";
+    opt.fgcolor->type = TYPE_STRING;
+    opt.fgcolor->answer = DEFAULT_COLOR;
+    opt.fgcolor->required = NO;
+    opt.fgcolor->description =
 	_("Text color, either a standard GRASS color or R:G:B triplet");
-    opt.color->gisprompt = GISPROMPT_COLOR;
+    opt.fgcolor->gisprompt = GISPROMPT_COLOR;
 
+    opt.bgcolor = G_define_option();
+    opt.bgcolor->key = "bgcolor";
+    opt.bgcolor->type = TYPE_STRING;
+    opt.bgcolor->required = NO;
+    opt.bgcolor->description =
+        _("Text background color, either a standard GRASS color or R:G:B triplet");
+    opt.bgcolor->gisprompt = GISPROMPT_COLOR;
+
     opt.line = G_define_option();
     opt.line->key = "line";
     opt.line->required = NO;
@@ -315,7 +326,15 @@
 	size = (int)(atof(opt.size->answer) / 100.0 * (win.b - win.t));
 #endif
 
-    set_color(opt.color->answer);
+    fg_color = D_parse_color(opt.fgcolor->answer, TRUE);
+    if (opt.bgcolor->answer) {
+	do_background = 1;
+	bg_color = D_parse_color(opt.bgcolor->answer, TRUE);
+	if (bg_color == 0) /* ie color="none" */
+	    do_background = 0;
+    } else
+       do_background = 0;
+    set_color(opt.fgcolor->answer);
 
     orig_x = orig_y = 0;
 
@@ -345,7 +364,7 @@
 	y2 = y;
 
 	if (text[0])
-	    draw_text(text, &x2, &y2, size, align, rotation, bold);
+	    draw_text(text, &x2, &y2, size, align, rotation, bold, do_background, fg_color, bg_color);
 	if (opt.at->answer || opt.line->answer)
 	    D_add_to_list(G_recreate_command());
 	else {
@@ -362,7 +381,8 @@
 
 		sprintf(buf, "%s text=\"%s\"", buf, opt.text->answer);
 		sprintf(buf, "%s size=%s", buf, opt.size->answer);
-		sprintf(buf, "%s color=%s", buf, opt.color->answer);
+		sprintf(buf, "%s color=%s", buf, opt.fgcolor->answer);
+		sprintf(buf, "%s bgcolor=%s", buf, opt.bgcolor->answer);
 		sprintf(buf, "%s align=%s", buf, opt.align->answer);
 		sprintf(buf, "%s rotation=%s", buf, opt.rotation->answer);
 		sprintf(buf, "%s linespacing=%s", buf,
@@ -430,7 +450,13 @@
 	    case 'C':
 		/* color */
 		set_color(buf_ptr);
+		fg_color = D_parse_color(buf_ptr, 1);
 		break;
+	    case 'G':
+		/* background color */
+		bg_color = D_parse_color(buf_ptr, 1);
+		do_background = 1;
+		break;
 	    case 'S':
 		/* size */
 		i = 0;
@@ -552,7 +578,7 @@
 	    }
 	    set_x = set_y = set_l = first_text = 0;
 
-	    draw_text(buf_ptr, &x, &y, size, align, rotation, bold);
+	    draw_text(buf_ptr, &x, &y, size, align, rotation, bold, do_background, fg_color, bg_color);
 	}
     }
 
@@ -646,11 +672,12 @@
 }
 
 static void draw_text(char *text, int *x, int *y, int size, char *align,
-		      double rotation, char bold)
+		      double rotation, char bold, int do_background, int fg_color, int bg_color)
 {
     int w, h;
     int t, b, l, r;
     double c, s;
+    int pt, pb, pl, pr;
 
     /* TODO: get text dimension */
     /* R_get_text_box() does not work with rotation and returns a little bit
@@ -706,6 +733,15 @@
 	}
     }
 
+    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;      /* due to bug in display system here not needed */
+	D_raster_use_color(bg_color);
+	R_box_abs(pl, pt, pr, pb);    /* draw the box */
+	D_raster_use_color(fg_color); /* restore */
+    }
     R_move_abs(*x, *y);
     R_text(text);
 



More information about the grass-commit mailing list