-
Notifications
You must be signed in to change notification settings - Fork 361
/
psconvert.c
3003 lines (2770 loc) · 133 KB
/
psconvert.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*--------------------------------------------------------------------
*
* Copyright (c) 1991-2025 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
* See LICENSE.TXT file for copying and redistribution conditions.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Contact info: www.generic-mapping-tools.org
*--------------------------------------------------------------------*/
/*
*
* Brief synopsis: psconvert converts one or several PostScript file(s) to other formats using Ghostscript.
* It works by modifying the page size in order that the image will have a size
* which is specified by the BoundingBox.
* As an option, a tight BoundingBox may be computed.
* psconvert uses the ideas of the EPS2XXX.m from Primoz Cermelj published in MatLab Central
* and of psbbox.sh of Remko Scharroo.
*
*--------------------------------------------------------------------*/
/*
* Authors: Joaquim Luis and Remko Scharroo
* Date: 1-JAN-2010
* Version: 6 API
*/
#include "gmt_dev.h"
#include "longopt/psconvert_inc.h"
#define THIS_MODULE_CLASSIC_NAME "psconvert"
#define THIS_MODULE_MODERN_NAME "psconvert"
#define THIS_MODULE_LIB "core"
#define THIS_MODULE_PURPOSE "Convert [E]PS file(s) to other formats using Ghostscript"
#define THIS_MODULE_KEYS "<X{+,FI)"
#define THIS_MODULE_NEEDS ""
#define THIS_MODULE_OPTIONS "-V"
#ifdef WIN32 /* Special for Windows */
# include <windows.h>
# include <process.h>
# define getpid _getpid
# define dup2 _dup2
# define execv _execv
# define pipe _pipe
static char quote = '\"';
static char *squote = "\"";
#else
static char quote = '\'';
static char *squote = "\'";
struct popen2 {
int fd[2]; /* The input [0] and output [1] file descriptors */
int n_closed; /* Number of times we have called gmt_pclose */
pid_t child_pid; /* Pid of child */
};
#endif
enum GMT_GS_Devices {
GS_DEV_EPS = 0,
GS_DEV_PDF,
GS_DEV_SVG,
GS_DEV_JPG,
GS_DEV_PNG,
GS_DEV_PPM,
GS_DEV_TIF,
GS_DEV_BMP,
GS_DEV_TPNG, /* PNG with transparency */
GS_DEV_JPGG, /* These are grayscale versions */
GS_DEV_PNGG,
GS_DEV_TIFG,
GS_DEV_BMPG,
N_GS_DEVICES}; /* Number of supported GS output devices */
enum GMT_KML_Elevation {
KML_GROUND_ABS = 0,
KML_GROUND_REL,
KML_ABS,
KML_SEAFLOOR_REL,
KML_SEAFLOOR_ABS,
N_KML_ELEVATIONS};
enum psconv_alias {
PSC_LINES = 0,
PSC_TEXT = 1,
PSC_GEO = 2
};
#define add_to_list(list,item) { if (list[0]) strcat (list, " "); strcat (list, item); }
#define add_to_qlist(list,item) { if (list[0]) strcat (list, " "); strcat (list, squote); strcat (list, item); strcat (list, squote); }
struct PSCONVERT_CTRL {
struct PSCONVERT_In { /* Input file info */
unsigned int n_files;
} In;
struct PSCONVERT_A { /* -A[+r][+u] */
bool active;
bool crop; /* Round HiRes BB instead of ceil (+r) */
bool round; /* Round HiRes BB instead of ceil (+r) */
bool strip; /* Remove the -U time-stamp (+u)*/
bool media; /* If true we must crop to current media size in PS_MEDIA. Only issued indirectly by gmt end */
} A;
struct PSCONVERT_C { /* -C<option> */
bool active;
char arg[GMT_LEN256];
} C;
struct PSCONVERT_D { /* -D<dir> */
bool active;
char *dir;
} D;
struct PSCONVERT_E { /* -E<resolution> */
bool active;
double dpi;
} E;
struct PSCONVERT_F { /* -F<out_name> */
bool active;
char *file;
} F;
struct PSCONVERT_G { /* -G<GSpath> */
bool active;
char *file;
} G;
struct PSCONVERT_H { /* -H<scale> */
bool active;
int factor;
} H;
struct PSCONVERT_I { /* -I[+m<margins>][+s|S[m]<width>[/<height>]] */
bool active;
bool max; /* Only scale if dim exceeds the given size */
bool resize; /* Resize to a user selected size */
bool rescale; /* Resize to a user selected scale factor */
double scale; /* Scale factor to go along with the 'rescale' option */
double new_size[2];
double margin[4];
double new_dpi_x, new_dpi_y;
} I;
struct PSCONVERT_L { /* -L<list> */
bool active;
char *file;
} L;
struct PSCONVERT_M { /* -Mb|f<PSfile> */
bool active;
char *file;
} M[2];
struct PSCONVERT_N { /* -N[+f<fade>][+g<backfill>][+k<fadefill>][+p<pen>] with deprecated [+i] */
bool active;
bool outline; /* Draw frame around plot with selected pen (+p) [0.25p] */
bool BB_paint; /* Paint box behind plot with selected fill (+g) */
bool fade; /* If true we must fade out the plot to black [or what +kfill says] */
bool use_ICC_profiles;
double fade_level; /* Fade to black at this level of transparency */
struct GMT_PEN pen;
struct GMT_FILL back_fill; /* Initialized to black */
struct GMT_FILL fade_fill; /* Initialized to black */
} N;
struct PSCONVERT_P { /* -P */
bool active;
} P;
struct PSCONVERT_Q { /* -Q[g|t]<bits> -Qp */
bool active;
bool on[3]; /* [0] for graphics, [1] for text antialiasing, [2] for pdfmark GeoPDF */
unsigned int bits[2];
} Q;
struct PSCONVERT_S { /* -S */
bool active;
} S;
struct PSCONVERT_T { /* -T */
bool active;
int eps; /* 1 if we want to make EPS, -1 with setpagedevice (possibly in addition to another format) */
int ps; /* 1 if we want to save the final PS under "modern" setting */
int device; /* May be negative */
int quality; /* For JPG [90] */
} T;
struct PSCONVERT_W { /* -W -- for world file production */
bool active;
bool folder;
bool warp;
bool kml;
bool no_crop;
unsigned int mode; /* 0 = clamp at ground, 1 is relative to ground, 2 is absolute 3 is relative to seafloor, 4 is clamp at seafloor */
int min_lod, max_lod; /* minLodPixels and maxLodPixels settings */
int min_fade, max_fade; /* minFadeExtent and maxFadeExtent settings */
char *doctitle; /* Name of KML document */
char *overlayname; /* Name of the image overlay */
char *URL; /* URL of remote site */
char *foldername; /* Name of KML folder */
double altitude;
} W;
struct PSCONVERT_Z { /* -Z */
bool active;
} Z;
};
#ifdef WIN32 /* Special for Windows */
GMT_LOCAL int psconvert_ghostbuster(struct GMTAPI_CTRL *API, struct PSCONVERT_CTRL *C);
#else
/* Abstraction to get popen to do bidirectional read/write */
GMT_LOCAL struct popen2 * psconvert_popen2 (const char *cmdline) {
struct popen2 *F = NULL;
/* Must implement a bidirectional popen instead */
pid_t p;
int pipe_stdin[2] = {0, 0}, pipe_stdout[2] = {0, 0};
if (pipe (pipe_stdin)) return NULL;
if (pipe (pipe_stdout)) return NULL;
printf ("pipe_stdin[0] = %d, pipe_stdin[1] = %d\n", pipe_stdin[0], pipe_stdin[1]);
printf ("pipe_stdout[0] = %d, pipe_stdout[1] = %d\n", pipe_stdout[0], pipe_stdout[1]);
if ((p = fork()) < 0) return NULL; /* Fork failed */
if (p == 0) { /* child */
close (pipe_stdin[1]);
dup2 (pipe_stdin[0], 0);
close (pipe_stdout[0]);
dup2 (pipe_stdout[1], 1);
execl ("/bin/sh", "sh", "-c", cmdline, NULL);
perror ("execl"); return NULL;
}
/* Return the file handles back via structure */
F = calloc (1, sizeof (struct popen2));
F->child_pid = p;
F->fd[1] = pipe_stdin[1];
F->fd[0] = pipe_stdout[0];
return F;
}
#ifndef _WIN32
#include <signal.h>
#include <sys/wait.h>
#endif
GMT_LOCAL void psconvert_pclose2 (struct popen2 **Faddr, int dir) {
struct popen2 *F = *Faddr;
F->n_closed++;
close (F->fd[dir]); /* Close this pipe */
if (F->n_closed == 2) { /* Done so free object */
/* Done, kill child */
#ifndef _WIN32
printf("kill(%d, 0) -> %d\n", F->child_pid, kill(F->child_pid, 0));
printf("waitpid() -> %d\n", waitpid(F->child_pid, NULL, 0));
printf("kill(%d, 0) -> %d\n", F->child_pid, kill(F->child_pid, 0));
#endif
free (F);
*Faddr = NULL;
}
}
#endif
GMT_LOCAL int psconvert_parse_new_A_settings (struct GMT_CTRL *GMT, char *arg, struct PSCONVERT_CTRL *Ctrl) {
/* Syntax: -A[+r][+u] */
gmt_M_unused (GMT);
Ctrl->A.crop = true;
if (strstr (arg, "r"))
Ctrl->A.round = true;
if (strstr (arg, "u"))
Ctrl->A.strip = true;
if (strstr (arg, "M")) /* +M is hidden and only issued by gmt end */
Ctrl->A.media = true;
return (GMT_NOERROR);
}
GMT_LOCAL int psconvert_parse_new_I_settings (struct GMT_CTRL *GMT, char *arg, struct PSCONVERT_CTRL *Ctrl) {
/* Syntax: I[+m<margins>][+s[m]<width>[/<height>]][+S<scale>]
* Repeatable, so can use -I to deal with grayshades as before
*/
unsigned int pos = 0, error = 0;
int k, j;
char p[GMT_LEN128] = {""}, txt_a[GMT_LEN64] = {""}, txt_b[GMT_LEN64] = {""}, txt_c[GMT_LEN64] = {""}, txt_d[GMT_LEN64] = {""};
if (arg[0] == '\0') { /* This is the old -I option */
if (gmt_M_compat_check (GMT, 6)) {
GMT_Report (GMT->parent, GMT_MSG_COMPAT, "-I (no args) is deprecated; use -N+i instead.\n");
Ctrl->N.use_ICC_profiles = true;
}
else {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -I: No arguments given\n");
error = 1;
}
return (error);
}
while (gmt_getmodopt (GMT, 'N', arg, "msS", &pos, p, &error) && error == 0) {
switch (p[0]) {
case 'm': /* Margins */
j = sscanf (&p[1], "%[^/]/%[^/]/%[^/]/%s", txt_a, txt_b, txt_c, txt_d);
switch (j) {
case 1: /* Got uniform margin */
Ctrl->I.margin[XLO] = Ctrl->I.margin[XHI] = Ctrl->I.margin[YLO] = Ctrl->I.margin[YHI] = gmt_M_to_points (GMT, txt_a);
break;
case 2: /* Got separate x/y margins */
Ctrl->I.margin[XLO] = Ctrl->I.margin[XHI] = gmt_M_to_points (GMT, txt_a);
Ctrl->I.margin[YLO] = Ctrl->I.margin[YHI] = gmt_M_to_points (GMT, txt_b);
break;
case 4: /* Got different margins for all sides */
Ctrl->I.margin[XLO] = gmt_M_to_points (GMT, txt_a);
Ctrl->I.margin[XHI] = gmt_M_to_points (GMT, txt_b);
Ctrl->I.margin[YLO] = gmt_M_to_points (GMT, txt_c);
Ctrl->I.margin[YHI] = gmt_M_to_points (GMT, txt_d);
break;
default:
error++;
GMT_Report (GMT->parent, GMT_MSG_ERROR, "-I+m: Must specify 1, 2, or 4 margins\n");
break;
}
break;
case 'S': /* New size via a scale factor */
Ctrl->I.rescale = true;
Ctrl->I.scale = atof (&p[1]);
break;
case 's': /* New size +s[m]<width>[/<height>] */
Ctrl->I.resize = true;
if (p[1] == 'm') { Ctrl->I.max = true, k = 2;} else k = 1;
j = sscanf (&p[k], "%[^/]/%s", txt_a, txt_b);
switch (j) {
case 1: /* Got width only. Height will be computed later */
Ctrl->I.new_size[0] = gmt_M_to_points (GMT, txt_a);
break;
case 2: /* Got separate width/height */
Ctrl->I.new_size[0] = gmt_M_to_points (GMT, txt_a);
Ctrl->I.new_size[1] = gmt_M_to_points (GMT, txt_b);
break;
default:
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -I+s[m]<width[/height]>: Wrong size parameters\n");
error++;
break;
}
break;
default: /* These are caught in gmt_getmodopt so break is just for Coverity */
break;
}
}
if (Ctrl->I.rescale && Ctrl->I.resize) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -I+s|S: Cannot set both -I+s and -I+S\n");
error++;
}
else if (Ctrl->I.rescale) /* But we can. This makes the coding simpler later on */
Ctrl->I.resize = true;
return (error);
}
GMT_LOCAL int psconvert_parse_new_N_settings (struct GMT_CTRL *GMT, char *arg, struct PSCONVERT_CTRL *Ctrl) {
/* Syntax: -N[+f<fade>][+g<backfill>][+k<fadefill>][+p<pen>] with deprecated [+i] */
unsigned int pos = 0, error = 0;
char p[GMT_LEN128] = {""};
if (gmt_validate_modifiers (GMT, arg, 'N', "fgikp", GMT_MSG_ERROR)) return (1); /* Bail right away */
while (gmt_getmodopt (GMT, 'N', arg, "fgikp", &pos, p, &error) && error == 0) {
switch (p[0]) {
case 'f': /* Fade out */
if (!p[1]) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "-N+f: Append the fade setting in 0-100 range.\n");
error++;
}
else if ((Ctrl->N.fade_level = atof (&p[1])) < 0.0 || Ctrl->N.fade_level > 100.0) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "-N+f: Must specify fading in 0 (no fade) - 100 (fully faded) range.\n");
error++;
}
Ctrl->N.fade_level *= 0.01; /* Normalized */
Ctrl->N.fade = true;
break;
case 'g': /* Fill background */
Ctrl->N.BB_paint = true;
if (!p[1]) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "-N+g: Append the background fill\n");
error++;
}
else if (gmt_getfill (GMT, &p[1], &Ctrl->N.back_fill)) {
gmt_rgb_syntax (GMT, 'N', "Modifier +g sets background fill attributes");
error++;
}
break;
case 'i': /* Formerly -I */
/* Ghostscript versions >= 9.00 change gray-shades by using ICC profiles.
GS 9.05 and above provide the '-dUseFastColor=true' option to prevent that
and that is what psconvert does by default, unless option -I is set.
Note that for GS >= 9.00 and < 9.05 the gray-shade shifting is applied
to all but PDF format. We have no solution to offer other than ... upgrade GS. */
Ctrl->N.use_ICC_profiles = true; /* Deprecated in docs but still honored under hood */
break;
case 'k': /* Fill for fading */
if (!p[1]) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "-N+k: Append the fade fill [black]\n");
error++;
}
else if (gmt_getfill (GMT, &p[1], &Ctrl->N.fade_fill)) {
gmt_rgb_syntax (GMT, 'N', "Modifier +k sets background fill attributes");
error++;
}
break;
case 'p': /* Draw outline */
Ctrl->N.outline = true;
if (!p[1])
Ctrl->N.pen = GMT->current.setting.map_default_pen;
else if (gmt_getpen (GMT, &p[1], &Ctrl->N.pen)) {
gmt_pen_syntax (GMT, 'N', NULL, "sets background outline pen attributes", NULL, 0);
error++;
}
break;
default: /* These are caught in gmt_getmodopt so break is just for Coverity */
break;
}
}
//if (Ctrl->N.fade) Ctrl->N.BB_paint = false; /* With fading, the paint color is the terminal color */
return (error);
}
GMT_LOCAL int psconvert_parse_A_settings (struct GMT_CTRL *GMT, char *arg, struct PSCONVERT_CTRL *Ctrl) {
/* Given there have been many syntax changes and most recently splitting of -A into -A, -I, -N we do
* an initial assessment here and build -I -N -A option strings from old-style -A arguments and
* call the -I -N parsers, if required, as well as the -A parser */
int k = 0, n_errors = 0, j;
char A_option[GMT_LEN128] = {""}, I_option[GMT_LEN128] = {""}, N_option[GMT_LEN128] = {""};
char string[GMT_LEN128] = {""};
/* Harvest -A arguments, if any */
if (arg[0] && strchr ("u-", arg[0])) { /* Ancient -A syntax */
if (gmt_M_compat_check (GMT, 4)) {
GMT_Report (GMT->parent, GMT_MSG_COMPAT, "-A[-][u][<margin>][...] is deprecated, see -A -I -N syntax.\n");
if (arg[0] == '-') k++; /* The old -A- no crop signal is now just skipped */
else if (arg[0] == 'u') { /* The old way of +u */
strcat (A_option, "+u");
k++;
}
}
else {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -A: Bad arguments %s.\n" ,arg);
n_errors++;
}
}
if (arg[k] && arg[k] != '+') { /* Old-style margin directives no goes to -I instead */
for (j = k + 1; arg[j] && arg[j] != '+'; j++); /* Wind to the end of margins */
strcat (I_option, "+m");
strncat (I_option, &arg[k], j-k); /* Append margin argument */
}
/* These are newer -A modifiers */
if (gmt_get_modifier (arg, 'r', string))
strcat (A_option, "+r");
if (gmt_get_modifier (arg, 'u', string))
strcat (A_option, "+u");
if (gmt_get_modifier (arg, 'M', string)) /* Only issued by gmt end and movie */
strcat (A_option, "+M");
/* Note: If -A+n is given then we handle it via backwards compatibility */
if (gmt_get_modifier (arg, 'n', string)) {
if (gmt_M_compat_check (GMT, 6)) {
GMT_Report (GMT->parent, GMT_MSG_COMPAT, "-A+n (no args) is deprecated, use -W+c instead.\n");
Ctrl->W.no_crop = true;
}
else {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -A: Unrecognized modifier +n.\n");
n_errors++;
}
}
/* Harvest -N arguments, if any */
if (gmt_get_modifier (arg, 'f', string)) {
strcat (N_option, "+f");
strcat (N_option, string);
}
if (gmt_get_modifier (arg, 'g', string)) {
strcat (N_option, "+g");
strcat (N_option, string);
}
if (gmt_get_modifier (arg, 'k', string)) {
strcat (N_option, "+k");
strcat (N_option, string);
}
if (gmt_get_modifier (arg, 'p', string)) {
strcat (N_option, "+p");
strcat (N_option, string);
}
/* Harvest -I arguments, if any */
if (gmt_get_modifier (arg, 'm', string)) {
strcat (I_option, "+m");
strcat (I_option, string);
}
if (gmt_get_modifier (arg, 's', string)) {
strcat (I_option, "+s");
strcat (I_option, string);
}
if (gmt_get_modifier (arg, 'S', string)) {
strcat (I_option, "+S");
strcat (I_option, string);
}
/* Now parse -A and possibly -I -N via backwards compatibility conversions */
n_errors += psconvert_parse_new_A_settings (GMT, A_option, Ctrl);
if (I_option[0]) {
n_errors += psconvert_parse_new_I_settings (GMT, I_option, Ctrl);
Ctrl->I.active = true;
}
if (N_option[0]) {
n_errors += psconvert_parse_new_N_settings (GMT, N_option, Ctrl);
Ctrl->N.active = true;
}
return (n_errors);
}
GMT_LOCAL int psconvert_parse_GE_settings (struct GMT_CTRL *GMT, char *arg, struct PSCONVERT_CTRL *C) {
/* Syntax: -W[+a<altmode>][+c][+f<minfade>/<maxfade>][+g][+k][+l<lodmin>/<lodmax>][+n<layername>][+o<folder>][+t<doctitle>][+u<URL>] */
unsigned int pos = 0, error = 0;
char p[GMT_LEN256] = {""};
gmt_M_unused(GMT);
while (gmt_getmodopt (GMT, 'W', arg, "acfgklnotu", &pos, p, &error) && error == 0) { /* Looking for +a, etc */
switch (p[0]) {
case 'a': /* Altitude setting */
switch (p[1]) { /* Check which altitude mode we selected */
case 'G':
C->W.mode = KML_GROUND_ABS;
break;
case 'g':
C->W.mode = KML_GROUND_REL;
C->W.altitude = atof (&p[2]);
break;
case 'A':
C->W.mode = KML_ABS;
C->W.altitude = atof (&p[2]);
break;
case 's':
C->W.mode = KML_SEAFLOOR_REL;
C->W.altitude = atof (&p[2]);
break;
case 'S':
C->W.mode = KML_SEAFLOOR_ABS;
break;
default:
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -W+a<mode>[par]: Unrecognized altitude mode %c\n", p[1]);
error++;
break;
}
break;
case 'c': /* Used to be done by -A+n */
C->W.no_crop = true;
break;
case 'f': /* Set fading options in KML */
sscanf (&p[1], "%d/%d", &C->W.min_fade, &C->W.max_fade);
break;
case 'g': /* Use gdal to make geotiff */
C->W.warp = true;
break;
case 'k': /* Produce a KML file */
C->W.kml = true;
break;
case 'l': /* Set KML level of detail for image */
sscanf (&p[1], "%d/%d", &C->W.min_lod, &C->W.max_lod);
break;
case 'n': /* Set KML document layer name */
gmt_M_str_free (C->W.overlayname); /* Already set, free then reset */
C->W.overlayname = gmt_assign_text (GMT, p);
break;
case 'o': /* Produce a KML overlay as a folder subset */
C->W.folder = true;
gmt_M_str_free (C->W.foldername); /* Already set, free then reset */
C->W.foldername = gmt_assign_text (GMT, p);
break;
case 't': /* Set KML document title */
gmt_M_str_free (C->W.doctitle); /* Already set, free then reset */
C->W.doctitle = gmt_assign_text (GMT, p);
break;
case 'u': /* Specify a remote address for image */
gmt_M_str_free (C->W.URL); /* Already set, free then reset */
C->W.URL = gmt_assign_text (GMT, p);
break;
default:
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -W+<opt>: Unrecognized option selection %c\n", p[1]);
error++;
break;
}
}
return (error);
}
static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new control structure */
struct PSCONVERT_CTRL *C;
C = gmt_M_memory (GMT, NULL, 1, struct PSCONVERT_CTRL);
/* Initialize values whose defaults are not 0/false/NULL */
#ifdef JULIA_GHOST_JLL
/* In Julia when using the precompiled Artifacts, the Ghost is also shipped with but when gmt_init makes
calls to psconvert it doesn't set -G with the path to the Ghostscript_jll executable and those processes
fail (mostly modern mode stuff). The solution is to try to read the gs path from ~/.gmt/ghost_jll_path.txt
This code should only be executed by binaries created Julia's BinaryBuilder.
*/
bool found_gs = false;
char line[GMT_LEN512] = {""}, file[GMT_LEN256] = {""};
FILE *fp = NULL;
sprintf(file, "%s/ghost_jll_path.txt", GMT->session.USERDIR);
if ((fp = fopen (file, "r")) != NULL) {
while (fgets (line, GMT_LEN512, fp) && line[0] == '#') {}
fclose(fp);
gmt_chop(line); /* Chop of the newline */
if (!access (line, F_OK)) { /* GS binary found */
C->G.file = strdup (line);
found_gs = true;
}
else
perror("Error Description while accessing the GS executable:");
}
if (!found_gs) { /* Shit. But try still the generic non-Julian paths */
#ifdef WIN32
if (psconvert_ghostbuster(GMT->parent, C) != GMT_NOERROR) /* Try first to find the gspath from registry */
C->G.file = strdup (GMT_GS_EXECUTABLE); /* Fall back to this default and expect a miracle */
#else
C->G.file = strdup (GMT_GS_EXECUTABLE);
#endif
}
#else
#ifdef WIN32
if (psconvert_ghostbuster(GMT->parent, C) != GMT_NOERROR) /* Try first to find the gspath from registry */
C->G.file = strdup (GMT_GS_EXECUTABLE); /* Fall back to this default and expect a miracle */
#else
C->G.file = strdup (GMT_GS_EXECUTABLE);
#endif
#endif
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Ghostscript executable full name: \n", C->G.file);
C->D.dir = strdup (".");
C->T.quality = GMT_JPEG_DEF_QUALITY; /* Default JPG quality */
C->W.doctitle = strdup ("GMT KML Document");
C->W.overlayname = strdup ("GMT Image Overlay");
C->W.foldername = strdup ("GMT Image Folder");
return (C);
}
static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSCONVERT_CTRL *C) { /* Deallocate control structure */
if (!C) return;
gmt_M_str_free (C->D.dir);
gmt_M_str_free (C->F.file);
gmt_M_str_free (C->G.file);
gmt_M_str_free (C->L.file);
gmt_M_str_free (C->M[0].file);
gmt_M_str_free (C->M[1].file);
gmt_M_str_free (C->W.doctitle);
gmt_M_str_free (C->W.overlayname);
gmt_M_str_free (C->W.foldername);
gmt_M_str_free (C->W.URL);
gmt_M_free (GMT, C);
}
#define GMT_CONV3_LIMIT 1.0e-3
GMT_LOCAL double psconvert_smart_ceil (double x) {
/* Avoid ceil (integer+[0-0.0099999999999]) from increasing size by a full pixel */
double fx = floor(x);
if ((x - fx) > GMT_CONV3_LIMIT) /* Only ceil if we exceed this limit */
fx = ceil (x);
return (fx);
}
static int usage (struct GMTAPI_CTRL *API, int level) {
const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE);
const char *Z = (API->GMT->current.setting.run_mode == GMT_CLASSIC) ? " [-Z]" : "";
if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR);
GMT_Usage (API, 0, "usage: %s <psfiles> [-A[+r][+u]] [-C<gs_option>] [-D<dir>] [-E<resolution>] "
"[-F<out_name>] [-G<gs_path>] [-H<scale>] [-I[+m<margins>][+s[m]<width>[/<height>]][+S<scale>]] [-L<list>] [-Mb|f<psfile>] "
"[-N[+f<fade>][+g<backfill>][+k<fadefill>][+p[<pen>]]] [-P] [-Q[g|p|t]1|2|4] [-S] [-Tb|e|E|f|F|g|G|j|m|s|t[+m][+q<quality>]] [%s] "
"[-W[+a<mode>[<alt>]][+c][+f<minfade>/<maxfade>][+g][+k][+l<lodmin>/<lodmax>][+n<name>][+o<folder>][+t<title>][+u<URL>]]%s "
"[%s]\n", name, GMT_V_OPT, Z, GMT_PAR_OPT);
if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS);
GMT_Usage (API, -1, "Works by modifying the page size in order that the resulting "
"image will have the size specified by the BoundingBox. "
"As an option, a tight BoundingBox may be computed.");
GMT_Message (API, GMT_TIME_NONE, "\n REQUIRED ARGUMENTS:\n");
GMT_Usage (API, 1, "\n<psfiles> One or more PostScript files to be converted.");
if (API->external)
GMT_Usage (API, -2, "Note: To access the current internal GMT plot, specify <psfiles> as \"=\".");
GMT_Message (API, GMT_TIME_NONE, "\n OPTIONAL ARGUMENTS:\n");
GMT_Usage (API, 1, "\n-A[+r][+u]");
GMT_Usage (API, -2, "Adjust the BoundingBox to the minimum required by the image contents. Optional modifiers:");
GMT_Usage (API, 3, "+r Force rounding of HighRes BoundingBox instead of ceil.");
GMT_Usage (API, 3, "+u Strip out time-stamps (produced by GMT -U options).");
GMT_Usage (API, 1, "\n-C<gs_option>");
GMT_Usage (API, -2, "Specify a single, custom option that will be passed on to Ghostscript "
"as is. Repeat to add several options [none].");
GMT_Usage (API, 1, "\n-D<dir>");
GMT_Usage (API, -2, "Set an alternative output directory (which must exist) "
"[Default is same directory as PS files]. "
"Use -D. to place the output in the current directory.");
GMT_Usage (API, 1, "\n-E<resolution>");
GMT_Usage (API, -2, "Set raster resolution in dpi [default = 720 for images in a PDF, 300 for other formats].");
GMT_Usage (API, 1, "\n-F<out_name>");
GMT_Usage (API, -2, "Force the output file name. By default output names are constructed "
"using the input names as base, which are appended with an appropriate "
"extension. Use this option to provide a different name, but WITHOUT "
"extension. Extension is still determined and appended automatically.");
GMT_Usage (API, 1, "\n-G<gs_path>");
GMT_Usage (API, -2, "Full path to your Ghostscript executable. "
"NOTE: Under Unix systems this is generally not necessary. "
"Under Windows, Ghostscript path is fished from the registry. "
"If this fails you can still add the GS path to system's path "
"or give the full path here, e.g., "
#ifdef WIN32
"-Gc:\\programs\\gs\\gs9.27\\bin\\gswin64c).");
#else
"-G/some/unusual/dir/bin/gs).");
#endif
GMT_Usage (API, 1, "\n-H<scale>");
GMT_Usage (API, -2, "Temporarily increase dpi by integer <scale>, rasterize, then downsample [no downsampling]. "
"Used to improve raster image quality, especially for lower raster resolutions.");
GMT_Usage (API, 1, "\n-I[+m<margins>][+s[m]<width>[/<height>]][+S<scale>]");
GMT_Usage (API, -2, "Scale image and add margins. Optional modifiers:");
GMT_Usage (API, 3, "+m Append <margin(s)> to enlarge the BoundingBox, with <margin(s)> being "
"<off> for uniform margin for all 4 sides, "
"<xoff>/<yoff> for separate x- and y-margins, or "
"<woff>/<eoff>/<soff>/<noff> for separate w-,e-,s-,n-margins.");
GMT_Usage (API, 3, "+s Append [m]<width>[/<height>] the select a new image size "
"but maintaining the DPI set by -E (Ghostscript does the re-interpolation work). "
"Use +sm to only change size if figure size exceeds the new maximum size(s). "
"Append measurement unit u (%s) [%c].",
GMT_DIM_UNITS_DISPLAY, API->GMT->session.unit_name[API->GMT->current.setting.proj_length_unit][0]);
GMT_Usage (API, 3, "+S Scale the image by the appended <scale> factor.");
GMT_Usage (API, 1, "\n-L<list>");
GMT_Usage (API, -2, "The <list> is an ASCII file with names of files to be converted. ");
GMT_Usage (API, 1, "\n-Mb|f<psfile>");
GMT_Usage (API, -2, "Sandwich current psfile between background and foreground plots:");
GMT_Usage (API, 3, "b: Append the name of a background PostScript plot [none].");
GMT_Usage (API, 3, "f: Append name of foreground PostScript plot [none].");
GMT_Usage (API, 1, "\n-N[+f<fade>][+g<backfill>][+k<fadefill>][+p[<pen>]]");
GMT_Usage (API, -2, "Specify painting, fading, or outline of the BoundingBox via optional modifiers:");
GMT_Usage (API, 3, "+f Append <fade> (0-100) to fade entire plot to black (100%% fade)[no fading].");
GMT_Usage (API, 3, "+g Append <backfill> to paint the BoundingBox first [no fill].");
GMT_Usage (API, 3, "+k Append <fadefill> to indicate color at full fade [black].");
GMT_Usage (API, 3, "+p Outline the BoundingBox, optionally append <pen> [%s].",
gmt_putpen (API->GMT, &API->GMT->current.setting.map_default_pen));
GMT_Usage (API, 1, "\n-P Force Portrait mode. All Landscape mode plots will be rotated back "
"so that they show unrotated in Portrait mode. "
"This is practical when converting to image formats or preparing "
"EPS or PDF plots for inclusion in documents.");
GMT_Usage (API, 1, "\n-Q[g|p|t]1|2|4");
GMT_Usage (API, -2, "Anti-aliasing setting for (g)raphics or (t)ext; append size (1,2,4) of sub-sampling box. "
"For PDF and EPS output, default is no anti-aliasing, which is the same as specifying size 1. "
"For raster formats the defaults are -Qg4 -Qt4 unless overridden explicitly. "
"Optionally, use -Qp to create a GeoPDF (requires -Tf).");
GMT_Usage (API, 1, "\n-S Apart from executing it, also writes the Ghostscript command to "
"standard error and keeps all intermediate files.");
GMT_Usage (API, 1, "\n-Tb|e|E|f|F|g|G|j|m|s|t[+m][+q<quality>]");
GMT_Usage (API, -2, "Set output format [default is JPEG]:");
GMT_Usage (API, 3, "b: Select BMP.");
GMT_Usage (API, 3, "e: Select EPS.");
GMT_Usage (API, 3, "E: Select EPS with setpagedevice command.");
GMT_Usage (API, 3, "f: Select PDF.");
GMT_Usage (API, 3, "F: Select multi-page PDF (requires -F).");
GMT_Usage (API, 3, "g: Select PNG.");
GMT_Usage (API, 3, "G: Select PNG (transparent where nothing is plotted).");
GMT_Usage (API, 3, "j: Select JPEG.");
GMT_Usage (API, 3, "m: Select PPM.");
GMT_Usage (API, 3, "t: Select TIF.");
GMT_Usage (API, -2, "Two raster modifiers may be appended:");
GMT_Usage (API, 3, "+m For b, g, j, and t, make a monochrome (grayscale) image [color].");
GMT_Usage (API, 3, "+q Append quality in 0-100 for JPEG only [%d].", GMT_JPEG_DEF_QUALITY);
GMT_Usage (API, -2, "Note: The EPS format can be combined with any of the other formats. "
"For example, -Tef creates both an EPS and PDF file.");
GMT_Option (API, "V");
GMT_Usage (API, -2, "Note: Shows the gdal_translate command, in case you want to use this program "
"to create a geoTIFF file.");
GMT_Usage (API, 1, "\n-W[+a<mode>[<alt>]][+c][+f<minfade>/<maxfade>][+g][+k][+l<lodmin>/<lodmax>][+n<name>][+o<folder>][+t<title>][+u<URL>]");
GMT_Usage (API, -2, "Write an ESRI type world file suitable to make .tif files "
"recognized as geotiff by software that know how to do it. Be aware, "
"however, that different results are obtained depending on the image "
"contents and if the -B option has been used or not. The trouble with "
"-B is that it creates a frame and very likely its ticks and annotations "
"introduces pixels outside the map data extent. As a consequence, "
"the map extent estimation will be wrong. To avoid this problem, use "
"the --MAP_FRAME_TYPE=inside option which plots all annotation-related "
"items inside the image and therefore does not compromise the coordinate "
"computations. The world file naming follows the convention of jamming "
"a 'w' in the file extension. So, if the output is tif (-Tt) the world "
"file is a .tfw, for jpeg a .jgw, and so on. A few modifiers are available:");
GMT_Usage (API, 3, "+g Do a system call to gdal_translate and produce a true "
"GeoTIFF image right away. The output file will have the extension "
".tiff. See the man page for other 'gotchas'. Automatically sets -A -P.");
GMT_Usage (API, 3, "+k Create a minimalist KML file that allows loading the "
"image in Google Earth. Note that for this option the image must be "
"in geographical coordinates. If not, a warning is issued but the "
"KML file is created anyway.");
GMT_Usage (API, -2, "Additional modifiers allow you to specify the content in the KML file:");
GMT_Usage (API, 3, "+a Append <altmode>[<altitude>] to set the altitude mode of this layer, where "
"<altmode> is one of 5 recognized by Google Earth:");
GMT_Usage (API, 4, "G: Clamped to the ground [Default].");
GMT_Usage (API, 4, "g: Append altitude (in m) relative to ground.");
GMT_Usage (API, 4, "A: Append absolute altitude (in m).");
GMT_Usage (API, 4, "s: Append altitude (in m) relative to seafloor.");
GMT_Usage (API, 4, "S: Clamped to the seafloor.");
GMT_Usage (API, 3, "+c Do not crop [Default crops the image].");
GMT_Usage (API, 3, "+f Append <minfade>/<maxfade>] to set distances over which we fade from opaque "
"to transparent [no fading].");
GMT_Usage (API, 3, "+l Append <minLOD>/<maxLOD>] to set Level Of Detail when layer should be "
"active [always active]. Image goes inactive when there are fewer "
"than minLOD pixels or more than maxLOD pixels visible. "
"-1 means never invisible.");
GMT_Usage (API, 3, "+n Append <layername> of this particular layer "
"[\"GMT Image Overlay\"].");
GMT_Usage (API, 3, "+o Append <foldername> to name this particular folder "
"\"GMT Image Folder\"]. This yields a KML snipped without header/trailer.");
GMT_Usage (API, 3, "+t Append <doctitle> to set the document name [\"GMT KML Document\"].");
GMT_Usage (API, 3, "+u Append <URL> and prepend it to the name of the image referenced in the "
"KML [local file]. "
"Escape any +? modifier inside strings with \\.");
if (API->GMT->current.setting.run_mode == GMT_CLASSIC)
GMT_Usage (API, 1, "\n-Z Remove input PostScript file(s) after successful conversion.");
GMT_Option (API, ".");
return (GMT_MODULE_USAGE);
}
static int parse (struct GMT_CTRL *GMT, struct PSCONVERT_CTRL *Ctrl, struct GMT_OPTION *options) {
/* This parses the options provided to psconvert and sets parameters in CTRL.
* Any GMT common options will override values set previously by other commands.
* It also replaces any file names specified as input or output with the data ID
* returned when registering these sources/destinations with the API.
*/
unsigned int n_errors = 0, mode;
int j = 0;
bool grayscale = false, halfbaked = false;
char *c = NULL;
struct GMT_OPTION *opt = NULL;
struct GMTAPI_CTRL *API = GMT->parent;
for (opt = options; opt; opt = opt->next) {
switch (opt->option) {
case '<': /* Input files [Allow for file "=" under API calls] */
if (strstr (opt->arg, ".ps-")) halfbaked = true;
if (!(GMT->parent->external && !strncmp (opt->arg, "=", 1))) { /* Can check if file is sane */
if (!halfbaked && GMT_Get_FilePath (API, GMT_IS_POSTSCRIPT, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++;
}
Ctrl->In.n_files++;
break;
/* Processes program-specific parameters */
case 'A': /* Crop settings (plus backwards compatible parsing of older -A option syntax) */
n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active);
n_errors += psconvert_parse_A_settings (GMT, opt->arg, Ctrl);
break;
case 'C': /* Append extra custom GS options (repeatable) */
Ctrl->C.active = true;
if (Ctrl->C.arg[0]) strcat (Ctrl->C.arg, " ");
strncat (Ctrl->C.arg, opt->arg, GMT_LEN256-1); /* Append to list of extra GS options */
break;
case 'D': /* Change output directory */
n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active);
n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_DATASET, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->D.dir));
break;
case 'E': /* Set output dpi */
n_errors += gmt_M_repeated_module_option (API, Ctrl->E.active);
n_errors += gmt_get_required_double (GMT, opt->arg, opt->option, 0, &Ctrl->E.dpi);
break;
case 'F': /* Set explicitly the output file name */
n_errors += gmt_M_repeated_module_option (API, Ctrl->F.active);
Ctrl->F.file = gmt_strdup_noquote (opt->arg);
gmt_filename_get (Ctrl->F.file);
break;
case 'G': /* Set GS path */
n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active);
gmt_M_str_free (Ctrl->G.file);
Ctrl->G.file = malloc (strlen (opt->arg)+3); /* Add space for quotes */
sprintf (Ctrl->G.file, "%c%s%c", quote, opt->arg, quote);
break;
case 'H': /* RIP at a higher dpi, then downsample in gs */
n_errors += gmt_M_repeated_module_option (API, Ctrl->H.active);
n_errors += gmt_get_required_int (GMT, opt->arg, opt->option, 0, &Ctrl->H.factor);
break;
case 'I': /* Set margins/scale modifiers [Deprecated -I: Do not use the ICC profile when converting gray shades] */
n_errors += gmt_M_repeated_module_option (API, Ctrl->I.active);
n_errors += psconvert_parse_new_I_settings (GMT, opt->arg, Ctrl);
break;
case 'L': /* Give list of files to convert */
n_errors += gmt_M_repeated_module_option (API, Ctrl->L.active);
n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(Ctrl->L.file));
break;
case 'M': /* Manage background and foreground layers for PostScript sandwich */
switch (opt->arg[0]) {
case 'b': j = 0; break; /* background */
case 'f': j = 1; break; /* foreground */
default: /* Bad argument */
GMT_Report (API, GMT_MSG_ERROR, "Option -M: Select -Mb or -Sf\n");
n_errors++;
break;
}
n_errors += gmt_M_repeated_module_option (API, Ctrl->M[j].active);
if (!n_errors && Ctrl->M[j].active) { /* Got -Mb<file> or -Mf<file> */
if (!gmt_access (GMT, &opt->arg[1], R_OK)) { /* The plot file exists */
Ctrl->M[j].file = strdup (&opt->arg[1]);
}
else {
GMT_Report (API, GMT_MSG_ERROR, "Option -M%c: Cannot read file %s\n", opt->arg[0], &opt->arg[1]);
n_errors++;
}
}
break;
case 'N': /* Set media paint, fade, outline */
n_errors += gmt_M_repeated_module_option (API, Ctrl->N.active);
n_errors += psconvert_parse_new_N_settings (GMT, opt->arg, Ctrl);
break;
case 'P': /* Force Portrait mode */
n_errors += gmt_M_repeated_module_option (API, Ctrl->P.active);
n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0);
break;
case 'Q': /* Anti-aliasing settings (repeatable) */
Ctrl->Q.active = true;
if (opt->arg[0] == 'g')
mode = PSC_LINES;
else if (opt->arg[0] == 't')
mode = PSC_TEXT;
else if (opt->arg[0] == 'p')
mode = PSC_GEO;
else {
GMT_Report (API, GMT_MSG_ERROR, "The -Q option requires setting -Qg, -Qp, or -Qt!\n");
n_errors++;
continue;
}
Ctrl->Q.on[mode] = true;
if (mode < PSC_GEO) Ctrl->Q.bits[mode] = (opt->arg[1]) ? atoi (&opt->arg[1]) : 4;
break;
case 'S': /* Write the GS command to STDERR */
n_errors += gmt_M_repeated_module_option (API, Ctrl->S.active);
n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0);
break;
case 'T': /* Select output format (optionally also request EPS) */
n_errors += gmt_M_repeated_module_option (API, Ctrl->T.active);
if ((j = (int)strlen(opt->arg)) > 1 && opt->arg[j-1] == '-') /* Old deprecated way of appending a single - sign at end */
grayscale = true;
else if (strstr (opt->arg, "+m")) /* Modern monochrome option (like -M in grdimage) */
grayscale = true;
if ((c = strstr (opt->arg, "+q"))) { /* Got a quality setting for JPG */
Ctrl->T.quality = atoi (&c[2]);
c[0] = '\0'; /* Chop this modifier off for now */
}
for (j = 0; opt->arg[j]; j++) {
switch (opt->arg[j]) {
case 'e': /* EPS */
Ctrl->T.eps = 1;
break;
case 'E': /* EPS with setpagedevice */
Ctrl->T.eps = -1;
break;
case 'f': /* PDF */
Ctrl->T.device = GS_DEV_PDF;
break;
case 'F': /* PDF (multipages) */
Ctrl->T.device = -GS_DEV_PDF;
break;
case 'b': /* BMP */
Ctrl->T.device = (grayscale) ? GS_DEV_BMPG : GS_DEV_BMP;
break;
case 'j': /* JPEG */
Ctrl->T.device = (grayscale) ? GS_DEV_JPGG : GS_DEV_JPG;
break;
case 'g': /* PNG */
Ctrl->T.device = (grayscale) ? GS_DEV_PNGG : GS_DEV_PNG;
break;
case 'G': /* PNG (transparent) */
Ctrl->T.device = GS_DEV_TPNG;
break;
case 'm': /* PPM */
Ctrl->T.device = GS_DEV_PPM;
break;
case 'p': /* PS */
Ctrl->T.ps = 1;
break;
case 's': /* SVG */
Ctrl->T.device = GS_DEV_SVG;
break;
case 't': /* TIFF */
Ctrl->T.device = (grayscale) ? GS_DEV_TIFG : GS_DEV_TIF;
break;
case '-': /* Just skip the trailing - for grayscale since it is handled separately above */
break;
case '+': /* Just skip the trailing +m for grayscale since it is handled separately above */
j++;
break;
default:
gmt_default_option_error (GMT, opt);
n_errors++;
break;
}
}
if (c) c[0] = '+'; /* Restore modifier */
break;
case 'W': /* Save world file */
n_errors += gmt_M_repeated_module_option (API, Ctrl->W.active);
n_errors += psconvert_parse_GE_settings (GMT, opt->arg, Ctrl);