Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

chore: revert unrelated churn from #2155

FredAppsac4f26a00df4
diff --git a/crates/automation/tests/it/automation.rs b/crates/automation/tests/it/automation.rs
index 080a6e657..7e8a75e12 100644
--- a/crates/automation/tests/it/automation.rs
+++ b/crates/automation/tests/it/automation.rs
@@ -1121,11 +1121,11 @@ fn a_recovered_page_tree_survives_a_full_save() {
original.extend_from_slice(b"\nendobj\n");
}
let xref = original.len();
- original.extend_from_slice(format!("xref\n0 {}\n0000000000 65535 f \n", objs.len() + 1).as_bytes());
+ original.extend_from_slice(b"xref\n0 5\n0000000000 65535 f \n");
for o in offsets {
original.extend_from_slice(format!("{o:010} 00000 n \n").as_bytes());
}
- original.extend_from_slice(format!("trailer\n<< /Size {} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n", objs.len() + 1).as_bytes());
+ original.extend_from_slice(format!("trailer\n<< /Size 5 /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n").as_bytes());
std::fs::write(dir.join("damaged.pdf"), &original).unwrap();
let mut a = auto(&dir);
diff --git a/crates/engine/src/camera_edges.rs b/crates/engine/src/camera_edges.rs
index 8ba00ea76..cee5c8f69 100644
--- a/crates/engine/src/camera_edges.rs
+++ b/crates/engine/src/camera_edges.rs
@@ -3,7 +3,7 @@
//! along most of its length. Pure Rust and deterministic; `None` when nothing convinces, so the
//! caller falls back to corners the user places.
//!
-//! Steps: shrink the picture to `WORK` pixels on its long side, blur it, take Sobel gradients
+//! Steps: shrink the picture to [`WORK`] pixels on its long side, blur it, take Sobel gradients
//! and keep thin, strong edges; vote for lines (a Hough transform that only votes along each
//! edge's own gradient direction, give or take a few degrees); pair two near-horizontal with two near-vertical lines; keep
//! the quadrilaterals whose four sides lie on edges, and choose the largest.
diff --git a/crates/engine/src/js.rs b/crates/engine/src/js.rs
index 4f38c0123..d1ee5c15b 100644
--- a/crates/engine/src/js.rs
+++ b/crates/engine/src/js.rs
@@ -393,7 +393,7 @@ pub(crate) fn words_with(text: &pdfcraft_render::PageText, map: impl Fn(f32, f32
impl Session {
/// Prepare a form ▸ automatic field detection: the fields `pages` (0-based; empty = all)
/// seem to ask for, named from their labels, as (page, candidate). Scanned pages (a picture
- /// and no drawn shapes) are read from their pixels, see `crate::scan_fields`.
+ /// and no drawn shapes) are read from their pixels, see [`crate::scan_fields`].
pub fn detect_fields(&self, id: DocId, pages: &[usize]) -> Vec<(usize, pdfcraft_forms::detect::Candidate)> {
self.detect_fields_turned(id, pages).into_iter().map(|(page, c, _)| (page, c)).collect()
}
diff --git a/crates/fonts/src/pdf.rs b/crates/fonts/src/pdf.rs
index 2c4689599..240b1c4d5 100644
--- a/crates/fonts/src/pdf.rs
+++ b/crates/fonts/src/pdf.rs
@@ -58,7 +58,7 @@ pub struct Metrics {
pub bold: bool,
pub italic: bool,
/// Whether this font draws Indic text in visual order (pre-base vowel signs before their
- /// consonant): a known legacy Indic font whose Unicode mapping is Indic. See `legacy_indic_font`.
+ /// consonant): a known legacy Indic font whose Unicode mapping is Indic. See [`legacy_indic_font`].
pub visual_order: bool,
/// Bytes per code for writing new text (1 for simple fonts, else the codespace length).
code_len: usize,
diff --git a/crates/forms/src/detect/raster.rs b/crates/forms/src/detect/raster.rs
index 8490d49c1..d54e36e5c 100644
--- a/crates/forms/src/detect/raster.rs
+++ b/crates/forms/src/detect/raster.rs
@@ -4,14 +4,14 @@
//! Steps:
//! - Ink is a pixel clearly darker than the paper around it (a local mean, so the uneven paper
//! of a scan or photo still reads as paper).
-//! - Straight lines are runs of ink at least `MIN_LINE` long, horizontal or vertical, with
+//! - Straight lines are runs of ink at least [`MIN_LINE`] long, horizontal or vertical, with
//! short gaps (noise, a faint print) bridged.
//! - A box is a patch of paper that the lines enclose and that is close to a rectangle. Its
//! writing area is the whole box when it is empty, or else the largest band of empty rows or
//! columns in it (many official forms print a small label in the corner of each box).
//! - The remaining horizontal lines, the ones that are not the edge of a box, are rules.
//!
-//! Everything is bounded: pictures larger than `MAX_PIXELS` are refused (the caller renders
+//! Everything is bounded: pictures larger than [`MAX_PIXELS`] are refused (the caller renders
//! at a resolution that fits), and the results are capped.
use super::Shapes;
diff --git a/crates/render/src/pixels.rs b/crates/render/src/pixels.rs
index 89a9b56bb..ff686ce32 100644
--- a/crates/render/src/pixels.rs
+++ b/crates/render/src/pixels.rs
@@ -30,7 +30,6 @@ impl Pixels {
}
/// Bytes the buffer holds allocated (its capacity), for memory budgets.
- #[allow(dead_code)]
pub(crate) fn byte_capacity(&self) -> usize {
self.0.capacity().saturating_mul(4)
}
diff --git a/crates/sign/src/keys.rs b/crates/sign/src/keys.rs
index fe3eec240..0521c5d91 100644
--- a/crates/sign/src/keys.rs
+++ b/crates/sign/src/keys.rs
@@ -441,7 +441,7 @@ impl PublicKey {
}
/// Check `sig` over a message whose digest (with `alg`) is `digest`. Encodings are read
- /// leniently (see `crate::rsa_pad`, `ecdsa_rs`); the cryptographic check never is.
+ /// leniently (see [`crate::rsa_pad`], [`ecdsa_rs`]); the cryptographic check never is.
/// `Err(Unsupported)` means "can't tell", as opposed to `Ok(false)`: "doesn't match".
pub fn verify(&self, scheme: Scheme, alg: DigestAlg, digest: &[u8], sig: &[u8]) -> Result<bool, SignError> {
self.verify_noting(scheme, alg, digest, sig, &mut Vec::new())
diff --git a/crates/sign/src/pkcs12.rs b/crates/sign/src/pkcs12.rs
index 3f2d0357b..a71d5c858 100644
--- a/crates/sign/src/pkcs12.rs
+++ b/crates/sign/src/pkcs12.rs
@@ -59,7 +59,7 @@ pub const MIN_PASSWORD_CHARS: usize = 8;
/// The most key-derivation work one [`open`] does, in hash blocks summed over every derivation
/// in the file. The file names its own iteration counts, so without a budget a crafted file
-/// hangs the caller on the password check (#1847). A file written by [`write()`] needs about
+/// hangs the caller on the password check (#1847). A file written by [`write`] needs about
/// 2 million; real files from other tools need far less.
const OPEN_BUDGET: u64 = 10_000_000;
diff --git a/crates/ui-egui/src/persist/units.rs b/crates/ui-egui/src/persist/units.rs
index c25065c6f..a345456fa 100644
--- a/crates/ui-egui/src/persist/units.rs
+++ b/crates/ui-egui/src/persist/units.rs
@@ -68,7 +68,6 @@ impl Unit {
/// The unit for a locale tag's region: `en_US.UTF-8`, `en-US`, `bg-BG`, `zh-Hans-CN`, `en_GB@euro`.
/// `None` without a region (`C`, `POSIX`, `en`).
-#[allow(dead_code)]
pub(crate) fn unit_for_tag(tag: &str) -> Option<Unit> {
let tag = tag.split(['.', '@']).next().unwrap_or_default();
let region = tag.split(['-', '_']).skip(1).filter(|p| p.len() == 2 && p.chars().all(|c| c.is_ascii_alphabetic())).last()?;
diff --git a/crates/ui-egui/src/platform/motion.rs b/crates/ui-egui/src/platform/motion.rs
index 316f82076..92ca469da 100644
--- a/crates/ui-egui/src/platform/motion.rs
+++ b/crates/ui-egui/src/platform/motion.rs
@@ -8,13 +8,13 @@
//!
//! - A wheel notch scrolls its whole distance in the frame it arrives. egui spreads a notch
//! over about a quarter of a second and has no switch for that, so each frame's wheel input
-//! is read again here, the way egui reads it but for the easing (`WheelReader`), and handed
+//! is read again here, the way egui reads it but for the easing ([`WheelReader`]), and handed
//! to egui's scroll areas in place of its own.
//! - ⌘/Ctrl-wheel zooms by a notch's whole step at once: egui makes its zoom factor from the
-//! same eased wheel motion. Views read `zoom_delta` instead of egui's.
+//! same eased wheel motion. Views read [`zoom_delta`] instead of egui's.
//! - Scrolling to a place (a row revealed by the keys, the Hand tool's drag) takes no time.
//! - egui's other animations (menus fading in, sections opening) take no time: its style's
-//! animation time is zero, which the app's own fades and sweeps ask about too (`animated`).
+//! animation time is zero, which the app's own fades and sweeps ask about too ([`animated`]).
//!
//! How far anything scrolls or zooms doesn't change, only how long it takes.
@@ -68,7 +68,7 @@ impl AnimationEffects {
}
/// Asks the system whether it wants no animations; `None` when it can't say, which leaves the
-/// last answer standing. Asked from the UI thread every `ASK_EVERY` seconds while the window
+/// last answer standing. Asked from the UI thread every [`ASK_EVERY`] seconds while the window
/// is in use, so it must answer at once.
pub type MotionSource = Box<dyn Fn() -> Option<bool>>;
diff --git a/crates/ui-egui/src/workflows/web_print.rs b/crates/ui-egui/src/workflows/web_print.rs
index 8dfd155e6..6af878daf 100644
--- a/crates/ui-egui/src/workflows/web_print.rs
+++ b/crates/ui-egui/src/workflows/web_print.rs
@@ -132,7 +132,7 @@ pub(crate) fn print_document_html(sheets: &[(f64, f64)], urls: &[String]) -> Str
}
/// A browser print being prepared: the print-ready PDF's sheets drawn one [`WebPrintJob::step`]
-/// at a time and handed to a sink (on the web, `blob_url`), which answers with the picture's URL.
+/// at a time and handed to a sink (on the web, [`blob_url`]), which answers with the picture's URL.
pub(crate) struct WebPrintJob {
exporter: Exporter,
/// The print-ready PDF, kept for the download fallback when the browser won't print.
@@ -207,7 +207,7 @@ impl Drop for WebPrintJob {
}
}
-/// Let go of pictures handed out by `blob_url`.
+/// Let go of pictures handed out by [`blob_url`].
fn revoke(urls: &[String]) {
#[cfg(target_arch = "wasm32")]
for url in urls {
diff --git a/crates/ui-egui/tests/it/combine_grid.rs b/crates/ui-egui/tests/it/combine_grid.rs
index 59a5a21c1..0339e0b6b 100644
--- a/crates/ui-egui/tests/it/combine_grid.rs
+++ b/crates/ui-egui/tests/it/combine_grid.rs
@@ -166,7 +166,7 @@ fn grid_duplicate_warnings_compare_contents_and_follow_undo() {
/// Run frames until `done`, giving render threads time; whether it happened.
fn settle(h: &mut Harness<'static, PdfCraftApp>, done: impl Fn(&PdfCraftApp) -> bool) -> bool {
- for _ in 0..800 {
+ for _ in 0..400 {
h.run_steps(1);
if done(h.state()) {
return true;
@@ -1258,21 +1258,18 @@ fn a_right_click_on_a_card_offers_preview_and_remove() {
#[test]
fn the_preview_closes_when_its_file_leaves_and_keeps_to_three_render_threads() {
- let files: Vec<(String, Vec<u8>)> = (0..12).map(|i| (format!("f{i:02}.pdf"), if i < 6 { heavy() } else { fixture(1) })).collect();
+ let files: Vec<(String, Vec<u8>)> = (0..12).map(|i| (format!("f{i:02}.pdf"), heavy())).collect();
let mut h = grid_after_one(files.iter().map(|(n, b)| (n.as_str(), b.clone())).collect(), vec2(1400.0, 900.0));
hover_card(&mut h, "f03.pdf");
h.get_by_label("Preview").click();
let (mut most, mut rendered) = (0, false);
- for frame in 0..120 {
+ for frame in 0..60 {
h.run_steps(1);
let threads = h.state_mut().combine_thumbnail_threads();
most = most.max(threads);
assert!(threads <= 3, "frame {frame}: {threads} render threads");
// The large page itself is rendered (under way, or done) among them.
rendered |= matches!(h.state().combine_preview(), Some((_, _, CombineThumb::Pending | CombineThumb::Ready { .. })));
- if rendered && frame >= 40 {
- break;
- }
std::thread::sleep(Duration::from_millis(5));
}
assert!(most > 0);
diff --git a/crates/ui-egui/tests/it/forms.rs b/crates/ui-egui/tests/it/forms.rs
index 21ca016ee..fa828a8f9 100644
--- a/crates/ui-egui/tests/it/forms.rs
+++ b/crates/ui-egui/tests/it/forms.rs
@@ -651,7 +651,7 @@ fn tabbing_back_to_the_same_field_then_saving_keeps_the_committed_value() {
("single-backward", false, true, false),
("shared-forward", true, false, false),
("shared-backward", true, true, false),
- ("tab-same-frame", false, false, true),
+ ("same-frame", false, false, true),
] {
let dir = scratch(case);
let out = dir.join("saved.pdf");