Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let -U take +ttext to override time stamp #7127

Merged
merged 7 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/rst/source/cookbook/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ are known. The **auto** flag is supported for the following parameters:
:term:`FONT_ANNOT_SECONDARY` Secondary annotation font [13.20p]
:term:`FONT_HEADING` Subplot heading font [30.80p]
:term:`FONT_LABEL` Axis label font [15.40p]
:term:`FONT_LOGO` Logo font [8.80p]
:term:`FONT_SUBTITLE` Plot subtitle font [19.80p]
:term:`FONT_TAG` Tag/labeling font [17.60p]
:term:`FONT_TITLE` Plot title font [24.20p]
Expand Down
4 changes: 3 additions & 1 deletion doc/rst/source/explain_-U.rst_
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The **-U** option

.. _-U:

**-U**\ [*label*\|\ **+c**][**+j**\ *just*][**+o**\ *dx*\ [/*dy*]]
**-U**\ [*label*\|\ **+c**][**+j**\ *just*][**+o**\ *dx*\ [/*dy*]][**+t**\ *text*]
Draw GMT time stamp logo on plot. |Add_-U|

**Description**
Expand All @@ -19,6 +19,8 @@ The **-U** option draws the GMT system time stamp on the plot. The following mod
**R**\ (ight)) and a vertical (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code [default is **BL**].
- **+o**\ *dx*\ [/*dy*] to offset the :ref:`anchor point <Anchor_Point_o>` for the time stamp by *dx* and optionally
*dy* (if different than *dx*).
- **+t** can be used to replace the UNIX time stamp with a custom *text* instead (< 64 characters). Place multi-word
*text* in quotes and let **+t** be the last modifier used.

The GMT parameters :term:`MAP_LOGO`, :term:`MAP_LOGO_POS`, :term:`FONT_LOGO` and :term:`FORMAT_TIME_STAMP` can affect
the appearance; see the :doc:`/gmt.conf` man page for details. The time string will be in the locale set by the
Expand Down
7 changes: 4 additions & 3 deletions doc/rst/source/gmt.conf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ FONT Parameters
size <auto-scaling>`.

**FONT_LOGO**
Font to use for text plotted as part of the GMT time logo [:doc:`theme
dependent <theme-settings>`]. Choose **auto** for :ref:`automatic scaling
with plot size <auto-scaling>`.
Font to use for text plotted as part of the GMT time logo. **Note**: Since the
time logo has a fixed height the font size for the time stamp is 8p and for the
optional label it is 7p. Hence, changing this font only affects the font style
and color but not its size.

**FONT_SUBTITLE**
Font to use when plotting titles over graphs that involve a subtitle
Expand Down
2 changes: 1 addition & 1 deletion doc/rst/source/std-opts-classic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Common Options (Classic Mode)
- :ref:`Select Portrait orientation <-P_full>`
* - **-R**\ *west/east/south/north*\ [*/zmin/zmax*][**+r**][**+u**\ *unit*]
- :ref:`Specify region of interest <-R_full>`
* - **-U**\ [*label*][**+c**][**+j**\ *just*][**+o**\ *dx*/*dy*]
* - **-U**\ [*label*][**+c**][**+j**\ *just*][**+o**\ *dx*/*dy*][**+t**\ *text*]
- :ref:`Plot time-stamp on plot <-U_full>`
* - **-V**\ [*verbosity*]
- :ref:`Run in verbose mode <-V_full>`
Expand Down
2 changes: 1 addition & 1 deletion doc/rst/source/std-opts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Common Options
- :ref:`Select map projection <-J_full>`
* - **-R**\ *west/east/south/north*\ [*/zmin/zmax*][**+r**][**+u**\ *unit*]
- :ref:`Specify region of interest <-R_full>`
* - **-U**\ [*label*][**+c**][**+j**\ *just*][**+o**\ *dx*/*dy*]
* - **-U**\ [*label*][**+c**][**+j**\ *just*][**+o**\ *dx*/*dy*][**+t**\ *text*]
- :ref:`Plot time-stamp on plot <-U_full>`
* - **-V**\ [*verbosity*]
- :ref:`Run in verbose mode <-V_full>`
Expand Down
2 changes: 0 additions & 2 deletions doc/rst/source/theme-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Default settings for built-in themes
+-----------------------------------+---------------------------------+---------------------------------+---------------------------------+
| :term:`FONT_LABEL` | 16p,Helvetica,black | auto,Helvetica,black | auto,AvantGarde-Book,black |
+-----------------------------------+---------------------------------+---------------------------------+---------------------------------+
| :term:`FONT_LOGO` | 8p,Helvetica,black | auto,Helvetica,black | auto,Helvetica,black |
+-----------------------------------+---------------------------------+---------------------------------+---------------------------------+
| :term:`FONT_SUBTITLE` | 18p,Helvetica,black | auto,Helvetica-Bold,black | auto,AvantGarde-Book,black |
+-----------------------------------+---------------------------------+---------------------------------+---------------------------------+
| :term:`FONT_TAG` | 20p,Helvetica,black | auto,Helvetica,black | auto,AvantGarde-Book,black |
Expand Down
1 change: 0 additions & 1 deletion share/themes/modern.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ FONT_ANNOT_PRIMARY = auto,Helvetica,black
FONT_ANNOT_SECONDARY = auto,Helvetica,black
FONT_HEADING = auto,Helvetica-Bold,black
FONT_LABEL = auto,Helvetica,black
FONT_LOGO = auto,Helvetica,black
FONT_SUBTITLE = auto,Helvetica-Bold,black
FONT_TAG = auto,Helvetica,black
FONT_TITLE = auto,Helvetica-Bold,black
Expand Down
1 change: 1 addition & 0 deletions src/gmt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct GMT_COMMON {
bool active;
unsigned int just;
double x, y;
char string[GMT_LEN64]; /* User override for timestamp */
char *label; /* Content not counted by sizeof (struct) */
} U;
struct V { /* -V */
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_common_longoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"r,u", "rectangular,unit" },
{ 0, 'U', "timestamp",
"", "",
"c,j,o", "command,justify,offset" },
"c,j,o,t", "command,justify,offset,text" },
{ 0, 'V', "verbosity",
"q,e,w,t,i,c,d", "quiet,error,warning,timing,info,compat,debug",
"", "" },
Expand Down
29 changes: 15 additions & 14 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2145,29 +2145,31 @@ int gmt_parse_model (struct GMT_CTRL *GMT, char option, char *in_arg, unsigned i
#define is_plus(item,k) (item[k-1] == '+') /* Previous char is a plus, so maybe start of modifier */
#define is_label(item,k) (item[k] == 'c' && (item[k+1] == '+' || item[k+1] == '\0')) /* Modifier c followed by another modifier or end of string */
#define is_just(item,k) (item[k] == 'j' && (strchr ("LCRBMT", item[k+1]) && strchr ("LCRBMT", item[k+2]))) /* Is +j<just> */
#define is_off(item,k) (item[k] == 'o' && strchr ("-+.0123456789", item[k+1])) /* Looks like +onumber> */
#define is_off(item,k) (item[k] == 'o' && strchr ("-+.0123456789", item[k+1])) /* Looks like +o<number> */
#define is_text(item,k) (item[k] == 't' && item[k+1]) /* Modifier t followed by random text */

/*! Parse the -U option. Full syntax: -U[<label>][+c][+j<just>][+o]<dx>[/<dy>]] Old syntax was -U[[<just>]/<dx>/<dy>/][c|<label>] */
/*! Parse the -U option. Full syntax: -U[<label>][+c][+j<just>][+o<dx>[/<dy>]][+t<string>] Old syntax was -U[[<just>]/<dx>/<dy>/][c|<label>] */
GMT_LOCAL int gmtinit_parse_U_option (struct GMT_CTRL *GMT, char *item) {
int just = 1, error = 0;

GMT->current.setting.map_logo = true;
gmt_M_memset (GMT->common.U.string, GMT_LEN64, char); /* Initialize to nothing */
if (!item || !item[0]) return (GMT_NOERROR); /* Just basic -U with no args */

if (gmt_found_modifier (GMT, item, "cjo")) { /* New syntax */
if (gmt_found_modifier (GMT, item, "cjot")) { /* New syntax */
unsigned int pos = 0, uerr = 0;
int k = 1, len = (int)strlen (item);
char word[GMT_LEN256] = {""}, *c = NULL;
/* Find the first +c|j|o that looks like it may be a modifier and not random text */
while (k < len && !(is_plus(item,k) && (is_label(item,k) || is_just(item,k) || is_off(item,k)))) k++;
if (k == len) /* MOdifiers were just random text */
/* Find the first +c|j|o|t that looks like it may be a modifier and not random text */
while (k < len && !(is_plus(item,k) && (is_label(item,k) || is_just(item,k) || is_off(item,k) || is_text(item,k)))) k++;
if (k == len) /* Modifiers were just random text */
strncpy (GMT->current.ps.map_logo_label, item, GMT_LEN256-1); /* Got a label */
else { /* Appears to have gotten a valid modifier or more */
c = &item[k-1]; /* Start of the modifier */
c[0] = '\0'; /* Chop off the + so we can parse the label, if any */
if (item[0]) strncpy (GMT->current.ps.map_logo_label, item, GMT_LEN256-1); /* Got a label */
c[0] = '+'; /* Restore modifiers */
while (gmt_getmodopt (GMT, 'U', c, "cjo", &pos, word, &uerr) && uerr == 0) {
while (gmt_getmodopt (GMT, 'U', c, "cjot", &pos, word, &uerr) && uerr == 0) {
switch (word[0]) {
case 'c': /* Maybe +c but only if at end of followed by another modifier */
if (word[1] == '+' || word[1] == '\0') /* Use command string */
Expand All @@ -2182,6 +2184,9 @@ GMT_LOCAL int gmtinit_parse_U_option (struct GMT_CTRL *GMT, char *item) {
if ((k = gmt_get_pair (GMT, &word[1], GMT_PAIR_DIM_DUP, GMT->current.setting.map_logo_pos)) < 1) error++;
}
break;
case 't': /* Short text to replace dateclock string */
strncpy (GMT->common.U.string, &word[1], GMT_LEN64);
break;
default: break; /* These are caught in gmt_getmodopt so break is just for Coverity */
}
}
Expand Down Expand Up @@ -6754,7 +6759,7 @@ GMT_LOCAL void gmtinit_conf_classic (struct GMT_CTRL *GMT) {
if (!strncmp (GMT_DEF_UNITS, "US", 2U))
gmtinit_conf_classic_US (GMT); /* Override with US settings */

if (GMT->current.setting.run_mode == GMT_MODERN) { /* Means we switch to classic in a modern mode setssion */
if (GMT->current.setting.run_mode == GMT_MODERN) { /* Means we switch to classic in a modern mode session */
GMT_keyword_updated[GMTCASE_FONT_ANNOT_PRIMARY] = true;
GMT_keyword_updated[GMTCASE_FONT_ANNOT_SECONDARY] = true;
GMT_keyword_updated[GMTCASE_FONT_LABEL] = true;
Expand Down Expand Up @@ -6820,7 +6825,7 @@ GMT_LOCAL void gmtinit_conf_modern_override (struct GMT_CTRL *GMT) {
error += gmt_getfont (GMT, "auto,Helvetica,black", &GMT->current.setting.font_tag);
GMT->current.setting.given_unit[GMTCASE_FONT_TAG] = 'p';
/* FONT_LOGO */
error += gmt_getfont (GMT, "auto,Helvetica,black", &GMT->current.setting.font_logo);
error += gmt_getfont (GMT, "8p,Helvetica,black", &GMT->current.setting.font_logo);
GMT->current.setting.given_unit[GMTCASE_FONT_LOGO] = 'p';

/* FORMAT_GEO_MAP */
Expand Down Expand Up @@ -7697,6 +7702,7 @@ void gmtlib_explain_options (struct GMT_CTRL *GMT, char *options) {
GMT_Usage (API, 3, "+c Use the command line as the label [%s].", GMT_choice[GMT->current.setting.map_logo]);
GMT_Usage (API, 3, "+j Set frame justification point [BL].");
GMT_Usage (API, 3, "+o Offset stamp by <dx>[/<dy>] [-54p/-54p].");
GMT_Usage (API, 3, "+t Override the UNIX time stamp using appended text.");
break;

case 'V': /* Verbose */
Expand Down Expand Up @@ -10325,11 +10331,6 @@ void gmt_set_undefined_defaults (struct GMT_CTRL *GMT, double plot_dim, bool con
auto_scale = true;
if (conf_update) GMT_keyword_updated[GMTCASE_FONT_SUBTITLE] = true;
}
if (gmt_M_is_dnan (GMT->current.setting.font_logo.size)) {
GMT->current.setting.font_logo.size = scale * 8.0; /* Classic 8p vs 10p */
auto_scale = true;
if (conf_update) GMT_keyword_updated[GMTCASE_FONT_LOGO] = true;
}

/* Offsets */

Expand Down
34 changes: 23 additions & 11 deletions src/gmt_plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ void gmt_linearx_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, dou
/* Get bitmapped 600 dpi GMT glyph for timestamp. The glyph is a 90 x 220 pixel 1-bit image
and it is here represented as ceil (220 / 8) * 90 = 2520 bytes */

static unsigned char GMT_glyph[2520] = {

#define GMT_TIMESTAMP_DATESIZE 8.0 /* Fixed font size for date-clock timestamp portion */
#define GMT_TIMESTAMP_LABELSIZE 7.0 /* Fixed font size for optional user label timestamp portion */
#define GMT_TIMESTAMP_GLYPH_WIDTH 220 /* Fixed pixel width of glyph image */
#define GMT_TIMESTAMP_GLYPH_HEIGHT 90 /* Fixed pixel height of glyph image */

static unsigned char GMT_glyph[2520] = { /* The GMT glyph bitmap */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -3161,24 +3167,28 @@ GMT_LOCAL void gmtplot_timestamp (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, do
* 1 2 3
*/

time_t right_now;
char label[GMT_LEN512] = {""}, text[GMT_LEN256] = {""};
char label[GMT_LEN512] = {""};
double dim[3] = {0.365, 0.15, 0.032}; /* Predefined dimensions in inches */
double unset_rgb[4] = {-1.0, -1.0, -1.0, 0.0};

/* Plot time string in format defined by format_time_stamp */

right_now = time ((time_t *)0);
strftime (text, sizeof(text), GMT->current.setting.format_time_stamp, localtime (&right_now));
snprintf (label, GMT_LEN256, " %s ", text);
if (GMT->common.U.string[0]) /* Override UNIX time stamp with custom short string */
snprintf (label, GMT_LEN256, " %s ", GMT->common.U.string);
else { /* Build UNIX time stamp based on current time */
time_t right_now = time ((time_t *)0);
char text[GMT_LEN256] = {""};
strftime (text, sizeof(text), GMT->current.setting.format_time_stamp, localtime (&right_now));
snprintf (label, GMT_LEN256, " %s ", text);
}

PSL_command (PSL, "%% Begin GMT time-stamp\nV\n");
PSL_setorigin (PSL, x, y, 0.0, PSL_FWD);
PSL_setlinewidth (PSL, 0.25);
PSL_setfont (PSL, GMT->current.setting.font_logo.id);
PSL_defunits (PSL, "PSL_g_w", dim[0]); /* Size of the black [GMT] box */
PSL_defunits (PSL, "PSL_g_h", dim[1]);
PSL_deftextdim (PSL, "PSL_b", 8.0, label); /* Size of the white [timestamp] box (use only length) */
PSL_deftextdim (PSL, "PSL_b", GMT_TIMESTAMP_DATESIZE, label); /* Size of the white [timestamp] box (use only length) */

/* When justification is not BL (justify == 1), add some PostScript code to move to the
location where the lower left corner of the time stamp box is to be drawn */
Expand All @@ -3200,16 +3210,18 @@ GMT_LOCAL void gmtplot_timestamp (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, do

PSL_setfill (PSL, GMT->current.setting.map_default_pen.rgb, 1);
PSL_plotsymbol (PSL, 0.5*dim[0], 0.5*dim[1], dim, PSL_RECT);
PSL_plotcolorimage (PSL, 0.0, 0.0, dim[0], dim[1], PSL_BL, GMT_glyph, 220, 90, 1);
PSL_plotcolorimage (PSL, 0.0, 0.0, dim[0], dim[1], PSL_BL, GMT_glyph, GMT_TIMESTAMP_GLYPH_WIDTH, GMT_TIMESTAMP_GLYPH_HEIGHT, 1);
PSL_setfill (PSL, GMT->PSL->init.page_rgb, 1);
PSL_command (PSL, "PSL_g_h PSL_b_w PSL_g_w 0 Sb\n");
PSL_plottext (PSL, dim[0], dim[2], 8.0, label, 0.0, PSL_BL, 0);
(void)gmt_setfont (GMT, &GMT->current.setting.font_logo);
/* Place timestamp label at 8p */
PSL_plottext (PSL, dim[0], dim[2], GMT_TIMESTAMP_DATESIZE, label, 0.0, PSL_BL, 0);

/* Optionally, add additional label to the right of the box */

if (U_label && U_label[0]) {
if (U_label && U_label[0]) { /* Place user label at 7p with 3 leading spaces */
snprintf (label, GMT_LEN512, " %s", U_label);
PSL_plottext (PSL, 0.0, 0.0, -7.0, label, 0.0, PSL_BL, 0);
PSL_plottext (PSL, 0.0, 0.0, -GMT_TIMESTAMP_LABELSIZE, label, 0.0, PSL_BL, 0);
}

PSL_command (PSL, "U\n%% End GMT time-stamp\n");
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_synopsis.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
#define GMT_J_OPT "-J<args>"
#define GMT_R2_OPT "-R<xmin>/<xmax>/<ymin>/<ymax>[+u<unit>][+r]"
#define GMT_R3_OPT "-R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>][+u<unit>][+r]"
#define GMT_U_OPT "-U[<label>][+c][+j<just>][+o<dx>[/<dy>]]"
#define GMT_U_OPT "-U[<label>][+c][+j<just>][+o<dx>[/<dy>]][+t<text>]"
#define GMT_V_OPT "-V[q|e|w|t|i|c|d]"
#define GMT_X_OPT "-X[a|c|f|r]<xshift>"
#define GMT_Y_OPT "-Y[a|c|f|r]<yshift>"
Expand Down