[librsvg: 6/7] Handle.get_pixbuf_sub() - return an empty pixbuf if the dimensions are zero



commit f15c1e6cd2df58884fb4c2a17abc738183dc92f4
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Feb 26 16:48:29 2019 -0600

    Handle.get_pixbuf_sub() - return an empty pixbuf if the dimensions are zero

 rsvg_internals/src/handle.rs       | 6 +++++-
 rsvg_internals/src/pixbuf_utils.rs | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index d24450f5..21c6fc6e 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -28,7 +28,7 @@ use drawing_ctx::{DrawingCtx, RsvgRectangle};
 use error::{set_gerror, DefsLookupErrorKind, LoadingError, RenderingError};
 use length::RsvgLength;
 use node::RsvgNode;
-use pixbuf_utils::pixbuf_from_surface;
+use pixbuf_utils::{empty_pixbuf, pixbuf_from_surface};
 use structure::{IntrinsicDimensions, NodeSvg};
 use surface_utils::{shared_surface::SharedImageSurface, shared_surface::SurfaceType};
 use svg::Svg;
@@ -645,6 +645,10 @@ impl Handle {
 
         let dimensions = self.get_dimensions()?;
 
+        if dimensions.width == 0 || dimensions.height == 0 {
+            return empty_pixbuf();
+        }
+
         let surface =
             ImageSurface::create(cairo::Format::ARgb32, dimensions.width, dimensions.height)?;
 
diff --git a/rsvg_internals/src/pixbuf_utils.rs b/rsvg_internals/src/pixbuf_utils.rs
index c31e6869..913d68cb 100644
--- a/rsvg_internals/src/pixbuf_utils.rs
+++ b/rsvg_internals/src/pixbuf_utils.rs
@@ -39,7 +39,7 @@ fn pixbuf_new(width: i32, height: i32) -> Result<Pixbuf, RenderingError> {
     }
 }
 
-fn empty_pixbuf() -> Result<Pixbuf, RenderingError> {
+pub fn empty_pixbuf() -> Result<Pixbuf, RenderingError> {
     // GdkPixbuf does not allow zero-sized pixbufs, but Cairo allows zero-sized
     // surfaces.  In this case, return a 1-pixel transparent pixbuf.
 


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