Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions pygmt/src/pygmtlogo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _create_logo( # noqa: PLR0915
size = 4
proj = "x1c"
region = {
"horizontal": [-size, size * 8.0, -size, size],
"horizontal": [-size, size * 7.0, -size, size],
"vertical": [-size, size, -size * 1.75, size],
"none": [-size, size, -size, size],
}[wordmark]
Expand Down Expand Up @@ -79,12 +79,27 @@ def _create_logo( # noqa: PLR0915
hex_factor = 1.1

# Define wordmark
# See https://github.com/GenericMappingTools/pygmt/pull/4627#issuecomment-4437317011
# for the rationale behind the magic values.
font = "AvantGarde-Book"
pheight = 0.739 # Height of letter "P"
plsb = 0.076 # Left side bearing of letter "P"
pstroke = 0.0735 # Stroke thickness of letter "P"

match wordmark:
case "vertical":
args_text_wm = {"x": 0, "y": -4.5, "justify": "CT", "font": f"2.4c,{font}"}
args_wordmark = {"x": 0, "y": -4.5, "justify": "CT", "font": f"2.4c,{font}"}
case "horizontal":
args_text_wm = {"x": 4.5, "y": 0.8, "justify": "LM", "font": f"8c,{font}"}
# The stroke width matches the outline thickness.
# The left edge of "P" is aligned at y=size * 1.25.
# Letters "PGMT" are placed vertically centered at y=0.
fontsize = thick_shape / pstroke
args_wordmark = {
"x": size * 1.25 - plsb * fontsize,
"y": -pheight / 2.0 * fontsize,
"justify": "BL",
"font": f"{fontsize}c,{font}",
}

def _letter_g_coords():
"""Coordinates for letter G."""
Expand Down Expand Up @@ -218,7 +233,7 @@ def _compass_lines():

# Add wordmark "PyGMT"
if wordmark != "none":
fig.text(text=f"@;{color_py};Py@;;@;{color_gmt};GMT@;;", **args_text_wm)
fig.text(text=f"@;{color_py};Py@;;@;{color_gmt};GMT@;;", **args_wordmark)

# Helpful for implementing the logo; not included in the logo
if debug:
Expand All @@ -237,6 +252,11 @@ def _compass_lines():
fig.hlines(y=[r4, r5], xmin=-size_s, xmax=size_s, pen=pen, perspective=True)
m_mid = (thick_gap + r4) / 2
fig.vlines(x=[r4, m_mid], ymin=-size_s, ymax=size_s, pen=pen, perspective=True)
# Lines for wordmark
if wordmark == "horizontal":
halfheight = pheight / 2.0 * fontsize
fig.hlines(y=[-halfheight, halfheight], xmin=size, pen=pen)
fig.vlines(x=[size * 1.25, size * 1.25 + pstroke * fontsize], pen=pen)

if figname:
fig.savefig(fname=figname)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: 8924c7d80afcc92df4e77e6856b553a4
size: 336254
- md5: 44a9a200fbac4c868b69cb1c13e6dfc5
size: 320394
hash: md5
path: test_pygmtlogo_design_circle-horizontal.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
outs:
- md5: 9715eb13bec45201818d701970a529c8
size: 63949
hash: md5
path: test_pygmtlogo_wordmark_horizontal_circle.png
29 changes: 29 additions & 0 deletions pygmt/tests/test_pygmtlogo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,32 @@ def test_pygmtlogo_wordmark_none(shape):
shape=shape,
)
return fig


@pytest.mark.mpl_image_compare
@pytest.mark.parametrize("shape", ["circle"])
def test_pygmtlogo_wordmark_horizontal(shape):
"""
Test the PyGMT logo with a horizontal wordmark, including both light/dark themes,
and colored/black-and-white versions.
"""
fig = Figure()
fig.basemap(
region=[-0.5, 8.0, -0.5, 10.0],
projection="x1c",
frame=Frame(fill="gray", axis=Axis(grid=0.5)),
)
for (x, y), theme, color in [
((0, 8.5), "light", True),
((0, 6), "dark", True),
((0, 3.5), "light", False),
((0, 1), "dark", False),
]:
fig.pygmtlogo(
position=Position((x, y), anchor="ML", cstype="mapcoords"),
theme=theme,
color=color,
shape=shape,
wordmark="horizontal",
)
return fig
Loading