Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction for the use of dpi_ratio #56

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading