Skip to content

Commit 1ad9d70

Browse files
committed
Ensure non-ASCII characters are typeset correctly even if PS_CHAR_ENCODING is not 'ISOLatin1+'
1 parent 763dc07 commit 1ad9d70

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

pygmt/helpers/utils.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,16 @@ def build_arg_list( # noqa: PLR0912
506506
else:
507507
gmt_args.append(f"-{key}{value}")
508508

509-
# Convert non-ASCII characters (if any) in the arguments to octal codes
510-
encoding = _check_encoding("".join(gmt_args))
511-
if encoding != "ascii":
512-
gmt_args = [non_ascii_to_octal(arg, encoding=encoding) for arg in gmt_args]
513509
gmt_args = sorted(gmt_args)
514510

515-
# Set --PS_CHAR_ENCODING=encoding if necessary
516-
if encoding not in {"ascii", "ISOLatin1+"} and not (
517-
confdict and "PS_CHAR_ENCODING" in confdict
518-
):
519-
gmt_args.append(f"--PS_CHAR_ENCODING={encoding}")
511+
# Convert non-ASCII characters (if any) in the arguments to octal codes and set
512+
# --PS_CHAR_ENCODING=encoding if necessary
513+
if (encoding := _check_encoding("".join(gmt_args))) != "ascii":
514+
gmt_args = [non_ascii_to_octal(arg, encoding=encoding) for arg in gmt_args]
515+
516+
# Set --PS_CHAR_ENCODING=encoding if necessary
517+
if not (confdict and "PS_CHAR_ENCODING" in confdict):
518+
gmt_args.append(f"--PS_CHAR_ENCODING={encoding}")
520519

521520
if confdict:
522521
gmt_args.extend(f"--{key}={value}" for key, value in confdict.items())

pygmt/src/text.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,12 @@ def text_( # noqa: PLR0912
238238

239239
# Append text to the last column. Text must be passed in as str type.
240240
text = np.asarray(text, dtype=np.str_)
241-
encoding = _check_encoding("".join(text.flatten()))
242-
if encoding != "ascii":
241+
if (encoding := _check_encoding("".join(text.flatten()))) != "ascii":
243242
text = np.vectorize(non_ascii_to_octal, excluded="encoding")(
244243
text, encoding=encoding
245244
)
245+
confdict["PS_CHAR_ENCODING"] = encoding
246246
extra_arrays.append(text)
247-
248-
if encoding not in {"ascii", "ISOLatin1+"}:
249-
confdict = {"PS_CHAR_ENCODING": encoding}
250247
else:
251248
if isinstance(position, str):
252249
kwargs["F"] += f"+c{position}+t{text}"

0 commit comments

Comments
 (0)