summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/drawing_ctx.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 3a617e06..8c426311 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1257,6 +1257,20 @@ impl DrawingCtx {
Ok(())
}
+ pub fn compute_path_extents(&self, path: &Path) -> Result<Option<Rect>, RenderingError> {
+ if path.is_empty() {
+ return Ok(None);
+ }
+
+ let surface = cairo::RecordingSurface::create(cairo::Content::ColorAlpha, None)?;
+ let cr = cairo::Context::new(&surface)?;
+
+ path.to_cairo(&cr, false)?;
+ let (x0, y0, x1, y1) = cr.path_extents()?;
+
+ Ok(Some(Rect::new(x0, y0, x1, y1)))
+ }
+
pub fn draw_shape(
&mut self,
view_params: &ViewParams,