[GRASS-SVN] r60088 - grass/branches/releasebranch_7_0/display/d.legend

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 4 18:45:38 PDT 2014


Author: hamish
Date: 2014-05-04 18:45:38 -0700 (Sun, 04 May 2014)
New Revision: 60088

Modified:
   grass/branches/releasebranch_7_0/display/d.legend/d.legend.html
   grass/branches/releasebranch_7_0/display/d.legend/main.c
Log:
replace funny text scaling parameter with absolute font size (merge from trunk)

Modified: grass/branches/releasebranch_7_0/display/d.legend/d.legend.html
===================================================================
--- grass/branches/releasebranch_7_0/display/d.legend/d.legend.html	2014-05-05 01:27:48 UTC (rev 60087)
+++ grass/branches/releasebranch_7_0/display/d.legend/d.legend.html	2014-05-05 01:45:38 UTC (rev 60088)
@@ -1,82 +1,76 @@
 <h2>DESCRIPTION</h2>
 
 <em>d.legend</em> displays a legend for a user-specified
-raster map layer in the active frame on the graphics
-monitor.  
+raster map layer in the active frame on the graphics monitor.  
 <p>
-The user can run <em>d.legend</em> either non-interactively
-or interactively.  If the user specifies the name of a
-raster <b>map</b> layer on the command line, the program
-will run non-interactively.  Default legend text
-<b>color</b> and position will be used unless
-the user specifies other values on the command line.
+The legend's default size is based on the dimensions of the
+active frame, specifically its height.  <em>d.legend</em> will only
+obscure those portions of the active frame that directly underlie the legend.
 
-<p>
-Alternately, the user can simply type <b>d.legend</b> on the command line; 
-in this case, the program will prompt the user for parameter values 
-using the standard GRASS GUI interface.
 
 <h2>NOTES</h2>
 
-The legend's default size is based on the dimensions of the
-active frame, specifically its height.  <em>d.legend</em> will only
-obscure those portions of the active frame that directly underlie the legend.
-<p>When using the mouse or <b>at</b> to size & place the legend, a user may
+When using the <b>at</b> to size & place the legend, a user may
 create a horizontal legend by making the box wider than it is tall.
-<p>Raster maps based on floating point values will display smoothed, from greatest
+<p>
+Raster maps based on floating point values will display smoothed, from greatest
 to smallest value, while categorial raster maps will display in order, from
 top to bottom. Horizontal legends will always be smoothed. If the box is defined
 with inverted y-values or an inverted <b>range</b>, the legend will automatically
 flip. If this is not the desired result, the <b>-f</b> flag may be used to flip
 it back.
-<p>If the user attempts to display a very long legend in a relatively short 
+<p>
+If the user attempts to display a very long legend in a relatively short 
 display frame, the legend may appear in unreadably small text, or even revert
 to a smooth gradient legend. Use the <b>lines</b>, <b>thin</b>, <b>use</b>, <b>range</b>,
 and/or <b>-n</b> options to reduce the number of categories to be displayed,
 or the <b>-s</b> flag to force a smooth gradient legend. 
-Additionally the fonts for smoothed floating point legends
-can be scaled by a scale factor <b>fontscale</b>, to adjust the automatically computed size of the legend font.
-<p>The <b>lines</b> option will display the first number of categories, as defined
+<p>
+The <b>lines</b> option will display the first number of categories, as defined
 by <em>value</em>, contained in the raster map. When used with the <b>-n</b> flag,
 it takes on a new meaning: "up to category #". When used with both
 <b>thin</b> and the <b>-n</b> flag, its meaning becomes more obscure. When
 using <b>lines</b>, auto-scaled text similar to "4 of 16 categories" will be placed at 
 the bottom of the legend.
-<p>The <b>thin</b> option sets the thinning factor. For raster maps with a 0th
+<p>
+The <b>thin</b> option sets the thinning factor. For raster maps with a 0th
 category, <b>thin=</b><em>10</em> gives cats [0,10,20,...]. For raster maps 
 starting at category 1, <b>thin=</b><em>10</em> gives cats [1,11,21,...].
-<p>The <b>use</b> option lets the user create a legend made up of arbitrary category
+<p>
+The <b>use</b> option lets the user create a legend made up of arbitrary category
 values. e.g. <b>use=</b><em>1000,100,10,0,-10,-100,-1000</em>
-<p>The <b>range</b> option lets the user define the minimum and maximum categories
+<p>
+The <b>range</b> option lets the user define the minimum and maximum categories
 to be used in the legend. It may also be used to define the limits of a smooth
 gradient legend created from a raster containing floating point values. Note
 the color scale will remain faithful to the category values as defined with
 <em><a href="r.colors.html">r.colors</a></em>, and the <b>range</b> may be
 extended to the limits defined by the <em><a href="r.colors.html">r.colors</a></em>
 color map.
-<p>The flag <b>-n</b> is useful for categorial maps, as it suppresses the
+<p>
+The flag <b>-n</b> is useful for categorial maps, as it suppresses the
 drawing of non-existing categories (otherwise the full range is shown).
-<p>Vertical legends produced with <em>d.legend</em> will place text labels to the
+<p>
+Vertical legends produced with <em>d.legend</em> will place text labels to the
 right of the legend box, horizontal legends will place text below. This text
 will be auto-scaled to fit within the frame, reducing the size of the legend
-if necessary. Legends positioned with the mouse or with the <b>at</b> option
+if necessary. Legends positioned with the <b>at</b> option
 will not auto-scale text, in order to provide more control to the user.
-Smaller text may be obtained in this case by reducing the
-height of the box. The <b>-c</b> and <b>-v</b> flags may be used to suppress the
-display of category numbers and labels respectively, or used together to 
-suppress all text of categorial raster maps.
-<p>The text produced from floating-point raster maps will automatically create
+Smaller text may be obtained in this case by reducing the height of the box
+or by using the <b>fontsize</b> option. The <b>-c</b> and <b>-v</b> flags may
+be used to suppress the display of category numbers and labels respectively,
+or used together to suppress all text of categorial raster maps.
+<p>
+The text produced from floating-point raster maps will automatically create
 output with a meaningful number of significant digits. For very small values,
 numbers will be expressed in scientific notation, e.g. "1.7e-9".
-<p>Legends placed with the mouse are not saved to the display window's history
-for automatic redraw. By setting the Debug level to 1 (see 
-<em><a href="g.gisenv.html">g.gisenv</a></em>) the corresponding <b>at</b>
-setting can be determined.
-<p>Note that old scripts which relied on setting <b>lines</b> greater than the
+<p>
+Note that old scripts which relied on setting <b>lines</b> greater than the
 number of categories to scale the legend may no longer produce the desired
 output, although the auto-scaling should still produce something that looks 
 good in this case.
 
+
 <h2>SEE ALSO</h2>
 
 <em>
@@ -86,14 +80,13 @@
 <a href="d.font.html">d.font</a>,
 <a href="d.grid.html">d.grid</a>,
 <a href="d.rast.html">d.rast</a>,
-<!-- <a href="d.rast.labels.html">d.rast.labels</a>, -->
 <a href="d.rast.leg.html">d.rast.leg</a>,
 <a href="d.text.html">d.text</a>,
 <a href="d.vect.thematic.html">d.vect.thematic</a>,
-<!--<a href="d.what.rast.html">d.what.rast</a>,-->
 <a href="r.reclass.html">r.reclass</a>
 </em>
 
+
 <h2>AUTHORS</h2>
 Bill Brown, U.S. Army Construction Engineering Research Laboratories
 <br>Late 2002: Rewrite of much of the code. Hamish Bowman,

Modified: grass/branches/releasebranch_7_0/display/d.legend/main.c
===================================================================
--- grass/branches/releasebranch_7_0/display/d.legend/main.c	2014-05-05 01:27:48 UTC (rev 60087)
+++ grass/branches/releasebranch_7_0/display/d.legend/main.c	2014-05-05 01:45:38 UTC (rev 60088)
@@ -1,11 +1,10 @@
-/* d.legend a.k.a d.leg.thin
- *
+/*
  * MODULE:      d.legend
  *
  *              Based on the old d.leg.thin, which replaced an even older
  *              module called "d.legend".
  *
- * PURPOSE:     Draw a graphical legend for a raster on the display mon
+ * PURPOSE:     Draw a graphical legend for a raster on the display monitor
  *
  * AUTHORS:
  *      Original version:
@@ -17,7 +16,7 @@
  *      Late 2002: Rewrite of much of the code:
  *         Hamish Bowman, Otago University, New Zealand
  *
- * COPYRIGHT:   (c) 2006 The GRASS Development Team
+ * COPYRIGHT:   (c) 2006-2014 by The GRASS Development Team
  *
  *              This program is free software under the GNU General Public
  *              License (>=v2). Read the file COPYING that comes with GRASS
@@ -58,7 +57,9 @@
     struct Categories cats;
     struct Colors colors;
     struct GModule *module;
-    struct Option *opt_input, *opt_color, *opt_lines, *opt_thin, *opt_labelnum, *opt_at, *opt_use, *opt_range, *opt_font, *opt_path, *opt_charset, *opt_fontscale;
+    struct Option *opt_input, *opt_color, *opt_lines, *opt_thin,
+		  *opt_labelnum, *opt_at, *opt_use, *opt_range,
+		  *opt_font, *opt_path, *opt_charset, *opt_fontsize;
     struct Flag *hidestr, *hidenum, *hidenodata, *smooth, *flipit, *size;
     struct Range range;
     struct FPRange fprange;
@@ -75,7 +76,7 @@
     double UserRangeMin, UserRangeMax, UserRangeTemp;
     double *catlist, maxCat;
     int catlistCount, use_catlist;
-    double fontscale;
+    double fontsize;
 
 
     /* Initialize the GIS calls */
@@ -157,15 +158,14 @@
     opt_font->description = _("Font name");
     opt_font->guisection = _("Font settings");
 
-    /* HB: this option should become redundant as soon as the bug in trunk's D_text_size() is fixed. */
-    opt_fontscale = G_define_option();
-    opt_fontscale->key = "fontscale";
-    opt_fontscale->type = TYPE_DOUBLE;
-    opt_fontscale->required = NO;
-    opt_fontscale->answer = "5";
-    opt_fontscale->options = "0-100";
-    opt_fontscale->description = _("Font scaling factor for floating point legends");
-    opt_fontscale->guisection = _("Font settings");
+    opt_fontsize = G_define_option();
+    opt_fontsize->key = "fontsize";
+    opt_fontsize->type = TYPE_DOUBLE;
+    opt_fontsize->required = NO;
+    opt_fontsize->options = "1-360";
+    opt_fontsize->label = _("Font size");
+    opt_fontsize->description = _("Default: Auto-scaled");
+    opt_fontsize->guisection = _("Font settings");
 
     opt_path = G_define_standard_option(G_OPT_F_INPUT);
     opt_path->key = "path";
@@ -225,9 +225,10 @@
     do_smooth = smooth->answer;
     flip = flipit->answer;
 
-    /* Create the fontscale factor for floating point legends */
-    fontscale = atof(opt_fontscale->answer);
-    fontscale = 1.0 / (100.0/fontscale);
+    if (opt_fontsize->answer != NULL)
+	fontsize = atof(opt_fontsize->answer);
+    else
+	fontsize = 12; /* dummy placeholder, should never be called */
 
     color = D_parse_color(opt_color->answer, TRUE);
 
@@ -506,7 +507,7 @@
 		    y0 = ((b - t) - (dots_per_line * lines)) / 2;
 	}
 
-	/*      D_text_size((int)(dots_per_line*4/5), (int)(dots_per_line*4/5)) ;    redundant */
+	/*      D_text_size(dots_per_line*4/5., dots_per_line*4/5.);    redundant */
 	/* if(Rast_is_c_null_value(&min_ind) && Rast_is_c_null_value(&max_ind))
 	   {
 	   min_ind = 1;
@@ -581,7 +582,7 @@
 
     if (do_smooth) {
 	int wleg, lleg, dx, dy;
-	int txsiz;
+	double txsiz;
 	int ppl;
 	int tcell;
 	float ScaleFactor = 1.0;
@@ -682,19 +683,22 @@
 
 	    /* Draw text */
 	    if (!horiz)
-		txsiz = (int)((y1 - y0) * fontscale);
+		txsiz = (y1 - y0) / 20;
 	    else
-		txsiz = (int)((x1 - x0) * fontscale);
+		txsiz = (x1 - x0) / 20;
 
 	    /* scale text to fit in window if position not manually set */
 	    /* usually not needed, except when frame is really narrow   */
 	    if (opt_at->answer == NULL) {	/* ie default scaling */
 		ScaleFactor = ((r - x1) / ((MaxLabelLen + 1) * txsiz * 0.81));	/* ?? txsiz*.81=actual text width. */
 		if (ScaleFactor < 1.0) {
-		    txsiz = (int)(txsiz * ScaleFactor);
+		    txsiz = txsiz * ScaleFactor;
 		}
 	    }
 
+	    if (opt_fontsize->answer != NULL)
+		txsiz = fontsize;
+
 	    if (txsiz < 0)
 		txsiz = 0;	/* keep it sane */
 
@@ -759,7 +763,8 @@
     }
     else {			/* non FP, no smoothing */
 
-	int txsiz, true_l, true_r;
+	int true_l, true_r;
+	double txsiz;
 	float ScaleFactor = 1.0;
 
 	/* set legend box bounds */
@@ -780,13 +785,13 @@
 
 	/* adjust text size */
 	/*      txsiz = (int)((y1-y0)/(1.5*(lines+5))); */
-	txsiz = (int)((y1 - y0) / (2.0 * lines));
+	txsiz = (y1 - y0) / (2.0 * lines);
 
 	/* scale text to fit in window if position not manually set */
 	if (opt_at->answer == NULL) {	/* ie defualt scaling */
 	    ScaleFactor = ((true_r - true_l) / ((MaxLabelLen + 3) * txsiz * 0.81));	/* ?? txsiz*.81=actual text width. */
 	    if (ScaleFactor < 1.0) {
-		txsiz = (int)floor(txsiz * ScaleFactor);
+		txsiz = txsiz * ScaleFactor;
 		dots_per_line = (int)floor(dots_per_line * ScaleFactor);
 	    }
 	}
@@ -794,6 +799,9 @@
 	if (dots_per_line < txsiz)
 	    txsiz = dots_per_line;
 
+	if (opt_fontsize->answer != NULL)
+	    txsiz = fontsize;
+
 	D_text_size(txsiz, txsiz);
 
 
@@ -928,7 +936,7 @@
 
 	if (do_cats != cats_num) {
 	    cur_dot_row += dots_per_line;
-	    /*          sprintf(buff, "%d of %d categories\n", (j-1), cats_num) ;   */
+	    /* sprintf(buff, "%d of %d categories\n", (j-1), cats_num); */
 
 	    sprintf(buff, "%d of %d categories\n", k, cats_num);
 
@@ -936,7 +944,11 @@
 	    MaxLabelLen = strlen(buff) + 4;
 	    ScaleFactor = ((true_r - true_l) / (MaxLabelLen * txsiz * 0.81));	/* ?? txsiz*.81=actual text width. */
 	    if (ScaleFactor < 1.0) {
-		txsiz = (int)floor(txsiz * ScaleFactor);
+		txsiz = txsiz * ScaleFactor;
+
+		if (opt_fontsize->answer != NULL)
+		    txsiz = fontsize;
+
 		D_text_size(txsiz, txsiz);
 	    }
 	    D_use_color(white);



More information about the grass-commit mailing list