-
Notifications
You must be signed in to change notification settings - Fork 218
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
Ensure non-ASCII characters are typeset correctly even if PS_CHAR_ENCODING is not 'ISOLatin1+' #3611
base: main
Are you sure you want to change the base?
Conversation
1ad9d70
to
a575805
Compare
a575805
to
8c34683
Compare
…ODING is not 'ISOLatin1+'
""" | ||
fig = Figure() | ||
if encoding == "Standard+": # Temporarily set the PS_CHAR_ENCODING to "Standard+". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we should test the case that PS_CHAR_ENCODING is set to "Standard+" in a global "gmt.conf" file. However, it's technically difficult. Similar to the test test_gmt_compat_6_is_applied
at
def test_gmt_compat_6_is_applied(capsys): |
Generally we need to:
- Generate a gmt.conf file in the current directory
- Kill the global session
- Start a new session
- Create a new figure and adding non-ASCII characters to it
- End the session so the "gmt.conf" file won't affect other tests
- Start a new, clean global session
But the issue is that, after starting a new global session, we can't return the Figure instance for comparing images, because mpl_image_compare
needs to call Figure.savefig
which no longer works after the session is destroied.
So here we only test the case that PS_CHAR_ENCODING
is changed in the middle of a script.
Description of proposed changes
Non-ASCII characters may not be typeset correctly if the default PS_CHAR_ENCODING setting is not
ISOLatin1+
. This can happen when (1) GMT is compiled with US units as default; (2) users have a globalgmt.conf
file withPS_CHAR_ENCODING
set toStandard+
; (3) users setPS_CHAR_ENCODING
toStandard+
in the middle of a script.Taking the gallery example at https://www.pygmt.org/dev/tutorials/advanced/non_ascii_text.html as an example.
If you have a
gmt.conf
file withPS_CHAR_ENCODING
set toStandard+
(e.g., you can create agmt.conf
file by running GMT commandgmt set PS_CHAR_ENCODING=Standard+
in terminal), running the gallery example will result in the incorrect figure shown in the left column below:Previously, we assumed the default PS_CHAR_ENCODING is
ISOLatin1+
and didn't add--PS_CHAR_ENCODING=ISOLatin1+
if the text string contains non-ASCII characters in the ISOLatin1+ charset. This PR fixes the issue by always adding--PS_CHAR_ENCODING=<encoding>
even if encoding isISOLatin1+
.In 8c34683, the existing test
test_text_nonascii
is modified to show that settingPS_CHAR_ENCODING
toStandard+
breaks the test (https://github.com/GenericMappingTools/pygmt/actions/runs/11800822308/job/32872646796?pr=3611). The fix is added in d9e5203.Closes #2204.