[GRASS-SVN] r38743 - grass/branches/develbranch_6/display/d.text.new

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 15 12:15:31 EDT 2009


Author: neteler
Date: 2009-08-15 12:15:30 -0400 (Sat, 15 Aug 2009)
New Revision: 38743

Modified:
   grass/branches/develbranch_6/display/d.text.new/description.html
   grass/branches/develbranch_6/display/d.text.new/main.c
Log:
support for background color added

Modified: grass/branches/develbranch_6/display/d.text.new/description.html
===================================================================
--- grass/branches/develbranch_6/display/d.text.new/description.html	2009-08-15 16:15:26 UTC (rev 38742)
+++ grass/branches/develbranch_6/display/d.text.new/description.html	2009-08-15 16:15:30 UTC (rev 38743)
@@ -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/develbranch_6/display/d.text.new/main.c
===================================================================
--- grass/branches/develbranch_6/display/d.text.new/main.c	2009-08-15 16:15:26 UTC (rev 38742)
+++ grass/branches/develbranch_6/display/d.text.new/main.c	2009-08-15 16:15:30 UTC (rev 38743)
@@ -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,13 @@
 	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, 1);
+    if (opt.bgcolor->answer) {
+       do_background = 1;
+       bg_color = D_parse_color(opt.bgcolor->answer, 1);
+    } else
+       do_background = 0;
+    set_color(opt.fgcolor->answer);
 
     orig_x = orig_y = 0;
 
@@ -345,7 +362,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 +379,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 +448,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 +576,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 +670,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 +731,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