Skip to content

Support @~ (Symbol font toggle) in -Sq quoted line labels#8952

Merged
joa-quim merged 1 commit intomasterfrom
fix-sq-symbol-font
Mar 24, 2026
Merged

Support @~ (Symbol font toggle) in -Sq quoted line labels#8952
joa-quim merged 1 commit intomasterfrom
fix-sq-symbol-font

Conversation

@joa-quim
Copy link
Member

The @~ escape sequence for switching to the Symbol font (Greek letters
etc.) was ignored in -Sq quoted line labels. The label text was rendered
via PostScript's show operator in PSL_label.ps, which doesn't understand
GMT's @~ escape sequences.

Add PostScript procedures (PSL_split_esc, PSL_has_esc, PSL_show_esc,
PSL_charpath_esc, PSL_sw_esc) that split label strings on @~ boundaries
and toggle between the current font and Symbol font for each segment.
Wrapper functions (PSL_label_show, PSL_label_charpath, PSL_label_sw)
dispatch to the escape-aware versions only when @~ is present, so labels
without escapes follow the exact same code path as before.

For curved text (+v), modify setchar to detect @~ at the current position
and toggle fonts without rendering, allowing the next real character to
be placed in the correct font along the path.

Fixes both straight baseline labels (PSL_ST_place_label*) and curved
baseline labels (PSL_pathtext/setchar), as well as width calculations
(PSL_ST_prepare_text, PSL_CT_calcstringwidth).

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com"

The @~ escape sequence for switching to the Symbol font (Greek letters
  etc.) was ignored in -Sq quoted line labels. The label text was rendered
  via PostScript's show operator in PSL_label.ps, which doesn't understand
  GMT's @~ escape sequences.

  Add PostScript procedures (PSL_split_esc, PSL_has_esc, PSL_show_esc,
  PSL_charpath_esc, PSL_sw_esc) that split label strings on @~ boundaries
  and toggle between the current font and Symbol font for each segment.
  Wrapper functions (PSL_label_show, PSL_label_charpath, PSL_label_sw)
  dispatch to the escape-aware versions only when @~ is present, so labels
  without escapes follow the exact same code path as before.

  For curved text (+v), modify setchar to detect @~ at the current position
  and toggle fonts without rendering, allowing the next real character to
  be placed in the correct font along the path.

  Fixes both straight baseline labels (PSL_ST_place_label*) and curved
  baseline labels (PSL_pathtext/setchar), as well as width calculations
  (PSL_ST_prepare_text, PSL_CT_calcstringwidth).

  Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
@joa-quim joa-quim requested a review from a team March 24, 2026 12:51
@Esteban82 Esteban82 self-requested a review March 24, 2026 14:13
@Esteban82 Esteban82 added the add-changelog Add PR to the changelog label Mar 24, 2026
Copy link
Member

@Esteban82 Esteban82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with this script and it worked:

cat > flights.txt << END
> "Buenos Aires to Frankfurt - 11483 km in 12:24h"
-58.54 -34.82
  8.57  50.03
> "Frankfurt to Johannesburg - 8658 km in 9:21h"
  8.57  50.03
 28.24 -26.13
END

gmt begin symbols png
  gmt coast -JM0/20c -R-87/50/-57/60 -W0.5p,grey43 -Sgrey88 -A300 -B
  gmt plot flights.txt -W5p,red --PS_LINE_CAP=round \
    -Sqn1:+f12p,Helvetica-Bold+l"@~p@~=0.5"
gmt end
Image

@joa-quim joa-quim merged commit 2194754 into master Mar 24, 2026
12 of 14 checks passed
@joa-quim joa-quim deleted the fix-sq-symbol-font branch March 24, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants