[GRASS-SVN] r69043 - in grass-addons/grass7/display: . d.legend.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 29 17:55:28 PDT 2016


Author: lazaa
Date: 2016-07-29 17:55:27 -0700 (Fri, 29 Jul 2016)
New Revision: 69043

Added:
   grass-addons/grass7/display/d.legend.vect/
   grass-addons/grass7/display/d.legend.vect/Makefile
   grass-addons/grass7/display/d.legend.vect/d.legend.vect.html
   grass-addons/grass7/display/d.legend.vect/draw.c
   grass-addons/grass7/display/d.legend.vect/local_proto.h
   grass-addons/grass7/display/d.legend.vect/main.c
Removed:
   grass-addons/grass7/display/d.vect.legend/
Modified:
   grass-addons/grass7/display/Makefile
Log:
d.vect.legend->d.legend.vect, 1st version for d.mon and GUI

Modified: grass-addons/grass7/display/Makefile
===================================================================
--- grass-addons/grass7/display/Makefile	2016-07-28 18:41:01 UTC (rev 69042)
+++ grass-addons/grass7/display/Makefile	2016-07-30 00:55:27 UTC (rev 69043)
@@ -3,7 +3,7 @@
 SUBDIRS = \
 	d.frame \
 	d.mon2 \
-	d.vect.legend\
+	d.legend.vect\
 	d.vect.thematic2
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make

Added: grass-addons/grass7/display/d.legend.vect/Makefile
===================================================================
--- grass-addons/grass7/display/d.legend.vect/Makefile	                        (rev 0)
+++ grass-addons/grass7/display/d.legend.vect/Makefile	2016-07-30 00:55:27 UTC (rev 69043)
@@ -0,0 +1,12 @@
+MODULE_TOPDIR = ../..
+
+PGM = d.legend.vect
+
+LIBES = $(DISPLAYLIB) $(GISLIB) $(SYMBLIB) 
+DEPENDENCIES = $(DISPLAYDEP) $(GISDEP) $(SYMBDEP)
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Added: grass-addons/grass7/display/d.legend.vect/d.legend.vect.html
===================================================================
--- grass-addons/grass7/display/d.legend.vect/d.legend.vect.html	                        (rev 0)
+++ grass-addons/grass7/display/d.legend.vect/d.legend.vect.html	2016-07-30 00:55:27 UTC (rev 69043)
@@ -0,0 +1,112 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.vect.legend</em> draws vector legend.
+<p>
+TO DO
+Example taken from d.vect.thematic
+<h2>NOTES</h2>
+
+The <b>-l</b> flag instructs the module to print legend information
+(<i>class min | class max | number of observations in class |
+color</i>) to standard output for futher use in graphical software.
+When combined with the <b>-e</b> flag, the legend information will
+be extended with some additional statistical information. If the
+<b>-n</b> flag is set, the module will only print the legend 
+information without drawing the map. If the user gives a
+<b>legendfile</b>, the module will
+write <em><a href="d.graph.html">d.graph</a></em> instructions for
+painting a legend into that file.
+
+
+<h2>EXAMPLES</h2>
+
+<h3>Thematic map with classes</h3>
+
+<div class="code"><pre>
+d.vect.thematic -l map=communes3 column=pop \
+  breaks=111393.250000,222785.500000,334177.750000 \
+  colors="255:0:0,0:255:0,0:0:255,0,0,0"
+</pre></div>
+
+<h3>Thematic map with calculated class breaks</h3>
+
+The following example uses a calculated attribute (<tt>density = 
+pop/area</tt>) and the standard deviation algorithm to calculate class 
+breaks for 5 classes:
+
+<div class="code"><pre>
+d.vect.thematic -l map=communes2 column=pop/area algorithm=std \
+  nbclasses=5 colors="0:0:255,50:100:255,255:100:50,255:0:0,156:0:0"
+</pre></div>
+
+To actually draw the legend for the polygons in the graphical
+display, the procedure is:
+
+<div class="code"><pre>
+# first save legend instructions to a file	
+d.vect.thematic -n map=communes2 column=pop/area algorithm=std \
+  nbclasses=5 colors="0:0:255,50:100:255,255:100:50,255:0:0,156:0:0" \
+  legendfile=legend_pop_dens  
+
+# open a monitor
+d.mon wx0
+
+# draw the map
+d.vect.thematic map=communes2 column=pop/area algorithm=std \
+  nbclasses=5 colors="0:0:255,50:100:255,255:100:50,255:0:0,156:0:0"
+
+# draw the legend
+d.graph input=legend_pop_dens
+</pre></div>
+
+In order to further enhance this legend, edit the legend file accordingly
+and rerun the process.
+
+<h3>Thematic map with calculated class breaks</h3>
+
+<!-- TODO: find better example -->
+
+Example for the North Carolina sample dataset, colorizing polygons by
+area size:
+
+<div class="code"><pre>
+# first save legend instructions to a file
+d.vect.thematic -n map=geology column=SHAPE_area algorithm=int nclasses=6 \
+ colors=215:48:39,252:141:89,254:224:139,217:239:139,145:207:96,26:152:80 \
+ legendfile=geology.leg
+
+# open the graphical display
+d.mon wx0
+# draw outline of polygons
+d.vect map=geology type=boundary
+# draw color fill
+d.vect.thematic map=geology column=SHAPE_area algorithm=int nclasses=6 \
+ colors="215:48:39,252:141:89,254:224:139,217:239:139,145:207:96,26:152:80" \
+# draw legend
+d.graph input=geology.leg
+</pre></div>
+
+<center>
+<img src="d_vect_thematic.png" alt="d_vect_thematic example" border=1><br>
+Thematic map of area sizes
+</center>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.class.html">v.class</a>,
+<a href="d.vect.html">d.vect</a>,
+<a href="d.graph.html">d.graph</a>,
+<a href="v.univar.html">v.univar</a>
+</em>
+
+<p>
+Check also Python module from
+AddOns: <em><a href="http://grass.osgeo.org/grass70/manuals/addons/d.vect.thematic2.html">d.vect.thematic2</a></em>
+
+<h2>AUTHOR</h2>
+
+Moritz Lennert
+
+<p>
+<i>Last changed: $Date: 2015-08-11 23:06:03 +0200 (Út, 11 srp 2015) $</i>

Added: grass-addons/grass7/display/d.legend.vect/draw.c
===================================================================
--- grass-addons/grass7/display/d.legend.vect/draw.c	                        (rev 0)
+++ grass-addons/grass7/display/d.legend.vect/draw.c	2016-07-30 00:55:27 UTC (rev 69043)
@@ -0,0 +1,309 @@
+/* draw.c:
+ *
+ *    With do_bg=1 compute position of all legend graphic item and draw only background.
+ *    Eith do_bg=0 compute position of all legend graphic item and draw all.
+ *
+ *    Copyright (C) 2016 by Adam Laza, GSoC 2016, and the GRASS Development Team*
+ *    This program is free software under the GPL (>=v2)
+ *    Read the COPYING file that comes with GRASS for details.
+ */
+
+#include <string.h>
+#include <math.h>
+#include <grass/display.h>
+#include <grass/glocale.h>
+#include <grass/colors.h>
+#include "local_proto.h"
+
+void draw(char *file_name, double LL, double LT, char *title, int cols, int bgcolor,
+          int bcolor, int do_bg, char* tit_font, int tit_size, char *sub_font, int sub_size,
+          char *font, int fontsize, int fontcolor, int symb_size)
+{
+    double db, dt, dl, dr;
+    double bb, bt, bl, br;
+    double x0, y0;
+    double offs_y, row_ind, offs_x;
+    double x, y;
+    FILE *file_in;
+    char buf[512];
+    int got_new;
+    SYMBOL *Symb;
+    char *symb_name, *line_color_str, *fill_color_str, *label, *type_str;
+    double size, line_width;
+    double row_w, text_h, title_h, title_w;
+    RGBA_Color *line_color, *fill_color;
+    int ret, R, G, B;
+    char *part, *sub_delim;
+    double maxlblw, sym_lbl_space;
+    double symb_h, symb_w, max_symb_w;
+    int item_count, item;
+    double it_per_col;
+    double margin, bg_h, bg_w;
+    char *sep;
+
+
+    D_get_src(&dt, &db, &dl, &dr);
+    x0 = dl + (int)((dr - dl) * LL / 100.);
+    y0 = dt + (int)((db - dt) * (100 - LT) / 100.);
+
+    /* Draw title */
+    title_h = 0;
+    if (strlen(title) > 0) {
+        D_font(tit_font);
+        D_text_size(tit_size, tit_size);
+        D_get_text_box(title, &bb, &bt, &bl, &br);
+        margin = 10;
+        title_h = bb - bt;
+        title_w = br - bl;
+        if (! do_bg) {
+            x = x0;
+            y = y0 + title_h;
+            D_pos_abs(x, y);
+            D_use_color(fontcolor);
+            D_text(title);
+        }
+    }
+
+    file_in = fopen(file_name, "r");
+    sep = "|";
+    if (!file_in)
+        G_fatal_error(_("Unable to open input file <%s>"), file_name);
+
+    /* Get number of legend row(item) and the biggest symbol*/
+    item_count = 0;
+    max_symb_w = 0;
+
+    got_new = G_getl2(buf, sizeof(buf), file_in);
+    G_strip(buf);
+    while (got_new) {
+        /* Get the maximum symbol size */
+        symb_name = G_malloc(strlen(buf) + 1);
+        type_str = G_malloc(strlen(buf) + 1);
+        line_color_str = G_malloc(strlen(buf) + 1);
+        fill_color_str = G_malloc(strlen(buf) + 1);
+
+        part = strtok(buf, sep);
+        sscanf(part, "%s", symb_name);
+        part = strtok(NULL, sep);
+        sscanf(part, "%s", type_str);
+        part = strtok(NULL, sep);
+        sscanf(part, "%s", line_color_str);
+        part = strtok(NULL, sep);
+        sscanf(part, "%s", fill_color_str);
+        part = strtok(NULL, sep);
+        sscanf(part, "%lf", &size);
+
+        /* Symbol */
+        if (strcmp(type_str,"area")==0) {
+            symb_name = "legend/area";
+            size = symb_size;
+        }
+        else if (strcmp(type_str,"line")==0) {
+            symb_name = "legend/line";
+            size = symb_size;
+        }
+
+        Symb = S_read(symb_name);
+        if (Symb == NULL)
+            G_warning(_("Cannot read symbol"));
+        else
+            S_stroke(Symb, size, 0, 0);
+        symb_w = Symb->xscale * size * 2;
+
+        if (symb_w > max_symb_w)
+                max_symb_w = symb_w;
+
+        item_count++;
+        got_new = G_getl2(buf, sizeof(buf), file_in);
+        G_strip(buf);
+    }
+    rewind(file_in);
+    it_per_col = ceil(item_count / (cols * 1.0));
+
+    bg_h = 0;
+    maxlblw = 0;
+    offs_y = title_h;
+    sym_lbl_space = 15;
+    item = 0;
+    offs_x = 0;
+    margin = 10;
+    sub_delim = G_malloc(strlen(buf)+1);
+    snprintf(sub_delim, sizeof(strlen(buf)+1), "%s%s%s%s%s", sep, sep, sep, sep, sep);
+
+
+
+    got_new = G_getl2(buf, sizeof(buf), file_in);
+    G_strip(buf);
+
+    while (got_new) {
+        if (item < it_per_col){
+            row_ind = 5;
+            item++;
+        }
+        else {
+            if (bg_h < offs_y)
+                bg_h = offs_y + symb_h/2.;
+            offs_x += maxlblw + margin;
+            offs_y = title_h + row_ind;
+            maxlblw = 0;
+            item = 1;
+            row_ind = 0;
+        }
+        if (strstr(buf, sub_delim) != NULL) {
+            /* Group subtitle */
+            label = G_malloc(strlen(buf)+1);
+            part = strtok(buf, sep);
+            sscanf(part, "%s", label);
+
+            D_text_size(sub_size, sub_size);
+            D_font(sub_font);
+            D_get_text_box(label, &bb, &bt, &bl, &br);
+            text_h = bb - bt;
+            row_w = br - bl;
+            offs_y += text_h + row_ind;
+            if (bg_h < offs_y)
+                bg_h = offs_y + symb_h/2.;
+            if (row_w > maxlblw)
+                maxlblw = row_w;
+
+            if (! do_bg) {
+                x = x0 + offs_x;
+                y = y0 + offs_y;
+                D_pos_abs(x, y);
+                D_use_color(fontcolor);
+                D_text(label);
+            }
+        }
+        else {
+            /* Map layers */
+            symb_name = G_malloc(strlen(buf) + 1);
+            type_str = G_malloc(strlen(buf) + 1);
+            line_color_str = G_malloc(strlen(buf) + 1);
+            fill_color_str = G_malloc(strlen(buf) + 1);
+            label = G_malloc(strlen(buf)+1);
+            line_color = G_malloc(sizeof(RGBA_Color));
+            fill_color = G_malloc(sizeof(RGBA_Color));
+
+            part = strtok(buf, sep);
+            sscanf(part, "%s", symb_name);
+            part = strtok(NULL, sep);
+            sscanf(part, "%s", type_str);
+            part = strtok(NULL, sep);
+            sscanf(part, "%s", line_color_str);
+            part = strtok(NULL, sep);
+            sscanf(part, "%s", fill_color_str);
+            part = strtok(NULL, sep);
+            sscanf(part, "%lf", &size);
+            part = strtok(NULL, sep);
+            sscanf(part, "%lf", &line_width);
+            part = strtok(NULL, sep);
+            sscanf(part, "%s", label);
+
+            /* Symbol */
+            if (strcmp(type_str,"area")==0) {
+                symb_name = "legend/area";
+                size = symb_size;
+            }
+            else if (strcmp(type_str,"line")==0) {
+                symb_name = "legend/line";
+                size = symb_size;
+            }
+            Symb = S_read(symb_name);
+            if (Symb == NULL)
+                G_warning(_("Cannot read symbol"));
+            else
+                S_stroke(Symb, size, 0, 0);
+
+            /* parse line color */
+            ret = G_str_to_color(line_color_str, &R, &G, &B);
+            line_color->r = (unsigned char)R;
+            line_color->g = (unsigned char)G;
+            line_color->b = (unsigned char)B;
+            if (ret == 1)
+                /* here alpha is only used as an on/off switch, otherwise unused by the display drivers */
+                line_color->a = RGBA_COLOR_OPAQUE;
+            else if (ret == 2)
+                line_color->a = RGBA_COLOR_NONE;
+            else
+                G_warning(_("[%s]: No such color"), line_color_str);
+            /* parse fill color */
+            ret = G_str_to_color(fill_color_str, &R, &G, &B);
+            fill_color->r = (unsigned char)R;
+            fill_color->g = (unsigned char)G;
+            fill_color->b = (unsigned char)B;
+            if (ret == 1)
+                fill_color->a = RGBA_COLOR_OPAQUE;
+            else if (ret == 2)
+                fill_color->a = RGBA_COLOR_NONE;
+            else
+                G_warning(_("[%s]: No such color"), fill_color_str);
+
+            /* Label */
+            D_text_size(fontsize, fontsize);
+            D_font(font);
+            D_get_text_box(label, &bb, &bt, &bl, &br);
+
+            symb_h = Symb->yscale * size * 2;
+            text_h = bb - bt;
+            row_w = max_symb_w + sym_lbl_space + br - bl;
+            if (symb_h >= text_h)
+                offs_y += symb_h + row_ind;
+            else
+                offs_y += text_h + row_ind;
+
+            if (bg_h <= offs_y)
+                bg_h = offs_y + symb_h/2.;
+            if (row_w > maxlblw)
+                maxlblw = row_w;
+
+            if (! do_bg) {
+                S_stroke(Symb, size, 0, 0);
+                x = x0 + offs_x + max_symb_w/2.;
+                y = y0 + offs_y - symb_h/2;
+                D_symbol(Symb, x, y, line_color, fill_color);
+
+                x = x0 + offs_x + max_symb_w + sym_lbl_space;
+                y = y0 + offs_y - symb_h/2. + text_h/2.;
+                D_pos_abs(x, y);
+                D_use_color(fontcolor);
+                D_text(label);
+            }
+        } /* end of Parse the line */
+
+        got_new = G_getl2(buf, sizeof(buf), file_in);
+        G_strip(buf);
+    }
+
+    fclose(file_in);
+
+    /* Draw background */
+    if (do_bg) {
+        double x0bg, y0bg, x1bg, y1bg;
+        if (title_w > offs_x + maxlblw)
+            bg_w = title_w;
+        else
+            bg_w = offs_x + maxlblw;
+
+        x0bg = x0 - margin;
+        y0bg = y0 - margin;
+        x1bg = x0 + bg_w + margin;
+        y1bg = y0 + bg_h + margin;
+
+        if (bgcolor) {
+            D_use_color(bgcolor);
+            D_box_abs(x0bg, y0bg, x1bg, y1bg);
+        }
+
+        D_use_color(bcolor);
+        D_begin();
+        D_move_abs(x0bg, y0bg);
+        D_cont_abs(x0bg, y1bg);
+        D_cont_abs(x1bg, y1bg);
+        D_cont_abs(x1bg, y0bg);
+        D_close();
+        D_end();
+        D_stroke();
+    }
+
+    D_save_command(G_recreate_command());
+}

Added: grass-addons/grass7/display/d.legend.vect/local_proto.h
===================================================================
--- grass-addons/grass7/display/d.legend.vect/local_proto.h	                        (rev 0)
+++ grass-addons/grass7/display/d.legend.vect/local_proto.h	2016-07-30 00:55:27 UTC (rev 69043)
@@ -0,0 +1,3 @@
+/* draw.c */
+void draw(char *, double, double, char *, int, int, int,
+          int, char *, int, char *, int, char *, int, int, int);

Added: grass-addons/grass7/display/d.legend.vect/main.c
===================================================================
--- grass-addons/grass7/display/d.legend.vect/main.c	                        (rev 0)
+++ grass-addons/grass7/display/d.legend.vect/main.c	2016-07-30 00:55:27 UTC (rev 69043)
@@ -0,0 +1,241 @@
+/*
+ ****************************************************************************
+ *
+ * MODULE:       d.vect.legend
+ * AUTHOR(S):    Adam Laza, CTU, GSoC 2016
+ * PURPOSE:      Display a vector layer
+ * COPYRIGHT:    (C) 2007-2016 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
+ *               for details.
+ *
+ *****************************************************************************/
+
+#include <stdlib.h>
+#include <grass/display.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+
+int main(int argc, char **argv)
+{
+    struct GModule *module;
+//    struct Option *opt_input, *opt_sep;
+    struct Option *opt_at, *opt_cols, *opt_font, *opt_fontsize,
+            *opt_fontcolor, *opt_title, *opt_tit_font, *opt_tit_fontsize, *opt_sub_font,
+            *opt_sub_fontsize, *opt_bcolor, *opt_bgcolor, *opt_symb_size;
+    struct Flag *fl_bg;
+
+    double LL, LT;
+    char *title, *file_name, *leg_dir;
+    int bcolor, bgcolor, do_bg;
+    int fontsize, fontcolor, tit_size, sub_size;
+    char *font, *tit_font, *sub_font;
+    int cols, symb_size;
+
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    G_add_keyword(_("display"));
+    G_add_keyword(_("cartography"));
+    G_add_keyword(_("vector"));
+    G_add_keyword(_("legend"));
+    module->description =
+    _("Displays a vector legend "
+      "in the active graphics frame.");
+
+//    opt_input = G_define_standard_option(G_OPT_F_INPUT);
+//    opt_input->key = "input";
+//    opt_input->description = _("Input file");
+//    opt_input->guisection = _("Input");
+
+//    opt_sep = G_define_standard_option(G_OPT_F_SEP);
+//    opt_sep->guisection = _("Input");
+
+    opt_at = G_define_option();
+    opt_at->key = "at";
+    opt_at->key_desc = "left,top";
+    opt_at->type = TYPE_DOUBLE;
+    opt_at->options = "0-100";
+    opt_at->answer = "10,40";
+    opt_at->required = NO;
+    opt_at->description =
+    _("Screen position of legend to be drawn (percentage, [0,0] is lower left)");
+    opt_at->guisection = _("Position");
+
+    opt_cols = G_define_option();
+    opt_cols->key = "columns";
+    opt_cols->type = TYPE_INTEGER;
+    opt_cols->answer = "1";
+    opt_cols->required = NO;
+    opt_cols->description =
+    _("Number of legend columns");
+    opt_cols->guisection = _("Position");
+
+    opt_title = G_define_option();
+    opt_title->key = "title";
+    opt_title->type = TYPE_STRING;
+    opt_title->required = NO;
+    opt_title->description = _("Legend title");
+    opt_title->guisection = _("Title");
+
+    opt_symb_size = G_define_option();
+    opt_symb_size->key = "symbol_size";
+    opt_symb_size->type = TYPE_INTEGER;
+    opt_symb_size->required = NO;
+    opt_symb_size->description = _("Symbol size");
+    opt_symb_size->answer = "20";
+    opt_symb_size->guisection = _("Symbols");
+
+    opt_bcolor = G_define_standard_option(G_OPT_CN);
+    opt_bcolor->key = "border_color";
+    opt_bcolor->answer = "black";
+    opt_bcolor->label = _("Border color");
+    opt_bcolor->guisection = _("Background");
+
+    opt_bgcolor = G_define_standard_option(G_OPT_CN);
+    opt_bgcolor->key = "bgcolor";
+    opt_bgcolor->answer = "white";
+    opt_bgcolor->label = _("Background color");
+    opt_bgcolor->guisection = _("Background");
+
+    opt_tit_font = G_define_option();
+    opt_tit_font->key = "title_font";
+    opt_tit_font->type = TYPE_STRING;
+    opt_tit_font->required = NO;
+    opt_tit_font->description = _("Title font name");
+    opt_tit_font->guisection = _("Font settings");
+
+    opt_tit_fontsize = G_define_option();
+    opt_tit_fontsize->key = "title_fontsize";
+    opt_tit_fontsize->type = TYPE_DOUBLE;
+    opt_tit_fontsize->required = NO;
+    opt_tit_fontsize->options = "1-360";
+    opt_tit_fontsize->label = _("Title font size");
+    opt_tit_fontsize->description = _("Default: 18");
+    opt_tit_fontsize->guisection = _("Title");
+
+    opt_sub_font = G_define_option();
+    opt_sub_font->key = "sub_font";
+    opt_sub_font->type = TYPE_STRING;
+    opt_sub_font->required = NO;
+    opt_sub_font->description = _("Subtitle font name");
+    opt_sub_font->guisection = _("Font settings");
+
+    opt_sub_fontsize = G_define_option();
+    opt_sub_fontsize->key = "sub_fontsize";
+    opt_sub_fontsize->type = TYPE_DOUBLE;
+    opt_sub_fontsize->required = NO;
+    opt_sub_fontsize->options = "1-360";
+    opt_sub_fontsize->label = _("Subtitle font size");
+    opt_sub_fontsize->description = _("Default: 14");
+    opt_sub_fontsize->guisection = _("Font settings");
+
+    opt_font = G_define_option();
+    opt_font->key = "font";
+    opt_font->type = TYPE_STRING;
+    opt_font->required = NO;
+    opt_font->description = _("Font name");
+    opt_font->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: 12");
+    opt_fontsize->guisection = _("Font settings");
+
+    opt_fontcolor = G_define_standard_option(G_OPT_CN);
+    opt_fontcolor->key = "fontcolor";
+    opt_fontcolor->answer = "black";
+    opt_fontcolor->label = _("font color");
+    opt_fontcolor->guisection = _("Font settings");
+
+    fl_bg = G_define_flag();
+    fl_bg->key = 'b';
+    fl_bg->description = _("Display legend background");
+    fl_bg->guisection = _("Background");
+
+
+    /* Check command line */
+    if (G_parser(argc, argv)) {
+        exit(EXIT_FAILURE);
+    }
+
+    D_open_driver();
+    D_setup_unity(0);
+
+    /* parse and check options and flags */
+    file_name = getenv("GRASS_LEGEND_FILE");
+//    file_name = opt_input->answer;
+    if (!file_name)
+        G_fatal_error("No legend file defined.");
+
+    if (opt_at->answer) {
+        sscanf(opt_at->answers[0], "%lf", &LL);
+        sscanf(opt_at->answers[1], "%lf", &LT);
+    }
+
+    if (opt_title->answer)
+        title = opt_title->answer;
+    else
+        title = "";
+
+    if (opt_cols->answer)
+        sscanf(opt_cols->answer, "%d", &cols);
+    else
+        cols = 1;
+
+    sscanf(opt_symb_size->answer, "%d", &symb_size);
+
+    /* Background */
+    do_bg = fl_bg->answer;
+    bcolor = D_parse_color(opt_bcolor->answer, TRUE);
+    bgcolor = D_parse_color(opt_bgcolor->answer, TRUE);
+
+    /* Font settings */
+    if (opt_font->answer)
+        font = opt_font->answer;
+    else
+        font = "sans";
+    if (opt_fontsize->answer != NULL)
+        sscanf(opt_fontsize->answer, "%d", &fontsize);
+    else
+        fontsize = 14;
+
+    if (opt_tit_font->answer)
+        tit_font = opt_tit_font->answer;
+    else
+        tit_font = font;
+    if (opt_tit_fontsize->answer)
+        sscanf(opt_tit_fontsize->answer, "%d", &tit_size);
+    else
+        tit_size = fontsize;
+
+    if (opt_sub_font->answer)
+        sub_font = opt_sub_font->answer;
+    else
+        sub_font = font;
+    if (opt_sub_fontsize->answer)
+        sscanf(opt_sub_fontsize->answer, "%d", &sub_size);
+    else
+        sub_size = fontsize;
+
+    fontcolor = D_parse_color(opt_fontcolor->answer, FALSE); /*default color: black */
+
+    /* Pre-calculate the layout */
+    if (do_bg)
+        draw(file_name, LL, LT, title, cols, bgcolor, bcolor, 1, tit_font, tit_size, sub_font, sub_size, font, fontsize, fontcolor, symb_size);
+
+    /* Draw legend */
+    draw(file_name, LL, LT, title, cols, bgcolor, bcolor, 0, tit_font, tit_size, sub_font, sub_size, font, fontsize, fontcolor, symb_size);
+
+    D_close_driver();
+
+    exit(EXIT_SUCCESS);
+}



More information about the grass-commit mailing list