Commit 6456715b authored by Federico Mena Quintero's avatar Federico Mena Quintero
Browse files

rsvg_handle_get_intrinsic_dimensions(): New API

parent 8afbe0d4
Pipeline #57330 failed with stages
in 15 minutes and 53 seconds
......@@ -337,6 +337,13 @@ extern RsvgHandle *rsvg_handle_rust_new_from_stream_sync (GInputStream *input_st
extern RsvgHandle *rsvg_handle_rust_new_from_data (const guint8 *data,
gsize data_len,
GError **error);
extern void rsvg_handle_rust_get_intrinsic_dimensions (RsvgHandle *handle,
gboolean *out_has_width,
RsvgLength *out_width,
gboolean *out_has_height,
RsvgLength *out_height,
gboolean *out_has_viewbox,
RsvgRectangle *out_viewbox);
typedef struct {
RsvgHandleRust *rust_handle;
......@@ -1265,6 +1272,26 @@ rsvg_handle_set_size_callback (RsvgHandle *handle,
user_data_destroy);
}
void
rsvg_handle_get_intrinsic_dimensions (RsvgHandle *handle,
gboolean *out_has_width,
RsvgLength *out_width,
gboolean *out_has_height,
RsvgLength *out_height,
gboolean *out_has_viewbox,
RsvgRectangle *out_viewbox)
{
g_return_if_fail (RSVG_IS_HANDLE (handle));
rsvg_handle_rust_get_intrinsic_dimensions (handle,
out_has_width,
out_width,
out_has_height,
out_height,
out_has_viewbox,
out_viewbox);
}
/**
* rsvg_handle_internal_set_testing:
* @handle: a #RsvgHandle
......
......@@ -221,6 +221,14 @@ typedef struct {
RsvgUnit unit;
} RsvgLength;
void rsvg_handle_get_intrinsic_dimensions (RsvgHandle *handle,
gboolean *out_has_width,
RsvgLength *out_width,
gboolean *out_has_height,
RsvgLength *out_height,
gboolean *out_has_viewbox,
RsvgRectangle *out_viewbox);
/* GIO APIs */
/**
......
......@@ -914,6 +914,17 @@ impl From<cairo::Rectangle> for RsvgRectangle {
}
}
impl From<ViewBox> for RsvgRectangle {
fn from(vb: ViewBox) -> RsvgRectangle {
RsvgRectangle {
x: vb.x,
y: vb.y,
width: vb.width,
height: vb.height,
}
}
}
pub struct AcquiredNode(Rc<RefCell<Vec<RsvgNode>>>, RsvgNode);
impl Drop for AcquiredNode {
......
......@@ -24,9 +24,10 @@ use allowed_url::{AllowedUrl, Href};
use dpi::Dpi;
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 structure::NodeSvg;
use structure::{IntrinsicDimensions, NodeSvg};
use surface_utils::{shared_surface::SharedImageSurface, shared_surface::SurfaceType};
use svg::Svg;
use util::rsvg_g_warning;
......@@ -535,6 +536,13 @@ impl Handle {
self.read_stream_sync(stream, cancellable)
}
fn get_intrinsic_dimensions(&self) -> IntrinsicDimensions {
let svg_ref = self.svg.borrow();
let svg = svg_ref.as_ref().unwrap();
svg.get_intrinsic_dimensions()
}
}
// Keep these in sync with rsvg.h:RsvgHandleFlags
......@@ -1124,3 +1132,46 @@ pub unsafe extern "C" fn rsvg_handle_rust_new_from_data(
gobject_sys::g_object_unref(raw_stream as *mut _);
ret
}
unsafe fn set_out_param<T: Copy>(out_has_param: *mut glib_sys::gboolean, out_param: *mut T, value: &Option<T>) {
let has_value = if let Some(ref v) = *value {
if !out_param.is_null() {
*out_param = *v;
}
true
} else {
false
};
if !out_has_param.is_null() {
*out_has_param = has_value.to_glib();
}
}
#[no_mangle]
pub unsafe extern "C" fn rsvg_handle_rust_get_intrinsic_dimensions(
handle: *mut RsvgHandle,
out_has_width: *mut glib_sys::gboolean,
out_width: *mut RsvgLength,
out_has_height: *mut glib_sys::gboolean,
out_height: *mut RsvgLength,
out_has_viewbox: *mut glib_sys::gboolean,
out_viewbox: *mut RsvgRectangle,
) {
let rhandle = get_rust_handle(handle);
if !is_loaded(rhandle) {
return;
}
let d = rhandle.get_intrinsic_dimensions();
let w = d.width.map(|l| l.to_length());
let h = d.width.map(|l| l.to_length());
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_viewbox, out_viewbox, &r);
}
......@@ -7,6 +7,8 @@ use parsers::Parse;
use parsers::ParseError;
use properties::ComputedValues;
pub type RsvgLength = Length;
// Keep this in sync with rsvg.h:RsvgUnit
/// Units for length values
......@@ -80,6 +82,10 @@ macro_rules! define_length_type {
self.0.get_unitless()
}
pub fn to_length(&self) -> Length {
self.0
}
pub fn check_nonnegative(self) -> Result<Self, ValueErrorKind> {
if self.length() >= 0.0 {
Ok(self)
......@@ -179,7 +185,7 @@ define_length_type!(LengthBoth, LengthDir::Both);
// Keep this in sync with rsvg.h:RsvgLength
#[repr(C)]
#[derive(Debug, PartialEq, Copy, Clone)]
struct Length {
pub struct Length {
pub length: f64,
pub unit: LengthUnit,
}
......
......@@ -50,6 +50,7 @@ pub use handle::{
rsvg_handle_rust_get_dpi_y,
rsvg_handle_rust_get_flags,
rsvg_handle_rust_get_geometry_sub,
rsvg_handle_rust_get_intrinsic_dimensions,
rsvg_handle_rust_get_pixbuf_sub,
rsvg_handle_rust_get_position_sub,
rsvg_handle_rust_has_sub,
......
......@@ -98,9 +98,9 @@ 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 width: Option<LengthHorizontal>,
pub height: Option<LengthVertical>,
pub vbox: Option<ViewBox>,
}
pub struct NodeSvg {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment