Skip to content
Open
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
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ flume = { version = "0.12.0", default-features = false, features = ["async"] }
xflags = "0.4.0-pre.2"
mimalloc = "0.1.43"
nix = { version = "0.31.0", features = ["signal"] }
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "2e0fae910fac8048c7008211fc4d3b9f5d227a07", default-features = false, features = ["svg", "system-fonts", "img"] }
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "d7441b9998c92135e329559c0aa71d9dc92cf4de", default-features = false, features = ["svg", "system-fonts", "img"] }
rayon = { version = "1", default-features = false }
# kittage = { path = "../kittage/", features = ["crossterm-tokio", "image-crate", "log"] }
kittage = { version = "0.1.1", features = ["crossterm-tokio", "image-crate", "log"] }
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn scale_img_for_area(

// and get the ratio that this page would have to be scaled by to fit perfectly within the
// area provided to us.
// we do this first by comparing the aspec ratio of the page with the aspect ratio of the
// we do this first by comparing the aspect ratio of the page with the aspect ratio of the
// area to fit it within. If the aspect ratio of the page is larger, then we need to scale
// the width of the page to fill perfectly within the height of the area. Otherwise, we
// scale the height to fit perfectly. The dimension that _is not_ scaled to fit perfectly
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ async fn enter_redraw_loop(
},
InputAction::Search(term) => to_renderer.send(RenderNotif::Search(term))?,
InputAction::Invert => to_renderer.send(RenderNotif::Invert)?,
InputAction::Rotate => to_renderer.send(RenderNotif::Rotate)?,
InputAction::Fullscreen => fullscreen = !fullscreen,
InputAction::SwitchRenderZoom(f_or_f) => {
to_renderer.send(RenderNotif::SwitchFitOrFill(f_or_f)).unwrap();
Expand Down
42 changes: 39 additions & 3 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub enum RenderNotif {
Search(String),
SwitchFitOrFill(FitOrFill),
Reload,
Invert
Invert,
Rotate
}

#[derive(Debug)]
Expand All @@ -37,6 +38,14 @@ pub enum RenderInfo {
Reloaded
}

#[derive(Debug, Copy, Clone)]
pub enum RotateDirection {
Deg0,
Deg90,
Deg180,
Deg270
}

#[derive(Clone)]
pub struct PageInfo {
pub img_data: ImageData,
Expand Down Expand Up @@ -98,6 +107,7 @@ pub fn start_rendering(

let mut stored_doc = None;
let mut invert = false;
let mut rotate = RotateDirection::Deg0;
let mut preserved_area = None;
let mut fit_or_fill = FitOrFill::Fit;

Expand Down Expand Up @@ -238,6 +248,18 @@ pub fn start_rendering(
}
continue 'render_pages;
}
RenderNotif::Rotate => {
rotate = match rotate {
RotateDirection::Deg0 => RotateDirection::Deg90,
RotateDirection::Deg90 => RotateDirection::Deg180,
RotateDirection::Deg180 => RotateDirection::Deg270,
RotateDirection::Deg270 => RotateDirection::Deg0
};
for page in &mut rendered {
page.successful = false;
}
continue 'render_pages;
}
}
}};
}
Expand Down Expand Up @@ -301,6 +323,7 @@ pub fn start_rendering(
black,
white,
fit_or_fill,
rotate,
(area_w, area_h)
) {
// If that fn returned Some, that means it needed to be re-rendered for some
Expand Down Expand Up @@ -455,6 +478,7 @@ fn render_single_page_to_ctx(
black: i32,
white: i32,
fit_or_fill: FitOrFill,
rotate: RotateDirection,
(area_w, area_h): (f32, f32)
) -> Result<RenderedContext, mupdf::error::Error> {
let result_rects = match prev_render.num_search_found {
Expand All @@ -465,7 +489,12 @@ fn render_single_page_to_ctx(

// then, get the size of the page
let bounds = page.bounds()?;
let page_dim = (bounds.x1 - bounds.x0, bounds.y1 - bounds.y0);
let page_dim = match rotate {
RotateDirection::Deg0 | RotateDirection::Deg180 =>
(bounds.x1 - bounds.x0, bounds.y1 - bounds.y0),
RotateDirection::Deg90 | RotateDirection::Deg270 =>
(bounds.y1 - bounds.y0, bounds.x1 - bounds.x0),
};

let scaled = scale_img_for_area(page_dim, (area_w, area_h), fit_or_fill);
let ScaledResult {
Expand All @@ -482,7 +511,13 @@ fn render_single_page_to_ctx(
}

let colorspace = Colorspace::device_rgb();
let matrix = Matrix::new_scale(scale_factor, scale_factor);
let mut matrix = Matrix::new_scale(scale_factor, scale_factor);
match rotate {
RotateDirection::Deg0 => matrix.rotate(0.0),
RotateDirection::Deg90 => matrix.rotate(90.0),
RotateDirection::Deg180 => matrix.rotate(180.0),
RotateDirection::Deg270 => matrix.rotate(270.0)
};

let mut pixmap = page.to_pixmap(&matrix, &colorspace, false, false)?;
if invert {
Expand All @@ -494,6 +529,7 @@ fn render_single_page_to_ctx(
let (x_res, y_res) = pixmap.resolution();
let new_x = (x_res as f32 * scale_factor) as i32;
let new_y = (y_res as f32 * scale_factor) as i32;

pixmap.set_resolution(new_x, new_y);

let result_rects = result_rects
Expand Down
2 changes: 2 additions & 0 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ impl Tui {
'G' if can_zoom => self.update_zoom(Zoom::pan_top),
'0' if can_zoom => self.update_zoom(Zoom::pan_left),
'$' if can_zoom => self.update_zoom(Zoom::pan_right),
'r' => Some(InputAction::Rotate),
_ => None
}
}
Expand Down Expand Up @@ -1115,6 +1116,7 @@ pub enum InputAction {
Search(String),
QuitApp,
Invert,
Rotate,
Fullscreen,
SwitchRenderZoom(crate::FitOrFill)
}
Expand Down
Loading