[librsvg/wip/dimensions-api] draw_in_viewport(): Take the viewport as a Rectangle, not as separate values
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/dimensions-api] draw_in_viewport(): Take the viewport as a Rectangle, not as separate values
- Date: Sat, 9 Feb 2019 17:49:37 +0000 (UTC)
commit 0b7d5fc9c78daac25565e5cef9d93e61c3ef8e60
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 8 20:34:34 2019 -0600
draw_in_viewport(): Take the viewport as a Rectangle, not as separate values
rsvg_internals/src/structure.rs | 27 ++++++++++++++-------------
rsvg_internals/src/viewport.rs | 17 ++++++-----------
2 files changed, 20 insertions(+), 24 deletions(-)
---
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 3040285d..e2a89d92 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -1,6 +1,8 @@
use std::cell::Cell;
use std::cell::RefCell;
+use cairo::Rectangle;
+
use allowed_url::Fragment;
use aspect_ratio::*;
use attributes::Attribute;
@@ -14,6 +16,7 @@ use node::*;
use parsers::{Parse, ParseValue};
use properties::Overflow;
use property_bag::{OwnedPropertyBag, PropertyBag};
+use rect::RectangleExt;
use viewbox::*;
use viewport::{draw_in_viewport, ClipMode};
@@ -220,18 +223,17 @@ impl NodeTrait for NodeSvg {
let params = draw_ctx.get_view_params();
- let nx = self.x.get().normalize(values, ¶ms);
- let ny = self.y.get().normalize(values, ¶ms);
- let nw = self.w.get().normalize(values, ¶ms);
- let nh = self.h.get().normalize(values, ¶ms);
+ let viewport = Rectangle::new(
+ self.x.get().normalize(values, ¶ms),
+ self.y.get().normalize(values, ¶ms),
+ self.w.get().normalize(values, ¶ms),
+ self.h.get().normalize(values, ¶ms),
+ );
let do_clip = !values.is_overflow() && node.get_parent().is_some();
draw_in_viewport(
- nx,
- ny,
- nw,
- nh,
+ &viewport,
ClipMode::ClipToViewport,
do_clip,
self.vbox.get(),
@@ -362,9 +364,11 @@ impl NodeTrait for NodeUse {
return Ok(());
}
+ let viewport = Rectangle::new(nx, ny, nw, nh);
+
if child.get_type() != NodeType::Symbol {
let cr = draw_ctx.get_cairo_context();
- cr.translate(nx, ny);
+ cr.translate(viewport.x, viewport.y);
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
dc.draw_node_from_stack(
@@ -379,10 +383,7 @@ impl NodeTrait for NodeUse {
|| (values.overflow == Overflow::Visible && child.is_overflow());
draw_in_viewport(
- nx,
- ny,
- nw,
- nh,
+ &viewport,
ClipMode::ClipToVbox,
do_clip,
symbol.vbox.get(),
diff --git a/rsvg_internals/src/viewport.rs b/rsvg_internals/src/viewport.rs
index f2641cf5..25203fec 100644
--- a/rsvg_internals/src/viewport.rs
+++ b/rsvg_internals/src/viewport.rs
@@ -7,7 +7,6 @@ use error::RenderingError;
use float_eq_cairo::ApproxEqCairo;
use node::RsvgNode;
use properties::ComputedValues;
-use rect::RectangleExt;
use viewbox::*;
#[derive(Debug, Copy, Clone, PartialEq)]
@@ -17,10 +16,7 @@ pub enum ClipMode {
}
pub fn draw_in_viewport(
- vx: f64,
- vy: f64,
- vw: f64,
- vh: f64,
+ viewport: &Rectangle,
clip_mode: ClipMode,
do_clip: bool,
vbox: Option<ViewBox>,
@@ -38,14 +34,14 @@ pub fn draw_in_viewport(
// https://www.w3.org/TR/SVG/struct.html#ImageElementWidthAttribute
// https://www.w3.org/TR/SVG/painting.html#MarkerWidthAttribute
- if vw.approx_eq_cairo(&0.0) || vh.approx_eq_cairo(&0.0) {
+ if viewport.width.approx_eq_cairo(&0.0) || viewport.height.approx_eq_cairo(&0.0) {
return Ok(());
}
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
if do_clip && clip_mode == ClipMode::ClipToViewport {
dc.get_cairo_context().set_matrix(affine);
- dc.clip(vx, vy, vw, vh);
+ dc.clip(viewport.x, viewport.y, viewport.width, viewport.height);
}
let _params = if let Some(vbox) = vbox {
@@ -60,8 +56,7 @@ pub fn draw_in_viewport(
let params = dc.push_view_box(vbox.width, vbox.height);
- let (x, y, w, h) =
- preserve_aspect_ratio.compute(&vbox, &Rectangle::new(vx, vy, vw, vh));
+ let (x, y, w, h) = preserve_aspect_ratio.compute(&vbox, viewport);
affine.translate(x, y);
affine.scale(w / vbox.width, h / vbox.height);
@@ -75,8 +70,8 @@ pub fn draw_in_viewport(
params
} else {
- let params = dc.push_view_box(vw, vh);
- affine.translate(vx, vy);
+ let params = dc.push_view_box(viewport.width, viewport.height);
+ affine.translate(viewport.x, viewport.y);
dc.get_cairo_context().set_matrix(affine);
params
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]