[librsvg: 1/9] DrawingCtx.compute_path_extents(): new function




commit 519fb8599483c676fd53edadd1bc37630f694a02
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Oct 5 19:37:39 2022 -0500

    DrawingCtx.compute_path_extents(): new function
    
    Let's try computing a shape's extents, to form its bounding box,
    outside of the drawing code.  First, a function to call
    cairo_path_extents().
    
    In the future we can do this with the kurbo crate, hopefully.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/757>

 src/drawing_ctx.rs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 3a617e066..8c4263119 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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]