[librsvg] Remove RsvgViewBox; return an additional gboolean from rsvg_node_svg_get_view_box()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Remove RsvgViewBox; return an additional gboolean from rsvg_node_svg_get_view_box()
- Date: Sat, 23 Jun 2018 02:24:34 +0000 (UTC)
commit 9c0af468078e1e230679751b03641c76b15b5218
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Jun 22 20:13:30 2018 -0500
Remove RsvgViewBox; return an additional gboolean from rsvg_node_svg_get_view_box()
The only purpose of the "active" field in
typedef struct {
cairo_rectangle_t rect;
gboolean active;
} RsvgViewBox;
was for rsvg_node_svg_get_view_box() to return whether the <svg>
element actually had a viewBox attribute. If not, the .rect was
set to all-zeros.
We get rid of this struct, and return a cairo_rectangle_t directly
from that function plus an extra boolean.
librsvg/rsvg-handle.c | 21 ++++++++++++++++-----
librsvg/rsvg-private.h | 6 ------
librsvg/rsvg-structure.h | 8 ++++----
rsvg_internals/src/lib.rs | 2 --
rsvg_internals/src/structure.rs | 30 ++++++++++++++++++++++++++++--
rsvg_internals/src/viewbox.rs | 33 ---------------------------------
6 files changed, 48 insertions(+), 52 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 14eb0d34..46cd47da 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -913,7 +913,8 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
RsvgDrawingCtx *draw;
RsvgNode *sself = NULL;
RsvgLength root_width, root_height;
- RsvgViewBox root_vbox;
+ gboolean has_root_vbox;
+ cairo_rectangle_t root_vbox;
gboolean handle_subelement = TRUE;
@@ -940,10 +941,10 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
g_assert (rsvg_node_get_type (handle->priv->treebase) == RSVG_NODE_TYPE_SVG);
rsvg_node_svg_get_size (handle->priv->treebase, &root_width, &root_height);
- root_vbox = rsvg_node_svg_get_view_box (handle->priv->treebase);
+ has_root_vbox = rsvg_node_svg_get_view_box (handle->priv->treebase, &root_vbox);
if (!id) {
- if ((root_width.unit == LENGTH_UNIT_PERCENT || root_height.unit == LENGTH_UNIT_PERCENT) &&
!root_vbox.active)
+ if ((root_width.unit == LENGTH_UNIT_PERCENT || root_height.unit == LENGTH_UNIT_PERCENT) &&
!has_root_vbox)
handle_subelement = TRUE;
else
handle_subelement = FALSE;
@@ -976,10 +977,20 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
cairo_destroy (cr);
cairo_surface_destroy (target);
} else {
+ double vbox_width, vbox_height;
+
+ if (has_root_vbox) {
+ vbox_width = root_vbox.width;
+ vbox_height = root_vbox.height;
+ } else {
+ vbox_width = 0.0;
+ vbox_height = 0.0;
+ }
+
dimension_data->width = (int) (rsvg_length_hand_normalize (&root_width, handle->priv->dpi_x,
- root_vbox.rect.width, 12) + 0.5);
+ vbox_width, 12) + 0.5);
dimension_data->height = (int) (rsvg_length_hand_normalize (&root_height, handle->priv->dpi_y,
- root_vbox.rect.height, 12) + 0.5);
+ vbox_height, 12) + 0.5);
}
dimension_data->em = dimension_data->width;
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 1e53fc1a..3992b3fe 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -175,12 +175,6 @@ struct RsvgHandlePrivate {
#endif
};
-/* Keep this in sync with rust/src/viewbox.rs::RsvgViewBox */
-typedef struct {
- cairo_rectangle_t rect;
- gboolean active;
-} RsvgViewBox;
-
/* Keep this in sync with rust/src/length.rs:LengthUnit */
typedef enum {
LENGTH_UNIT_DEFAULT,
diff --git a/librsvg/rsvg-structure.h b/librsvg/rsvg-structure.h
index 43a34d34..72bb47b7 100644
--- a/librsvg/rsvg-structure.h
+++ b/librsvg/rsvg-structure.h
@@ -34,15 +34,15 @@
G_BEGIN_DECLS
-/* Implemented in rust/src/structure.rs */
+/* Implemented in rsvg_internals/src/structure.rs */
G_GNUC_INTERNAL
void rsvg_node_svg_get_size (RsvgNode *node, RsvgLength *out_width, RsvgLength *out_height);
-/* Implemented in rust/src/structure.rs */
+/* Implemented in rsvg_internals/src/structure.rs */
G_GNUC_INTERNAL
-RsvgViewBox rsvg_node_svg_get_view_box (RsvgNode *node);
+gboolean rsvg_node_svg_get_view_box (RsvgNode *node, cairo_rectangle_t *out_vbox);
-/* Implemented in rust/src/structure.rs */
+/* Implemented in rsvg_internals/src/structure.rs */
G_GNUC_INTERNAL
void rsvg_node_svg_apply_atts (RsvgNode *node, RsvgHandle *handle);
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index da8ad486..1f34497b 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -99,8 +99,6 @@ pub use structure::{rsvg_node_svg_apply_atts, rsvg_node_svg_get_size, rsvg_node_
pub use text::{rsvg_node_chars_append, rsvg_node_chars_new};
-pub use viewbox::RsvgViewBox;
-
#[macro_use]
mod coord_units;
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index aaf48071..54f7afcb 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -1,6 +1,11 @@
use std::cell::Cell;
use std::cell::RefCell;
+use cairo;
+use cairo_sys;
+use glib::translate::*;
+use glib_sys;
+
use aspect_ratio::*;
use attributes::Attribute;
use drawing_ctx::DrawingCtx;
@@ -409,8 +414,13 @@ pub extern "C" fn rsvg_node_svg_get_size(
}
#[no_mangle]
-pub extern "C" fn rsvg_node_svg_get_view_box(raw_node: *const RsvgNode) -> RsvgViewBox {
+pub extern "C" fn rsvg_node_svg_get_view_box(
+ raw_node: *const RsvgNode,
+ out_vbox: *mut cairo_sys::cairo_rectangle_t,
+) -> glib_sys::gboolean {
assert!(!raw_node.is_null());
+ assert!(!out_vbox.is_null());
+
let node: &RsvgNode = unsafe { &*raw_node };
let mut vbox: Option<ViewBox> = None;
@@ -419,7 +429,23 @@ pub extern "C" fn rsvg_node_svg_get_view_box(raw_node: *const RsvgNode) -> RsvgV
vbox = svg.vbox.get();
});
- RsvgViewBox::from(vbox)
+ if let Some(vb) = vbox {
+ unsafe {
+ *out_vbox = vb.0;
+ }
+ true.to_glib()
+ } else {
+ unsafe {
+ *out_vbox = cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: 0.0,
+ height: 0.0,
+ };
+ }
+
+ false.to_glib()
+ }
}
#[no_mangle]
diff --git a/rsvg_internals/src/viewbox.rs b/rsvg_internals/src/viewbox.rs
index 2ed1f756..155a70e1 100644
--- a/rsvg_internals/src/viewbox.rs
+++ b/rsvg_internals/src/viewbox.rs
@@ -1,23 +1,11 @@
use cairo;
use cssparser::Parser;
-use glib;
-use glib_sys;
use error::*;
use parsers;
use parsers::Parse;
use parsers::{ListLength, ParseError};
-use self::glib::translate::*;
-
-// Keep this in sync with rsvg-private.h:RsvgViewBox
-#[repr(C)]
-#[derive(Debug, Copy, Clone, PartialEq)]
-pub struct RsvgViewBox {
- pub rect: cairo::Rectangle,
- active: glib_sys::gboolean,
-}
-
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ViewBox(pub cairo::Rectangle);
@@ -37,27 +25,6 @@ impl ViewBox {
}
}
-impl From<Option<ViewBox>> for RsvgViewBox {
- fn from(v: Option<ViewBox>) -> RsvgViewBox {
- if let Some(vb) = v {
- RsvgViewBox {
- rect: vb.0,
- active: true.to_glib(),
- }
- } else {
- RsvgViewBox {
- rect: cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 0.0,
- height: 0.0,
- },
- active: false.to_glib(),
- }
- }
- }
-}
-
impl Parse for ViewBox {
type Data = ();
type Err = AttributeError;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]