Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -20455,6 +20455,14 @@ void gmt_add_legend_item (struct GMTAPI_CTRL *API, struct GMT_SYMBOL *S, bool do
else if (symbol == GMT_SYMBOL_CUSTOM) { /* Custom symbol */
fprintf (fp, "S - %c%s %s %s %s - %s\n", GMT_SYMBOL_CUSTOM, S->custom->name, size_string, (do_fill) ? gmtlib_putfill (API->GMT, fill) : "-", (do_line) ? gmt_putpen (API->GMT, pen) : "-", label);
}
else if (symbol == GMT_SYMBOL_FRONT) { /* Front symbol: must pass along the front-type and sense modifiers or pslegend will default to +l+b (left box) for all entries */
char scode[GMT_LEN64] = {""};
static char f_type[7] = {'f', 'v', 't', 's', 'S', 'c', 'b'}; /* Maps GMT_FRONT_* enum to its -Sf modifier letter */
sprintf (scode, "f+%c", f_type[S->f.f_symbol]);
if (S->f.f_sense == GMT_FRONT_LEFT) strcat (scode, "+l");
else if (S->f.f_sense == GMT_FRONT_RIGHT) strcat (scode, "+r");
fprintf (fp, "S - %s %s %s %s - %s\n", scode, size_string, (do_fill) ? gmtlib_putfill (API->GMT, fill) : "-", (do_line) ? gmt_putpen (API->GMT, pen) : "-", label);
}
else
fprintf (fp, "S - %c %s %s %s - %s\n", symbol, size_string, (do_fill) ? gmtlib_putfill (API->GMT, fill) : "-", (do_line) ? gmt_putpen (API->GMT, pen) : "-", label);
}
Expand Down
6 changes: 3 additions & 3 deletions src/pslegend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ EXTERN_MSC int GMT_pslegend (void *V_API, int mode, void *args) {
/* Place pen and fill colors in segment header */
sprintf (buffer, "-Sf%s/%gi%s", B, tlen, sub);
if (txt_c[0] != '-') {strcat (buffer, " -G"); strcat (buffer, txt_c);}
if (txt_d[0] != '-') {strcat (buffer, " -W"); strcat (buffer, txt_d);}
strcat (buffer, " -W"); strcat (buffer, (txt_d[0] != '-') ? txt_d : gmt_putpen (GMT, &GMT->current.setting.map_default_pen)); /* Always give an explicit pen (given or default) so this segment does not inherit the previous entry's pen */
/* Prepare next output segment */
if ((D[FRONT] = pslegend_get_dataset_pointer (API, D[FRONT], GMT_IS_LINE, GMT_SMALL_CHUNK, 2U, 2U, false)) == NULL) return (API->error);
S[FRONT] = pslegend_get_segment (D, FRONT, n_fronts); /* Next front segment */
Expand All @@ -1623,7 +1623,7 @@ EXTERN_MSC int GMT_pslegend (void *V_API, int mode, void *args) {
x = 0.5 * length;
/* Place pen and fill colors in segment header */
sprintf (buffer, "-S%s", symbol);
if (txt_d[0] != '-') {strcat (buffer, " -W"); strcat (buffer, txt_d);}
strcat (buffer, " -W"); strcat (buffer, (txt_d[0] != '-') ? txt_d : gmt_putpen (GMT, &GMT->current.setting.map_default_pen)); /* Always give an explicit pen (given or default) so this segment does not inherit the previous entry's pen */
S[QLINE] = pslegend_get_segment (D, QLINE, n_quoted_lines); /* Next quoted line segment */
S[QLINE]->header = strdup (buffer);
GMT_Report (API, GMT_MSG_DEBUG, "QLINE: %s\n", buffer);
Expand All @@ -1642,7 +1642,7 @@ EXTERN_MSC int GMT_pslegend (void *V_API, int mode, void *args) {
x = 0.5 * length;
/* Place pen and fill colors in segment header */
sprintf (buffer, "-S%s", symbol);
if (txt_d[0] != '-') {strcat (buffer, " -W"); strcat (buffer, txt_d);}
strcat (buffer, " -W"); strcat (buffer, (txt_d[0] != '-') ? txt_d : gmt_putpen (GMT, &GMT->current.setting.map_default_pen)); /* Always give an explicit pen (given or default) so this segment does not inherit the previous entry's pen */
S[DLINE] = pslegend_get_segment (D, DLINE, n_decorated_lines); /* Next decorated line segment */
S[DLINE]->header = strdup (buffer);
GMT_Report (API, GMT_MSG_DEBUG, "DLINE: %s\n", buffer);
Expand Down
29 changes: 29 additions & 0 deletions test/pslegend/autolegendfront.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# Test auto-legend for front (fault) symbols (-Sf).
#
# GRAPHICSMAGICK_RMS = 0.02
# GMT_KNOWN_FAILURE
#
# Regression test for issue #9066:
# 1) Each auto-legend entry must show the correct front sub-type
# (e.g., +c circle vs +b box), not always a box.
# 2) An entry with no explicit -W must not inherit the pen from a
# previous entry that did specify one (here, "circle thick" uses
# an explicit thick red pen, while "box" specifies no pen at all
# and must fall back to the default pen, not thick red).
cat << EOF > t1.txt
0 1
1 1
EOF
cat << EOF > t2.txt
0 2
1 2
EOF
gmt begin autolegendfront ps
gmt basemap -R0/1/0/5 -JX5c -Bf
gmt plot -Wthick,red -Gblack -Sf2+c+r t2.txt -l"circle thick"
gmt plot -Gpurple -Sf2+b+r t1.txt -l"box"
gmt end

rm t*.txt
Loading