فهرست منبع

add line sytle by name and linecap (trac https://trac.osgeo.org/grass/ticket/250; merge from devbr6)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33489 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 16 سال پیش
والد
کامیت
83011b7f53
4فایلهای تغییر یافته به همراه68 افزوده شده و 14 حذف شده
  1. 6 0
      ps/ps.map/do_vectors.c
  2. 18 9
      ps/ps.map/ps.map.html
  3. 36 4
      ps/ps.map/r_vlines.c
  4. 8 1
      ps/ps.map/vector.h

+ 6 - 0
ps/ps.map/do_vectors.c

@@ -63,6 +63,12 @@ int do_vectors(int after_masking)
 
 	    fprintf(PS.fp, "%.8f W\n", vector.layer[n].width);
 	    set_ps_color(&(vector.layer[n].color));
+
+	    if (vector.layer[n].linecap >= 0) {
+		G_debug(1, "Line cap: '%d'", vector.layer[n].linecap);
+		fprintf(PS.fp, "%d setlinecap\n",vector.layer[n].linecap);		 
+	    }
+
 	    dashes[0] = '[';
 	    dashes[1] = 0;
 	    lz = 0;

+ 18 - 9
ps/ps.map/ps.map.html

@@ -1321,6 +1321,7 @@ USAGE:	<B>vlines</B> vectormap
 	<B>coffset</B> #
 	<B>ref</B> left|right
 	<B>style</B> 00001111
+	<B>linecap</B> style
 	<B>label</B> label
 	<B>lpos</B> #
 	<B>end</B>
@@ -1331,7 +1332,8 @@ The user can specify:
 <P>
 <B>color</B> - color of the vector lines or area boundaries;
 <P>
-<B>rgbcolumn</B> - name of color definition column used for the vector lines or area boundaries;
+<B>rgbcolumn</B> - name of color definition column used for the vector lines
+or area boundaries;
 <P>
 <B>width</B> - width of the vectors lines or area boundaries in pixels
 (accepts decimal points [floating points] as well as integers);
@@ -1344,13 +1346,13 @@ used in legend;
 <P>
 <B>hwidth</B> - the width of the highlight color in pixels;
 <P>
-<B>offset</B> (experimental) - offset for the vectors lines in pixels for plotting
-parallel lines in distance equal to offset (accepts positive or 
+<B>offset</B> (experimental) - offset for the vectors lines in pixels for
+plotting parallel lines in distance equal to offset (accepts positive or 
 negative decimal points). Useful to print streets with several parallel lanes;
 <P>
-<B>coffset</B> (experimental) - offset for the vectors lines. If coffset is used then 
-offset of line is equal to coffset * category value and offset is 
-used in legend;
+<B>coffset</B> (experimental) - offset for the vectors lines. If coffset
+is used then  offset of line is equal to coffset * category value and offset
+is used in legend;
 <P>
 <B>ref</B> (experimental) - line justification. 
 <P>
@@ -1359,15 +1361,22 @@ by the current mask;
 (see manual entry <EM><A HREF="r.mask.html">r.mask</A></EM>
 for more information on the mask);
 <P>
-<B>style</B> - the line style allows the vectors
-to be dashed in different patterns.  This is done by typing a
-series of numbers (0's and 1's) in a desired sequence or pattern.
+<B>style</B> - the line style allows the vectors to be dashed in different
+patterns.  This is done by either typing "solid", "dashed", "dotted", or
+"dashdotted", or as a series of 0's and 1's in a desired sequence or pattern.
 The first block of repeated zeros or ones represents "draw", the second
 block represents "blank".
 An even number of blocks will repeat the pattern, an odd number of blocks
 will alternate the pattern.
 The default is "solid";
 <P>
+<B>linecap</B> - the linecap specifies the look of the ends of the line,
+or the end of the dashes in a dashed line. The parameters are:
+'butt' for butt caps (default), 'round' for round caps and 'extended_butt'
+for extended butt caps. The shape of the round and the extended butt caps
+is related to the line thickness: for round butts the radius is half the
+linewidth, while for extended butt the line will extend for half the linewidth.  
+<P>
 <B>cats</B> - which categories should be plotted (default is all);
 <P>
 <B>label</B> - for description in <a href="#vlegend">vlegend</a>.

+ 36 - 4
ps/ps.map/r_vlines.c

@@ -8,8 +8,8 @@
  */
 #include <stdlib.h>
 #include <string.h>
-#include "vector.h"
 #include <grass/Vect.h>
+#include "vector.h"
 #include "ps_info.h"
 #include "local_proto.h"
 
@@ -24,7 +24,8 @@ static char *help[] = {
     "offset      #",
     "coffset     #",
     "masked      [y|n]",
-    "style       solid|[0|1]...",
+    "style       solid|dashed|dotted|dashdotted|[0|1]...",
+    "linecap     butt|round|extended_butt"
     "line_cat    #",
     "acolor      r g b",
     "label       label",
@@ -38,7 +39,7 @@ static char *help[] = {
 
 int read_vlines(char *name, char *mapset)
 {
-    char fullname[100];
+    char fullname[GNAME_MAX];
     char buf[1024];
     char *key, *data, *dp;
     double width;
@@ -79,6 +80,7 @@ int read_vlines(char *name, char *mapset)
     set_color(&(vector.layer[vec].color), 0, 0, 0);
     vector.layer[vec].rgbcol = NULL;
     vector.layer[vec].linestyle = NULL;
+    vector.layer[vec].linecap = LINECAP_BUTT;
     vector.layer[vec].ref = LINE_REF_CENTER;
     vector.layer[vec].hwidth = 0.;
     unset_color(&(vector.layer[vec].hcolor));
@@ -132,10 +134,21 @@ int read_vlines(char *name, char *mapset)
 	if (KEY("style")) {
 	    G_strip(data);
 	    if (strcmp(data, "solid") == 0) {
-/* TODO: add "dotted" and "dashed" preset line patterns */
 		vector.layer[vec].linestyle = NULL;
 		continue;
 	    }
+	    else if (strcmp(data, "dashed") == 0) {
+		vector.layer[vec].linestyle = G_store("000000111");
+		continue;
+	    }
+	    else if (strcmp(data, "dotted") == 0) {
+		vector.layer[vec].linestyle = G_store("100000");
+		continue;
+	    }
+	    else if (strcmp(data, "dashdotted") == 0) {
+		vector.layer[vec].linestyle = G_store("000000111011111");
+		continue;
+	    }
 	    for (dp = data; *dp; dp++)
 		if (*dp < '0' || *dp > '9')
 		    break;
@@ -147,6 +160,25 @@ int read_vlines(char *name, char *mapset)
 	    continue;
 	}
 
+	if (KEY("linecap")) {
+	    G_strip(data);
+	    if (strcmp(data, "butt") == 0) {
+		vector.layer[vec].linecap = LINECAP_BUTT;
+		continue;
+	    }
+	    else if (strcmp(data, "round") == 0) {
+		vector.layer[vec].linecap = LINECAP_ROUND;
+		continue;
+	    }
+	    else if (strcmp(data, "extended_butt") == 0) {
+		vector.layer[vec].linecap = LINECAP_EXTBUTT;
+		continue;
+	    }
+	    else
+		error(key, data, "illegal line cap (vlines)");		
+	    continue;
+	}
+
 	if (KEY("width")) {
 	    width = -1.;
 	    *mapset = 0;

+ 8 - 1
ps/ps.map/vector.h

@@ -30,6 +30,12 @@
 #define CLOSE_PATH  2
 #define WHOLE_PATH  3
 
+/* line end style */
+#define LINECAP_BUTT 0
+#define LINECAP_ROUND 1
+#define LINECAP_EXTBUTT 2
+
+
 typedef struct
 {
     /* All types */
@@ -54,7 +60,8 @@ typedef struct
     double coffset;		/* category offset */
     int ref;			/* justification */
     char *linestyle;		/* line or boundary style */
-    char *setdash;		/* ? */
+    char *setdash;		/* line style converted to PS setdash format */
+    int linecap;		/* line end style */
     double hwidth;		/* line or boundary highlight line width */
     PSCOLOR hcolor;