Skip to content

(#930): Validate all clipPath and mask transforms

Previously, an invalid "transform" property specified for clipPath would bubble up as a non-recoverable "invalid matrix" error from Cairo, stopping rendering at that point. Instead, we want to validate all transforms and just not render the offending element.

This commit has many changes:

  • Introduce a ValidTransform newtype, created with "impl TryFrom for Transform". This sees if the transform is invertible before wrapping it. The idea is to do all transform operations first, then see if the result is valid by trying to convert to a ValidTransform.

  • There is no "impl From for cairo::Matrix" anymore, but there is From. That way, we guarantee that an unvalidated transform cannot be easily set on a Cairo context.

  • DrawingCtx::get_transform() returns a ValidTransform, since a) it comes from the cr, and Cairo already validated that transform for us. Otherwise, the cr would have been in an error state.

  • There is a new variant RenderingError::InvalidTransform, which lets us use "?" everywhere as normal. This error case is caught in Node::draw() and the node is just not drawn. Eventually we can move to a scheme where we distinguish between fatal errors (e.g. RenderingError::LimitExceeded) and recoverable ones.

Merge request reports