Skip to content

Commit

Permalink
Fix #152 Add dev.capabilities support
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Oct 11, 2023
1 parent 5f9d18a commit 2cd6e62
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# svglite (development version)

* Windows: use libpng included with Rtools on R 4.2 and up.
* Add support for `dev.capabilities()`

# svglite 2.1.1

Expand Down
42 changes: 41 additions & 1 deletion src/devSVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,40 @@ void svg_release_mask(SEXP ref, pDevDesc dd) {
}
}

SEXP svg_capabilities(SEXP capabilities) {
#if R_GE_version >= 15
// Pattern support
SEXP pat = PROTECT(Rf_allocVector(INTSXP, 3));
INTEGER(pat)[0] = R_GE_linearGradientPattern;
INTEGER(pat)[1] = R_GE_radialGradientPattern;
INTEGER(pat)[2] = R_GE_tilingPattern;
SET_VECTOR_ELT(capabilities, R_GE_capability_patterns, pat);
UNPROTECT(1);

// Clipping path support
SET_VECTOR_ELT(capabilities, R_GE_capability_clippingPaths, Rf_ScalarInteger(1));

// Mask support
SEXP masks = PROTECT(Rf_allocVector(INTSXP, 2));
INTEGER(masks)[0] = R_GE_alphaMask;
INTEGER(masks)[1] = R_GE_luminanceMask;
SET_VECTOR_ELT(capabilities, R_GE_capability_masks, masks);
UNPROTECT(1);

// Group composition
SET_VECTOR_ELT(capabilities, R_GE_capability_compositing, Rf_ScalarInteger(0));
UNPROTECT(1);

// Group transformation
SET_VECTOR_ELT(capabilities, R_GE_capability_transformations, Rf_ScalarInteger(0));

// Path stroking and filling
SET_VECTOR_ELT(capabilities, R_GE_capability_paths, Rf_ScalarInteger(0));

#endif
return capabilities;
}

pDevDesc svg_driver_new(SvgStreamPtr stream, int bg, double width,
double height, double pointsize,
bool standalone, cpp11::list& aliases,
Expand Down Expand Up @@ -1401,15 +1435,21 @@ pDevDesc svg_driver_new(SvgStreamPtr stream, int bg, double width,
dd->ipr[1] = 1.0 / (72.0 * scaling);

// Capabilities
#if R_GE_version >= 15
dd->capabilities = svg_capabilities;
#endif
dd->canClip = TRUE;
#if R_GE_version >= 14
dd->deviceClip = TRUE;
#endif
dd->canHAdj = 1;
dd->canChangeGamma = FALSE;
dd->displayListOn = FALSE;
dd->haveTransparency = 2;
dd->haveTransparentBg = 2;

#if R_GE_version >= 13
dd->deviceVersion = R_GE_definitions;
dd->deviceVersion = 15; //R_GE_group;
#endif

dd->deviceSpecific = new SVGDesc(stream, standalone, aliases, webfonts, file,
Expand Down

0 comments on commit 2cd6e62

Please sign in to comment.