[librsvg/librsvg-2.44] ViewParams: Use accessor functions; make fields private
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.44] ViewParams: Use accessor functions; make fields private
- Date: Fri, 21 Sep 2018 17:38:26 +0000 (UTC)
commit 128b2cc5cf951f347d9f4fa5438fd7f2597549fb
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Sep 4 15:08:12 2018 -0500
ViewParams: Use accessor functions; make fields private
rsvg_internals/src/drawing_ctx.rs | 39 +++++++++++++++++++++++++++++++++----
rsvg_internals/src/length.rs | 41 +++++++++++----------------------------
2 files changed, 46 insertions(+), 34 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 7be101a7..a0806943 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -40,11 +40,42 @@ use unitinterval::UnitInterval;
use viewbox::ViewBox;
/// Holds values that are required to normalize `Length` values to a current viewport.
+///
+/// This struct is created by calling `DrawingCtx::push_view_box()` or
+/// `DrawingCtx::get_view_params()`.
pub struct ViewParams {
- pub dpi_x: f64,
- pub dpi_y: f64,
- pub view_box_width: f64,
- pub view_box_height: f64,
+ dpi_x: f64,
+ dpi_y: f64,
+ view_box_width: f64,
+ view_box_height: f64,
+}
+
+impl ViewParams {
+ #[cfg(test)]
+ pub fn new(dpi_x: f64, dpi_y: f64, view_box_width: f64, view_box_height: f64) -> ViewParams {
+ ViewParams {
+ dpi_x,
+ dpi_y,
+ view_box_width,
+ view_box_height,
+ }
+ }
+
+ pub fn dpi_x(&self) -> f64 {
+ self.dpi_x
+ }
+
+ pub fn dpi_y(&self) -> f64 {
+ self.dpi_y
+ }
+
+ pub fn view_box_width(&self) -> f64 {
+ self.view_box_width
+ }
+
+ pub fn view_box_height(&self) -> f64 {
+ self.view_box_height
+ }
}
pub enum RsvgDrawingCtx {}
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index b1bf6723..3fe004a4 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -99,10 +99,11 @@ impl Length {
LengthUnit::Default => self.length,
LengthUnit::Percent => match self.dir {
- LengthDir::Horizontal => self.length * params.view_box_width,
- LengthDir::Vertical => self.length * params.view_box_height,
+ LengthDir::Horizontal => self.length * params.view_box_width(),
+ LengthDir::Vertical => self.length * params.view_box_height(),
LengthDir::Both => {
- self.length * viewport_percentage(params.view_box_width, params.view_box_height)
+ self.length
+ * viewport_percentage(params.view_box_width(), params.view_box_height())
}
},
@@ -225,9 +226,9 @@ impl Length {
fn font_size_from_inch(length: f64, dir: LengthDir, params: &ViewParams) -> f64 {
match dir {
- LengthDir::Horizontal => length * params.dpi_x,
- LengthDir::Vertical => length * params.dpi_y,
- LengthDir::Both => length * viewport_percentage(params.dpi_x, params.dpi_y),
+ LengthDir::Horizontal => length * params.dpi_x(),
+ LengthDir::Vertical => length * params.dpi_y(),
+ LengthDir::Both => length * viewport_percentage(params.dpi_x(), params.dpi_y()),
}
}
@@ -408,12 +409,7 @@ mod tests {
#[test]
fn normalize_default_works() {
- let params = ViewParams {
- dpi_x: 40.0,
- dpi_y: 40.0,
- view_box_width: 100.0,
- view_box_height: 100.0,
- };
+ let params = ViewParams::new(40.0, 40.0, 100.0, 100.0);
let values = ComputedValues::default();
@@ -425,12 +421,7 @@ mod tests {
#[test]
fn normalize_absolute_units_works() {
- let params = ViewParams {
- dpi_x: 40.0,
- dpi_y: 50.0,
- view_box_width: 100.0,
- view_box_height: 100.0,
- };
+ let params = ViewParams::new(40.0, 50.0, 100.0, 100.0);
let values = ComputedValues::default();
@@ -446,12 +437,7 @@ mod tests {
#[test]
fn normalize_percent_works() {
- let params = ViewParams {
- dpi_x: 40.0,
- dpi_y: 40.0,
- view_box_width: 100.0,
- view_box_height: 200.0,
- };
+ let params = ViewParams::new(40.0, 40.0, 100.0, 200.0);
let values = ComputedValues::default();
@@ -468,12 +454,7 @@ mod tests {
#[test]
fn normalize_font_em_ex_works() {
- let params = ViewParams {
- dpi_x: 40.0,
- dpi_y: 40.0,
- view_box_width: 100.0,
- view_box_height: 200.0,
- };
+ let params = ViewParams::new(40.0, 40.0, 100.0, 200.0);
let values = ComputedValues::default();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]