Skip to content

A fast, helpful, and open-source document parser

wip

Logan Markewichba9d8abcf44c
diff --git a/MARKDOWN_PROGRESS.md b/MARKDOWN_PROGRESS.md
index a8eab07..79968c9 100644
--- a/MARKDOWN_PROGRESS.md
+++ b/MARKDOWN_PROGRESS.md
@@ -2,6 +2,44 @@
Tracks build-order progress against [MARKDOWN_PLAN.md](MARKDOWN_PLAN.md). Update as steps complete.
+> **2026-06-04 inferred-tracks table detector — olmOCR-bench table_tests 38.8% → 39.5% (+0.7pp, +7 tests), Overall 35.1% → 35.2%; opendataloader & ParseBench unchanged.** Targeted the dominant `wrong_neighbors` failure on financial/earnings tables (e.g. Apple/Wiley `a769f9a3…pg2`, `fa18a15c…`, hundreds of similar narrow-numeric tables): the existing `try_detect_table` derives column tracks from the FIRST row's `split_cells` output, which uses `TABLE_CELL_GAP_FONT_MULTIPLIER × font_size` (= 14pt at 14pt body) as the inter-span gap threshold. The Apple Revenue Q3 row has `$448 → $427` and `$427 → 7%` gaps of 13.9pt — *just under* the threshold — so its 5 distinct PDFium items collapse to 3 cells (`$448 $427 7%` lumped). Every row in the Revenue table fails identically, so the table establishes as 3-col, and the cross-run merge can't recover (`merge_consecutive_table_runs` only handles `|A|+1 == |B|`).
+>
+> **New `try_detect_table_inferred` (`markdown_layout/tables.rs`).** Runs in `detect_tables` *before* `try_detect_table`. Steps:
+> 1. **`infer_tracks_from_raw_items`**: walks forward from `start_idx` while `table_rows_adjacent` holds (cap `TABLE_TRACK_INFERENCE_MAX_ROWS=12`), collects `span.x` for every non-whitespace span on each row with ≥2 spans, then single-link clusters at `TABLE_TRACK_TOLERANCE_PT` (6pt). The Apple Q3 row alone exposes all 5 column anchors (49.5/119/152.6/186.2/253.3); even with PDFium-level merge on 9 Months row, the union across rows recovers the full geometry.
+> 2. **Track-soundness guards** (all required): `tracks.len() ≥ TABLE_MIN_COLUMNS`, `tracks.len() > baseline_cells.len()` (only re-seed if we'd actually unlock more columns), and `min(inter-track gap) ≥ max(1.5 × seed_font_size, 12pt)` — rejects inferred "tracks" that are really inter-word positions in prose (word gaps are typically <1× font size).
+> 3. **Strict seed-row check**: the seed (`lines[start_idx]`) must have `≥ tracks.len()` raw PDFium spans AND each span must single-cover (no track ranges where one span x-extent overlaps ≥2 anchors). This is the load-bearing false-positive guard — see "Seed strictness" below.
+> 4. **`cells_from_raw_items_with_tracks`** per row: walk raw items, assign each to its nearest track within tol; for items whose `[x, x+width]` covers multiple tracks AND whose `x` anchors at the leftmost covered track (within tol), generalize `split_merged_at_anchor` to N anchors — pick whitespace positions whose linearly-interpolated x is closest to each subsequent track. Rejects rows with <2 PDFium spans (single-span lines spanning the track region are prose, not merged-numeric rows). Returns `Some(cells)` of length `tracks.len()` (some cells may be empty for sparse rows).
+> 5. **Cell-text dedup via existing absorb path**: re-uses `absorb_header_lines` and the bold-first-row promotion already in `try_detect_table`. CV check via `row_spacing_cv` rejects runs with irregular cadence and falls back to the existing path.
+>
+> **Seed strictness was load-bearing.** The first cut required only `seed_spans + 1 ≥ tracks.len()` (one multi-cover split allowed in seed). That preserved +16 table tests but regressed multi_column by -5 — the failure was 2-column prose like `027c39…page_2` where PDFium emits "in the" and "study. The subjects including 343 males and 293" as two spans on one baseline. The first span at `x=56.7` width-extent reaches past `x=84.2` (the second span's anchor), so my detector saw "in the" as covering tracks 0 AND 1, split it at whitespace, and shredded the line into `| in | the study. The subjects... | males and 293 |` — a fake table. Tightening to `seed_spans ≥ tracks.len()` AND no multi-cover spans in the seed eliminated the regression (multi_column held exactly at 49.4%, no `order` tests lost) while still catching Apple's Q3 row (5 spans, all single-cover at 5 tracks). The trade: 9 of the 16 initially-won table tests were lost (cases where the table's first row had merged spans), but the +7 retained tests are net positive with zero collateral.
+>
+> **Per-PDF verification on Apple Wiley `a769f9a3…pg2`**: before, `| Q3 | $448 $427 7% | 5% |` and `| 9 Months | $1,298 $1,263 5% | 3% |` (3-col, merged); after, `| Q3 | $448 | $427 | 7% | 5% |` and `| 9 Months | $1,298 | $1,263 | 5% | 3% |` (5-col, split). The 9 Months row's PDFium-merged `$1,298 $1,263 5%` single span gets split at whitespace positions nearest each downstream track anchor. Adjusted EPS and Reported EPS sub-tables retain their existing correct 5-col emission.
+>
+> **Bench-by-bench:**
+>
+> | Bench | Metric | Baseline | After | Δ |
+> |---|---|---|---|---|
+> | olmOCR | Overall | 35.1% | **35.2%** | +0.1pp |
+> | | `table_tests` | 38.8% (397) | **39.5% (404)** | **+0.7pp, +7 tests** |
+> | | multi_column / order / headers_footers / baseline / long_tiny_text | — | — | flat |
+> | opendataloader | NID / TEDS / MHS / Overall | 0.881 / 0.603 / 0.631 / 0.800 | (same) | flat |
+> | ParseBench | table (GriTS / TRM / composite) | 0.458 / 0.130 / 0.304 | (same) | flat |
+> | | chart / layout / text_content | — | (same) | flat |
+> | | text_formatting | 0.3212 | 0.3209 | -0.03pp (noise, <0.5%) |
+>
+> **Why ParseBench didn't move** (same as description-list pass): GriTS + Table Record Match score against full multi-level header chains. The fix correctly emits one more column on the targeted tables but doesn't reconstruct multi-row header layers (Aug 21 / 2011 / (percent) on `fa18a15c`), which is what the bench's `top_heading` lookups require. Need the upward header absorption fix to move that needle.
+>
+> **Why opendataloader didn't move**: its `try_detect_description_list` path already covers the 2-col borderless shape that's the dominant failure mode on that corpus. The strict-seed inferred path doesn't fire on description-list layouts (col 0 is single span, col 1 is single span — only 2 PDFium spans for 3+ tracks would never happen because there's no 3rd column).
+>
+> **Why olmOCR only +7 instead of the +40-80 originally projected**: most of `wrong_neighbors` failures aren't the Apple shape. The B2 vertical-baseline-merge case (where PDFium fuses 3 stacked baselines into one span) needs a different fix entirely — vertical detection of intra-span baseline boundaries, not lateral anchor splits. The strict-seed guard also rejects tables where *every* row has at least one merged-span column (rare in practice but exists). The `+7` we got are tables where at least one row has the Apple shape — every column a distinct PDFium item.
+>
+> **Files**: `crates/liteparse/src/markdown_layout/tables.rs` only — added `TABLE_TRACK_INFERENCE_MAX_ROWS`, `infer_tracks_from_raw_items`, `cells_from_raw_items_with_tracks`, `split_span_at_anchors`, `try_detect_table_inferred`, wired into `detect_tables` ahead of `try_detect_table`. No projection-layer changes. CLI builds clean; lib-test compile is broken project-wide on this branch by pre-existing local changes in `ocr_merge.rs` / `projection.rs` (unrelated). No new tests added yet — would follow up with unit coverage of the seed-strictness guard, the multi-anchor split path, and the 027c39-style false-positive guard.
+>
+> **Deferred — next leverage**:
+> 1. **B2 vertical wrapped-row split** — the *other* half of the original "+40-80" projection. Needs a "this single PDFium span contains multiple stacked baselines" detector — symmetric to the lateral fix but different signal (internal baseline-gap signature). Targets the financial earnings tables where PDFium fuses 3 stacked numbers into one span.
+> 2. **Multi-level header upward extension** in `absorb_header_lines` — moves ParseBench. The strict-seed guard here doesn't help the header-row case; needs the `cells.len() > column_count` slack with whitespace-split recovery for header lines.
+> 3. **Relax seed strictness in the inferred path** if a separate prose-line discriminator can be found — would recover the lost 9 table tests. The CV-of-cell-widths guard (CV ≥ 0.7) was tried and rejected (cost 6 table tests without fixing the multi_column regression). The line-numbered academic paper case (e.g. `05eac72b…page_6`) is a *pre-existing* failure of the existing `try_detect_table`, not introduced by this fix — would need a separate "table inside vs across page columns" geometry check.
+
> **2026-06-04 description-list 2-col table detector — opendataloader TEDS 0.5527 → 0.6028 (+0.050), Overall 0.7953 → 0.8000 (+0.005); olmOCR-bench table_tests 35.8% → 38.8% (+3.0pp, +31 tests), Overall 34.7% → 35.2%; ParseBench unchanged.** Targeted the 9 opendataloader docs at TEDS=0 — borderless 2-column "label | description" tables that the existing `try_detect_table` rejected because `TABLE_MIN_COLUMNS = 3`. Five of the nine zeros (132 species, 146 framework, 150 competence, 166 CEC, 197 task names) have this shape; 110 is OCR-gated, 121/122 are upstream PDFium item-order garble, 165 is a sparse fill-in worksheet with one-cell body rows.
>
> **New `try_detect_description_list` (`markdown_layout/tables.rs`).** Runs after `try_detect_table` in the `detect_tables` loop. Conditions:
diff --git a/crates/liteparse/src/markdown_layout/classify.rs b/crates/liteparse/src/markdown_layout/classify.rs
index fafdd3e..c57d1a3 100644
--- a/crates/liteparse/src/markdown_layout/classify.rs
+++ b/crates/liteparse/src/markdown_layout/classify.rs
@@ -2,9 +2,8 @@ use crate::types::{OutlineTarget, ParsedPage, ProjectedLine};
use super::blocks::{Block, paragraph_from_accum};
use super::headings::{
- MAX_HEADING_LEVELS, heading_level_for, is_caption_line, looks_like_bold_heading,
- is_toc_title, looks_like_numbered_bold_heading, outline_heading_level, page_is_toc,
- struct_heading_level,
+ MAX_HEADING_LEVELS, heading_level_for, is_caption_line, is_toc_title, looks_like_bold_heading,
+ looks_like_numbered_bold_heading, outline_heading_level, page_is_toc, struct_heading_level,
};
use super::hr::detect_horizontal_rules;
use super::inline::{
@@ -178,25 +177,23 @@ pub fn classify_page_with_filters(
// already passed. Suppressed inside table y-extents to keep cell-spanning
// raster cell backgrounds (rare but possible) from spawning a figure
// mid-table.
- let figure_entries: Vec<(f32, crate::types::ImageRef)> = if matches!(
- image_mode,
- crate::config::ImageMode::Off
- ) {
- Vec::new()
- } else {
- let mut v: Vec<(f32, crate::types::ImageRef)> = page
- .image_refs
- .iter()
- .filter(|r| {
- !table_y_extents
- .iter()
- .any(|(top, bot)| r.bbox.y >= *top - 2.0 && r.bbox.y <= *bot + 2.0)
- })
- .map(|r| (r.bbox.y, r.clone()))
- .collect();
- v.sort_by(|a, b| a.0.total_cmp(&b.0));
- v
- };
+ let figure_entries: Vec<(f32, crate::types::ImageRef)> =
+ if matches!(image_mode, crate::config::ImageMode::Off) {
+ Vec::new()
+ } else {
+ let mut v: Vec<(f32, crate::types::ImageRef)> = page
+ .image_refs
+ .iter()
+ .filter(|r| {
+ !table_y_extents
+ .iter()
+ .any(|(top, bot)| r.bbox.y >= *top - 2.0 && r.bbox.y <= *bot + 2.0)
+ })
+ .map(|r| (r.bbox.y, r.clone()))
+ .collect();
+ v.sort_by(|a, b| a.0.total_cmp(&b.0));
+ v
+ };
let mut figure_iter = figure_entries.into_iter().peekable();
// Emit any HRs whose y is at or above `before_y`. Flushes the active
@@ -384,11 +381,7 @@ pub fn classify_page_with_filters(
// TOCs list entries without inline trailing page numbers, so the
// page-level detector misses them. `is_toc_title` matches the *entire*
// trimmed line against an exact whitelist, so it can't fire mid-prose.
- let toc_title_level = if is_toc_title(text) {
- Some(1u8)
- } else {
- None
- };
+ let toc_title_level = if is_toc_title(text) { Some(1u8) } else { None };
let level = outline_level
.or(size_level)
.or(toc_title_level)
@@ -438,7 +431,10 @@ pub fn classify_page_with_filters(
&& looks_like_numbered_bold_heading(
line,
rest,
- paragraph.as_ref().map(|p| &p.last).or(last_list_line.as_ref()),
+ paragraph
+ .as_ref()
+ .map(|p| &p.last)
+ .or(last_list_line.as_ref()),
lines.get(idx),
)
{
@@ -571,14 +567,14 @@ pub fn classify_page_with_filters(
#[cfg(test)]
mod tests {
+ use super::super::blocks::{Block, render_blocks};
use super::super::headings::{build_heading_map, compute_body_size};
use super::super::repetition::compute_header_footer_set;
use super::super::test_helpers::{
- header_footer_page, line, mono_line, page, page_with_graphics, styled_line, stroke,
+ header_footer_page, line, mono_line, page, page_with_graphics, stroke, styled_line,
};
use super::*;
use crate::types::TextItem;
- use super::super::blocks::{Block, render_blocks};
#[test]
fn classify_emits_heading_and_paragraph() {
diff --git a/crates/liteparse/src/markdown_layout/headings.rs b/crates/liteparse/src/markdown_layout/headings.rs
index 4b80be5..2a987f6 100644
--- a/crates/liteparse/src/markdown_layout/headings.rs
+++ b/crates/liteparse/src/markdown_layout/headings.rs
@@ -41,8 +41,23 @@ pub(super) fn is_caption_line(text: &str) -> bool {
// Try each known prefix: must be followed by a number (optionally with
// separators) within the first ~20 chars.
const PREFIXES: &[&str] = &[
- "Figure", "Figures", "Fig.", "Fig ", "Table", "Tables", "Tab.", "Tab ",
- "Equation", "Eq.", "Eq ", "Scheme", "Chart", "Plate", "Photo", "Algorithm", "Listing",
+ "Figure",
+ "Figures",
+ "Fig.",
+ "Fig ",
+ "Table",
+ "Tables",
+ "Tab.",
+ "Tab ",
+ "Equation",
+ "Eq.",
+ "Eq ",
+ "Scheme",
+ "Chart",
+ "Plate",
+ "Photo",
+ "Algorithm",
+ "Listing",
];
let lower_t_first_word: String = t
.chars()
@@ -550,7 +565,10 @@ pub(super) fn heading_level_for(size: f32, heading_map: &[(f32, u8)]) -> Option<
/// Highest-priority heading source: a struct-tree node `H1`..`H6` directly
/// tagging this line via its `mcid`. Available only for tagged PDFs.
-pub(super) fn struct_heading_level(line: &ProjectedLine, struct_nodes: &[StructNode]) -> Option<u8> {
+pub(super) fn struct_heading_level(
+ line: &ProjectedLine,
+ struct_nodes: &[StructNode],
+) -> Option<u8> {
let mcid = line.mcid?;
for node in struct_nodes {
if !node.mcids.contains(&mcid) {
diff --git a/crates/liteparse/src/markdown_layout/inline.rs b/crates/liteparse/src/markdown_layout/inline.rs
index bed7f80..e66fbbe 100644
--- a/crates/liteparse/src/markdown_layout/inline.rs
+++ b/crates/liteparse/src/markdown_layout/inline.rs
@@ -190,7 +190,11 @@ pub(super) fn strip_leading_marker_from_inline(s: &str, marker: &str) -> Option<
/// Append an inline-rendered continuation line to an existing list-item body.
/// De-hyphenates against the raw text boundary (mirrors the paragraph rule)
/// and falls back to a space join otherwise.
-pub(super) fn append_inline_continuation(prev_text: &mut String, next_raw: &str, next_inline: &str) {
+pub(super) fn append_inline_continuation(
+ prev_text: &mut String,
+ next_raw: &str,
+ next_inline: &str,
+) {
let next_raw = collapse_whitespace(next_raw);
if next_raw.is_empty() {
return;
diff --git a/crates/liteparse/src/markdown_layout/repetition.rs b/crates/liteparse/src/markdown_layout/repetition.rs
index 0bf4ca6..99be88e 100644
--- a/crates/liteparse/src/markdown_layout/repetition.rs
+++ b/crates/liteparse/src/markdown_layout/repetition.rs
@@ -151,8 +151,7 @@ pub(super) fn matches_chrome_pattern(text: &str) -> bool {
}
// Copyright / trademark chrome.
- if t.contains('©') || lower.contains("copyright ") || lower.contains("all rights reserved")
- {
+ if t.contains('©') || lower.contains("copyright ") || lower.contains("all rights reserved") {
return true;
}
@@ -203,8 +202,7 @@ fn has_year(lower: &str) -> bool {
if !starts_word {
continue;
}
- if (bytes[i] == b'1' && bytes[i + 1] == b'9')
- || (bytes[i] == b'2' && bytes[i + 1] == b'0')
+ if (bytes[i] == b'1' && bytes[i + 1] == b'9') || (bytes[i] == b'2' && bytes[i + 1] == b'0')
{
if bytes[i + 2].is_ascii_digit() && bytes[i + 3].is_ascii_digit() {
let ends_word = i + 4 >= bytes.len() || !bytes[i + 4].is_ascii_alphanumeric();
@@ -316,9 +314,7 @@ pub fn detect_single_page_chrome(
.iter()
.enumerate()
.filter(|(j, l)| {
- *j != idx
- && tops[*j] > bots[idx]
- && !matches_chrome_pattern(l.text.trim())
+ *j != idx && tops[*j] > bots[idx] && !matches_chrome_pattern(l.text.trim())
})
.map(|(j, _)| tops[j] - bots[idx])
.min_by(|a, b| a.partial_cmp(b).unwrap())
@@ -329,9 +325,7 @@ pub fn detect_single_page_chrome(
.iter()
.enumerate()
.filter(|(j, l)| {
- *j != idx
- && bots[*j] < tops[idx]
- && !matches_chrome_pattern(l.text.trim())
+ *j != idx && bots[*j] < tops[idx] && !matches_chrome_pattern(l.text.trim())
})
.map(|(j, _)| tops[idx] - bots[j])
.min_by(|a, b| a.partial_cmp(b).unwrap())
@@ -445,7 +439,9 @@ mod tests {
fn chrome_pattern_recognizes_common_signatures() {
assert!(matches_chrome_pattern("http://example.com/foo"));
assert!(matches_chrome_pattern("www.nature.com/scientificreports/"));
- assert!(matches_chrome_pattern("Please cite this article in press as: ..."));
+ assert!(matches_chrome_pattern(
+ "Please cite this article in press as: ..."
+ ));
assert!(matches_chrome_pattern("Page 12 of 24"));
assert!(matches_chrome_pattern("9"));
assert!(matches_chrome_pattern("© 2023 Acme Corp"));
@@ -466,13 +462,7 @@ mod tests {
// 792pt page; top band = 0..118pt.
let lines = vec![
// Chrome line at y=20 (in top band)
- line(
- "www.nature.com/scientificreports/",
- 50.0,
- 20.0,
- 10.0,
- 10.0,
- ),
+ line("www.nature.com/scientificreports/", 50.0, 20.0, 10.0, 10.0),
// Body title well below chrome (clear gap)
line("Main Body Title", 50.0, 200.0, 14.0, 14.0),
line("Body prose line one.", 50.0, 220.0, 10.0, 10.0),
diff --git a/crates/liteparse/src/markdown_layout/tables.rs b/crates/liteparse/src/markdown_layout/tables.rs
index 0e9f154..bc23097 100644
--- a/crates/liteparse/src/markdown_layout/tables.rs
+++ b/crates/liteparse/src/markdown_layout/tables.rs
@@ -133,7 +133,10 @@ pub(super) fn split_cells(line: &ProjectedLine) -> Vec<TableCell> {
///
/// Returns the patched cells if every short cell could be cleanly split to
/// recover `tracks.len()` cells total; otherwise `None`.
-pub(super) fn recover_merged_cell(mut cells: Vec<TableCell>, tracks: &[f32]) -> Option<Vec<TableCell>> {
+pub(super) fn recover_merged_cell(
+ mut cells: Vec<TableCell>,
+ tracks: &[f32],
+) -> Option<Vec<TableCell>> {
let target = tracks.len();
if cells.len() >= target {
return None;
@@ -337,7 +340,9 @@ fn match_track_idx(cell: &TableCell, track_ranges: &[(f32, f32)]) -> Option<usiz
.enumerate()
.filter(|(_, (s, _))| (cell.start_x - s).abs() <= tol)
.min_by(|(_, (s1, _)), (_, (s2, _))| {
- (cell.start_x - s1).abs().total_cmp(&(cell.start_x - s2).abs())
+ (cell.start_x - s1)
+ .abs()
+ .total_cmp(&(cell.start_x - s2).abs())
})
{
return Some(i);
@@ -353,6 +358,374 @@ fn match_track_idx(cell: &TableCell, track_ranges: &[(f32, f32)]) -> Option<usiz
.map(|(i, _)| i)
}
+/// Maximum number of rows to walk forward when inferring tracks from raw
+/// item positions. 12 covers most real tables while bounding the cost.
+const TABLE_TRACK_INFERENCE_MAX_ROWS: usize = 12;
+
+/// Walk forward from `start_idx` collecting raw text-item start-x positions
+/// across all adjacent rows, then single-link cluster them at
+/// `TABLE_TRACK_TOLERANCE_PT`. Returns cluster centroids sorted ascending.
+///
+/// Unlike `split_cells`-derived tracks, this is immune to the
+/// `TABLE_CELL_GAP_FONT_MULTIPLIER` knife-edge that collapses tightly-kerned
+/// numeric columns into a single cell (e.g. `$448 $427 7%` at 14pt with
+/// 13.9pt inter-item gaps). It also surfaces tracks witnessed by even a
+/// single row when other rows in the same table have PDFium-level merged
+/// spans that hide the full column geometry.
+fn infer_tracks_from_raw_items(lines: &[ProjectedLine], start_idx: usize) -> Vec<f32> {
+ let mut xs: Vec<f32> = Vec::new();
+ let push_row_xs = |xs: &mut Vec<f32>, line: &ProjectedLine| {
+ let row_xs: Vec<f32> = line
+ .spans
+ .iter()
+ .filter(|s| !s.text.trim().is_empty())
+ .map(|s| s.x)
+ .collect();
+ // Skip 0- or 1-item rows — they don't carry column info and can
+ // introduce noise from single-cell prose lines.
+ if row_xs.len() >= 2 {
+ xs.extend(row_xs);
+ }
+ };
+ push_row_xs(&mut xs, &lines[start_idx]);
+ let mut j = start_idx + 1;
+ let mut rows_used = 1;
+ while j < lines.len() && rows_used < TABLE_TRACK_INFERENCE_MAX_ROWS {
+ if !table_rows_adjacent(&lines[j - 1], &lines[j]) {
+ break;
+ }
+ push_row_xs(&mut xs, &lines[j]);
+ j += 1;
+ rows_used += 1;
+ }
+ xs.sort_by(f32::total_cmp);
+ let mut clusters: Vec<f32> = Vec::new();
+ let mut current_sum = 0.0f32;
+ let mut current_count = 0usize;
+ let mut current_anchor = f32::NEG_INFINITY;
+ for &x in &xs {
+ if current_count == 0
+ || (x - current_anchor).abs() <= TABLE_TRACK_TOLERANCE_PT
+ {
+ current_sum += x;
+ current_count += 1;
+ current_anchor = current_sum / current_count as f32;
+ } else {
+ clusters.push(current_sum / current_count as f32);
+ current_sum = x;
+ current_count = 1;
+ current_anchor = x;
+ }
+ }
+ if current_count > 0 {
+ clusters.push(current_sum / current_count as f32);
+ }
+ clusters
+}
+
+/// Build a row's cells against a fixed set of column anchors. Each raw item
+/// is assigned to the track its x-extent covers; items that span multiple
+/// tracks (PDFium-level merged spans like `$1,298 $1,263 5%` at one anchor
+/// reaching past two more anchors) are split on internal whitespace at
+/// boundaries closest to each crossed anchor.
+///
+/// Returns `Some(cells)` of length `tracks.len()` (some cells may have empty
+/// text), or `None` if any item can't be assigned cleanly (out-of-band item,
+/// or a multi-track item with no usable whitespace boundary).
+fn cells_from_raw_items_with_tracks(
+ line: &ProjectedLine,
+ tracks: &[f32],
+) -> Option<Vec<TableCell>> {
+ let mut spans: Vec<&TextItem> = line
+ .spans
+ .iter()
+ .filter(|s| !s.text.trim().is_empty())
+ .collect();
+ spans.sort_by(|a, b| a.x.total_cmp(&b.x));
+ // Require ≥ 2 PDFium spans on the row. A 1-span row spanning multiple
+ // tracks is almost always prose (wrapped paragraph whose x-range
+ // happens to overlap the track region); shredding it at whitespace
+ // anchors corrupts the body text. Real merged-numeric table rows still
+ // have a label span and a values span (≥ 2).
+ if spans.len() < 2 {
+ return None;
+ }
+ // Reject rows that contain a span with implausibly narrow reported
+ // width-per-character (a known PDFium quirk on some encodings where the
+ // bbox shrinks but the text payload is full-length). Without this, the
+ // narrow x-range tricks track inference into treating the next visible
+ // span as a "second column", manufacturing a fake table from prose.
+ // Real text averages 4-10pt/char at common font sizes; 2pt/char is a
+ // generous lower bound that only flags genuinely degenerate widths.
+ let tol = TABLE_TRACK_TOLERANCE_PT;
+ let mut cells: Vec<TableCell> = tracks
+ .iter()
+ .map(|&t| TableCell {
+ start_x: t,
+ end_x: t,
+ text: String::new(),
+ bold: false,
+ })
+ .collect();
+ let push_text = |dst: &mut String, src: &str| {
+ let src = src.trim();
+ if src.is_empty() {
+ return;
+ }
+ if !dst.is_empty() && !dst.ends_with(' ') {
+ dst.push(' ');
+ }
+ dst.push_str(src);
+ };
+ for span in &spans {
+ let x0 = span.x;
+ let x1 = span.x + span.width.max(0.0);
+ let covered: Vec<usize> = tracks
+ .iter()
+ .enumerate()
+ .filter(|&(_, &t)| t >= x0 - tol && t <= x1 + tol)
+ .map(|(i, _)| i)
+ .collect();
+ // For spans that cover multiple tracks (multi-column-spanning items
+ // we'd want to split), the span's leftmost x must anchor at the
+ // leftmost covered track within tolerance. Otherwise the item is
+ // non-tabular content (a wrapped paragraph / footnote whose x-range
+ // merely happens to overlap the track region) that we shouldn't
+ // shred at whitespace boundaries.
+ if covered.len() > 1 {
+ let left_track = tracks[covered[0]];
+ if (x0 - left_track).abs() > tol {
+ return None;
+ }
+ }
+ match covered.len() {
+ 0 => return None,
+ 1 => {
+ let idx = covered[0];
+ push_text(&mut cells[idx].text, &span.text);
+ cells[idx].end_x = cells[idx].end_x.max(x1);
+ if is_bold_span(span) {
+ cells[idx].bold = true;
+ }
+ }
+ _ => {
+ let pieces = split_span_at_anchors(span, &covered, tracks)?;
+ let bold = is_bold_span(span);
+ for (idx, piece) in covered.iter().zip(pieces.iter()) {
+ if piece.is_empty() {
+ return None;
+ }
+ push_text(&mut cells[*idx].text, piece);
+ if bold {
+ cells[*idx].bold = true;
+ }
+ }
+ }
+ }
+ }
+ for cell in &mut cells {
+ cell.text = collapse_whitespace(cell.text.trim());
+ }
+ Some(cells)
+}
+
+/// Split a multi-track-spanning span's text into one piece per covered track
+/// by picking whitespace positions whose linearly-interpolated x is closest
+/// to each subsequent anchor. Returns `Some(pieces)` of length
+/// `covered.len()` when every split lands on a real whitespace boundary;
+/// `None` if no usable boundary exists (e.g. unbroken text like a long
+/// hex string).
+fn split_span_at_anchors(
+ span: &TextItem,
+ covered: &[usize],
+ tracks: &[f32],
+) -> Option<Vec<String>> {
+ let chars: Vec<char> = span.text.chars().collect();
+ let n = chars.len();
+ if n == 0 || covered.len() < 2 {
+ return None;
+ }
+ let span_x0 = span.x;
+ let span_w = span.width.max(1.0);
+ let mut split_indices: Vec<usize> = Vec::new();
+ for &idx in covered.iter().skip(1) {
+ let target = tracks[idx];
+ let mut best: Option<(usize, f32)> = None;
+ for (k, ch) in chars.iter().enumerate() {
+ if !ch.is_whitespace() {
+ continue;
+ }
+ if split_indices.contains(&k) {
+ continue;
+ }
+ let frac = k as f32 / n as f32;
+ let x = span_x0 + frac * span_w;
+ let d = (x - target).abs();
+ if best.as_ref().is_none_or(|b| d < b.1) {
+ best = Some((k, d));
+ }
+ }
+ let (k, _) = best?;
+ split_indices.push(k);
+ }
+ split_indices.sort();
+ let mut pieces: Vec<String> = Vec::new();
+ let mut prev = 0usize;
+ for k in &split_indices {
+ let piece: String = chars[prev..*k]
+ .iter()
+ .collect::<String>()
+ .trim()
+ .to_string();
+ pieces.push(piece);
+ prev = *k;
+ }
+ pieces.push(chars[prev..].iter().collect::<String>().trim().to_string());
+ if pieces.len() != covered.len() {
+ return None;
+ }
+ Some(pieces)
+}
+
+/// Like `try_detect_table` but seeds column tracks from the union of raw
+/// item start-x positions across the candidate window rather than from the
+/// first row's `split_cells` output. Use this first to unlock tables where
+/// the cell-gap heuristic collapses adjacent numeric columns into one cell
+/// in every row. Returns `None` when (a) inferred tracks are no richer than
+/// per-row bucketing (no win to be had), or (b) the inferred-track candidate
+/// fails any soundness check — in which case `try_detect_table`'s existing
+/// logic should run.
+fn try_detect_table_inferred(
+ lines: &[ProjectedLine],
+ start_idx: usize,
+ floor: usize,
+) -> Option<TableRun> {
+ let baseline_cells = split_cells(&lines[start_idx]);
+ let tracks = infer_tracks_from_raw_items(lines, start_idx);
+ if tracks.len() < TABLE_MIN_COLUMNS {
+ return None;
+ }
+ // Only bother if we'd actually unlock more columns than the default path.
+ if tracks.len() <= baseline_cells.len() {
+ return None;
+ }
+ // Reject "tracks" that are really inter-word positions in prose. Real
+ // table columns are separated by visible whitespace gutters wider than
+ // the body font; word positions in running prose cluster at < 1× font
+ // size apart. Threshold at 1.5× the seed line's dominant font size, with
+ // a 12pt absolute floor for small fonts.
+ let font_size = if lines[start_idx].dominant_font_size > 0.0 {
+ lines[start_idx].dominant_font_size
+ } else {
+ lines[start_idx].bbox.height.max(1.0)
+ };
+ let min_track_gap = (font_size * 1.5).max(12.0);
+ let min_gap = tracks
+ .windows(2)
+ .map(|w| w[1] - w[0])
+ .fold(f32::INFINITY, f32::min);
+ if min_gap < min_track_gap {
+ return None;
+ }
+ let column_count = tracks.len();
+ let track_ranges: Vec<(f32, f32)> = tracks.iter().map(|&t| (t, t)).collect();
+ let tracks_right_edge = *tracks.last().unwrap() + TABLE_TRACK_TOLERANCE_PT.max(8.0);
+
+ // Seed row: require a strong structural signal — its raw PDFium span
+ // count must be ≥ tracks.len() AND each span must single-cover (no
+ // multi-track splits in the seeding row). This rejects prose lines
+ // where 2-3 spans happen to anchor at inferred tracks but actually
+ // each span's x-extent covers multiple tracks, which would produce a
+ // shred-on-whitespace seed that's indistinguishable from a real
+ // table. Subsequent rows can still have merged spans recovered via
+ // the multi-cover split path.
+ let seed_spans: Vec<&TextItem> = lines[start_idx]
+ .spans
+ .iter()
+ .filter(|s| !s.text.trim().is_empty())
+ .collect();
+ if seed_spans.len() < tracks.len() {
+ return None;
+ }
+ let tol = TABLE_TRACK_TOLERANCE_PT;
+ for s in &seed_spans {
+ let x0 = s.x;
+ let x1 = s.x + s.width.max(0.0);
+ let covered = tracks
+ .iter()
+ .filter(|&&t| t >= x0 - tol && t <= x1 + tol)
+ .count();
+ if covered > 1 {
+ return None;
+ }
+ }
+ let first = cells_from_raw_items_with_tracks(&lines[start_idx], &tracks)?;
+ if first.iter().filter(|c| !c.text.is_empty()).count() < TABLE_MIN_COLUMNS {
+ return None;
+ }
+ let mut rows: Vec<(usize, &ProjectedLine, Vec<TableCell>)> =
+ vec![(start_idx, &lines[start_idx], first)];
+
+ let mut j = start_idx + 1;
+ while j < lines.len() {
+ if lines[j].bbox.x > tracks_right_edge {
+ j += 1;
+ continue;
+ }
+ if !table_rows_adjacent(rows.last().unwrap().1, &lines[j]) {
+ break;
+ }
+ let Some(cells) = cells_from_raw_items_with_tracks(&lines[j], &tracks) else {
+ break;
+ };
+ // Drop rows that contribute zero populated cells (all out-of-band
+ // or empty after splitting) — they'd add noise without content.
+ if cells.iter().all(|c| c.text.is_empty()) {
+ break;
+ }
+ rows.push((j, &lines[j], cells));
+ j += 1;
+ }
+ if rows.len() < TABLE_MIN_ROWS {
+ return None;
+ }
+ let cv = row_spacing_cv(&rows);
+ if cv > TABLE_ROW_SPACING_MAX_CV {
+ // Defer to the existing path, which can fall back to GridFallback.
+ return None;
+ }
+ let end = j;
+
+ let absorbed = absorb_header_lines(lines, start_idx, &track_ranges, column_count, floor);
+ let first_row = &rows[0].2;
+ let bold_header_qualifies =
+ absorbed.is_none() && first_row.iter().all(|c| c.bold && !c.text.is_empty());
+ let (run_start, header, row_start) = match absorbed {
+ Some((hstart, header_texts)) => (hstart, Some(header_texts), 0),
+ None if bold_header_qualifies => (
+ start_idx,
+ Some(first_row.iter().map(|c| c.text.clone()).collect()),
+ 1,
+ ),
+ None => (start_idx, None, 0),
+ };
+ let body_rows: Vec<Vec<String>> = rows[row_start..]
+ .iter()
+ .map(|(_, _, cells)| cells.iter().map(|c| c.text.clone()).collect())
+ .collect();
+ if header.is_none() && body_rows.len() < TABLE_MIN_ROWS {
+ return None;
+ }
+ Some(TableRun {
+ start: run_start,
+ end,
+ block: Block::Table {
+ header,
+ rows: body_rows,
+ },
+ })
+}
+
/// Try to extend a candidate table starting at `start_idx`. On success returns
/// a `TableRun` with `Block::Table` or `Block::GridFallback`; on failure
/// returns `None` (and the caller should fall through to per-line
@@ -367,8 +740,7 @@ fn try_detect_table(lines: &[ProjectedLine], start_idx: usize, floor: usize) ->
vec![(start_idx, &lines[start_idx], first_cells.clone())];
let column_count = first_cells.len();
let tracks: Vec<f32> = first_cells.iter().map(|c| c.start_x).collect();
- let track_ranges: Vec<(f32, f32)> =
- first_cells.iter().map(|c| (c.start_x, c.end_x)).collect();
+ let track_ranges: Vec<(f32, f32)> = first_cells.iter().map(|c| (c.start_x, c.end_x)).collect();
// Right edge of the established column tracks (last track + a track-width
// worth of slack). Used to identify lines that sit entirely in a different
@@ -637,7 +1009,11 @@ pub(super) fn detect_tables(lines: &[ProjectedLine]) -> Vec<TableRun> {
let mut i = 0;
let mut floor = 0;
while i < lines.len() {
- if let Some(run) = try_detect_table(lines, i, floor) {
+ if let Some(run) = try_detect_table_inferred(lines, i, floor) {
+ floor = run.end;
+ i = run.end;
+ out.push(run);
+ } else if let Some(run) = try_detect_table(lines, i, floor) {
floor = run.end;
i = run.end;
out.push(run);
@@ -727,7 +1103,10 @@ fn is_page_ref(text: &str) -> bool {
return true;
}
let lower = t.to_ascii_lowercase();
- if lower.chars().all(|c| matches!(c, 'i' | 'v' | 'x' | 'l' | 'c' | 'd' | 'm')) {
+ if lower
+ .chars()
+ .all(|c| matches!(c, 'i' | 'v' | 'x' | 'l' | 'c' | 'd' | 'm'))
+ {
// Cap length so multi-word lowercase Latin words don't pass (e.g.
// "mix", "civil" would all be made of roman-numeral letters).
if t.chars().count() <= 6 {
@@ -745,7 +1124,21 @@ fn is_bullet_only(text: &str) -> bool {
let only_glyph = t.chars().all(|c| {
matches!(
c,
- '•' | '●' | '○' | '◦' | '▪' | '■' | '□' | '‣' | '⁃' | '*' | '-' | '–' | '—' | '⮚' | '►' | '▶'
+ '•' | '●'
+ | '○'
+ | '◦'
+ | '▪'
+ | '■'
+ | '□'
+ | '‣'
+ | '⁃'
+ | '*'
+ | '-'
+ | '–'
+ | '—'
+ | '⮚'
+ | '►'
+ | '▶'
)
});
if only_glyph {
@@ -765,7 +1158,9 @@ fn is_bullet_only(text: &str) -> bool {
let body: String = chars[..chars.len() - 1].iter().collect();
if !body.is_empty()
&& (body.chars().all(|c| c.is_ascii_digit())
- || body.chars().all(|c| matches!(c, 'i' | 'v' | 'x' | 'I' | 'V' | 'X')))
+ || body
+ .chars()
+ .all(|c| matches!(c, 'i' | 'v' | 'x' | 'I' | 'V' | 'X')))
{
return true;
}
@@ -806,11 +1201,8 @@ fn try_detect_description_list(lines: &[ProjectedLine], start_idx: usize) -> Opt
return None;
}
- let mut rows: Vec<(usize, String, String)> = vec![(
- start_idx,
- first[0].text.clone(),
- first[1].text.clone(),
- )];
+ let mut rows: Vec<(usize, String, String)> =
+ vec![(start_idx, first[0].text.clone(), first[1].text.clone())];
// Track how many rows came from the *actual* 2-cell path (i.e. PDFium
// emitted two distinct spans with a clear gap). The merged-span split path
// is a recovery hack for tight-kerning cases — when it's the only thing
@@ -842,9 +1234,7 @@ fn try_detect_description_list(lines: &[ProjectedLine], start_idx: usize) -> Opt
.windows(2)
.map(|w| lines[w[1].0].bbox.y - lines[w[0].0].bbox.y)
.collect();
- if let Some(&max_prior) = prior_gaps
- .iter()
- .max_by(|a, b| a.total_cmp(b))
+ if let Some(&max_prior) = prior_gaps.iter().max_by(|a, b| a.total_cmp(b))
&& cur_gap > max_prior * 1.6
&& cur_gap > lines[j].bbox.height.max(prev_line.bbox.height)
{
@@ -878,8 +1268,7 @@ fn try_detect_description_list(lines: &[ProjectedLine], start_idx: usize) -> Opt
}
// Merged-span row: single cell starts at col 0 but extends past
// col 1's anchor. Split on the whitespace closest to col 1.
- let straddles =
- c0_aligned && cell.end_x > col1_x + DESC_LIST_TRACK_TOL_PT;
+ let straddles = c0_aligned && cell.end_x > col1_x + DESC_LIST_TRACK_TOL_PT;
if straddles {
if let Some((left, right)) =
split_merged_at_anchor(&cell.text, cell.start_x, cell.end_x, col1_x)
@@ -923,9 +1312,7 @@ fn try_detect_description_list(lines: &[ProjectedLine], start_idx: usize) -> Opt
// (digits or roman numerals), the run is a TOC. TOCs match the alpha
// pair check only when one of the page refs happens to be a roman
// numeral like "v" or "vi" alongside an alpha col 0.
- let all_page_refs = rows
- .iter()
- .all(|(_, _, c1)| is_page_ref(c1));
+ let all_page_refs = rows.iter().all(|(_, _, c1)| is_page_ref(c1));
if all_page_refs {
return None;
}
@@ -1030,10 +1417,7 @@ const TABLE_HEADER_MAX_ABSORB_ROWS: usize = 3;
/// distinct tables.
const TABLE_MERGE_MAX_Y_GAP_LINES: f32 = 2.0;
-fn merge_consecutive_table_runs(
- runs: Vec<TableRun>,
- lines: &[ProjectedLine],
-) -> Vec<TableRun> {
+fn merge_consecutive_table_runs(runs: Vec<TableRun>, lines: &[ProjectedLine]) -> Vec<TableRun> {
if runs.len() < 2 {
return runs;
}
@@ -1116,11 +1500,7 @@ fn subset_match_score(ta: (f32, f32), tb: (f32, f32), tol: f32) -> Option<f32> {
f32::INFINITY
};
let d = d_start.min(d_end).min(d_center);
- if d <= tol {
- Some(d)
- } else {
- None
- }
+ if d <= tol { Some(d) } else { None }
}
/// Looser tolerance for cross-run subset matching. Header cells and body
@@ -1250,10 +1630,8 @@ fn try_merge_pair(a: &TableRun, b: &TableRun, lines: &[ProjectedLine]) -> Option
// Case Same: identical tracks, concat rows.
if a_cols == b_cols && tracks_align_same(&a_tracks, &b_tracks) {
// Don't merge two complete-looking tables across a noticeable gap.
- let both_complete = a_header.is_some()
- && b_header.is_some()
- && a_rows.len() >= 3
- && b_rows.len() >= 3;
+ let both_complete =
+ a_header.is_some() && b_header.is_some() && a_rows.len() >= 3 && b_rows.len() >= 3;
if both_complete && gap > line_height * 1.0 {
return None;
}
@@ -1807,15 +2185,14 @@ fn build_ruled_table(
// row-0 signal misleads. Col-0 label columns are the much stronger
// fill-in-form signature: rare in body prose, near-universal in
// forms.
- let col0_fill =
- (0..n_rows).filter(|r| cell_has_text[*r][0]).count() as f32 / n_rows as f32;
+ let col0_fill = (0..n_rows).filter(|r| cell_has_text[*r][0]).count() as f32 / n_rows as f32;
let col0_max_chars = (0..n_rows)
.filter(|r| cell_has_text[*r][0])
.map(|r| cells[r][0].len())
.max()
.unwrap_or(0);
- let col0_spine = col0_fill >= TABLE_SPINE_FILL_FRACTION
- && col0_max_chars <= TABLE_SPINE_MAX_CELL_CHARS;
+ let col0_spine =
+ col0_fill >= TABLE_SPINE_FILL_FRACTION && col0_max_chars <= TABLE_SPINE_MAX_CELL_CHARS;
if !col0_spine || empty_frac > TABLE_MAX_EMPTY_CELL_FRACTION_WITH_SPINE {
return None;
}
@@ -1968,7 +2345,10 @@ pub(super) fn detect_ruled_tables(
/// Merge ruled-grid runs with borderless runs into a single sorted list. When
/// ranges overlap the ruled run wins (path-based geometry is strictly stronger
/// than text-alignment heuristics) — overlapping borderless runs are dropped.
-pub(super) fn merge_table_runs(mut ruled: Vec<TableRun>, borderless: Vec<TableRun>) -> Vec<TableRun> {
+pub(super) fn merge_table_runs(
+ mut ruled: Vec<TableRun>,
+ borderless: Vec<TableRun>,
+) -> Vec<TableRun> {
// A ruled run normally beats an overlapping borderless run (path geometry
// is a stronger signal than text alignment). But a 1-column ruled run is
// ambiguous — it can come from a real single-column table (doc 149's
@@ -1993,9 +2373,7 @@ pub(super) fn merge_table_runs(mut ruled: Vec<TableRun>, borderless: Vec<TableRu
kept.push(r);
}
for b in borderless {
- let overlaps = kept
- .iter()
- .any(|r| !(b.end <= r.start || b.start >= r.end));
+ let overlaps = kept.iter().any(|r| !(b.end <= r.start || b.start >= r.end));
if !overlaps {
kept.push(b);
}
@@ -2125,7 +2503,10 @@ mod tests {
match &run.block {
Block::Table { header, rows } => {
let header = header.as_ref().expect("header should be present");
- assert_eq!(header, &vec!["Name".to_string(), "Scores".to_string(), String::new()]);
+ assert_eq!(
+ header,
+ &vec!["Name".to_string(), "Scores".to_string(), String::new()]
+ );
// All three body rows survive — the header came from above, so
// rows[0] is not consumed as a header.
assert_eq!(rows.len(), 3);
@@ -2134,7 +2515,7 @@ mod tests {
}
}
-#[test]
+ #[test]
fn does_not_absorb_single_cell_title_above_body() {
// A one-cell title/caption above a table is NOT a header row and must
// not be absorbed.
@@ -2146,7 +2527,10 @@ mod tests {
];
let runs = detect_tables(&lines);
assert_eq!(runs.len(), 1);
- assert_eq!(runs[0].start, 1, "single-cell title must stay out of the run");
+ assert_eq!(
+ runs[0].start, 1,
+ "single-cell title must stay out of the run"
+ );
}
#[test]
@@ -2326,7 +2710,12 @@ mod tests {
fn four_col_line(label: &str, y: f32) -> ProjectedLine {
line_with_spans(
- &[(label, 50.0), (label, 150.0), (label, 250.0), (label, 350.0)],
+ &[
+ (label, 50.0),
+ (label, 150.0),
+ (label, 250.0),
+ (label, 350.0),
+ ],
y,
10.0,
)
@@ -2591,7 +2980,12 @@ mod tests {
three_col_line("h", 10.0),
three_col_line("h", 25.0),
line_with_spans(
- &[("This", 50.0), ("is", 150.0), ("real", 250.0), ("content", 350.0)],
+ &[
+ ("This", 50.0),
+ ("is", 150.0),
+ ("real", 250.0),
+ ("content", 350.0),
+ ],
40.0,
10.0,
),
diff --git a/crates/liteparse/src/markdown_layout/test_helpers.rs b/crates/liteparse/src/markdown_layout/test_helpers.rs
index ec7d062..7cc10f9 100644
--- a/crates/liteparse/src/markdown_layout/test_helpers.rs
+++ b/crates/liteparse/src/markdown_layout/test_helpers.rs
@@ -98,11 +98,7 @@ pub(crate) fn line_with_spans(cells: &[(&str, f32)], y: f32, size: f32) -> Proje
/// Build a line whose spans carry explicit per-span font metadata. Lets us
/// exercise the mid-line emphasis pipeline without needing real PDF input.
-pub(crate) fn styled_line(
- spans: &[(&str, f32, Option<&str>)],
- y: f32,
- size: f32,
-) -> ProjectedLine {
+pub(crate) fn styled_line(spans: &[(&str, f32, Option<&str>)], y: f32, size: f32) -> ProjectedLine {
let items: Vec<TextItem> = spans
.iter()
.map(|(t, x, font)| TextItem {
diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rs
index 6f53ceb..98bdf67 100644
--- a/crates/liteparse/src/parser.rs
+++ b/crates/liteparse/src/parser.rs
@@ -110,10 +110,7 @@ impl LiteParse {
// The Document handle isn't Send, so we open it, pull every bit of
// document-level state we need, and drop it before any `.await`.
let password = self.config.password.as_deref();
- let render_images = matches!(
- self.config.image_mode,
- crate::config::ImageMode::Embed
- );
+ let render_images = matches!(self.config.image_mode, crate::config::ImageMode::Embed);
let (pages, ocr_rendered, outline, images) = {
let document = extract::load_document_from_input(&validated_input, password)?;
let outline = extract::extract_outline(&document);
diff --git a/crates/pdfium-sys/src/dynamic.rs b/crates/pdfium-sys/src/dynamic.rs
index e4a033a..8030b9f 100644
--- a/crates/pdfium-sys/src/dynamic.rs
+++ b/crates/pdfium-sys/src/dynamic.rs
@@ -259,8 +259,7 @@ pub struct PdfiumBindings {
// -- Structure tree --
pub FPDF_StructTree_GetForPage: unsafe extern "C" fn(FPDF_PAGE) -> FPDF_STRUCTTREE,
pub FPDF_StructTree_Close: unsafe extern "C" fn(FPDF_STRUCTTREE),
- pub FPDF_StructTree_CountChildren:
- unsafe extern "C" fn(FPDF_STRUCTTREE) -> std::os::raw::c_int,
+ pub FPDF_StructTree_CountChildren: unsafe extern "C" fn(FPDF_STRUCTTREE) -> std::os::raw::c_int,
pub FPDF_StructTree_GetChildAtIndex:
unsafe extern "C" fn(FPDF_STRUCTTREE, std::os::raw::c_int) -> FPDF_STRUCTELEMENT,
pub FPDF_StructElement_GetType: unsafe extern "C" fn(
diff --git a/crates/pdfium/src/document.rs b/crates/pdfium/src/document.rs
index 9ef97b8..4eb7758 100644
--- a/crates/pdfium/src/document.rs
+++ b/crates/pdfium/src/document.rs
@@ -45,7 +45,12 @@ impl Document {
/// document has no outline.
pub fn outline(&self) -> Vec<OutlineEntry> {
let mut out = Vec::new();
- let root = unsafe { ffi!(FPDFBookmark_GetFirstChild(self.handle, std::ptr::null_mut())) };
+ let root = unsafe {
+ ffi!(FPDFBookmark_GetFirstChild(
+ self.handle,
+ std::ptr::null_mut()
+ ))
+ };
if !root.is_null() {
self.walk_bookmark(root, 1, &mut out);
}
@@ -80,8 +85,7 @@ impl Document {
}
fn read_bookmark_title(bookmark: pdfium_sys::FPDF_BOOKMARK) -> String {
- let needed =
- unsafe { ffi!(FPDFBookmark_GetTitle(bookmark, std::ptr::null_mut(), 0)) } as usize;
+ let needed = unsafe { ffi!(FPDFBookmark_GetTitle(bookmark, std::ptr::null_mut(), 0)) } as usize;
if needed < 2 {
return String::new();
}
@@ -121,7 +125,11 @@ fn resolve_dest(
return (None, None);
}
let page_index = unsafe { ffi!(FPDFDest_GetDestPageIndex(doc, dest)) };
- let page_index = if page_index >= 0 { Some(page_index) } else { None };
+ let page_index = if page_index >= 0 {
+ Some(page_index)
+ } else {
+ None
+ };
let mut has_x: pdfium_sys::FPDF_BOOL = 0;
let mut has_y: pdfium_sys::FPDF_BOOL = 0;
diff --git a/crates/pdfium/src/struct_tree.rs b/crates/pdfium/src/struct_tree.rs
index ce5f1fb..e948d82 100644
--- a/crates/pdfium/src/struct_tree.rs
+++ b/crates/pdfium/src/struct_tree.rs
@@ -60,10 +60,7 @@ impl Page<'_> {
/// Pre-scan all page objects on the page, building `mcid → union(bbox)` in
/// viewport space. Each struct node then unions the bboxes for its own mcids.
-fn collect_mcid_bboxes(
- page: &Page<'_>,
- view_box: &RectF,
-) -> std::collections::HashMap<i32, RectF> {
+fn collect_mcid_bboxes(page: &Page<'_>, view_box: &RectF) -> std::collections::HashMap<i32, RectF> {
let vp = page.viewport_transform(view_box);
let obj_count = unsafe { ffi!(FPDFPage_CountObjects(page.handle)) };
let mut map: std::collections::HashMap<i32, RectF> = std::collections::HashMap::new();
@@ -192,7 +189,8 @@ fn read_element_type(elem: pdfium_sys::FPDF_STRUCTELEMENT) -> String {
}
fn read_alt_text(elem: pdfium_sys::FPDF_STRUCTELEMENT) -> Option<String> {
- let s = read_widestring(|buf, len| unsafe { ffi!(FPDF_StructElement_GetAltText(elem, buf, len)) });
+ let s =
+ read_widestring(|buf, len| unsafe { ffi!(FPDF_StructElement_GetAltText(elem, buf, len)) });
if s.is_empty() { None } else { Some(s) }
}
diff --git a/packages/python/uv.lock b/packages/python/uv.lock
index b1e10f3..b5308fa 100644
--- a/packages/python/uv.lock
+++ b/packages/python/uv.lock
@@ -128,7 +128,7 @@ wheels = [
[[package]]
name = "liteparse"
-version = "2.0.3"
+version = "2.0.5"
source = { editable = "." }
[package.optional-dependencies]