diff --git a/pygmt/src/pygmtlogo.py b/pygmt/src/pygmtlogo.py index 93ad9cbcc3b..b73c575cfaf 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.""" @@ -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: @@ -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) diff --git a/pygmt/tests/baseline/test_pygmtlogo_design_circle-horizontal.png.dvc b/pygmt/tests/baseline/test_pygmtlogo_design_circle-horizontal.png.dvc index 55cb442316c..2cfbd3a8396 100644 --- a/pygmt/tests/baseline/test_pygmtlogo_design_circle-horizontal.png.dvc +++ b/pygmt/tests/baseline/test_pygmtlogo_design_circle-horizontal.png.dvc @@ -1,5 +1,5 @@ outs: -- md5: 8924c7d80afcc92df4e77e6856b553a4 - size: 336254 +- md5: 44a9a200fbac4c868b69cb1c13e6dfc5 + size: 320394 hash: md5 path: test_pygmtlogo_design_circle-horizontal.png diff --git a/pygmt/tests/baseline/test_pygmtlogo_wordmark_horizontal_circle.png.dvc b/pygmt/tests/baseline/test_pygmtlogo_wordmark_horizontal_circle.png.dvc new file mode 100644 index 00000000000..b73cf065b0f --- /dev/null +++ b/pygmt/tests/baseline/test_pygmtlogo_wordmark_horizontal_circle.png.dvc @@ -0,0 +1,5 @@ +outs: +- md5: 9715eb13bec45201818d701970a529c8 + size: 63949 + hash: md5 + path: test_pygmtlogo_wordmark_horizontal_circle.png diff --git a/pygmt/tests/test_pygmtlogo.py b/pygmt/tests/test_pygmtlogo.py index 6280a6573b1..9565802bcf0 100644 --- a/pygmt/tests/test_pygmtlogo.py +++ b/pygmt/tests/test_pygmtlogo.py @@ -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