Skip to content

Commit

Permalink
Refactor to improve the user experience with non-ASCII characters (Ge…
Browse files Browse the repository at this point in the history
…nericMappingTools#3206)

Co-authored-by: Yvonne Fröhlich <[email protected]>
Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
3 people committed Jun 29, 2024
1 parent 3574603 commit b907b4a
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 90 deletions.
1 change: 1 addition & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ external_resources.md
:caption: Reference documentation
api/index.rst
techref/index.md
changes.md
minversions.md
```
Expand Down
108 changes: 108 additions & 0 deletions doc/techref/encodings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Supported Encodings and Non-ASCII Characters

GMT supports a number of encodings and each encoding contains a set of ASCII and non-ASCII
characters. Below are some of the most common encodings and characters that are supported.

In PyGMT, you can use any of these ASCII and non-ASCII characters in arguments and text
strings. When using non-ASCII characters in PyGMT, the easiest way is to copy and paste
the character from the tables below.

**Note**: The special character &#xfffd; (REPLACEMENT CHARACTER) is used to indicate that
the character is not defined in the encoding.

## Adobe ISOLatin1+ Encoding

| octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| **\03x** | &#xfffd; | &#x2022; | &#x2026; | &#x2122; | &#x2014; | &#x2013; | &#xfb01; | &#x017e; |
| **\04x** | &#x0020; | &#x0021; | &#x0022; | &#x0023; | &#x0024; | &#x0025; | &#x0026; | &#x2019; |
| **\05x** | &#x0028; | &#x0029; | &#x002a; | &#x002b; | &#x002c; | &#x002d; | &#x002e; | &#x002f; |
| **\06x** | &#x0030; | &#x0031; | &#x0032; | &#x0033; | &#x0034; | &#x0035; | &#x0036; | &#x0037; |
| **\07x** | &#x0038; | &#x0039; | &#x003a; | &#x003b; | &#x003c; | &#x003d; | &#x003e; | &#x003f; |
| **\10x** | &#x0040; | &#x0041; | &#x0042; | &#x0043; | &#x0044; | &#x0045; | &#x0046; | &#x0047; |
| **\11x** | &#x0048; | &#x0049; | &#x004a; | &#x004b; | &#x004c; | &#x004d; | &#x004e; | &#x004f; |
| **\12x** | &#x0050; | &#x0051; | &#x0052; | &#x0053; | &#x0054; | &#x0055; | &#x0056; | &#x0057; |
| **\13x** | &#x0058; | &#x0059; | &#x005a; | &#x005b; | &#x005c; | &#x005d; | &#x005e; | &#x005f; |
| **\14x** | &#x2018; | &#x0061; | &#x0062; | &#x0063; | &#x0064; | &#x0065; | &#x0066; | &#x0067; |
| **\15x** | &#x0068; | &#x0069; | &#x006a; | &#x006b; | &#x006c; | &#x006d; | &#x006e; | &#x006f; |
| **\16x** | &#x0070; | &#x0071; | &#x0072; | &#x0073; | &#x0074; | &#x0075; | &#x0076; | &#x0077; |
| **\17x** | &#x0078; | &#x0079; | &#x007a; | &#x007b; | &#x007c; | &#x007d; | &#x007e; | &#x0161; |
| **\20x** | &#x0152; | &#x2020; | &#x2021; | &#x0141; | &#x2044; | &#x2039; | &#x0160; | &#x203a; |
| **\21x** | &#x0153; | &#x0178; | &#x017d; | &#x0142; | &#x2030; | &#x201e; | &#x201c; | &#x201d; |
| **\22x** | &#x0131; | &#x0060; | &#x00b4; | &#x005e; | &#x02dc; | &#x00af; | &#x02d8; | &#x02d9; |
| **\23x** | &#x00a8; | &#x201a; | &#x02da; | &#x00b8; | &#x0027; | &#x02dd; | &#x02db; | &#x02c7; |
| **\24x** | &#xfffd; | &#x00a1; | &#x00a2; | &#x00a3; | &#x00a4; | &#x00a5; | &#x00a6; | &#x00a7; |
| **\25x** | &#x00a8; | &#x00a9; | &#x00aa; | &#x00ab; | &#x00ac; | &#x00ad; | &#x00ae; | &#x00af; |
| **\26x** | &#x00b0; | &#x00b1; | &#x00b2; | &#x00b3; | &#x00b4; | &#x00b5; | &#x00b6; | &#x00b7; |
| **\27x** | &#x00b8; | &#x00b9; | &#x00ba; | &#x00bb; | &#x00bc; | &#x00bd; | &#x00be; | &#x00bf; |
| **\30x** | &#x00c0; | &#x00c1; | &#x00c2; | &#x00c3; | &#x00c4; | &#x00c5; | &#x00c6; | &#x00c7; |
| **\31x** | &#x00c8; | &#x00c9; | &#x00ca; | &#x00cb; | &#x00cc; | &#x00cd; | &#x00ce; | &#x00cf; |
| **\32x** | &#x00d0; | &#x00d1; | &#x00d2; | &#x00d3; | &#x00d4; | &#x00d5; | &#x00d6; | &#x00d7; |
| **\33x** | &#x00d8; | &#x00d9; | &#x00da; | &#x00db; | &#x00dc; | &#x00dd; | &#x00de; | &#x00df; |
| **\34x** | &#x00e0; | &#x00e1; | &#x00e2; | &#x00e3; | &#x00e4; | &#x00e5; | &#x00e6; | &#x00e7; |
| **\35x** | &#x00e8; | &#x00e9; | &#x00ea; | &#x00eb; | &#x00ec; | &#x00ed; | &#x00ee; | &#x00ef; |
| **\36x** | &#x00f0; | &#x00f1; | &#x00f2; | &#x00f3; | &#x00f4; | &#x00f5; | &#x00f6; | &#x00f7; |
| **\37x** | &#x00f8; | &#x00f9; | &#x00fa; | &#x00fb; | &#x00fc; | &#x00fd; | &#x00fe; | &#x00ff; |

## Adobe Symbol Encoding

| octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| **\04x** | &#x0020; | &#x0021; | &#x2200; | &#x0023; | &#x2203; | &#x0025; | &#x0026; | &#x220b; |
| **\05x** | &#x0028; | &#x0029; | &#x2217; | &#x002b; | &#x002c; | &#x2212; | &#x002e; | &#x002f; |
| **\06x** | &#x0030; | &#x0031; | &#x0032; | &#x0033; | &#x0034; | &#x0035; | &#x0036; | &#x0037; |
| **\07x** | &#x0038; | &#x0039; | &#x003a; | &#x003b; | &#x003c; | &#x003d; | &#x003e; | &#x003f; |
| **\10x** | &#x2245; | &#x0391; | &#x0392; | &#x03a7; | &#x2206; | &#x0395; | &#x03a6; | &#x0393; |
| **\11x** | &#x0397; | &#x0399; | &#x03d1; | &#x039a; | &#x039b; | &#x039c; | &#x039d; | &#x039f; |
| **\12x** | &#x03a0; | &#x0398; | &#x03a1; | &#x03a3; | &#x03a4; | &#x03a5; | &#x03c2; | &#x2126; |
| **\13x** | &#x039e; | &#x03a8; | &#x0396; | &#x005b; | &#x2234; | &#x005d; | &#x22a5; | &#x005f; |
| **\14x** | &#xf8e5; | &#x03b1; | &#x03b2; | &#x03c7; | &#x03b4; | &#x03b5; | &#x03c6; | &#x03b3; |
| **\15x** | &#x03b7; | &#x03b9; | &#x03d5; | &#x03ba; | &#x03bb; | &#x03bc; | &#x03bd; | &#x03bf; |
| **\16x** | &#x03c0; | &#x03b8; | &#x03c1; | &#x03c3; | &#x03c4; | &#x03c5; | &#x03d6; | &#x03c9; |
| **\17x** | &#x03be; | &#x03c8; | &#x03b6; | &#x007b; | &#x007c; | &#x007d; | &#x223c; | &#xfffd; |
| **\24x** | &#x20ac; | &#x03d2; | &#x2032; | &#x2264; | &#x2215; | &#x221e; | &#x0192; | &#x2663; |
| **\25x** | &#x2666; | &#x2665; | &#x2660; | &#x2194; | &#x2190; | &#x2191; | &#x2192; | &#x2193; |
| **\26x** | &#x00b0; | &#x00b1; | &#x2033; | &#x2265; | &#x00d7; | &#x221d; | &#x2202; | &#x2022; |
| **\27x** | &#x00f7; | &#x2260; | &#x2261; | &#x2248; | &#x2026; | &#x23d0; | &#x23af; | &#x21b5; |
| **\30x** | &#x2135; | &#x2111; | &#x211c; | &#x2118; | &#x2297; | &#x2295; | &#x2205; | &#x2229; |
| **\31x** | &#x222a; | &#x2283; | &#x2287; | &#x2284; | &#x2282; | &#x2286; | &#x2208; | &#x2209; |
| **\32x** | &#x2220; | &#x2207; | &#x00ae; | &#x00a9; | &#x2122; | &#x220f; | &#x221a; | &#x22c5; |
| **\33x** | &#x00ac; | &#x2227; | &#x2228; | &#x21d4; | &#x21d0; | &#x21d1; | &#x21d2; | &#x21d3; |
| **\34x** | &#x25ca; | &#x2329; | &#x00ae; | &#x00a9; | &#x2122; | &#x2211; | &#x239b; | &#x239c; |
| **\35x** | &#x239d; | &#x23a1; | &#x23a2; | &#x23a3; | &#x23a7; | &#x23a8; | &#x23a9; | &#x23aa; |
| **\36x** | &#xfffd; | &#x232a; | &#x222b; | &#x2320; | &#x23ae; | &#x2321; | &#x239e; | &#x239f; |
| **\37x** | &#x23a0; | &#x23a4; | &#x23a5; | &#x23a6; | &#x23ab; | &#x23ac; | &#x23ad; | &#xfffd; |

**Note**: The octal code `\140` represents the RADICAL EXTENDER character, which is not available in
the Unicode character set.

## Adobe ZapfDingbats Encoding

| octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| **\04x** | &#x0020; | &#x2701; | &#x2702; | &#x2703; | &#x2704; | &#x260e; | &#x2706; | &#x2707; |
| **\05x** | &#x2708; | &#x2709; | &#x261b; | &#x261e; | &#x270c; | &#x270d; | &#x270e; | &#x270f; |
| **\06x** | &#x2710; | &#x2711; | &#x2712; | &#x2713; | &#x2714; | &#x2715; | &#x2716; | &#x2717; |
| **\07x** | &#x2718; | &#x2719; | &#x271a; | &#x271b; | &#x271c; | &#x271d; | &#x271e; | &#x271f; |
| **\10x** | &#x2720; | &#x2721; | &#x2722; | &#x2723; | &#x2724; | &#x2725; | &#x2726; | &#x2727; |
| **\11x** | &#x2605; | &#x2729; | &#x272a; | &#x272b; | &#x272c; | &#x272d; | &#x272e; | &#x272f; |
| **\12x** | &#x2730; | &#x2731; | &#x2732; | &#x2733; | &#x2734; | &#x2735; | &#x2736; | &#x2737; |
| **\13x** | &#x2738; | &#x2739; | &#x273a; | &#x273b; | &#x273c; | &#x273d; | &#x273e; | &#x273f; |
| **\14x** | &#x2740; | &#x2741; | &#x2742; | &#x2743; | &#x2744; | &#x2745; | &#x2746; | &#x2747; |
| **\15x** | &#x2748; | &#x2749; | &#x274a; | &#x274b; | &#x25cf; | &#x274d; | &#x25a0; | &#x274f; |
| **\16x** | &#x2750; | &#x2751; | &#x2752; | &#x25b2; | &#x25bc; | &#x25c6; | &#x2756; | &#x25d7; |
| **\17x** | &#x2758; | &#x2759; | &#x275a; | &#x275b; | &#x275c; | &#x275d; | &#x275e; | &#xfffd; |
| **\20x** | &#x2768; | &#x2769; | &#x276a; | &#x276b; | &#x276c; | &#x276d; | &#x276e; | &#x276f; |
| **\21x** | &#x2770; | &#x2771; | &#x2772; | &#x2773; | &#x2774; | &#x2775; | &#xfffd; | &#xfffd; |
| **\24x** | &#xfffd; | &#x2761; | &#x2762; | &#x2763; | &#x2764; | &#x2765; | &#x2766; | &#x2767; |
| **\25x** | &#x2663; | &#x2666; | &#x2665; | &#x2660; | &#x2460; | &#x2461; | &#x2462; | &#x2463; |
| **\26x** | &#x2464; | &#x2465; | &#x2466; | &#x2467; | &#x2468; | &#x2469; | &#x2776; | &#x2777; |
| **\27x** | &#x2778; | &#x2779; | &#x277a; | &#x277b; | &#x277c; | &#x277d; | &#x277e; | &#x277f; |
| **\30x** | &#x2780; | &#x2781; | &#x2782; | &#x2783; | &#x2784; | &#x2785; | &#x2786; | &#x2787; |
| **\31x** | &#x2788; | &#x2789; | &#x278a; | &#x278b; | &#x278c; | &#x278d; | &#x278e; | &#x278f; |
| **\32x** | &#x2790; | &#x2791; | &#x2792; | &#x2793; | &#x2794; | &#x2192; | &#x2194; | &#x2195; |
| **\33x** | &#x2798; | &#x2799; | &#x279a; | &#x279b; | &#x279c; | &#x279d; | &#x279e; | &#x279f; |
| **\34x** | &#x27a0; | &#x27a1; | &#x27a2; | &#x27a3; | &#x27a4; | &#x27a5; | &#x27a6; | &#x27a7; |
| **\35x** | &#x27a8; | &#x27a9; | &#x27aa; | &#x27ab; | &#x27ac; | &#x27ad; | &#x27ae; | &#x27af; |
| **\36x** | &#xfffd; | &#x27b1; | &#x27b2; | &#x27b3; | &#x27b4; | &#x27b5; | &#x27b6; | &#x27b7; |
| **\37x** | &#x27b8; | &#x27b9; | &#x27ba; | &#x27bb; | &#x27bc; | &#x27bd; | &#x27be; | &#xfffd; |
12 changes: 12 additions & 0 deletions doc/techref/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Technical Reference

The Technical Reference section provides detailed information on the technical aspects of
GMT and PyGMT, including supported encodings, fonts, bit and hachure patterns, and other
essential components for creating high-quality visualizations. For additional details,
visit the :gmt-docs:`GMT Technical Reference <reference.html>`.

```{toctree}
:maxdepth: 1
encodings.md
```
131 changes: 131 additions & 0 deletions pygmt/encodings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""
Adobe character encodings supported by GMT.
Currently, only Adobe Symbol, Adobe ZapfDingbats, and Adobe ISOLatin1+ encodings are
supported.
The corresponding Unicode characters in each Adobe character encoding are generated
from the mapping table and conversion script in the GMT-octal-codes
(https://github.com/seisman/GMT-octal-codes) repository. Refer to that repository for
details.
Some code points are undefined and are assigned with the replacement character
(``\ufffd``).
References
----------
- GMT-octal-codes: https://github.com/seisman/GMT-octal-codes
- GMT official documentation: https://docs.generic-mapping-tools.org/dev/reference/octal-codes.html
- Adobe Postscript Language Reference: https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf
- ISOLatin1+: https://en.wikipedia.org/wiki/PostScript_Latin_1_Encoding
- Adobe Symbol: https://en.wikipedia.org/wiki/Symbol_(typeface)
- Zapf Dingbats: https://en.wikipedia.org/wiki/Zapf_Dingbats
- Adobe Glyph List: https://github.com/adobe-type-tools/agl-aglfn
"""

# Dictionary of character mappings for different encodings.
charset: dict = {}

# Adobe ISOLatin1+ charset.
charset["ISOLatin1+"] = dict(
zip(
range(0o030, 0o400),
"\ufffd\u2022\u2026\u2122\u2014\u2013\ufb01\u017e"
"\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u2019"
"\u0028\u0029\u002a\u002b\u002c\u2212\u002e\u002f"
"\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037"
"\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f"
"\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047"
"\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f"
"\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057"
"\u0058\u0059\u005a\u005b\u005c\u005d\u005e\u005f"
"\u2018\u0061\u0062\u0063\u0064\u0065\u0066\u0067"
"\u0068\u0069\u006a\u006b\u006c\u006d\u006e\u006f"
"\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077"
"\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u0161"
"\u0152\u2020\u2021\u0141\u2044\u2039\u0160\u203a"
"\u0153\u0178\u017d\u0142\u2030\u201e\u201c\u201d"
"\u0131\u0060\u00b4\u02c6\u02dc\u00af\u02d8\u02d9"
"\u00a8\u201a\u02da\u00b8\u0027\u02dd\u02db\u02c7"
"\u0020\u00a1\u00a2\u00a3\u00a4\u00a5\u00a6\u00a7"
"\u00a8\u00a9\u00aa\u00ab\u00ac\u002d\u00ae\u00af"
"\u00b0\u00b1\u00b2\u00b3\u00b4\u00b5\u00b6\u00b7"
"\u00b8\u00b9\u00ba\u00bb\u00bc\u00bd\u00be\u00bf"
"\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7"
"\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf"
"\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d7"
"\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u00df"
"\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7"
"\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef"
"\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f7"
"\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff",
strict=False,
)
)

# Adobe Symbol charset.
charset["Symbol"] = dict(
zip(
[*range(0o040, 0o200), *range(0o240, 0o400)],
"\u0020\u0021\u2200\u0023\u2203\u0025\u0026\u220b"
"\u0028\u0029\u2217\u002b\u002c\u2212\u002e\u002f"
"\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037"
"\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f"
"\u2245\u0391\u0392\u03a7\u2206\u0395\u03a6\u0393"
"\u0397\u0399\u03d1\u039a\u039b\u039c\u039d\u039f"
"\u03a0\u0398\u03a1\u03a3\u03a4\u03a5\u03c2\u2126"
"\u039e\u03a8\u0396\u005b\u2234\u005d\u22a5\u005f"
"\uf8e5\u03b1\u03b2\u03c7\u03b4\u03b5\u03c6\u03b3"
"\u03b7\u03b9\u03d5\u03ba\u03bb\u03bc\u03bd\u03bf"
"\u03c0\u03b8\u03c1\u03c3\u03c4\u03c5\u03d6\u03c9"
"\u03be\u03c8\u03b6\u007b\u007c\u007d\u223c\ufffd"
"\u20ac\u03d2\u2032\u2264\u2215\u221e\u0192\u2663"
"\u2666\u2665\u2660\u2194\u2190\u2191\u2192\u2193"
"\u00b0\u00b1\u2033\u2265\u00d7\u221d\u2202\u2022"
"\u00f7\u2260\u2261\u2248\u2026\u23d0\u23af\u21b5"
"\u2135\u2111\u211c\u2118\u2297\u2295\u2205\u2229"
"\u222a\u2283\u2287\u2284\u2282\u2286\u2208\u2209"
"\u2220\u2207\u00ae\u00a9\u2122\u220f\u221a\u22c5"
"\u00ac\u2227\u2228\u21d4\u21d0\u21d1\u21d2\u21d3"
"\u25ca\u2329\u00ae\u00a9\u2122\u2211\u239b\u239c"
"\u239d\u23a1\u23a2\u23a3\u23a7\u23a8\u23a9\u23aa"
"\ufffd\u232a\u222b\u2320\u23ae\u2321\u239e\u239f"
"\u23a0\u23a4\u23a5\u23a6\u23ab\u23ac\u23ad\ufffd",
strict=False,
)
)

# Adobe ZapfDingbats charset.
charset["ZapfDingbats"] = dict(
zip(
[*range(0o040, 0o220), *range(0o240, 0o400)],
"\u0020\u2701\u2702\u2703\u2704\u260e\u2706\u2707"
"\u2708\u2709\u261b\u261e\u270c\u270d\u270e\u270f"
"\u2710\u2711\u2712\u2713\u2714\u2715\u2716\u2717"
"\u2718\u2719\u271a\u271b\u271c\u271d\u271e\u271f"
"\u2720\u2721\u2722\u2723\u2724\u2725\u2726\u2727"
"\u2605\u2729\u272a\u272b\u272c\u272d\u272e\u272f"
"\u2730\u2731\u2732\u2733\u2734\u2735\u2736\u2737"
"\u2738\u2739\u273a\u273b\u273c\u273d\u273e\u273f"
"\u2740\u2741\u2742\u2743\u2744\u2745\u2746\u2747"
"\u2748\u2749\u274a\u274b\u25cf\u274d\u25a0\u274f"
"\u2750\u2751\u2752\u25b2\u25bc\u25c6\u2756\u25d7"
"\u2758\u2759\u275a\u275b\u275c\u275d\u275e\ufffd"
"\u2768\u2769\u276a\u276b\u276c\u276d\u276e\u276f"
"\u2770\u2771\u2772\u2773\u2774\u2775\ufffd\ufffd"
"\ufffd\u2761\u2762\u2763\u2764\u2765\u2766\u2767"
"\u2663\u2666\u2665\u2660\u2460\u2461\u2462\u2463"
"\u2464\u2465\u2466\u2467\u2468\u2469\u2776\u2777"
"\u2778\u2779\u277a\u277b\u277c\u277d\u277e\u277f"
"\u2780\u2781\u2782\u2783\u2784\u2785\u2786\u2787"
"\u2788\u2789\u278a\u278b\u278c\u278d\u278e\u278f"
"\u2790\u2791\u2792\u2793\u2794\u2192\u2194\u2195"
"\u2798\u2799\u279a\u279b\u279c\u279d\u279e\u279f"
"\u27a0\u27a1\u27a2\u27a3\u27a4\u27a5\u27a6\u27a7"
"\u27a8\u27a9\u27aa\u27ab\u27ac\u27ad\u27ae\u27af"
"\ufffd\u27b1\u27b2\u27b3\u27b4\u27b5\u27b6\u27b7"
"\u27b8\u27b9\u27ba\u27bb\u27bc\u27bd\u27be\ufffd",
strict=False,
)
)
Loading

0 comments on commit b907b4a

Please sign in to comment.