Skip to content

Commit

Permalink
Merge PR #32 from Gipson62/main
Browse files Browse the repository at this point in the history
fix: issues with windows displaying images
  • Loading branch information
josueBarretogit authored Aug 31, 2024
2 parents 26313d0 + bd4cdf1 commit 37e2cb9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 34 deletions.
68 changes: 39 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ clap = { version = "4.4.5", features = ["derive", "cargo"] }
zip = "2.1.6"
toml = "0.8.19"
epub-builder = "0.7.4"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_HiDpi"]}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![forbid(unsafe_code)]
#![allow(dead_code)]
#![allow(deprecated)]
use std::time::Duration;
Expand Down
37 changes: 33 additions & 4 deletions src/view/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,41 @@ fn get_picker() -> Option<Picker> {
})
.filter(|picker| picker.protocol_type != ProtocolType::Halfblocks)
}

#[cfg(target_os = "windows")]
fn get_picker() -> Option<Picker> {
// Todo! figure out how to get the size of the terminal on windows
// I think with the winapi it is possible
let mut picker = Picker::new((10, 17));
use windows_sys::Win32::System::Console::GetConsoleWindow;
use windows_sys::Win32::UI::HiDpi::GetDpiForWindow;

struct FontSize {
pub width: u16,
pub height: u16,
}
impl Default for FontSize {
fn default() -> Self {
FontSize {
width: 17,
height: 38,
}
}
}

let size: FontSize = match unsafe { GetDpiForWindow(GetConsoleWindow()) } {
96 => FontSize {
width: 9,
height: 20,
},
120 => FontSize {
width: 12,
height: 25,
},
144 => FontSize {
width: 14,
height: 32,
},
_ => FontSize::default(),
};

let mut picker = Picker::new((size.width, size.height));

let protocol = picker.guess_protocol();

Expand Down

0 comments on commit 37e2cb9

Please sign in to comment.