[librsvg] DrawingCtx::new() - set up the initial coordinate system per the spec
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] DrawingCtx::new() - set up the initial coordinate system per the spec
- Date: Wed, 20 Feb 2019 15:36:10 +0000 (UTC)
commit ee56c82a90dc2c0c607dfbe5afb9ab9325221c7f
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 20 09:26:46 2019 -0600
DrawingCtx::new() - set up the initial coordinate system per the spec
This has (0, 0) at the upper-left corner of the viewport, and matches
the viewport's size. That is, the initial coordinate system is not
concerned with the viewBox of the toplevel <svg> element.
NodeSvg will handle its viewBox through its call to draw_in_viewport().
rsvg_internals/src/drawing_ctx.rs | 26 +++++++++++++++++++-------
rsvg_internals/src/handle.rs | 19 +------------------
2 files changed, 20 insertions(+), 25 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 8f966b70..630e7207 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -115,18 +115,12 @@ impl DrawingCtx {
svg: Rc<Svg>,
cr: &cairo::Context,
viewport: &cairo::Rectangle,
- vbox: &ViewBox,
dpi: Dpi,
testing: bool,
) -> DrawingCtx {
let mut affine = cr.get_matrix();
let rect = viewport.transform(&affine).outer();
- // scale according to size set by size_func callback
- let mut scale = cairo::Matrix::identity();
- scale.scale(viewport.width / vbox.width, viewport.height / vbox.height);
- affine = cairo::Matrix::multiply(&affine, &scale);
-
// adjust transform so that the corner of the
// bounding box above is at (0,0)
affine.x0 -= rect.x;
@@ -134,7 +128,25 @@ impl DrawingCtx {
cr.set_matrix(affine);
let mut view_box_stack = Vec::new();
- view_box_stack.push(*vbox);
+
+ // https://www.w3.org/TR/SVG2/coords.html#InitialCoordinateSystem
+ //
+ // "For the outermost svg element, the SVG user agent must
+ // determine an initial viewport coordinate system and an
+ // initial user coordinate system such that the two
+ // coordinates systems are identical. The origin of both
+ // coordinate systems must be at the origin of the SVG
+ // viewport."
+ //
+ // "... the initial viewport coordinate system (and therefore
+ // the initial user coordinate system) must have its origin at
+ // the top/left of the viewport"
+ view_box_stack.push(ViewBox {
+ x: 0.0,
+ y: 0.0,
+ width: viewport.width,
+ height: viewport.height,
+ });
DrawingCtx {
svg: svg.clone(),
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 11d0b483..f79feb32 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -31,7 +31,6 @@ use structure::{IntrinsicDimensions, NodeSvg};
use surface_utils::{shared_surface::SharedImageSurface, shared_surface::SurfaceType};
use svg::Svg;
use util::rsvg_g_warning;
-use viewbox::ViewBox;
use xml::XmlState;
use xml2_load::xml_state_load_from_possibly_compressed_stream;
@@ -295,14 +294,12 @@ impl Handle {
&self,
cr: &cairo::Context,
viewport: &cairo::Rectangle,
- vbox: &ViewBox,
node: Option<&RsvgNode>,
) -> DrawingCtx {
let mut draw_ctx = DrawingCtx::new(
self.svg.borrow().as_ref().unwrap().clone(),
cr,
viewport,
- vbox,
self.dpi.get(),
self.is_testing.get(),
);
@@ -400,7 +397,6 @@ impl Handle {
width: f64::from(dimensions.width),
height: f64::from(dimensions.height),
},
- &ViewBox::new(0.0, 0.0, dimensions.em, dimensions.ex),
Some(node),
);
let root = self.get_root();
@@ -536,7 +532,6 @@ impl Handle {
width: f64::from(dimensions.width),
height: f64::from(dimensions.height),
},
- &ViewBox::new(0.0, 0.0, dimensions.em, dimensions.ex),
node.as_ref(),
);
let res = draw_ctx.draw_node_from_stack(&root.get_cascaded_values(), &root, false);
@@ -561,20 +556,8 @@ impl Handle {
let root = self.get_root();
- let svg_ref = self.svg.borrow();
- let svg = svg_ref.as_ref().unwrap();
-
- let dimensions = svg.get_intrinsic_dimensions();
-
- let vbox = dimensions.vbox.unwrap_or_else(|| ViewBox {
- x: 0.0,
- y: 0.0,
- width: viewport.width,
- height: viewport.height,
- });
-
cr.save();
- let mut draw_ctx = self.create_drawing_ctx_for_node(cr, viewport, &vbox, node.as_ref());
+ let mut draw_ctx = self.create_drawing_ctx_for_node(cr, viewport, node.as_ref());
let res = draw_ctx.draw_node_from_stack(&root.get_cascaded_values(), &root, false);
cr.restore();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]