From 476bb0c2cd7cbd06c952b99baf926796d4e91d40 Mon Sep 17 00:00:00 2001 From: Ultraxime <36888699+Ultraxime@users.noreply.github.com> Date: Wed, 7 Feb 2024 00:10:45 +0100 Subject: [PATCH] Correction for the use of dpi_ratio and adding comments on it (#56) --- src/lib.rs | 5 +++-- src/util/helper.rs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9d75737a..17617d85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -393,8 +393,9 @@ fn pdf_size(tree: &Tree, options: Options) -> Size { // If no custom viewport is defined, we use the size of the tree. let viewport_size = options.viewport.unwrap_or(tree.size); Size::from_wh( - viewport_size.width() * dpi_ratio(options.dpi), - viewport_size.height() * dpi_ratio(options.dpi), + // dpi_ratio is in dot per user unit so dividing by it gave user unit + viewport_size.width() / dpi_ratio(options.dpi), + viewport_size.height() / dpi_ratio(options.dpi), ) .unwrap() } diff --git a/src/util/helper.rs b/src/util/helper.rs index 901e595f..9fe984e0 100644 --- a/src/util/helper.rs +++ b/src/util/helper.rs @@ -196,6 +196,7 @@ pub fn fit_view_box(size: Size, vb: &usvg::ViewBox) -> usvg::Size { } /// Calculate the scale ratio of a DPI value. +/// Turns a DPI in a dot per user unit (1/72nd of an inch by default) pub fn dpi_ratio(dpi: f32) -> f32 { dpi / 72.0 }