[librsvg/rustify-rsvg-convert] rsvg-convert: use legacy sizing also for layers
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustify-rsvg-convert] rsvg-convert: use legacy sizing also for layers
- Date: Sat, 9 Jan 2021 09:58:32 +0000 (UTC)
commit 2937392e1bb69a951bb72a8ac3bccf803645823b
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 9 10:54:41 2021 +0100
rsvg-convert: use legacy sizing also for layers
src/bin/rsvg-convert/main.rs | 20 ++++++++++----------
src/c_api/handle.rs | 19 +++++--------------
src/c_api/sizing.rs | 20 ++++++++++++++++++--
3 files changed, 33 insertions(+), 26 deletions(-)
---
diff --git a/src/bin/rsvg-convert/main.rs b/src/bin/rsvg-convert/main.rs
index e0719080..78fee0f2 100644
--- a/src/bin/rsvg-convert/main.rs
+++ b/src/bin/rsvg-convert/main.rs
@@ -65,8 +65,15 @@ fn main() {
if target.is_none() {
let (width, height) = renderer
- .legacy_document_size_in_pixels()
- .unwrap_or_else(|e| exit!("Error rendering SVG {}: {}", input, e));
+ .legacy_layer_size_in_pixels(args.export_id())
+ .unwrap_or_else(|e| match e {
+ RenderingError::IdNotFound => exit!(
+ "File {} does not have an object with id \"{}\")",
+ input,
+ args.export_id().unwrap()
+ ),
+ _ => exit!("Error rendering SVG {}: {}", input, e),
+ });
let strategy = match (args.width, args.height) {
// when w and h are not specified, scale to the requested zoom (if any)
@@ -116,14 +123,7 @@ fn main() {
surface
.render(&renderer, &cr, args.export_id())
- .unwrap_or_else(|e| match e {
- RenderingError::IdNotFound => exit!(
- "File {} does not have an object with id \"{}\")",
- input,
- args.export_id().unwrap()
- ),
- _ => exit!("Error rendering SVG {}: {}", input, e),
- });
+ .unwrap_or_else(|e| exit!("Error rendering SVG {}: {}", input, e));
}
}
diff --git a/src/c_api/handle.rs b/src/c_api/handle.rs
index c17fb73c..c328d0af 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -658,8 +658,7 @@ impl Drop for SizeCallback {
}
}
}
-
-trait CairoRectangleExt {
+pub trait CairoRectangleExt {
fn from_size(width: f64, height: f64) -> Self;
}
@@ -976,14 +975,10 @@ impl CHandle {
let handle = self.get_handle_ref()?;
let renderer = self.make_renderer(&handle);
- match id {
- Some(id) => Ok(renderer.geometry_for_layer(Some(id), &unit_rectangle())?),
-
- None => Ok(renderer.legacy_document_size_in_pixels().map(|(w, h)| {
- let rect = cairo::Rectangle::from_size(w, h);
- (rect, rect)
- })?),
- }
+ Ok(renderer.legacy_layer_size_in_pixels(id).map(|(w, h)| {
+ let rect = cairo::Rectangle::from_size(w, h);
+ (rect, rect)
+ })?)
}
fn set_stylesheet(&self, css: &str) -> Result<(), LoadingError> {
@@ -1133,10 +1128,6 @@ impl CHandle {
}
}
-pub(crate) fn unit_rectangle() -> cairo::Rectangle {
- cairo::Rectangle::from_size(1.0, 1.0)
-}
-
fn is_rsvg_handle(obj: *const RsvgHandle) -> bool {
unsafe { instance_of::<CHandle>(obj as *const _) }
}
diff --git a/src/c_api/sizing.rs b/src/c_api/sizing.rs
index fe1e893d..213f5d4f 100644
--- a/src/c_api/sizing.rs
+++ b/src/c_api/sizing.rs
@@ -1,7 +1,7 @@
use crate::api::{CairoRenderer, IntrinsicDimensions, Length, RenderingError};
use float_cmp::approx_eq;
-use super::handle::unit_rectangle;
+use super::handle::CairoRectangleExt;
pub trait LegacySize {
/// Returns the SVG's size suitable for the legacy C API.
@@ -13,6 +13,9 @@ pub trait LegacySize {
///
/// See https://www.w3.org/TR/css-images-3/#sizing-terms for terminology and logic.
fn legacy_document_size_in_pixels(&self) -> Result<(f64, f64), RenderingError>;
+
+ /// Returns the specified layer's size suitable for the legacy C API.
+ fn legacy_layer_size_in_pixels(&self, id: Option<&str>) -> Result<(f64, f64), RenderingError>;
}
impl<'a> LegacySize for CairoRenderer<'a> {
@@ -25,11 +28,24 @@ impl<'a> LegacySize for CairoRenderer<'a> {
// We have a size directly computed from the <svg> attributes
Ok(dim)
} else {
- // Compute the extents of all objects in the SVG
let (ink_r, _) = self.geometry_for_layer(None, &unit_rectangle())?;
Ok((ink_r.width, ink_r.height))
}
}
+
+ fn legacy_layer_size_in_pixels(&self, id: Option<&str>) -> Result<(f64, f64), RenderingError> {
+ match id {
+ Some(_) => {
+ let (ink_r, _) = self.geometry_for_layer(id, &unit_rectangle())?;
+ Ok((ink_r.width, ink_r.height))
+ }
+ None => self.legacy_document_size_in_pixels(),
+ }
+ }
+}
+
+fn unit_rectangle() -> cairo::Rectangle {
+ cairo::Rectangle::from_size(1.0, 1.0)
}
/// If the width and height are in percentage units, computes a size equal to the
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]