[librsvg: 1/3] vbox: do not wrap a cairo rectangle
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/3] vbox: do not wrap a cairo rectangle
- Date: Sat, 19 Jan 2019 00:28:34 +0000 (UTC)
commit 0e1a758b4b6b91330c847f6e6184845d7919a97e
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Jan 18 18:39:07 2019 +0100
vbox: do not wrap a cairo rectangle
We never use the rect, accessing x, y, width and height directly
makes things clearer.
rsvg_internals/src/drawing_ctx.rs | 4 ++--
rsvg_internals/src/marker.rs | 12 ++++++------
rsvg_internals/src/pattern.rs | 12 ++++++------
rsvg_internals/src/structure.rs | 6 +++---
rsvg_internals/src/viewbox.rs | 16 ++++++++++------
rsvg_internals/src/viewport.rs | 12 ++++++------
6 files changed, 33 insertions(+), 29 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 45084ffc..51c0304a 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -214,8 +214,8 @@ impl DrawingCtx {
ViewParams {
dpi_x: self.dpi.x(),
dpi_y: self.dpi.y(),
- view_box_width: stack_top.0.width,
- view_box_height: stack_top.0.height,
+ view_box_width: stack_top.width,
+ view_box_height: stack_top.height,
view_box_stack: None,
}
}
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 4a291da2..3043a218 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -159,21 +159,21 @@ impl NodeMarker {
let params = if let Some(vbox) = self.vbox.get() {
let (_, _, w, h) = self.aspect.get().compute(
- vbox.0.width,
- vbox.0.height,
+ vbox.width,
+ vbox.height,
0.0,
0.0,
marker_width,
marker_height,
);
- if vbox.0.width.approx_eq_cairo(&0.0) || vbox.0.height.approx_eq_cairo(&0.0) {
+ if vbox.width.approx_eq_cairo(&0.0) || vbox.height.approx_eq_cairo(&0.0) {
return Ok(());
}
- affine.scale(w / vbox.0.width, h / vbox.0.height);
+ affine.scale(w / vbox.width, h / vbox.height);
- draw_ctx.push_view_box(vbox.0.width, vbox.0.height)
+ draw_ctx.push_view_box(vbox.width, vbox.height)
} else {
draw_ctx.push_view_box(marker_width, marker_height)
};
@@ -189,7 +189,7 @@ impl NodeMarker {
if !values.is_overflow() {
if let Some(vbox) = self.vbox.get() {
- draw_ctx.clip(vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
+ draw_ctx.clip(vbox.x, vbox.y, vbox.width, vbox.height);
} else {
draw_ctx.clip(0.0, 0.0, marker_width, marker_height);
}
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index 729db60c..d95effe3 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -373,20 +373,20 @@ impl PaintSource for NodePattern {
let _params = if let Some(vbox) = vbox {
// If there is a vbox, use that
let (mut x, mut y, w, h) = preserve_aspect_ratio.compute(
- vbox.0.width,
- vbox.0.height,
+ vbox.width,
+ vbox.height,
0.0,
0.0,
pattern_width * bbwscale,
pattern_height * bbhscale,
);
- x -= vbox.0.x * w / vbox.0.width;
- y -= vbox.0.y * h / vbox.0.height;
+ x -= vbox.x * w / vbox.width;
+ y -= vbox.y * h / vbox.height;
- caffine = cairo::Matrix::new(w / vbox.0.width, 0.0, 0.0, h / vbox.0.height, x, y);
+ caffine = cairo::Matrix::new(w / vbox.width, 0.0, 0.0, h / vbox.height, x, y);
- draw_ctx.push_view_box(vbox.0.width, vbox.0.height)
+ draw_ctx.push_view_box(vbox.width, vbox.height)
} else if content_units == PatternContentUnits(CoordUnits::ObjectBoundingBox) {
// If coords are in terms of the bounding box, use them
let bbrect = bbox.rect.unwrap();
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index a9044d5b..8f430808 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -127,9 +127,9 @@ impl NodeSvg {
pub fn get_size(&self, dpi: Dpi) -> Option<(i32, i32)> {
match (self.w.get(), self.h.get(), self.vbox.get()) {
- (w, h, Some(vb)) => Some((
- w.hand_normalize(dpi.x(), vb.0.width, 12.0).round() as i32,
- h.hand_normalize(dpi.y(), vb.0.height, 12.0).round() as i32,
+ (w, h, Some(vbox)) => Some((
+ w.hand_normalize(dpi.x(), vbox.width, 12.0).round() as i32,
+ h.hand_normalize(dpi.y(), vbox.height, 12.0).round() as i32,
)),
(w, h, None) if w.unit != LengthUnit::Percent && h.unit != LengthUnit::Percent => {
Some((
diff --git a/rsvg_internals/src/viewbox.rs b/rsvg_internals/src/viewbox.rs
index a26f8239..37c8d8f8 100644
--- a/rsvg_internals/src/viewbox.rs
+++ b/rsvg_internals/src/viewbox.rs
@@ -1,4 +1,3 @@
-use cairo;
use cssparser::Parser;
use error::*;
@@ -7,7 +6,12 @@ use parsers::Parse;
use parsers::{ListLength, ParseError};
#[derive(Debug, Copy, Clone, PartialEq)]
-pub struct ViewBox(pub cairo::Rectangle);
+pub struct ViewBox {
+ pub x: f64,
+ pub y: f64,
+ pub width: f64,
+ pub height: f64,
+}
impl ViewBox {
pub fn new(x: f64, y: f64, w: f64, h: f64) -> ViewBox {
@@ -16,12 +20,12 @@ impl ViewBox {
"width and height must not be negative"
);
- ViewBox(cairo::Rectangle {
+ ViewBox {
x,
y,
width: w,
height: h,
- })
+ }
}
}
@@ -44,12 +48,12 @@ impl Parse for ViewBox {
let (x, y, w, h) = (v[0], v[1], v[2], v[3]);
if w >= 0.0 && h >= 0.0 {
- Ok(ViewBox(cairo::Rectangle {
+ Ok(ViewBox {
x,
y,
width: w,
height: h,
- }))
+ })
} else {
Err(ValueErrorKind::Value(
"width and height must not be negative".to_string(),
diff --git a/rsvg_internals/src/viewport.rs b/rsvg_internals/src/viewport.rs
index 9d617eba..aec978f9 100644
--- a/rsvg_internals/src/viewport.rs
+++ b/rsvg_internals/src/viewport.rs
@@ -51,25 +51,25 @@ pub fn draw_in_viewport(
// the preserveAspectRatio attribute is only used if viewBox is specified
// https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
- if vbox.0.width.approx_eq_cairo(&0.0) || vbox.0.height.approx_eq_cairo(&0.0) {
+ if vbox.width.approx_eq_cairo(&0.0) || vbox.height.approx_eq_cairo(&0.0) {
// Width or height of 0 for the viewBox disables rendering of the element
// https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
return Ok(());
}
- let params = dc.push_view_box(vbox.0.width, vbox.0.height);
+ let params = dc.push_view_box(vbox.width, vbox.height);
let (x, y, w, h) =
- preserve_aspect_ratio.compute(vbox.0.width, vbox.0.height, vx, vy, vw, vh);
+ preserve_aspect_ratio.compute(vbox.width, vbox.height, vx, vy, vw, vh);
affine.translate(x, y);
- affine.scale(w / vbox.0.width, h / vbox.0.height);
- affine.translate(-vbox.0.x, -vbox.0.y);
+ affine.scale(w / vbox.width, h / vbox.height);
+ affine.translate(-vbox.x, -vbox.y);
dc.get_cairo_context().set_matrix(affine);
if do_clip && clip_mode == ClipMode::ClipToVbox {
- dc.clip(vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
+ dc.clip(vbox.x, vbox.y, vbox.width, vbox.height);
}
params
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]