Skip to content
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
44 changes: 30 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use tdf::{
PrerenderLimit,
converter::{ConvertedPage, ConverterMsg, run_conversion_loop},
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}
};

Expand Down Expand Up @@ -128,21 +128,37 @@ async fn inner_main() -> Result<(), WrappedErr> {
.canonicalize()
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;

let black =
parse_color_to_i32(flags.black_color.as_deref().unwrap_or("000000")).map_err(|e| {
WrappedErr(
format!("Couldn't parse black color: {e} - is it formatted like a CSS color?")
let black = flags
.black_color
.as_deref()
.map(|color| {
parse_color_to_i32(color).map_err(|e| {
WrappedErr(
format!(
"Couldn't parse black color {color:?}: {e} - is it formatted like a CSS color?"
)
.into()
)
})?;

let white =
parse_color_to_i32(flags.white_color.as_deref().unwrap_or("FFFFFF")).map_err(|e| {
WrappedErr(
format!("Couldn't parse white color: {e} - is it formatted like a CSS color?")
)
})
})
.transpose()?
.unwrap_or(MUPDF_BLACK);

let white = flags
.white_color
.as_deref()
.map(|color| {
parse_color_to_i32(color).map_err(|e| {
WrappedErr(
format!(
"Couldn't parse white color {color:?}: {e} - is it formatted like a CSS color?"
)
.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.
// Just need to make sure it doesn't get dropped yet.
Expand Down
21 changes: 16 additions & 5 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct PrevRender {
num_search_found: Option<usize>
}

const MUPDF_BLACK: i32 = 0;
const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]);
pub const MUPDF_BLACK: i32 = 0;
pub const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]);

#[inline]
pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
Expand Down Expand Up @@ -152,8 +152,8 @@ pub fn start_rendering(

sender.send(Ok(RenderInfo::NumPages(n_pages.get())))?;

// We're using this vec of bools to indicate which page numbers have already been rendered,
// to support people jumping to specific pages and having quick rendering results. We
// We're using this vec to indicate which page numbers have already been rendered, to
// support people jumping to specific pages and having quick rendering results. We
// `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,
// then we can split at that page and render at both sides of it
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn start_rendering(
// we only want to continue if one of the following is met:
// 1. It failed to render last time (we want to retry)
// 2. The `contained_term` is set to Unknown, meaning that we need to at least
// check if it contains the current term to see if it needs a re-render
// check if it contains the current term to see if it needs a re-render
if rendered.successful && rendered.num_search_found.is_some() {
continue;
}
Expand Down Expand Up @@ -570,4 +570,15 @@ impl Iterator for PopOnNext<'_> {
fn next(&mut self) -> Option<Self::Item> {
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()
}
}
Loading