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

Treat stroke symbols like other symbols #7789

Merged
merged 26 commits into from Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3873249
WIP Treat stroke symbols like other symbols
PaulWessel Sep 5, 2023
27d453b
Same for psxyz
PaulWessel Sep 5, 2023
1061057
Only override color it one has been set
PaulWessel Sep 5, 2023
3182e9f
Update the docs for strokable symbols
PaulWessel Sep 5, 2023
ebad147
Add a constant for the default size to pen width factor
PaulWessel Sep 5, 2023
8fbfaa8
Update gmt_constants.h
PaulWessel Sep 5, 2023
4146672
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 5, 2023
43388ec
Fix color assignment if -G or -C given
PaulWessel Sep 6, 2023
aff7715
Introduce new default MAP_STROKE_WIDTH
PaulWessel Sep 6, 2023
370f465
Minor fixes
PaulWessel Sep 6, 2023
fb3526d
Deal with resets after reading symbols from data file
PaulWessel Sep 6, 2023
9c15b41
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 7, 2023
2fd6eb3
Fix some PS and scripts
PaulWessel Sep 7, 2023
bc6867a
More PS updates
PaulWessel Sep 7, 2023
1587b72
Update images.dvc
PaulWessel Sep 7, 2023
b628aea
fix output name and 2 PS files
PaulWessel Sep 8, 2023
8f3cf8a
Update psevents.dvc
PaulWessel Sep 8, 2023
d8947fd
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 8, 2023
904301f
Fix inverted CPT
PaulWessel Sep 8, 2023
85c106b
Increase RMS threshold due to architectures
PaulWessel Sep 8, 2023
eba393e
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 8, 2023
f230825
typos
PaulWessel Sep 8, 2023
a6404b0
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 8, 2023
9227ef1
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 9, 2023
5d7352f
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 9, 2023
dcbbeb4
Merge branch 'master' into stroke-symbol-revival
PaulWessel Sep 9, 2023
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
9 changes: 7 additions & 2 deletions doc/rst/source/explain_symbols.rst_
Expand Up @@ -83,10 +83,15 @@
**-Sy**\ *size*
y-dash (\|). *size* is the length of a short vertical (y-dir) line segment.

**Note**: The uppercase symbols **A**, **C**, **D**, **G**, **H**, **I**, **N**,
**Notes**: (1) The uppercase symbols **A**, **C**, **D**, **G**, **H**, **I**, **N**,
**S**, **T** are normalized to have the same *area* as a circle with
diameter *size*, while the *size* of the corresponding lowercase symbols
refers to the diameter of a circumscribed circle.
refers to the diameter of a circumscribed circle. (2) The stroke-only symbols
**x**, **y**, **+** and **-** will derive their pen widths from the symbol size
and their pen color from |-G| or |-C|. In that sense they behave as the other
symbols (but no outline). You can override this behavior by specifying |-W|,
modify it by adjusting :term:`MAP_STROKE_WIDTH` [15%], or set it to zero to
rely on pen defaults (and |-W|).

The next collection shows five symbols that require two or more parameters, and
some have optional modifiers to enhance the symbol appearance.
Expand Down
7 changes: 7 additions & 0 deletions doc/rst/source/gmt.conf.rst
Expand Up @@ -868,6 +868,13 @@ MAP Parameters
cap is reversed, i.e., *85/90* will draw a r = 5 radius circle at the
center of the map with less frequent radial lines there.

**MAP_STROKE_WIDTH**
Used to convert non-fillable (**x**, **y**, **+** and **-**) symbol sizes
to the width of the pen used to stroke these symbols. Give a factor in the
0-1 range (e.g., 0.18) or specify a percentage (e.g., 10%) [15%]. **Note**:
If set to 0 then no such conversion takes place and pen settings must rely on
**-W** or module defaults.

**MAP_SCALE_HEIGHT**
Sets the height (> 0) on the map of the map scale bars drawn by
various programs [default is **5p**].
Expand Down
3 changes: 3 additions & 0 deletions src/gmt_constants.h
Expand Up @@ -257,6 +257,9 @@ enum GMT_time_period {
#define GMT_TEXT_CLEARANCE 15 /* Clearance around text in textboxes, in percent */
#define GMT_TEXT_OFFSET 20 /* Offset of text from refpoint, in percent */

/* Conversion from symbol size to pen width for stroke-only symbols x,y,+, - */
#define GMT_SYMBOL_SIZE_TO_PEN_WIDTH 15 /* 15% */

#define GMT_N_MAX_MODEL 20 /* No more than 20 basis functions in a trend model */

#define GMT_PAIR_COORD 0 /* Tell gmt_get_pair to get both x and y as coordinates */
Expand Down
2 changes: 2 additions & 0 deletions src/gmt_defaults.h
Expand Up @@ -154,6 +154,8 @@ struct GMT_DEFAULTS {
double map_graph_extension; /* If map_frame_type is graph, how must longer to make axis length. [7.5%] */
double map_graph_origin[2]; /* x- and y-origin of graph axis if graph-origin is in use [data 0/0] */
double map_graph_shift; /* Extra offset for title to avoid overwriting the centered y-axis */
double map_stroke_width; /* Conversion factor from symbol size to stroke pen width (non-fillable symbols only) */
char map_stroke_width_unit; /* Either % or not */
unsigned int map_annot_oblique; /* Controls annotations and tick angles etc. [GMT_OBL_ANNOT_ANYWHERE] */
unsigned int map_grid_cross_type[2]; /* 0 = normal cross, 1 = symmetric tick, 2 = asymmetric tick */
unsigned int map_logo_justify; /* Justification of the GMT timestamp box [1 (BL)] */
Expand Down
25 changes: 24 additions & 1 deletion src/gmt_init.c
Expand Up @@ -208,7 +208,7 @@ struct GMT_parameter {
const char *name;
};

/* These are the active GMT5+ keywords, containing no backwards-compatible variants.
/* These are the active >= GMT5 keywords, containing no backwards-compatible variants.
* Also, some grouped keywords such as FONT and FONT_ANNOT are also not listed since they are not in gmt.conf.
* If new keywords are added they need to be added here as well as to gmt_keywords.txt, plus
* specific entries in both gmtlib_setparameter and gmtlib_getparameter, and gmt.conf.rst */
Expand Down Expand Up @@ -314,6 +314,7 @@ static struct GMT_parameter GMT_keyword_active[]= {
{ 0, "MAP_ORIGIN_Y"},
{ 0, "MAP_POLAR_CAP"},
{ 0, "MAP_SCALE_HEIGHT"},
{ 0, "MAP_STROKE_WIDTH"},
{ 0, "MAP_TICK_LENGTH_PRIMARY"},
{ 0, "MAP_TICK_LENGTH_SECONDARY"},
{ 0, "MAP_TICK_PEN_PRIMARY"},
Expand Down Expand Up @@ -6616,6 +6617,9 @@ GMT_LOCAL void gmtinit_conf_classic (struct GMT_CTRL *GMT) {
/* MAP_POLAR_CAP */
GMT->current.setting.map_polar_cap[0] = 85;
GMT->current.setting.map_polar_cap[1] = 90;
/* MAP_STROKE_WIDTH */
GMT->current.setting.map_stroke_width = GMT_SYMBOL_SIZE_TO_PEN_WIDTH / 100.0; /* Given as percentage */
GMT->current.setting.map_stroke_width_unit = '%';
/* MAP_SCALE_HEIGHT */
GMT->current.setting.map_scale_height = 5 * pt; /* 5p */
GMT->current.setting.given_unit[GMTCASE_MAP_SCALE_HEIGHT] = 'p';
Expand Down Expand Up @@ -11237,6 +11241,19 @@ unsigned int gmtlib_setparameter (struct GMT_CTRL *GMT, const char *keyword, cha
GMT->current.setting.map_polar_cap[1] = inc[GMT_X];
}
break;
case GMTCASE_MAP_STROKE_WIDTH:
dval = atof (value);
if (value[len] == '%') {
dval /= 100.0; /* Got factor as a percentage */
GMT->current.setting.map_stroke_width_unit = '%';
}
else /* Got a fraction */
GMT->current.setting.map_stroke_width_unit = '\0';
if (dval < 0.0)
error = true;
else
GMT->current.setting.map_stroke_width = dval;
break;
case GMTCASE_MAP_SCALE_HEIGHT:
dval = gmt_M_to_inch (GMT, value);
if (dval <= 0.0)
Expand Down Expand Up @@ -12798,6 +12815,12 @@ char *gmtlib_getparameter (struct GMT_CTRL *GMT, const char *keyword) {
else
snprintf (value, GMT_LEN256, "%g/%g", GMT->current.setting.map_polar_cap[0], GMT->current.setting.map_polar_cap[1]);
break;
case GMTCASE_MAP_STROKE_WIDTH:
if (GMT->current.setting.map_stroke_width_unit == '%') /* Report as percentage */
snprintf (value, GMT_LEN256, "%g%%", GMT->current.setting.map_stroke_width * 100.0);
else /* Just a factor */
snprintf (value, GMT_LEN256, "%g", GMT->current.setting.map_stroke_width);
break;
case GMTCASE_MAP_SCALE_HEIGHT:
snprintf (value, GMT_LEN256, "%g%c", GMT->current.setting.map_scale_height * gmt_M_def_scale(GMTCASE_MAP_SCALE_HEIGHT), gmt_M_def_unit(GMTCASE_MAP_SCALE_HEIGHT));
break;
Expand Down
1 change: 1 addition & 0 deletions src/gmt_keywords.txt
Expand Up @@ -127,6 +127,7 @@ MAP_ORIGIN_X # x-value of lower-left corner of map relative to page [1i]
MAP_ORIGIN_Y # y-value of lower-left corner of map relative to page [1i]
MAP_POLAR_CAP # Modify gridline spacing for polar caps
MAP_SCALE_HEIGHT # Height of scale bar on maps
MAP_STROKE_WIDTH # Percent of strokable-only symbol size for stroke pen width [15%]
MAP_TICK_LENGTH # Length of major and minor frame axes ticks [does not go in gmt.conf]
MAP_TICK_LENGTH_PRIMARY # Length of major and minor primary frame axes ticks
MAP_TICK_LENGTH_SECONDARY # Length of major and minor secondary frame axes ticks
Expand Down
22 changes: 20 additions & 2 deletions src/psxy.c
Expand Up @@ -501,6 +501,15 @@ GMT_LOCAL void psxy_plot_end_vectors (struct GMT_CTRL *GMT, double *x, double *y
PSL_command (GMT->PSL, "U\n");
}

GMT_LOCAL bool psxy_is_stroke_symbol (int symbol) {
/* Return true if cross, x, y, - symbols */
if (symbol == PSL_CROSS) return true;
if (symbol == PSL_XDASH) return true;
if (symbol == PSL_YDASH) return true;
if (symbol == PSL_PLUS) return true;
return false;
}

static int usage (struct GMTAPI_CTRL *API, int level) {
/* This displays the psxy synopsis and optionally full usage information */

Expand Down Expand Up @@ -1706,6 +1715,13 @@ EXTERN_MSC int GMT_psxy (void *V_API, int mode, void *args) {
PSL_command (PSL, "/QR_outline false def\n");
}

if (psxy_is_stroke_symbol (S.symbol)) { /* These are only stroked, not filled */
/* Unless -W was set, compute pen width from symbol size and get pen color from G or z->CPT */
if (!Ctrl->W.active) /* No pen width given, compute from symbol size unless conversion factor is 0 */
current_pen.width = (gmt_M_is_zero (GMT->current.setting.map_stroke_width)) ? GMT->current.setting.map_default_pen.width : GMT->current.setting.map_stroke_width * S.size_x * PSL_POINTS_PER_INCH;
if (current_fill.rgb[0] > -0.5) /* Color given, use it for the stroke */
gmt_M_rgb_copy (current_pen.rgb, current_fill.rgb);
}
if (gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y)) continue; /* NaNs on input */

if (gmt_M_is_dnan (plot_x)) { /* Transformation of x yielded a NaN (e.g. log (-ve)) */
Expand Down Expand Up @@ -2065,9 +2081,11 @@ EXTERN_MSC int GMT_psxy (void *V_API, int mode, void *args) {
}
break;
case GMT_SYMBOL_TEXT:
if (Ctrl->G.active && !outline_active)
if (fill_active && !outline_active)
PSL_setcolor (PSL, current_fill.rgb, PSL_IS_FILL);
else if (!Ctrl->G.active)
else if (fill_active)
PSL_setcolor (PSL, current_fill.rgb, outline_setting);
else
PSL_setfill (PSL, GMT->session.no_rgb, outline_setting);
(void) gmt_setfont (GMT, &S.font);
direction = (S.azim) ? gmt_azim_to_angle (GMT, in[GMT_X], in[GMT_Y], 0.1, S.angle) : S.angle;
Expand Down
17 changes: 17 additions & 0 deletions src/psxyz.c
Expand Up @@ -136,6 +136,15 @@ struct PSXYZ_DATA {
struct GMT_CUSTOM_SYMBOL *custom;
};

GMT_LOCAL bool psxyz_is_stroke_symbol (int symbol) {
/* Return true if cross, x, y, - symbols */
if (symbol == PSL_CROSS) return true;
if (symbol == PSL_XDASH) return true;
if (symbol == PSL_YDASH) return true;
if (symbol == PSL_PLUS) return true;
return false;
}

static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new control structure */
struct PSXYZ_CTRL *C;

Expand Down Expand Up @@ -1352,6 +1361,14 @@ EXTERN_MSC int GMT_psxyz (void *V_API, int mode, void *args) {

if (S.base_set & GMT_BASE_ORIGIN) data[n].flag |= 32; /* Flag that base needs to be added to height(s) */

if (psxyz_is_stroke_symbol (S.symbol)) { /* These are only stroked, not filled */
/* Unless -W was set, compute pen width from symbol size and get pen color from G or z->CPT */
if (!Ctrl->W.active) /* No pen width given, compute from symbol size */
current_pen.width = (gmt_M_is_zero (GMT->current.setting.map_stroke_width)) ? GMT->current.setting.map_default_pen.width : GMT->current.setting.map_stroke_width * S.size_x * PSL_POINTS_PER_INCH;
if (current_fill.rgb[0] > -0.5) /* Color given, use it for the stroke */
gmt_M_rgb_copy (current_pen.rgb, current_fill.rgb);
}

if (Ctrl->W.cpt_effect) {
if (Ctrl->W.pen.cptmode & 1) { /* Change pen color via CPT */
gmt_M_rgb_copy (Ctrl->W.pen.rgb, current_fill.rgb);
Expand Down
2 changes: 1 addition & 1 deletion test/psxy/all_psxy_symbols.txt
@@ -1,5 +1,5 @@
# All the basic psxy symbols + two customs to fill the table
# ALl dimensions hardwired to be in inches
# All dimensions hardwired to be in inches
0.5 0.5 1i -
1.5 0.5 1i +
2.5 0.5 1i a
Expand Down
4 changes: 2 additions & 2 deletions test/psxy/plot_symbols.sh
Expand Up @@ -4,7 +4,7 @@

ps=plot_symbols.ps

gmt psxy -R0/4/1/6 -Jx1i -P -Bg1 -Gred -W0.25p -S1i -X2i -Y2i << EOF > $ps
gmt psxy -R0/4/1/6 -Jx1i -P -Bg1 -W0.25p -S1i -X2i -Y2i << EOF > $ps
> Fat pen -W2p
0.5 5.5 -
> Plain red symbols -W- -Gred
Expand All @@ -29,7 +29,7 @@ gmt psxy -R0/4/1/6 -Jx1i -P -Bg1 -Gred -W0.25p -S1i -X2i -Y2i << EOF > $ps
> Blue wedges -Gblue
3.5 2.5 80 30 w
0.5 1.5 30 80 w
> Fat red pen -W2p,red
> Fat red pen -W2p,red -G-
1.5 1.5 x
> Fat pen -W2p
1.5 1.5 +
Expand Down