Support @~ (Symbol font toggle) in -Sq quoted line labels#8952
Merged
Support @~ (Symbol font toggle) in -Sq quoted line labels#8952
Conversation
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>"
Esteban82
approved these changes
Mar 24, 2026
Member
Esteban82
left a comment
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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"