Skip to content

Commit 93f0503

Browse files
DOC: Generate the list of supported fonts dynamically from codes (#3406)
Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 97cba7e commit 93f0503

File tree

3 files changed

+124
-22
lines changed

3 files changed

+124
-22
lines changed

doc/_static/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,19 @@ a.copybtn {
203203
.sphx-glr-single-img {
204204
max-width: 80%!important;
205205
}
206+
207+
/*
208+
* Styles for aligning table cells.
209+
* https://myst-parser.readthedocs.io/en/latest/syntax/tables.html#markdown-syntax
210+
*/
211+
th.text-left, td.text-left {
212+
text-align: left !important;
213+
}
214+
215+
th.text-center, td.text-center {
216+
text-align: center !important;
217+
}
218+
219+
th.text-right, td.text-right {
220+
text-align: right !important;
221+
}

doc/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
"requires": requirements,
6262
}
6363

64+
# MyST-NB configurations.
65+
# Reference: https://myst-nb.readthedocs.io/en/latest/configuration.html
66+
nb_render_markdown_format = "myst" # The format to use for text/markdown rendering
6467

6568
# Make the list of returns arguments and attributes render the same as the
6669
# parameters list

doc/techref/fonts.md

Lines changed: 105 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
file_format: mystnb
3+
---
4+
15
# Supported Fonts
26

37
PyGMT supports the 35 standard PostScript fonts. The table below lists them with their
@@ -7,25 +11,104 @@ either `"Helvetica"` or `"0"`. For the special fonts "Symbol" (**12**) and
711
"ZapfDingbats" (**34**), see the {doc}`/techref/encodings` for the character set.
812
The image below the table shows a visual sample for each font.
913

10-
| Font No. | Font Name | Font No. | Font Name |
11-
|----------|------------------------|----------|------------------------------|
12-
| 0 | Helvetica | 17 | Bookman-Demi |
13-
| 1 | Helvetica-Bold | 18 | Bookman-DemiItalic |
14-
| 2 | Helvetica-Oblique | 19 | Bookman-Light |
15-
| 3 | Helvetica-BoldOblique | 20 | Bookman-LightItalic |
16-
| 4 | Times-Roman | 21 | Helvetica-Narrow |
17-
| 5 | Times-Bold | 22 | Helvetica-Narrow-Bold |
18-
| 6 | Times-Italic | 23 | Helvetica-Narrow-Oblique |
19-
| 7 | Times-BoldItalic | 24 | Helvetica-Narrow-BoldOblique |
20-
| 8 | Courier | 25 | NewCenturySchlbk-Roman |
21-
| 9 | Courier-Bold | 26 | NewCenturySchlbk-Italic |
22-
| 10 | Courier-Oblique | 27 | NewCenturySchlbk-Bold |
23-
| 11 | Courier-BoldOblique | 28 | NewCenturySchlbk-BoldItalic |
24-
| 12 | Symbol | 29 | Palatino-Roman |
25-
| 13 | AvantGarde-Book | 30 | Palatino-Italic |
26-
| 14 | AvantGarde-BookOblique | 31 | Palatino-Bold |
27-
| 15 | AvantGarde-Demi | 32 | Palatino-BoldItalic |
28-
| 16 | AvantGarde-DemiOblique | 33 | ZapfChancery-MediumItalic |
29-
| | | 34 | ZapfDingbats |
30-
31-
![Standard PostScript Fonts](https://docs.generic-mapping-tools.org/dev/_images/GMT_App_G.png){width="67.5%"}
14+
```{code-cell}
15+
---
16+
tags: [remove-input]
17+
---
18+
from IPython.display import display, Markdown
19+
20+
fonts = [
21+
"Helvetica",
22+
"Helvetica-Bold",
23+
"Helvetica-Oblique",
24+
"Helvetica-BoldOblique",
25+
"Times-Roman",
26+
"Times-Bold",
27+
"Times-Italic",
28+
"Times-BoldItalic",
29+
"Courier",
30+
"Courier-Bold",
31+
"Courier-Oblique",
32+
"Courier-BoldOblique",
33+
"Symbol",
34+
"AvantGarde-Book",
35+
"AvantGarde-BookOblique",
36+
"AvantGarde-Demi",
37+
"AvantGarde-DemiOblique",
38+
"Bookman-Demi",
39+
"Bookman-DemiItalic",
40+
"Bookman-Light",
41+
"Bookman-LightItalic",
42+
"Helvetica-Narrow",
43+
"Helvetica-Narrow-Bold",
44+
"Helvetica-Narrow-Oblique",
45+
"Helvetica-Narrow-BoldOblique",
46+
"NewCenturySchlbk-Roman",
47+
"NewCenturySchlbk-Italic",
48+
"NewCenturySchlbk-Bold",
49+
"NewCenturySchlbk-BoldItalic",
50+
"Palatino-Roman",
51+
"Palatino-Italic",
52+
"Palatino-Bold",
53+
"Palatino-BoldItalic",
54+
"ZapfChancery-MediumItalic",
55+
"ZapfDingbats",
56+
]
57+
58+
text = "| Font No. | Font Name | Font No. | Font Name |\n"
59+
text += "|:---:|:---|:---:|:---|\n"
60+
for i in range(17):
61+
j = i + 17
62+
text += f"| {i} | {fonts[i]} | {j} | {fonts[j]} |\n"
63+
text += f"| | | 34 | {fonts[34]} |\n"
64+
65+
display(Markdown(text))
66+
```
67+
68+
```{code-cell}
69+
---
70+
tags: [remove-input]
71+
---
72+
"""
73+
Script to generate visual samples of the fonts.
74+
"""
75+
import pygmt
76+
77+
x1, x2, dx = 0, 7, 0.75
78+
79+
fig = pygmt.Figure()
80+
# Draw the table
81+
fig.basemap(region=[-0.5, 14, -1.5, 18], projection="X14c/-10c", frame=0)
82+
fig.plot(x=[-0.5, 14], y=[-0.5, -0.5])
83+
for x in (0.5, 6.5, 7.5):
84+
fig.plot(x=[x, x], y=[-1.5, 18])
85+
# Table header
86+
fig.text(
87+
x=[x1, x1 + dx, x2, x2 + dx],
88+
y=[-1] * 4,
89+
text=["#", "Font Name"] * 2,
90+
justify=["MC", "ML"] * 2,
91+
font="Helvetica-Bold",
92+
)
93+
# Fonts
94+
for i, font in enumerate(fonts):
95+
x0 = x1 if i < 17 else x2
96+
y0 = i % 17
97+
font_no, font_name = i, font
98+
99+
# Deal with special cases
100+
if font in ["Symbol", "ZapfDingbats"]:
101+
font_name = f"{font} @%0%({font})@%%"
102+
if font == "ZapfDingbats":
103+
font_no = "@%0%34@%%"
104+
y0 = 17
105+
106+
fig.text(
107+
x=[x0, x0 + dx],
108+
y=[y0] * 2,
109+
text=[font_no, font_name],
110+
justify=["MC", "ML"],
111+
font=font,
112+
)
113+
fig.show(width=600)
114+
```

0 commit comments

Comments
 (0)