diff --git a/pygmt/src/pygmtlogo.py b/pygmt/src/pygmtlogo.py index ec1bb7d9250..e8cfc7fa643 100644 --- a/pygmt/src/pygmtlogo.py +++ b/pygmt/src/pygmtlogo.py @@ -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] @@ -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.""" @@ -229,7 +244,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: @@ -248,6 +263,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) diff --git a/pygmt/tests/baseline/test_pygmtlogo_circle_design_horizontal.png.dvc b/pygmt/tests/baseline/test_pygmtlogo_circle_design_horizontal.png.dvc index 3648ff8045d..9095a7fbc48 100644 --- a/pygmt/tests/baseline/test_pygmtlogo_circle_design_horizontal.png.dvc +++ b/pygmt/tests/baseline/test_pygmtlogo_circle_design_horizontal.png.dvc @@ -1,5 +1,5 @@ outs: -- md5: de3f281a09815faff7fed339c1635bc5 - size: 336254 +- md5: 44a9a200fbac4c868b69cb1c13e6dfc5 + size: 320394 hash: md5 path: test_pygmtlogo_circle_design_horizontal.png diff --git a/pygmt/tests/baseline/test_pygmtlogo_circle_horizontal_wordmark.png.dvc b/pygmt/tests/baseline/test_pygmtlogo_circle_horizontal_wordmark.png.dvc new file mode 100644 index 00000000000..bf1e1bb0b02 --- /dev/null +++ b/pygmt/tests/baseline/test_pygmtlogo_circle_horizontal_wordmark.png.dvc @@ -0,0 +1,5 @@ +outs: +- md5: 6510d43c7860d79f4c4dc43e6b784325 + size: 64867 + hash: md5 + path: test_pygmtlogo_circle_horizontal_wordmark.png diff --git a/pygmt/tests/test_pygmtlogo.py b/pygmt/tests/test_pygmtlogo.py index 71078f95548..0b61d88eea3 100644 --- a/pygmt/tests/test_pygmtlogo.py +++ b/pygmt/tests/test_pygmtlogo.py @@ -4,7 +4,7 @@ import pytest from pygmt import Figure -from pygmt.params import Axis, Position +from pygmt.params import Axis, Frame, Position from pygmt.src.pygmtlogo import _create_logo @@ -49,3 +49,40 @@ def test_pygmtlogo_circle_no_wordmark(): color=False, ) return fig + + +@pytest.mark.mpl_image_compare +def test_pygmtlogo_circle_horizontal_wordmark(): + """ + Test the PyGMT circular 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)), + ) + fig.pygmtlogo( + position=Position((0, 8.5), anchor="ML", cstype="mapcoords"), + theme="light", + wordmark="horizontal", + ) + fig.pygmtlogo( + position=Position((0, 6), anchor="ML", cstype="mapcoords"), + theme="dark", + wordmark="horizontal", + ) + fig.pygmtlogo( + position=Position((0, 3.5), anchor="ML", cstype="mapcoords"), + theme="light", + color=False, + wordmark="horizontal", + ) + fig.pygmtlogo( + position=Position((0, 1), anchor="ML", cstype="mapcoords"), + theme="dark", + color=False, + wordmark="horizontal", + ) + return fig