mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
Compare commits
2 Commits
main
...
boring_cleanups
| Author | SHA1 | Date | |
|---|---|---|---|
| e2a9c90b34 | |||
| 16c0aed9a3 |
+25
-9
@@ -39,7 +39,7 @@ use tdf::{
|
|||||||
PrerenderLimit,
|
PrerenderLimit,
|
||||||
converter::{ConvertedPage, ConverterMsg, run_conversion_loop},
|
converter::{ConvertedPage, ConverterMsg, run_conversion_loop},
|
||||||
kitty::{KittyDisplay, display_kitty_images, do_shms_work, run_action},
|
kitty::{KittyDisplay, display_kitty_images, do_shms_work, run_action},
|
||||||
renderer::{self, RenderError, RenderInfo, RenderNotif},
|
renderer::{self, MUPDF_BLACK, MUPDF_WHITE, RenderError, RenderInfo, RenderNotif},
|
||||||
tui::{BottomMessage, InputAction, MessageSetting, Tui}
|
tui::{BottomMessage, InputAction, MessageSetting, Tui}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -128,21 +128,37 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
.canonicalize()
|
.canonicalize()
|
||||||
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;
|
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;
|
||||||
|
|
||||||
let black =
|
let black = flags
|
||||||
parse_color_to_i32(flags.black_color.as_deref().unwrap_or("000000")).map_err(|e| {
|
.black_color
|
||||||
|
.as_deref()
|
||||||
|
.map(|color| {
|
||||||
|
parse_color_to_i32(color).map_err(|e| {
|
||||||
WrappedErr(
|
WrappedErr(
|
||||||
format!("Couldn't parse black color: {e} - is it formatted like a CSS color?")
|
format!(
|
||||||
|
"Couldn't parse black color {color:?}: {e} - is it formatted like a CSS color?"
|
||||||
|
)
|
||||||
.into()
|
.into()
|
||||||
)
|
)
|
||||||
})?;
|
})
|
||||||
|
})
|
||||||
|
.transpose()?
|
||||||
|
.unwrap_or(MUPDF_BLACK);
|
||||||
|
|
||||||
let white =
|
let white = flags
|
||||||
parse_color_to_i32(flags.white_color.as_deref().unwrap_or("FFFFFF")).map_err(|e| {
|
.white_color
|
||||||
|
.as_deref()
|
||||||
|
.map(|color| {
|
||||||
|
parse_color_to_i32(color).map_err(|e| {
|
||||||
WrappedErr(
|
WrappedErr(
|
||||||
format!("Couldn't parse white color: {e} - is it formatted like a CSS color?")
|
format!(
|
||||||
|
"Couldn't parse white color {color:?}: {e} - is it formatted like a CSS color?"
|
||||||
|
)
|
||||||
.into()
|
.into()
|
||||||
)
|
)
|
||||||
})?;
|
})
|
||||||
|
})
|
||||||
|
.transpose()?
|
||||||
|
.unwrap_or(MUPDF_WHITE);
|
||||||
|
|
||||||
// need to keep it around throughout the lifetime of the program, but don't rly need to use it.
|
// need to keep it around throughout the lifetime of the program, but don't rly need to use it.
|
||||||
// Just need to make sure it doesn't get dropped yet.
|
// Just need to make sure it doesn't get dropped yet.
|
||||||
|
|||||||
+15
-4
@@ -57,8 +57,8 @@ struct PrevRender {
|
|||||||
num_search_found: Option<usize>
|
num_search_found: Option<usize>
|
||||||
}
|
}
|
||||||
|
|
||||||
const MUPDF_BLACK: i32 = 0;
|
pub const MUPDF_BLACK: i32 = 0;
|
||||||
const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]);
|
pub const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
|
pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
|
||||||
@@ -152,8 +152,8 @@ pub fn start_rendering(
|
|||||||
|
|
||||||
sender.send(Ok(RenderInfo::NumPages(n_pages.get())))?;
|
sender.send(Ok(RenderInfo::NumPages(n_pages.get())))?;
|
||||||
|
|
||||||
// We're using this vec of bools to indicate which page numbers have already been rendered,
|
// We're using this vec to indicate which page numbers have already been rendered, to
|
||||||
// to support people jumping to specific pages and having quick rendering results. We
|
// support people jumping to specific pages and having quick rendering results. We
|
||||||
// `split_at_mut` at 0 initially (which bascially makes `right == rendered && left == []`),
|
// `split_at_mut` at 0 initially (which bascially makes `right == rendered && left == []`),
|
||||||
// doing basically nothing, but if we get a notification that something has been jumped to,
|
// doing basically nothing, but if we get a notification that something has been jumped to,
|
||||||
// then we can split at that page and render at both sides of it
|
// then we can split at that page and render at both sides of it
|
||||||
@@ -570,4 +570,15 @@ impl Iterator for PopOnNext<'_> {
|
|||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.inner.pop_front()
|
self.inner.pop_front()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
let l = self.len();
|
||||||
|
(l, Some(l))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ExactSizeIterator for PopOnNext<'_> {
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
self.inner.len()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user