[GRASS-SVN] r37431 - grass-addons/ps/ps.output
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 24 12:25:47 EDT 2009
Author: ejtizado
Date: 2009-05-24 12:25:47 -0400 (Sun, 24 May 2009)
New Revision: 37431
Modified:
grass-addons/ps/ps.output/scanners.c
grass-addons/ps/ps.output/set_draw.c
Log:
now labels work
Modified: grass-addons/ps/ps.output/scanners.c
===================================================================
--- grass-addons/ps/ps.output/scanners.c 2009-05-24 15:25:23 UTC (rev 37430)
+++ grass-addons/ps/ps.output/scanners.c 2009-05-24 16:25:47 UTC (rev 37431)
@@ -49,18 +49,20 @@
*xref = CENTER;
else if(strcmp(refx, "RIGHT") == 0 || strcmp(refx, "right") == 0)
*xref = RIGHT;
+ /*
else
return 0;
-
+ */
if(strcmp(refy, "UPPER") == 0 || strcmp(refy, "upper") == 0)
*yref = UPPER;
else if(strcmp(refy, "CENTER") == 0 || strcmp(refy, "center") == 0)
*yref = CENTER;
else if(strcmp(refy, "LOWER") == 0 || strcmp(refy, "lower") == 0)
*yref = LOWER;
+ /*
else
return 0;
-
+ */
return 1;
}
Modified: grass-addons/ps/ps.output/set_draw.c
===================================================================
--- grass-addons/ps/ps.output/set_draw.c 2009-05-24 15:25:23 UTC (rev 37430)
+++ grass-addons/ps/ps.output/set_draw.c 2009-05-24 16:25:47 UTC (rev 37431)
@@ -11,13 +11,17 @@
#include <math.h>
#include <grass/symbol.h>
#include <grass/gprojects.h>
-#include "colors.h"
+#include "frames.h"
#include "ps_info.h"
+#include "local_proto.h"
#define PI 3.14159265359
#define KEY(x) (strcmp(x,key)==0)
+#define CODE(x) strcmp(x,code)==0
+void label_in_file(char *);
+
int set_draw(char * key, char *data)
{
char label[100], buf[256];
@@ -215,8 +219,15 @@
set_xy_where("cP exch 2 copy", e1, n1, "L cP 2 copy 8 2 roll");
fprintf(PS.fp,
" 4 -1 roll add 2 div 3 1 roll add 2 div exch M"
- " 4 1 roll sub 3 1 roll exch sub atan GS ROT 0 1 MR (%s) SHC GR S\n", buf);
+ " 4 1 roll sub 3 1 roll exch sub atan GS ROT 0 1 MR (%s) SHC GR S\n", buf);
}
+ else if (KEY("labels") || KEY("label"))
+ {
+ if (sscanf(data, "%s", label) != 1) {
+ error(key, data, "labels need 1 parameters (filename)");
+ }
+ label_in_file(label);
+ }
else
{
error(key, data, "not found\n");
@@ -225,3 +236,112 @@
return 1;
}
+
+void label_in_file(char *name)
+{
+ FILE *in = NULL;
+ char buf[1024], code[1024], data[1024];
+ int x, y;
+ double n;
+ PSFRAME frame;
+ PSFONT font;
+
+ frame.xref = CENTER;
+ frame.yref = CENTER;
+
+ if (*name) {
+ in = fopen(name, "r");
+ if (in == NULL) {
+ G_message("Labels file <%s> can't open", name);
+ return;
+ }
+ }
+
+ while (fgets(buf, sizeof(buf), in))
+ {
+ *code = 0;
+ *data = 0;
+ if (sscanf(buf, "%[^:]:%[^\n]", code, data) < 1)
+ continue;
+
+ G_strip(data);
+ if (CODE("text")) {
+
+ G_plot_where_xy(frame.x, frame.y, &x, &y);
+ frame.x = ((double)x) / 10.;
+ frame.y = ((double)y) / 10.;
+ set_ps_font(&font);
+ fprintf(PS.fp, "GS\n");
+ fprintf(PS.fp, "/ARo [(%s)] def\n", data);
+ fprintf(PS.fp, "/ARw 1 array def ARw 0 ARo SWx put ");
+ fprintf(PS.fp, "/ARh [2.0] def\n");
+ set_box_auto(&frame, &font, 0.25);
+ set_box_readjust_title(&frame, data);
+ set_box_draw(&frame);
+ fprintf(PS.fp, "GR\n");
+ fprintf(PS.fp, "(%s) xo wd 2 div add yo hg 2 div sub M SHCC\n", data);
+ }
+ /* Option to modify the text */
+ else if (CODE("east")) {
+ frame.x = atof(data);
+ }
+ else if (CODE("north")) {
+ frame.y = atof(data);
+ }
+ else if (CODE("xoffset")) {
+ frame.xset = atof(data);
+ }
+ else if (CODE("yoffset")) {
+ frame.yset = atof(data);
+ }
+ else if (CODE("ref")) {
+ scan_ref(data, &(frame.xref), &(frame.yref));
+ }
+ else if (CODE("font")) {
+ get_font(data);
+ strcpy(font.name, data);
+ }
+ else if (CODE("fontsize")) {
+ if (scan_dimen(data, &(font.size)) != 1)
+ font.size = 10.;
+ }
+ else if (CODE("size")) {
+ n = atof(data);
+ font.size = (n * MT_TO_POINT)/PS.scale;
+ }
+ else if (CODE("color")) {
+ if (!scan_color(data, &(font.color))) {
+ set_color_rgb(&(font.color), 0, 0, 0);
+ }
+ }
+ else if (CODE("space")) {
+ }
+ else if (CODE("rotation")) {
+ frame.rotate = atof(data);
+ }
+ else if (CODE("width")) {
+ if (scan_dimen(data, &(frame.border)) != 1) {
+ frame.border = -1;
+ }
+ }
+ else if (CODE("hcolor")) {
+ }
+ else if (CODE("hwidth")) {
+ }
+ else if (CODE("background")) {
+ if (!scan_color(data, &(frame.fcolor))) {
+ unset_color(&(frame.fcolor));
+ }
+ }
+ else if (CODE("border")) {
+ if (!scan_color(data, &(frame.color))) {
+ unset_color(&(frame.color));
+ }
+ }
+ else if (CODE("opaque")) {
+ }
+ }
+ fclose(in);
+
+ return;
+}
More information about the grass-commit
mailing list