[librsvg/librsvg-2.48] Move the implementation of get_dimensions_sub to c_api
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.48] Move the implementation of get_dimensions_sub to c_api
- Date: Wed, 29 Apr 2020 18:05:52 +0000 (UTC)
commit 203845064b05bfeb1c9b8bb12b0df7094edde6ff
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Apr 24 19:42:00 2020 -0500
Move the implementation of get_dimensions_sub to c_api
librsvg/c_api.rs | 48 ++++++++++++++++++++++++++++++++++----------
rsvg_internals/src/handle.rs | 43 ---------------------------------------
2 files changed, 37 insertions(+), 54 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 2e24776f..69613454 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -682,9 +682,41 @@ impl CHandle {
fn get_dimensions_sub(&self, id: Option<&str>) -> Result<RsvgDimensionData, RenderingError> {
let handle = self.get_handle_ref()?;
let inner = self.inner.borrow();
- handle
- .get_dimensions_sub(id, inner.dpi, &inner.size_callback, inner.is_testing)
- .map_err(warn_on_invalid_id)
+
+ // This function is probably called from the cairo_render functions,
+ // or is being erroneously called within the size_func.
+ // To prevent an infinite loop we are saving the state, and
+ // returning a meaningless size.
+ if inner.size_callback.get_in_loop() {
+ return Ok(RsvgDimensionData {
+ width: 1,
+ height: 1,
+ em: 1.0,
+ ex: 1.0,
+ });
+ }
+
+ inner.size_callback.start_loop();
+
+ let res = handle
+ .get_geometry_sub(id, inner.dpi, inner.is_testing)
+ .and_then(|(ink_r, _)| {
+ let width = ink_r.width().round() as libc::c_int;
+ let height = ink_r.height().round() as libc::c_int;
+
+ let (w, h) = inner.size_callback.call(width, height);
+
+ Ok(RsvgDimensionData {
+ width: w,
+ height: h,
+ em: ink_r.width(),
+ ex: ink_r.height(),
+ })
+ });
+
+ inner.size_callback.end_loop();
+
+ res.map_err(warn_on_invalid_id)
}
fn get_position_sub(&self, id: Option<&str>) -> Result<RsvgPositionData, RenderingError> {
@@ -728,18 +760,12 @@ impl CHandle {
width: f64::from(dimensions.width),
height: f64::from(dimensions.height),
};
-
+
self.render_layer(cr, id, &viewport)
}
fn get_pixbuf_sub(&self, id: Option<&str>) -> Result<Pixbuf, RenderingError> {
- let handle = self.get_handle_ref()?;
- let inner = self.inner.borrow();
-
- let dpi = inner.dpi;
- let is_testing = inner.is_testing;
-
- let dimensions = handle.get_dimensions_sub(None, dpi, &inner.size_callback, is_testing)?;
+ let dimensions = self.get_dimensions_sub(None)?;
if dimensions.width == 0 || dimensions.height == 0 {
return empty_pixbuf();
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index a2fecb40..b9f96ea9 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -217,49 +217,6 @@ impl Handle {
}
}
- pub fn get_dimensions_sub(
- &self,
- id: Option<&str>,
- dpi: Dpi,
- size_callback: &SizeCallback,
- is_testing: bool,
- ) -> Result<RsvgDimensionData, RenderingError> {
- // This function is probably called from the cairo_render functions,
- // or is being erroneously called within the size_func.
- // To prevent an infinite loop we are saving the state, and
- // returning a meaningless size.
- if size_callback.get_in_loop() {
- return Ok(RsvgDimensionData {
- width: 1,
- height: 1,
- em: 1.0,
- ex: 1.0,
- });
- }
-
- size_callback.start_loop();
-
- let res = self
- .get_geometry_sub(id, dpi, is_testing)
- .and_then(|(ink_r, _)| {
- let width = ink_r.width().round() as libc::c_int;
- let height = ink_r.height().round() as libc::c_int;
-
- let (w, h) = size_callback.call(width, height);
-
- Ok(RsvgDimensionData {
- width: w,
- height: h,
- em: ink_r.width(),
- ex: ink_r.height(),
- })
- });
-
- size_callback.end_loop();
-
- res
- }
-
pub fn get_position_sub(
&self,
id: Option<&str>,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]