mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 997631aac9 | |||
| 725c6c6bfd | |||
| fca61d55b5 | |||
| 59c0e2338b | |||
| 52994b8b89 | |||
| 2f957cdcbb |
+79
-13
@@ -2,32 +2,57 @@ name: Rust
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: ["main"]
|
||||||
|
tags: ["v*.*.*"]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: ["main"]
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
test-build:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- { os: "macos-latest", target: "aarch64-apple-darwin" }
|
||||||
|
- { os: "ubuntu-latest", target: "x86_64-unknown-linux-gnu" }
|
||||||
|
- {
|
||||||
|
os: "windows-latest",
|
||||||
|
target: "x86_64-pc-windows-msvc",
|
||||||
|
ext: ".exe",
|
||||||
|
}
|
||||||
|
- { os: "ubuntu-24.04-arm", target: "aarch64-unknown-linux-gnu" }
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup sccache
|
- name: Setup sccache
|
||||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||||
uses: mozilla-actions/sccache-action@v0.0.8
|
uses: mozilla-actions/sccache-action@v0.0.8
|
||||||
- name: Configure sccache
|
- name: Configure sccache
|
||||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||||
run: |
|
run: |
|
||||||
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
|
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
|
||||||
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
|
||||||
- name: Install build dependencies
|
|
||||||
run: |
|
- name: Setup rust cache action
|
||||||
sudo apt-get update
|
uses: swatinem/rust-cache@v2
|
||||||
sudo apt-get install -y libfontconfig1-dev libgoogle-perftools-dev google-perftools
|
with:
|
||||||
- uses: actions/checkout@v4
|
cache-on-failure: true
|
||||||
|
|
||||||
|
- name: install build dependencies on ubuntu and cache
|
||||||
|
if: contains(matrix.os, 'ubuntu')
|
||||||
|
uses: awalsh128/cache-apt-pkgs-action@latest
|
||||||
|
with:
|
||||||
|
packages: libfontconfig1-dev libgoogle-perftools-dev google-perftools
|
||||||
|
version: latest # could be anything
|
||||||
|
|
||||||
- name: Install clippy and fmt
|
- name: Install clippy and fmt
|
||||||
run: rustup component add clippy rustfmt
|
run: rustup component add clippy rustfmt
|
||||||
- name: Clippy
|
- name: Clippy
|
||||||
@@ -38,5 +63,46 @@ jobs:
|
|||||||
run: cargo fmt -- --check
|
run: cargo fmt -- --check
|
||||||
- name: Run benchmarks as tests
|
- name: Run benchmarks as tests
|
||||||
run: cargo test --locked --benches -- adobe_example
|
run: cargo test --locked --benches -- adobe_example
|
||||||
- name: Build
|
|
||||||
run: cargo build --locked
|
- name: Set build mode
|
||||||
|
shell: bash
|
||||||
|
run: if [ "${{github.ref_type}}" == "tag" ] || [ ${{ github.event_name == 'push' && github.ref_name == 'main' }} ]; then echo "BMODE=production">>"$GITHUB_ENV"; fi
|
||||||
|
|
||||||
|
- name: Build in ${{env.BMODE || 'debug'}} mode
|
||||||
|
run: cargo build --verbose --locked --profile ${{env.BMODE || 'dev'}}
|
||||||
|
|
||||||
|
- name: Prepare artifact
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p dist
|
||||||
|
cp "target/${{env.BMODE || 'debug'}}/tdf${{ matrix.ext }}" dist/tdf-${{ matrix.target }}${{ matrix.ext }}
|
||||||
|
tree dist || ls -la dist
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v5
|
||||||
|
with:
|
||||||
|
name: tdf-${{ matrix.target }}
|
||||||
|
path: dist/tdf*
|
||||||
|
|
||||||
|
tag-release:
|
||||||
|
name: Release on tag push
|
||||||
|
runs-on: ubuntu-slim
|
||||||
|
if: github.ref_type == 'tag'
|
||||||
|
needs: test-build
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v6
|
||||||
|
with:
|
||||||
|
pattern: "**/tdf-*"
|
||||||
|
path: release-artifacts
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: What's up?
|
||||||
|
run: tree release-artifacts # beautiful!
|
||||||
|
|
||||||
|
- name: Create a GitHub release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
generate_release_notes: true
|
||||||
|
files: release-artifacts/*
|
||||||
|
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- Added windows support! (thank you to [@jarjk](https://github.com/jarjk) for helping out!)
|
||||||
- Added keybindings (`0`/`$`) to scroll to left or right side of zoomed-in image ([#131](https://github.com/itsjunetime/tdf/pull/131), thank you [@IshDeshpa](https://github.com/IshDeshpa)!)
|
- Added keybindings (`0`/`$`) to scroll to left or right side of zoomed-in image ([#131](https://github.com/itsjunetime/tdf/pull/131), thank you [@IshDeshpa](https://github.com/IshDeshpa)!)
|
||||||
|
- (Internal) decreased runtime footprint of tokio runtime
|
||||||
|
|
||||||
# v0.5.0
|
# v0.5.0
|
||||||
|
|
||||||
|
|||||||
Generated
+20
-20
@@ -177,9 +177,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "avif-serialize"
|
name = "avif-serialize"
|
||||||
version = "0.8.6"
|
version = "0.8.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "47c8fbc0f831f4519fe8b810b6a7a91410ec83031b8233f730a0480029f6a23f"
|
checksum = "375082f007bd67184fb9c0374614b29f9aaa604ec301635f72338bb65386a53d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
]
|
]
|
||||||
@@ -476,18 +476,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.57"
|
version = "4.5.58"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6899ea499e3fb9305a65d5ebf6e3d2248c5fab291f300ad0a704fbe142eae31a"
|
checksum = "63be97961acde393029492ce0be7a1af7e323e6bae9511ebfac33751be5e6806"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.57"
|
version = "4.5.58"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7b12c8b680195a62a8364d16b8447b01b6c2c8f9aaf68bee653be34d4245e238"
|
checksum = "7f13174bda5dfd69d7e947827e5af4b0f2f94a4a3ee92912fba07a66150f21e2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"clap_lex",
|
"clap_lex",
|
||||||
@@ -495,9 +495,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.7.7"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
|
checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "compact_str"
|
name = "compact_str"
|
||||||
@@ -799,9 +799,9 @@ checksum = "7f2e5bc95e82bd8e9b333f4c5ff6dceab54e2e99f4d8cef2a680d417206ead34"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.5.5"
|
version = "0.5.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587"
|
checksum = "cc3dc5ad92c2e2d1c193bbbbdf2ea477cb81331de4f3103f267ca18368b988c4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
]
|
]
|
||||||
@@ -1526,9 +1526,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kittage"
|
name = "kittage"
|
||||||
version = "0.1.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "be6b61789e2841119b210569d4acd950d47dae805f8d3235190d28cb40677632"
|
checksum = "60c7c5cd12fa1b81b892fe06e04daa9e58ccd8993693378e8c1792aa0a4245fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64-simd",
|
"base64-simd",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
@@ -1584,9 +1584,9 @@ checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libfuzzer-sys"
|
name = "libfuzzer-sys"
|
||||||
version = "0.4.10"
|
version = "0.4.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5037190e1f70cbeef565bd267599242926f724d3b8a9f510fd7e0b540cfa4404"
|
checksum = "f12a681b7dd8ce12bff52488013ba614b869148d54dd79836ab85aafdd53f08d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"cc",
|
"cc",
|
||||||
@@ -1786,8 +1786,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mupdf"
|
name = "mupdf"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/messense/mupdf-rs.git?rev=2e0fae910fac8048c7008211fc4d3b9f5d227a07#2e0fae910fac8048c7008211fc4d3b9f5d227a07"
|
source = "git+https://github.com/messense/mupdf-rs.git?rev=d7441b9998c92135e329559c0aa71d9dc92cf4de#d7441b9998c92135e329559c0aa71d9dc92cf4de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
"font-kit",
|
"font-kit",
|
||||||
@@ -1798,8 +1798,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mupdf-sys"
|
name = "mupdf-sys"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/messense/mupdf-rs.git?rev=2e0fae910fac8048c7008211fc4d3b9f5d227a07#2e0fae910fac8048c7008211fc4d3b9f5d227a07"
|
source = "git+https://github.com/messense/mupdf-rs.git?rev=d7441b9998c92135e329559c0aa71d9dc92cf4de#d7441b9998c92135e329559c0aa71d9dc92cf4de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"cc",
|
"cc",
|
||||||
@@ -3535,9 +3535,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winmmf"
|
name = "winmmf"
|
||||||
version = "0.5.1"
|
version = "0.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "71505e812c82834e7a5a31481592e5c244d7f9177a28fb88817dfa8360b40021"
|
checksum = "859506e40270a5938da41bb216376bae2e681ed8027392bddc068d62d74243f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fixedstr",
|
"fixedstr",
|
||||||
"microseh",
|
"microseh",
|
||||||
|
|||||||
+2
-2
@@ -38,10 +38,10 @@ flume = { version = "0.12.0", default-features = false, features = ["async"] }
|
|||||||
xflags = "0.4.0-pre.2"
|
xflags = "0.4.0-pre.2"
|
||||||
mimalloc = "0.1.43"
|
mimalloc = "0.1.43"
|
||||||
nix = { version = "0.31.0", features = ["signal"] }
|
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 }
|
rayon = { version = "1", default-features = false }
|
||||||
# kittage = { path = "../kittage/", features = ["crossterm-tokio", "image-crate", "log"] }
|
# kittage = { path = "../kittage/", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||||
kittage = { version = "0.1.1", features = ["crossterm-tokio", "image-crate", "log"] }
|
kittage = { version = "0.3.4", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||||
memmap2 = "0"
|
memmap2 = "0"
|
||||||
csscolorparser = { version = "0.8.0", default-features = false }
|
csscolorparser = { version = "0.8.0", default-features = false }
|
||||||
debounce = "0.2.2"
|
debounce = "0.2.2"
|
||||||
|
|||||||
@@ -34,7 +34,12 @@ fn for_all_combos(
|
|||||||
name: &'static str,
|
name: &'static str,
|
||||||
mut f: impl FnMut(&Runtime, BenchmarkId, &'static str, ProtocolType)
|
mut f: impl FnMut(&Runtime, BenchmarkId, &'static str, ProtocolType)
|
||||||
) {
|
) {
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(3)
|
||||||
|
.enable_time()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
for proto in PROTOS {
|
for proto in PROTOS {
|
||||||
for file in FILES {
|
for file in FILES {
|
||||||
f(
|
f(
|
||||||
|
|||||||
+1
-1
Submodule ratatui-image updated: a276a87cb8...8ad154a219
+25
-14
@@ -1,11 +1,12 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
io::Cursor,
|
||||||
num::NonZeroUsize,
|
num::NonZeroUsize,
|
||||||
time::{SystemTime, UNIX_EPOCH}
|
time::{SystemTime, UNIX_EPOCH}
|
||||||
};
|
};
|
||||||
|
|
||||||
use flume::{Receiver, SendError, Sender, TryRecvError};
|
use flume::{Receiver, SendError, Sender, TryRecvError};
|
||||||
use futures_util::stream::StreamExt as _;
|
use futures_util::stream::StreamExt as _;
|
||||||
use image::DynamicImage;
|
use image::{DynamicImage, codecs::pnm::PnmDecoder};
|
||||||
use kittage::{NumberOrId, action::NONZERO_ONE};
|
use kittage::{NumberOrId, action::NONZERO_ONE};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
use ratatui_image::{
|
use ratatui_image::{
|
||||||
@@ -111,22 +112,26 @@ pub async fn run_conversion_loop(
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut dyn_img = image::load_from_memory_with_format(
|
let decoder = PnmDecoder::new(Cursor::new(&page_info.img_data.pixels)).map_err(|e| {
|
||||||
&page_info.img_data.pixels,
|
RenderError::Converting(format!(
|
||||||
image::ImageFormat::Pnm
|
"The image data provided from mupdf was not in pnm format ({e}); don't know how to convert"
|
||||||
)
|
))
|
||||||
.map_err(|e| RenderError::Converting(format!("Can't load image: {e}")))?;
|
})?;
|
||||||
|
|
||||||
|
// The image we get should always already be `ImageRgb8`, so this `into` shouldn't do any
|
||||||
|
// conversions or anything, but just in case some underlying detail of mupdf or image
|
||||||
|
// changes, we do the `into` instead of just `match + unreachable!()` to avoid panicking
|
||||||
|
let mut dyn_img = DynamicImage::from_decoder(decoder)
|
||||||
|
.map_err(|e| RenderError::Converting(format!("Can't load image: {e}")))?
|
||||||
|
.into_rgb8();
|
||||||
|
|
||||||
match dyn_img {
|
|
||||||
DynamicImage::ImageRgb8(ref mut img) =>
|
|
||||||
for quad in &*page_info.result_rects {
|
for quad in &*page_info.result_rects {
|
||||||
img.par_enumerate_pixels_mut()
|
dyn_img
|
||||||
|
.par_enumerate_pixels_mut()
|
||||||
.filter(|(x, y, _)| {
|
.filter(|(x, y, _)| {
|
||||||
*x > quad.ul_x && *x < quad.lr_x && *y > quad.ul_y && *y < quad.lr_y
|
*x > quad.ul_x && *x < quad.lr_x && *y > quad.ul_y && *y < quad.lr_y
|
||||||
})
|
})
|
||||||
.for_each(|(_, _, px)| px.0[2] = px.0[2].saturating_sub(u8::MAX / 2));
|
.for_each(|(_, _, px)| px.0[2] = px.0[2].saturating_sub(u8::MAX / 2));
|
||||||
},
|
|
||||||
_ => unreachable!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let img_area = Rect {
|
let img_area = Rect {
|
||||||
@@ -136,6 +141,8 @@ pub async fn run_conversion_loop(
|
|||||||
y: 0
|
y: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let dyn_img = DynamicImage::ImageRgb8(dyn_img);
|
||||||
|
|
||||||
let txt_img = match picker.protocol_type() {
|
let txt_img = match picker.protocol_type() {
|
||||||
ProtocolType::Kitty => {
|
ProtocolType::Kitty => {
|
||||||
let rn = SystemTime::now()
|
let rn = SystemTime::now()
|
||||||
@@ -144,9 +151,13 @@ pub async fn run_conversion_loop(
|
|||||||
.as_nanos() % 1_000_000;
|
.as_nanos() % 1_000_000;
|
||||||
|
|
||||||
let mut img = if shms_work {
|
let mut img = if shms_work {
|
||||||
kittage::image::Image::shm_from(dyn_img, &format!("/tdf_{pid}_{rn}_{page_num}"))
|
let shm_name = format!("/tdf_{pid}_{rn}_{page_num}");
|
||||||
.map_err(|e| {
|
|
||||||
RenderError::Converting(format!("Couldn't write to shm: {e:?}"))
|
#[cfg(unix)]
|
||||||
|
let shm_name = &*shm_name;
|
||||||
|
|
||||||
|
kittage::image::Image::shm_from(dyn_img, shm_name).map_err(|e| {
|
||||||
|
RenderError::Converting(format!("Couldn't create shm: {e:?}"))
|
||||||
})?
|
})?
|
||||||
} else {
|
} else {
|
||||||
kittage::image::Image::from(dyn_img)
|
kittage::image::Image::from(dyn_img)
|
||||||
|
|||||||
+6
-1
@@ -78,7 +78,12 @@ pub async fn run_action<'es>(
|
|||||||
pub async fn do_shms_work(ev_stream: &mut EventStream) -> bool {
|
pub async fn do_shms_work(ev_stream: &mut EventStream) -> bool {
|
||||||
let img = DynamicImage::new_rgb8(1, 1);
|
let img = DynamicImage::new_rgb8(1, 1);
|
||||||
let pid = std::process::id();
|
let pid = std::process::id();
|
||||||
let Ok(mut k_img) = kittage::image::Image::shm_from(img, &format!("tdf_test_{pid}")) else {
|
let shm_name = format!("tdf_test_{pid}");
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
let shm_name = &*shm_name;
|
||||||
|
|
||||||
|
let Ok(mut k_img) = kittage::image::Image::shm_from(img, shm_name) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -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
|
// and get the ratio that this page would have to be scaled by to fit perfectly within the
|
||||||
// area provided to us.
|
// 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
|
// 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
|
// 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
|
// scale the height to fit perfectly. The dimension that _is not_ scaled to fit perfectly
|
||||||
|
|||||||
+10
-2
@@ -70,11 +70,18 @@ fn reset_term() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
fn main() -> Result<(), WrappedErr> {
|
||||||
async fn main() -> Result<(), WrappedErr> {
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(3)
|
||||||
|
.enable_time()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
rt.block_on(async move {
|
||||||
let result = inner_main().await;
|
let result = inner_main().await;
|
||||||
reset_term();
|
reset_term();
|
||||||
result
|
result
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn inner_main() -> Result<(), WrappedErr> {
|
async fn inner_main() -> Result<(), WrappedErr> {
|
||||||
@@ -401,6 +408,7 @@ async fn enter_redraw_loop(
|
|||||||
},
|
},
|
||||||
InputAction::Search(term) => to_renderer.send(RenderNotif::Search(term))?,
|
InputAction::Search(term) => to_renderer.send(RenderNotif::Search(term))?,
|
||||||
InputAction::Invert => to_renderer.send(RenderNotif::Invert)?,
|
InputAction::Invert => to_renderer.send(RenderNotif::Invert)?,
|
||||||
|
InputAction::Rotate => to_renderer.send(RenderNotif::Rotate)?,
|
||||||
InputAction::Fullscreen => fullscreen = !fullscreen,
|
InputAction::Fullscreen => fullscreen = !fullscreen,
|
||||||
InputAction::SwitchRenderZoom(f_or_f) => {
|
InputAction::SwitchRenderZoom(f_or_f) => {
|
||||||
to_renderer.send(RenderNotif::SwitchFitOrFill(f_or_f)).unwrap();
|
to_renderer.send(RenderNotif::SwitchFitOrFill(f_or_f)).unwrap();
|
||||||
|
|||||||
+47
-4
@@ -20,7 +20,8 @@ pub enum RenderNotif {
|
|||||||
Search(String),
|
Search(String),
|
||||||
SwitchFitOrFill(FitOrFill),
|
SwitchFitOrFill(FitOrFill),
|
||||||
Reload,
|
Reload,
|
||||||
Invert
|
Invert,
|
||||||
|
Rotate
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -37,6 +38,14 @@ pub enum RenderInfo {
|
|||||||
Reloaded
|
Reloaded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub enum RotateDirection {
|
||||||
|
Deg0,
|
||||||
|
Deg90,
|
||||||
|
Deg180,
|
||||||
|
Deg270
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PageInfo {
|
pub struct PageInfo {
|
||||||
pub img_data: ImageData,
|
pub img_data: ImageData,
|
||||||
@@ -98,13 +107,21 @@ pub fn start_rendering(
|
|||||||
|
|
||||||
let mut stored_doc = None;
|
let mut stored_doc = None;
|
||||||
let mut invert = false;
|
let mut invert = false;
|
||||||
|
let mut rotate = RotateDirection::Deg0;
|
||||||
let mut preserved_area = None;
|
let mut preserved_area = None;
|
||||||
let mut fit_or_fill = FitOrFill::Fit;
|
let mut fit_or_fill = FitOrFill::Fit;
|
||||||
|
|
||||||
let mut need_rerender = VecDeque::new();
|
let mut need_rerender = VecDeque::new();
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
let path = path.to_string_lossy();
|
||||||
|
|
||||||
'reload: loop {
|
'reload: loop {
|
||||||
let doc = match Document::open(path) {
|
// Need to do this weird borrow thing so that we convert `Cow<'_, str>` -> `&str` on windows
|
||||||
|
// and keep unix a `&Path` -> `&Path` 'cause there are different requirements within mupdf
|
||||||
|
// about file paths per-platform
|
||||||
|
#[cfg_attr(unix, expect(clippy::borrow_deref_ref))]
|
||||||
|
let doc = match Document::open(&*path) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// if there's an error, tell the main loop
|
// if there's an error, tell the main loop
|
||||||
sender.send(Err(RenderError::Doc(e)))?;
|
sender.send(Err(RenderError::Doc(e)))?;
|
||||||
@@ -238,6 +255,18 @@ pub fn start_rendering(
|
|||||||
}
|
}
|
||||||
continue 'render_pages;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@@ -301,6 +330,7 @@ pub fn start_rendering(
|
|||||||
black,
|
black,
|
||||||
white,
|
white,
|
||||||
fit_or_fill,
|
fit_or_fill,
|
||||||
|
rotate,
|
||||||
(area_w, area_h)
|
(area_w, area_h)
|
||||||
) {
|
) {
|
||||||
// If that fn returned Some, that means it needed to be re-rendered for some
|
// If that fn returned Some, that means it needed to be re-rendered for some
|
||||||
@@ -455,6 +485,7 @@ fn render_single_page_to_ctx(
|
|||||||
black: i32,
|
black: i32,
|
||||||
white: i32,
|
white: i32,
|
||||||
fit_or_fill: FitOrFill,
|
fit_or_fill: FitOrFill,
|
||||||
|
rotate: RotateDirection,
|
||||||
(area_w, area_h): (f32, f32)
|
(area_w, area_h): (f32, f32)
|
||||||
) -> Result<RenderedContext, mupdf::error::Error> {
|
) -> Result<RenderedContext, mupdf::error::Error> {
|
||||||
let result_rects = match prev_render.num_search_found {
|
let result_rects = match prev_render.num_search_found {
|
||||||
@@ -465,7 +496,12 @@ fn render_single_page_to_ctx(
|
|||||||
|
|
||||||
// then, get the size of the page
|
// then, get the size of the page
|
||||||
let bounds = page.bounds()?;
|
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 scaled = scale_img_for_area(page_dim, (area_w, area_h), fit_or_fill);
|
||||||
let ScaledResult {
|
let ScaledResult {
|
||||||
@@ -482,7 +518,13 @@ fn render_single_page_to_ctx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let colorspace = Colorspace::device_rgb();
|
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)?;
|
let mut pixmap = page.to_pixmap(&matrix, &colorspace, false, false)?;
|
||||||
if invert {
|
if invert {
|
||||||
@@ -494,6 +536,7 @@ fn render_single_page_to_ctx(
|
|||||||
let (x_res, y_res) = pixmap.resolution();
|
let (x_res, y_res) = pixmap.resolution();
|
||||||
let new_x = (x_res as f32 * scale_factor) as i32;
|
let new_x = (x_res as f32 * scale_factor) as i32;
|
||||||
let new_y = (y_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);
|
pixmap.set_resolution(new_x, new_y);
|
||||||
|
|
||||||
let result_rects = result_rects
|
let result_rects = result_rects
|
||||||
|
|||||||
+12
-5
@@ -9,10 +9,6 @@ use crossterm::{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
use kittage::display::DisplayLocation;
|
use kittage::display::DisplayLocation;
|
||||||
use nix::{
|
|
||||||
sys::signal::{Signal::SIGSTOP, kill},
|
|
||||||
unistd::Pid
|
|
||||||
};
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
layout::{Constraint, Flex, Layout, Position, Rect},
|
layout::{Constraint, Flex, Layout, Position, Rect},
|
||||||
@@ -801,10 +797,17 @@ impl Tui {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
disable_raw_mode().unwrap();
|
disable_raw_mode().unwrap();
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
// This process will hang after the SIGSTOP call until we get
|
// This process will hang after the SIGSTOP call until we get
|
||||||
// foregrounded again by something else, at which point we need to
|
// foregrounded again by something else, at which point we need to
|
||||||
// re-setup everything so that it all gets drawn again.
|
// re-setup everything so that it all gets drawn again.
|
||||||
kill(Pid::this(), SIGSTOP).unwrap();
|
nix::sys::signal::kill(
|
||||||
|
nix::unistd::Pid::this(),
|
||||||
|
nix::sys::signal::Signal::SIGSTOP
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
enable_raw_mode().unwrap();
|
enable_raw_mode().unwrap();
|
||||||
execute!(
|
execute!(
|
||||||
@@ -836,6 +839,7 @@ impl Tui {
|
|||||||
'G' if can_zoom => self.update_zoom(Zoom::pan_top),
|
'G' if can_zoom => self.update_zoom(Zoom::pan_top),
|
||||||
'0' if can_zoom => self.update_zoom(Zoom::pan_left),
|
'0' if can_zoom => self.update_zoom(Zoom::pan_left),
|
||||||
'$' if can_zoom => self.update_zoom(Zoom::pan_right),
|
'$' if can_zoom => self.update_zoom(Zoom::pan_right),
|
||||||
|
'r' => Some(InputAction::Rotate),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1107,6 +1111,8 @@ H, J, K, L (when zoomed in):
|
|||||||
Pan direction around page
|
Pan direction around page
|
||||||
0/$ (when on fill-screen):
|
0/$ (when on fill-screen):
|
||||||
Scroll to left/right side of page
|
Scroll to left/right side of page
|
||||||
|
r:
|
||||||
|
Rotate by 90 degrees
|
||||||
";
|
";
|
||||||
|
|
||||||
pub enum InputAction {
|
pub enum InputAction {
|
||||||
@@ -1115,6 +1121,7 @@ pub enum InputAction {
|
|||||||
Search(String),
|
Search(String),
|
||||||
QuitApp,
|
QuitApp,
|
||||||
Invert,
|
Invert,
|
||||||
|
Rotate,
|
||||||
Fullscreen,
|
Fullscreen,
|
||||||
SwitchRenderZoom(crate::FitOrFill)
|
SwitchRenderZoom(crate::FitOrFill)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user