[GRASS-SVN] r45322 - grass/trunk/ps/ps.map
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 7 02:19:53 EST 2011
Author: hamish
Date: 2011-02-06 23:19:53 -0800 (Sun, 06 Feb 2011)
New Revision: 45322
Modified:
grass/trunk/ps/ps.map/colortable.h
grass/trunk/ps/ps.map/ps_clrtbl.c
grass/trunk/ps/ps.map/ps_fclrtbl.c
grass/trunk/ps/ps.map/r_colortable.c
Log:
RGB color for colortables; bugfix for number of columns hangover (merge from devbr6 r45314-8
Modified: grass/trunk/ps/ps.map/colortable.h
===================================================================
--- grass/trunk/ps/ps.map/colortable.h 2011-02-07 07:13:32 UTC (rev 45321)
+++ grass/trunk/ps/ps.map/colortable.h 2011-02-07 07:19:53 UTC (rev 45322)
@@ -4,6 +4,7 @@
*/
#include <stdio.h>
+#include "clr.h"
struct colortable
{
@@ -14,7 +15,7 @@
char *name;
const char *mapset;
int fontsize;
- int color;
+ PSCOLOR color;
int cols;
int nodata;
int tickbar;
Modified: grass/trunk/ps/ps.map/ps_clrtbl.c
===================================================================
--- grass/trunk/ps/ps.map/ps_clrtbl.c 2011-02-07 07:13:32 UTC (rev 45321)
+++ grass/trunk/ps/ps.map/ps_clrtbl.c 2011-02-07 07:19:53 UTC (rev 45322)
@@ -5,13 +5,17 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-
#include "ps_info.h"
#include "colortable.h"
+#include "local_proto.h"
-#define NSTEPS 5 /* number of steps to divide color box when showing color for
- category data range */
+#define NSTEPS 5 /* number of steps to divide color box when
+ showing color for category data range */
+#define FONTFIT_FACT 4.0 /* how agressive to be with shrinking the font size
+ to get it to fit in the column (normal range: 2-4) */
+#define PRETEXT_MULT 2.0 /* space between box and text (this*fontsize) */
+
int PS_colortable(void)
{
char *label;
@@ -80,8 +84,8 @@
r = l + 72.0 * ct.width;
col_width = ct.width / (double)ct.cols;
- G_debug(3, "clrtbl: adjusted ct.x=[%.3f] ct.y=[%.3f] ct.width=[%.3f]",
- ct.x, ct.y, ct.width);
+ G_debug(3, "clrtbl: adjusted ct.x=[%.3f] ct.y=[%.3f] ct.width=[%.3f] "
+ "col_width=[%.3f]", ct.x, ct.y, ct.width, col_width);
/* read cats into PostScript array "a" */
fprintf(PS.fp, "/a [\n");
@@ -107,7 +111,8 @@
if (ct.cols == 1)
tl = 72.0 * col_width - 2.0 * fontsize;
else
- tl = 72.0 * col_width - 4.0 * fontsize;
+ tl = 72.0 * col_width - FONTFIT_FACT * fontsize;
+ G_debug(5, "clrtbl: fontsize=%.1f adjusted tl=%.1f", fontsize, tl);
fprintf(PS.fp, "/s %.1f def\n", fontsize);
fprintf(PS.fp, "mw %.1f gt {/s s %.1f mul mw div def } if\n", tl, tl);
fprintf(PS.fp, "(%s) FN s SF\n", ct.font);
@@ -128,7 +133,7 @@
k = 0;
for (i = 0; i <= num_cats;) {
if (!i && !ct.nodata)
- i++; /* step over 'no data' */
+ i++; /* step over 'no data' */
/* test for bottom of page */
y -= dy;
@@ -191,10 +196,14 @@
if (center_cols)
fprintf(PS.fp, "mvx ");
fprintf(PS.fp, "%.1f ", y + fontsize);
- fprintf(PS.fp, "B F BW stroke\n");
+/* no border fprintf(PS.fp, "B CF stroke\n"); */
+/* grey border fprintf(PS.fp, "B F .247 .247 .247 C 1 W stroke\n"); */
+ fprintf(PS.fp, "B F ");
+ set_ps_color(&ct.color);
+ fprintf(PS.fp, "1 W stroke\n");
}
else
- /* split the rectangle into NSTEPS horisontal strips and
+ /* split the rectangle into NSTEPS horizontal strips and
draw each with the corresponding value's color */
{
for (jj = 0; jj < NSTEPS; jj++) {
@@ -228,15 +237,17 @@
fprintf(PS.fp, "mvx ");
fprintf(PS.fp, "%.1f ", y + fontsize);
fprintf(PS.fp, "B BW stroke\n");
- } /* done drawing the box */
+ } /* done drawing the box */
/* do the text */
- fprintf(PS.fp, "a %d get %.1f ", k++, x1 + 2.0 * fontsize);
+ set_ps_color(&ct.color);
+ fprintf(PS.fp, "a %d get %.1f ", k++, x1 + PRETEXT_MULT * fontsize);
if (center_cols)
fprintf(PS.fp, "mvx ");
fprintf(PS.fp, "%.1f MS\n", y);
+
i++;
- if (i >= num_cats)
+ if (i > num_cats)
j = ct.cols + 1;
}
}
Modified: grass/trunk/ps/ps.map/ps_fclrtbl.c
===================================================================
--- grass/trunk/ps/ps.map/ps_fclrtbl.c 2011-02-07 07:13:32 UTC (rev 45321)
+++ grass/trunk/ps/ps.map/ps_fclrtbl.c 2011-02-07 07:19:53 UTC (rev 45322)
@@ -153,7 +153,7 @@
/* Frame around */
fprintf(PS.fp, "NP\n");
- set_rgb_color(ct.color);
+ set_ps_color(&ct.color);
fprintf(PS.fp, "%.8f W\n", lwidth);
fprintf(PS.fp, "%f %f %f %f B\n", x1,
t - (ncols - 1) * cwidth - (cwidth + lwidth) / 2, x2,
Modified: grass/trunk/ps/ps.map/r_colortable.c
===================================================================
--- grass/trunk/ps/ps.map/r_colortable.c 2011-02-07 07:13:32 UTC (rev 45321)
+++ grass/trunk/ps/ps.map/r_colortable.c 2011-02-07 07:19:53 UTC (rev 45322)
@@ -6,8 +6,10 @@
#include <stdlib.h>
#include <string.h>
#include <grass/raster.h>
+#include <grass/glocale.h>
#include "colortable.h"
#include "ps_info.h"
+#include "clr.h"
#include "local_proto.h"
#define KEY(x) (strcmp(key,x)==0)
@@ -33,14 +35,16 @@
char buf[1024];
char *key, *data;
char name[GNAME_MAX], mapset[GMAPSET_MAX];
- int color, fontsize, cols, nodata, tickbar, discrete;
+ int fontsize, cols, nodata, tickbar, discrete;
double w, h, x, y;
int range_override;
double min, max, tmpD;
+ int r, g, b, ret;
+ PSCOLOR color;
fontsize = 0;
- color = BLACK;
+ set_color(&color, 0, 0, 0);
cols = 1;
h = w = x = y = 0.0;
ct.nodata = TRUE;
@@ -55,7 +59,7 @@
if (KEY("where")) {
if (sscanf(data, "%lf %lf", &x, &y) != 2) {
x = y = 0.0;
- error(key, data, "illegal where request");
+ error(key, data, _("illegal where request"));
}
else
continue;
@@ -63,7 +67,7 @@
if (KEY("width")) {
if (sscanf(data, "%lf", &w) != 1 || w <= 0) {
- error(key, data, "illegal width request");
+ error(key, data, _("illegal width request"));
}
else
continue;
@@ -71,7 +75,7 @@
if (KEY("height")) {
if (sscanf(data, "%lf", &h) != 1 || h <= 0) {
- error(key, data, "illegal height request");
+ error(key, data, _("illegal height request"));
}
else
continue;
@@ -88,7 +92,7 @@
if (KEY("range")) {
if (sscanf(data, "%lf %lf", &min, &max) != 2) {
range_override = FALSE;
- error(key, data, "illegal range request");
+ error(key, data, _("illegal range request"));
}
else {
range_override = TRUE;
@@ -104,7 +108,7 @@
if (KEY("cols")) {
if (sscanf(data, "%d", &cols) != 1) {
cols = 1;
- error(key, data, "illegal columns request");
+ error(key, data, _("illegal columns request"));
}
else
continue;
@@ -118,11 +122,15 @@
}
if (KEY("color")) {
- color = get_color_number(data);
- if (color < 0) {
- color = BLACK;
- error(key, data, "illegal color request");
- }
+ ret = G_str_to_color(data, &r, &g, &b);
+ if (ret == 1)
+ set_color(&color, r, g, b);
+ else if (ret == 2) /* i.e. "none" */
+ /* unset_color(&color); */
+ error(key, data, _("Unsupported color request (colortable)"));
+ else
+ error(key, data, _("illegal color request (colortable)"));
+
continue;
}
@@ -148,7 +156,7 @@
continue;
}
- error(key, data, "illegal colortabe sub-request");
+ error(key, data, _("illegal colortabe sub-request"));
}
ct.x = x;
@@ -159,7 +167,7 @@
/* Check for Raster */
if (!ct.name) {
if (!PS.cell_name) {
- error(key, data, "No raster selected for colortable !");
+ error(key, data, _("No raster selected for colortable!"));
}
else {
ct.name = PS.cell_name;
More information about the grass-commit
mailing list