Center pdf page in window
This commit is contained in:
parent
19b1ccfcbf
commit
1f33d09ec1
12
src/main.rs
12
src/main.rs
@ -131,20 +131,30 @@ fn build_ui(app: &Application, arguments: Vec<OsString>) {
|
|||||||
|
|
||||||
let page = doc.get_page(**current_page_number - 1).unwrap();
|
let page = doc.get_page(**current_page_number - 1).unwrap();
|
||||||
let (w, h) = page.get_size();
|
let (w, h) = page.get_size();
|
||||||
|
|
||||||
let width_diff = area.width() as f64 / w;
|
let width_diff = area.width() as f64 / w;
|
||||||
let height_diff = area.height() as f64 / h;
|
let height_diff = area.height() as f64 / h;
|
||||||
context.save().unwrap();
|
context.save().unwrap();
|
||||||
if width_diff > height_diff {
|
if width_diff > height_diff {
|
||||||
|
context.translate(
|
||||||
|
(area.width() as f64 - w * height_diff) / 2.0,
|
||||||
|
(area.height() as f64 - h * height_diff) / 2.0,
|
||||||
|
);
|
||||||
context.scale(height_diff, height_diff);
|
context.scale(height_diff, height_diff);
|
||||||
} else {
|
} else {
|
||||||
|
context.translate(
|
||||||
|
(area.width() as f64 - w * width_diff) / 2.0,
|
||||||
|
(area.height() as f64 - h * width_diff) / 2.0,
|
||||||
|
);
|
||||||
context.scale(width_diff, width_diff);
|
context.scale(width_diff, width_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
page.render(&context);
|
page.render(&context);
|
||||||
|
|
||||||
let r = ctx.paint();
|
let r = ctx.paint();
|
||||||
match r {
|
match r {
|
||||||
Err(v) => println!("Error painting PDF: {v:?}"),
|
Err(v) => println!("Error painting PDF: {v:?}"),
|
||||||
Ok(_v) => println!(""),
|
Ok(_v) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.show_page().unwrap();
|
ctx.show_page().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user