[librsvg/wip/dimensions-api: 10/11] Svg::get_intrinsic_dimensions(): New method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/dimensions-api: 10/11] Svg::get_intrinsic_dimensions(): New method
- Date: Fri, 8 Feb 2019 01:38:46 +0000 (UTC)
commit 8afbe0d493062483d905f52e0e8a42a6eb0d46aa
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Feb 7 18:00:25 2019 -0600
Svg::get_intrinsic_dimensions(): New method
rsvg_internals/src/structure.rs | 18 ++++++++++++++++++
rsvg_internals/src/svg.rs | 11 ++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 04fb6e3b..ba2205d8 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -95,6 +95,14 @@ impl NodeTrait for NodeSwitch {
}
}
+/// Intrinsic dimensions of an SVG document fragment
+#[derive(Copy, Clone)]
+pub struct IntrinsicDimensions {
+ width: Option<LengthHorizontal>,
+ height: Option<LengthVertical>,
+ vbox: Option<ViewBox>,
+}
+
pub struct NodeSvg {
preserve_aspect_ratio: Cell<AspectRatio>,
x: Cell<LengthHorizontal>,
@@ -140,6 +148,16 @@ impl NodeSvg {
(_, _, _) => None,
}
}
+
+ pub fn get_intrinsic_dimensions(&self) -> IntrinsicDimensions {
+ // FIXME: width/height are Option<>, and we don't store that yet;
+ // we resolve to 100% for default values at parsing time.
+ IntrinsicDimensions {
+ width: Some(self.w.get()),
+ height: Some(self.h.get()),
+ vbox: self.vbox.get(),
+ }
+ }
}
impl NodeTrait for NodeSvg {
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index dc75d9d5..45caad2b 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -11,8 +11,9 @@ use allowed_url::{AllowedUrl, Fragment};
use error::LoadingError;
use handle::LoadOptions;
use io;
-use node::RsvgNode;
+use node::{NodeType, RsvgNode};
use properties::ComputedValues;
+use structure::{IntrinsicDimensions, NodeSvg};
use surface_utils::shared_surface::SharedImageSurface;
use xml::XmlState;
use xml2_load::xml_state_load_from_possibly_compressed_stream;
@@ -85,6 +86,14 @@ impl Svg {
pub fn lookup_image(&self, href: &str) -> Result<SharedImageSurface, LoadingError> {
self.images.borrow_mut().lookup(&self.load_options, href)
}
+
+ pub fn get_intrinsic_dimensions(&self) -> IntrinsicDimensions {
+ let root = self.root();
+
+ assert!(root.get_type() == NodeType::Svg);
+
+ root.with_impl(|svg: &NodeSvg| svg.get_intrinsic_dimensions())
+ }
}
struct Resources {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]