24 #define DATE_FORMAT "%c"
28 static double width, height;
34 double left, right, bot, top;
37 static const struct paper papers[] = {
39 {
"a4", 8.268, 11.693, 0.5, 0.5, 1.0, 1.0},
40 {
"a3", 11.693, 16.535, 0.5, 0.5, 1.0, 1.0},
41 {
"a2", 16.54, 23.39, 1.0, 1.0, 1.0, 1.0},
42 {
"a1", 23.39, 33.07, 1.0, 1.0, 1.0, 1.0},
43 {
"a0", 33.07, 46.77, 1.0, 1.0, 1.0, 1.0},
44 {
"us-legal", 8.5, 14.0, 1.0, 1.0, 1.0, 1.0},
45 {
"us-letter", 8.5, 11.0, 1.0, 1.0, 1.0, 1.0},
46 {
"us-tabloid", 11.0, 17.0, 1.0, 1.0, 1.0, 1.0},
47 {
NULL, 0, 0, 0, 0, 0, 0}};
49 static void write_prolog(
void)
54 time_t
t = time(
NULL);
55 struct tm *tm = localtime(&
t);
57 strftime(date_str,
sizeof(date_str),
DATE_FORMAT, tm);
59 sprintf(prolog_file,
"%s/etc/psdriver.ps",
G_gisbase());
61 prolog_fp = fopen(prolog_file,
"r");
66 output(
"%%!PS-Adobe-3.0 EPSF-3.0\n");
68 output(
"%%!PS-Adobe-3.0\n");
70 output(
"%%%%LanguageLevel: %d\n", 3);
71 output(
"%%%%Creator: GRASS PS Driver\n");
74 output(
"%%%%Orientation: %s\n", landscape ?
"Landscape" :
"Portrait");
75 output(
"%%%%BoundingBox: %d %d %d %d\n", (
int)floor(
ps.
left),
77 output(
"%%%%CreationDate: %s\n", date_str);
78 output(
"%%%%EndComments\n");
80 output(
"%%%%BeginProlog\n");
81 while (!feof(prolog_fp)) {
84 if (!fgets(buf,
sizeof(buf), prolog_fp))
96 output(
"%%%%BeginSetup\n");
101 output(
"90 rotate 0 1 -1 scale\n");
103 output(
"0 %.1f translate 1 -1 scale\n", height);
105 output(
"%.1f %.1f BEGIN\n", width, height);
108 output(
"%%%%Page: 1 1\n");
111 static double in2pt(
double x)
116 static void swap(
double *
x,
double *y)
124 static void get_paper(
void)
126 const char *
name = getenv(
"GRASS_RENDER_PS_PAPER");
127 const struct paper *paper;
154 ps.
left = in2pt(paper->left);
155 ps.
right = in2pt(paper->width) - in2pt(paper->right);
156 ps.
bot = in2pt(paper->bot);
157 ps.
top = in2pt(paper->height) - in2pt(paper->top);
160 height = in2pt(paper->height) - in2pt(paper->top) - in2pt(paper->bot);
163 swap(&width, &height);
175 p = getenv(
"GRASS_RENDER_FILE");
176 if (!p || strlen(p) == 0)
183 p = getenv(
"GRASS_RENDER_TRUECOLOR");
186 p = getenv(
"GRASS_RENDER_PS_LANDSCAPE");
187 landscape = p && strcmp(p,
"TRUE") == 0;
189 p = getenv(
"GRASS_RENDER_PS_HEADER");
192 p = getenv(
"GRASS_RENDER_PS_TRAILER");
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_rename_file(const char *, const char *)
Rename a file or a directory in the filesystem.
void void G_verbose_message(const char *,...) __attribute__((format(printf
const char * G_whoami(void)
Gets user's name.
char * G_tempfile(void)
Returns a temporary file name.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
const char * G_gisbase(void)
Get full path name of the top level module directory.
const char * PS_Graph_get_file(void)
Get render file.
void output(const char *fmt,...)