diff --git a/.gitignore b/.gitignore index 9579a3846a8..fcdb05ae2f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build ?build ?build-mp +Testing .*~ cmake/ConfigUser.cmake cmake/ConfigUserAdvanced.cmake @@ -12,6 +13,8 @@ src/newsuppl* doc/examples/**/*.mp4 doc/examples/**/*.png doc/examples/**/*.gif +test/**/*.ps +!test/**/*.ps.dvc .vscode cmake/ConfigUser.cmake.orig cmake/ConfigUserAdvanced.cmake.orig diff --git a/src/postscriptlight.c b/src/postscriptlight.c index a1df1ada0e0..0ad399699dc 100644 --- a/src/postscriptlight.c +++ b/src/postscriptlight.c @@ -5166,12 +5166,27 @@ int PSL_setcolor (struct PSL_CTRL *PSL, double rgb[], int mode) { if (PSL_eq (rgb[0], -2.0) || PSL_eq (rgb[0], -1.0)) return (PSL_NO_ERROR); /* Settings to be ignored */ if (PSL_same_rgb (rgb, PSL->current.rgb[mode])) return (PSL_NO_ERROR); /* Same color as already set */ - /* Because psl_putcolor does not set transparency if it is 0%, we reset it here when needed */ - if (PSL_eq (rgb[3], 0.0) && !PSL_eq (PSL->current.rgb[mode][3], 0.0)) + /* Guard: When setting stroke or fill with transparency, preserve the other channel's transparency */ + if (!PSL_eq (rgb[3], 0.0) && (mode == PSL_IS_STROKE || mode == PSL_IS_FILL)) { + double transp[2], rgb_copy[4]; + /* Preserve current transparencies and update only the relevant channel */ + transp[PSL_FILL_TRANSP] = (mode == PSL_IS_FILL) ? rgb[3] : PSL->current.rgb[PSL_IS_FILL][3]; + transp[PSL_PEN_TRANSP] = (mode == PSL_IS_STROKE) ? rgb[3] : PSL->current.rgb[PSL_IS_STROKE][3]; + /* Set transparency explicitly for both channels */ + PSL_command (PSL, "%.12g %.12g /%s PSL_transp\n", 1.0 - transp[PSL_FILL_TRANSP], 1.0 - transp[PSL_PEN_TRANSP], PSL->current.transparency_mode); + /* Make a copy with transparency zeroed out for psl_putcolor to avoid double-setting */ + PSL_rgb_copy (rgb_copy, rgb); + rgb_copy[3] = 0.0; + PSL_command (PSL, "%s\n", psl_putcolor (PSL, rgb_copy, 0)); + } + else { + /* Because psl_putcolor does not set transparency if it is 0%, we reset it here when needed */ + if (PSL_eq (rgb[3], 0.0) && !PSL_eq (PSL->current.rgb[mode][3], 0.0)) PSL_command (PSL, "%.12g %.12g /Normal PSL_transp ", PSL->init.transparencies[PSL_FILL_TRANSP], PSL->init.transparencies[PSL_PEN_TRANSP]); - /* Then, finally, set the color using psl_putcolor */ - PSL_command (PSL, "%s\n", psl_putcolor (PSL, rgb, 0)); + /* Then, finally, set the color using psl_putcolor */ + PSL_command (PSL, "%s\n", psl_putcolor (PSL, rgb, 0)); + } /* Update the current stroke/fill color information */ diff --git a/test/baseline/.gitignore b/test/baseline/.gitignore index a30031e47ab..984083bd9da 100644 --- a/test/baseline/.gitignore +++ b/test/baseline/.gitignore @@ -55,7 +55,6 @@ /pscontour /psclip /project -/postscriptlight /ogr /nearneighbor /movie diff --git a/test/baseline/postscriptlight.dvc b/test/baseline/postscriptlight.dvc deleted file mode 100644 index b5251baa584..00000000000 --- a/test/baseline/postscriptlight.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: e5ec08fe1ffe6b7a29733983a3dc988b.dir - nfiles: 1 - path: postscriptlight diff --git a/test/baseline/postscriptlight/fillTransparency.ps.dvc b/test/baseline/postscriptlight/fillTransparency.ps.dvc new file mode 100644 index 00000000000..ced6e64c5bb --- /dev/null +++ b/test/baseline/postscriptlight/fillTransparency.ps.dvc @@ -0,0 +1,5 @@ +outs: +- md5: cd022252f83b80a3c67e52094323d52d + size: 26087 + hash: md5 + path: fillTransparency.ps diff --git a/test/postscriptlight/fillTransparency.sh b/test/postscriptlight/fillTransparency.sh new file mode 100755 index 00000000000..43166ab8e76 --- /dev/null +++ b/test/postscriptlight/fillTransparency.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env -S bash -ex +# GMT modern mode bash template +# Date: 2026-01-21T12:44:22 +# User: solarsmith +# Purpose: Purpose of this script +set -e +export GMT_SESSION_NAME=$$ # Set a unique session name + +gmt begin fillTransparency ps + gmt basemap -R-2/2/-2/2 -JX10c/4c -B + echo -1 0 | gmt plot -Ss1c -W1p,blue@60 -Gbrown + echo 0 0 | gmt plot -Ss1c -W1p,blue -Gbrown@30 + echo 1 0 | gmt plot -Ss1c -W1p,blue@60 -Gbrown@30 +gmt end \ No newline at end of file