summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2022-10-05 19:37:39 -0500
committerFederico Mena Quintero <federico@gnome.org>2022-10-06 19:14:26 -0500
commit519fb8599483c676fd53edadd1bc37630f694a02 (patch)
treec8832aa04ccb6120cca821a1aa88873581d04bae
parente9f6b7dfcde2ce59e0d163b44766ddb03eddb72f (diff)
downloadlibrsvg-519fb8599483c676fd53edadd1bc37630f694a02.tar.gz
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>
-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,