ViewParams: Use accessor functions; make fields private

parent 36fe1041
......@@ -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 {}
......
......@@ -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()),
}
}
......@@ -405,12 +406,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();
......@@ -422,12 +418,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();
......@@ -443,12 +434,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();
......@@ -465,12 +451,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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment