Skip to content

Commit

Permalink
Add modifier +hheight to set logo height instead of width (#7458)
Browse files Browse the repository at this point in the history
Since the logo aspect ratio is fixed, one can only specify one of the dimensions.  Tis PR adds +h and makes it clear in th synopsis and usage that both are optional [Default is 144p wide logo].
  • Loading branch information
PaulWessel committed May 12, 2023
1 parent c6aa40e commit 031b5cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/rst/source/gmtlogo-classic.rst
Expand Up @@ -12,7 +12,7 @@ Synopsis

.. include:: common_SYN_OPTs.rst_

**gmtlogo** [ |-D|\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ **+w**\ *width*\ [**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]] ]
**gmtlogo** [ |-D|\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+h**\ *height*\|\ **+w**\ *width*\ ][**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]] ]
[ |-F|\ [**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]][**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]] ]
[ |-J|\ *parameters* ]
[ |-K| ]
Expand Down
7 changes: 4 additions & 3 deletions doc/rst/source/gmtlogo.rst
Expand Up @@ -12,7 +12,7 @@ Synopsis

.. include:: common_SYN_OPTs.rst_

**gmt logo** [ |-D|\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ **+w**\ *width*\ [**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]] ]
**gmt logo** [ |-D|\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+h**\ *height*\|\ **+w**\ *width*\ ][**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]] ]
[ |-F|\ [**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]][**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]] ]
[ |-J|\ *parameters* ] [ |-J|\ **z**\|\ **Z**\ *parameters* ]
[ |SYN_OPT-Rz| ]
Expand Down Expand Up @@ -50,14 +50,15 @@ Optional Arguments

.. _-D:

**-D**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ **+w**\ *width*\ [**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]]
**-D**\ [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ [**+h**\ *height*\|\ **+w**\ *width*\ ][**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]]
Sets reference point on the map for the image using one of four coordinate systems:
(1) Use **-Dg** for map (user) coordinates, (2) use **-Dj** or **-DJ** for setting *refpoint* via
a 2-char justification code that refers to the (invisible) map domain rectangle,
(3) use **-Dn** for normalized (0-1) coordinates, or (4) use **-Dx** for plot coordinates
(inches, cm, etc.). All but **-Dx** requires both |-R| and |-J| to be specified.
Use **+w**\ *width* to set the width of the GMT logo in plot coordinates
(inches, cm, etc.).
(inches, cm, etc.). Alternatively, use **+h**\ *height* to instead specify the logo height.
**Note**: Since the aspect ratio is fixed, only one of height and width can be specified.
By default, the anchor point on the GMT logo is assumed to be the bottom left corner (BL), but this
can be changed by appending **+j** followed by a 2-char justification code *justify* (see :doc:`text`).
**Note**: If **-Dj** is used then *justify* defaults to the same as *refpoint*,
Expand Down
24 changes: 18 additions & 6 deletions src/gmtlogo.c
Expand Up @@ -172,11 +172,12 @@ enum gmtlogo_label {
/* Control structure for gmtlogo */

struct GMTLOGO_CTRL {
struct GMTLOGO_D { /* -D[g|j|n|x]<refpoint>+w<width>[+j<justify>][+o<dx>[/<dy>]] */
struct GMTLOGO_D { /* -D[g|j|n|x]<refpoint>[+h<height>|+w<width>][+j<justify>][+o<dx>[/<dy>]] */
bool active;
struct GMT_REFPOINT *refpoint;
double off[2];
double width;
double height;
int justify;
} D;
struct GMTLOGO_F { /* -F[+c<clearance>][+g<fill>][+i[<off>/][<pen>]][+p[<pen>]][+r[<radius>]][+s[<dx>/<dy>/][<shade>]][+d] */
Expand Down Expand Up @@ -208,7 +209,7 @@ 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);
if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR);
GMT_Usage (API, 0, "usage: %s [-D%s[+w<width>]%s] [-F%s] [%s] "
GMT_Usage (API, 0, "usage: %s [-D%s[+h<height>|+w<width>]%s] [-F%s] [%s] "
"%s%s%s[%s] [-S[l|n|u]] [%s] [%s] [%s] [%s] %s[%s] [%s]\n",
name, GMT_XYANCHOR, GMT_OFFSET, GMT_PANEL, GMT_J_OPT, API->K_OPT, API->O_OPT,
API->P_OPT, GMT_Rgeoz_OPT, GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, API->c_OPT, GMT_t_OPT, GMT_PAR_OPT);
Expand All @@ -218,7 +219,8 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
GMT_Message (API, GMT_TIME_NONE, " OPTIONAL ARGUMENTS:\n");
gmt_refpoint_syntax (API->GMT, "\n-D", "Specify position of the GMT logo [0/0].", GMT_ANCHOR_LOGO, 1);
gmt_refpoint_syntax (API->GMT, "D", NULL, GMT_ANCHOR_LOGO, 2);
GMT_Usage (API, 3, "+w Set the <width> of the GMT logo. [144p]");
GMT_Usage (API, 3, "+h Set the <height> of the GMT logo [72p], or");
GMT_Usage (API, 3, "+w Set the <width> of the GMT logo [144p]");
gmt_mappanel_syntax (API->GMT, 'F', "Specify a rectangular panel behind the GMT logo.", 0);
GMT_Option (API, "J-Z,K,O,P,R");
GMT_Usage (API, 1, "\n-S[l|n|u]");
Expand Down Expand Up @@ -255,15 +257,17 @@ static int parse (struct GMT_CTRL *GMT, struct GMTLOGO_CTRL *Ctrl, struct GMT_OP
n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active);
if ((Ctrl->D.refpoint = gmt_get_refpoint (GMT, opt->arg, 'D')) == NULL)
n_errors++; /* Failed basic parsing */
else { /* args are [+w<width>][+j<justify>][+o<dx>[/<dy>]] */
if (gmt_validate_modifiers (GMT, Ctrl->D.refpoint->args, 'D', "jow", GMT_MSG_ERROR)) n_errors++;
else { /* args are [+h<height>|w<width>][+j<justify>][+o<dx>[/<dy>]] */
if (gmt_validate_modifiers (GMT, Ctrl->D.refpoint->args, 'D', "hjow", GMT_MSG_ERROR)) n_errors++;
if (gmt_get_modifier (Ctrl->D.refpoint->args, 'j', string))
Ctrl->D.justify = gmt_just_decode (GMT, string, PSL_NO_DEF);
else /* With -Dj or -DJ, set default to reference justify point, else BL */
Ctrl->D.justify = gmt_M_just_default (GMT, Ctrl->D.refpoint, PSL_BL);
if (gmt_get_modifier (Ctrl->D.refpoint->args, 'o', string)) {
if ((n = gmt_get_pair (GMT, string, GMT_PAIR_DIM_DUP, Ctrl->D.off)) < 0) n_errors++;
}
if (gmt_get_modifier (Ctrl->D.refpoint->args, 'h', string)) /* Get logo height */
Ctrl->D.height = gmt_M_to_inch (GMT, string);
if (gmt_get_modifier (Ctrl->D.refpoint->args, 'w', string)) /* Get logo width */
Ctrl->D.width = gmt_M_to_inch (GMT, string);
}
Expand Down Expand Up @@ -301,7 +305,15 @@ static int parse (struct GMT_CTRL *GMT, struct GMTLOGO_CTRL *Ctrl, struct GMT_OP
Ctrl->D.width = gmt_M_to_inch (GMT, string);
Ctrl->D.active = true;
}
if (Ctrl->D.width == 0.0) Ctrl->D.width = 2.0; /* Default width */
if (Ctrl->D.width == 0.0) { /* Either size not set or got height instead */
if (Ctrl->D.height > 0.0) /* Got height, now compute width */
Ctrl->D.width = (Ctrl->S.mode == GMTLOGO_LABEL_NONE) ? Ctrl->D.height / (1.55 * 0.25) : 2.0 * Ctrl->D.height;
else /* Default width */
Ctrl->D.width = 2.0;
}
else if (Ctrl->D.height > 0.0) { /* Cannot specify both dimensions since aspect is fixed */
n_errors += gmt_M_check_condition (GMT, Ctrl->D.width > 0.0, "Option -D+w|+h modifiers: Cannot set both width and height since aspecf is fixed!\n");
}
if (Ctrl->D.refpoint && Ctrl->D.refpoint->mode != GMT_REFPOINT_PLOT) { /* Anything other than -Dx need -R -J; other cases don't */
static char *kind = GMT_REFPOINT_CODES; /* The five types of refpoint specifications */
n_errors += gmt_M_check_condition (GMT, !GMT->common.R.active[RSET], "Option -D%c requires the -R option\n", kind[Ctrl->D.refpoint->mode]);
Expand Down

0 comments on commit 031b5cf

Please sign in to comment.