Skip to content

Commit c92deea

Browse files
committed
MPLCAIRO_SCRIPT_SURFACE.
1 parent 7927eb2 commit c92deea

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,12 @@ The API is similar:
390390
``cairo-script`` output
391391
-----------------------
392392

393-
Setting the ``MPLCAIRO_DEBUG`` environment variable to a non-empty value allows
394-
one to save figures (with ``savefig``) in the ``.cairoscript`` format, which is
395-
a "native script that matches the cairo drawing model". This may be helpful
396-
for troubleshooting purposes.
393+
Setting the ``MPLCAIRO_SCRIPT_SURFACE`` environment variable to ``vector``
394+
or ``raster`` allows one to save figures (with ``savefig``) in the
395+
``.cairoscript`` format, which is a "native script that matches the cairo
396+
drawing model". The value of the variable determines the rendering path used
397+
(e.g., whether marker stamping is used at all). This may be helpful for
398+
troubleshooting purposes.
397399

398400
Note that this may crash the process after the file is written, due to `cairo
399401
bug #104410 <cairo-104410_>`_.

lib/mplcairo/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _print_method(
255255
_print_method, GraphicsContextRendererCairo._for_svg_output)
256256
print_svgz = partialmethod(
257257
_print_method, GraphicsContextRendererCairo._for_svgz_output)
258-
if os.environ.get("MPLCAIRO_DEBUG"):
258+
if os.environ.get("MPLCAIRO_SCRIPT_SURFACE") in ["raster", "vector"]:
259259
print_cairoscript = partialmethod(
260260
_print_method, GraphicsContextRendererCairo._for_script_output)
261261

src/_util.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,16 @@ bool has_vector_surface(cairo_t* cr)
115115
case CAIRO_SURFACE_TYPE_PS:
116116
case CAIRO_SURFACE_TYPE_SVG:
117117
case CAIRO_SURFACE_TYPE_RECORDING:
118-
case CAIRO_SURFACE_TYPE_SCRIPT:
119118
return true;
119+
case CAIRO_SURFACE_TYPE_SCRIPT:
120+
if (auto script_surface =
121+
std::string{std::getenv("MPLCAIRO_SCRIPT_SURFACE")};
122+
script_surface == "raster") {
123+
return false;
124+
} else if (script_surface == "vector") {
125+
return true;
126+
}
127+
[[fallthrough]];
120128
default:
121129
throw
122130
std::invalid_argument(

0 commit comments

Comments
 (0)