Skip to content

Commit

Permalink
Correction for the use of dpi_ratio and adding comments on it (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultraxime authored Feb 6, 2024
1 parent 042109f commit 476bb0c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions src/util/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 476bb0c

Please sign in to comment.