[librsvg: 5/10] Make RsvgLength the #[repr(C)] type, separate from Length
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/10] Make RsvgLength the #[repr(C)] type, separate from Length
- Date: Wed, 13 Nov 2019 03:38:41 +0000 (UTC)
commit e628b7f43b5029ce6b16e5ea579e93ebd96a8ec1
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Nov 12 18:45:32 2019 -0600
Make RsvgLength the #[repr(C)] type, separate from Length
We'll modify Length next, to be exclusive for internal use.
librsvg/c_api.rs | 4 +--
librsvg_crate/src/lib.rs | 7 ++---
rsvg_internals/src/length.rs | 61 +++++++++++++++++++++++++++++---------------
3 files changed, 46 insertions(+), 26 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 6d6592e5..4bd2ed0d 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -1274,8 +1274,8 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_intrinsic_dimensions(
let h = d.height;
let r = d.vbox.map(RsvgRectangle::from);
- set_out_param(out_has_width, out_width, &w);
- set_out_param(out_has_height, out_height, &h);
+ set_out_param(out_has_width, out_width, &w.map(Into::into));
+ set_out_param(out_has_height, out_height, &h.map(Into::into));
set_out_param(out_has_viewbox, out_viewbox, &r);
}
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index 53a68030..e193ed85 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -102,10 +102,11 @@ use rsvg_internals::{Dpi, Handle, LoadOptions};
pub use rsvg_internals::{
DefsLookupErrorKind,
HrefError,
- Length,
+ Length as InternalLength,
LengthUnit,
LoadingError,
RenderingError,
+ RsvgLength as Length,
};
/// Builder for loading an [`SvgHandle`][SvgHandle].
@@ -402,8 +403,8 @@ impl<'a> CairoRenderer<'a> {
let d = self.handle.0.get_intrinsic_dimensions();
IntrinsicDimensions {
- width: d.width,
- height: d.height,
+ width: d.width.map(Into::into),
+ height: d.height.map(Into::into),
vbox: d.vbox.map(|v| cairo::Rectangle {
x: v.x,
y: v.y,
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index 3d802126..c25efd6a 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -39,14 +39,49 @@ use crate::parsers::Parse;
use crate::parsers::{finite_f32, ParseError};
use crate::properties::ComputedValues;
-/// Type alias for use by the [`librsvg_c_api`] crate.
+/// A CSS length value.
+///
+/// This is equivalent to [CSS lengths].
+///
+/// [CSS lengths]: https://www.w3.org/TR/CSS21/syndata.html#length-units
+///
+/// It is up to the calling application to convert lengths in non-pixel units
+/// (i.e. those where the [`unit`] field is not [`LengthUnit::Px`]) into something
+/// meaningful to the application. For example, if your application knows the
+/// dots-per-inch (DPI) it is using, it can convert lengths with [`unit`] in
+/// [`LengthUnit::In`] or other physical units.
///
-/// [`librsvg_c_api`]: ../../librsvg_c_api/index.html
-pub type RsvgLength = Length;
+/// [`unit`]: #structfield.unit
+/// [`LengthUnit::Px`]: enum.LengthUnit.html#variant.Px
+/// [`LengthUnit::In`]: enum.LengthUnit.html#variant.In
+// Keep this in sync with rsvg.h:RsvgLength
+#[repr(C)]
+#[derive(Debug, PartialEq, Copy, Clone)]
+pub struct RsvgLength {
+ /// Numeric part of the length
+ pub length: f64,
+
+ /// Unit part of the length
+ pub unit: LengthUnit,
+}
+
+impl From<Length> for RsvgLength {
+ fn from(l: Length) -> RsvgLength {
+ RsvgLength {
+ length: l.length,
+ unit: l.unit,
+ }
+ }
+}
+
+impl RsvgLength {
+ pub fn new(l: f64, unit: LengthUnit) -> RsvgLength {
+ RsvgLength { length: l, unit }
+ }
+}
/// Units for length values.
-///
-/// This needs to be kept in sync with `rsvg.h:RsvgUnit`.
+// This needs to be kept in sync with `rsvg.h:RsvgUnit`.
#[repr(C)]
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum LengthUnit {
@@ -280,22 +315,6 @@ define_length_type! {
}
/// A CSS length value.
-///
-/// This is equivalent to [CSS lengths].
-///
-/// [CSS lengths]: https://www.w3.org/TR/CSS21/syndata.html#length-units
-///
-/// It is up to the calling application to convert lengths in non-pixel units
-/// (i.e. those where the [`unit`] field is not [`LengthUnit::Px`]) into something
-/// meaningful to the application. For example, if your application knows the
-/// dots-per-inch (DPI) it is using, it can convert lengths with [`unit`] in
-/// [`LengthUnit::In`] or other physical units.
-///
-/// [`unit`]: #structfield.unit
-/// [`LengthUnit::Px`]: enum.LengthUnit.html#variant.Px
-/// [`LengthUnit::In`]: enum.LengthUnit.html#variant.In
-// Keep this in sync with rsvg.h:RsvgLength
-#[repr(C)]
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Length {
/// Numeric part of the length
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]